Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
95f4fb5c
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
95f4fb5c
编写于
3月 18, 2010
作者:
W
weijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
Reviewed-by: chegar
上级
b9f2049e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
112 addition
and
44 deletion
+112
-44
src/share/classes/sun/net/www/protocol/http/spnego/NegotiateCallbackHandler.java
...et/www/protocol/http/spnego/NegotiateCallbackHandler.java
+32
-25
test/sun/security/krb5/auto/HttpNegotiateServer.java
test/sun/security/krb5/auto/HttpNegotiateServer.java
+80
-19
未找到文件。
src/share/classes/sun/net/www/protocol/http/spnego/NegotiateCallbackHandler.java
浏览文件 @
95f4fb5c
/*
* Copyright 2005-20
09
Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2005-20
10
Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
...
...
@@ -45,43 +45,50 @@ public class NegotiateCallbackHandler implements CallbackHandler {
private
String
username
;
private
char
[]
password
;
/**
* Authenticator asks for username and password in a single prompt,
* but CallbackHandler checks one by one. So, no matter which callback
* gets handled first, make sure Authenticator is only called once.
*/
private
boolean
answered
;
private
final
HttpCallerInfo
hci
;
public
NegotiateCallbackHandler
(
HttpCallerInfo
hci
)
{
this
.
hci
=
hci
;
}
private
void
getAnswer
()
{
if
(!
answered
)
{
answered
=
true
;
PasswordAuthentication
passAuth
=
Authenticator
.
requestPasswordAuthentication
(
hci
.
host
,
hci
.
addr
,
hci
.
port
,
hci
.
protocol
,
hci
.
prompt
,
hci
.
scheme
,
hci
.
url
,
hci
.
authType
);
/**
* To be compatible with existing callback handler implementations,
* when the underlying Authenticator is canceled, username and
* password are assigned null. No exception is thrown.
*/
if
(
passAuth
!=
null
)
{
username
=
passAuth
.
getUserName
();
password
=
passAuth
.
getPassword
();
}
}
}
public
void
handle
(
Callback
[]
callbacks
)
throws
UnsupportedCallbackException
,
IOException
{
for
(
int
i
=
0
;
i
<
callbacks
.
length
;
i
++)
{
Callback
callBack
=
callbacks
[
i
];
if
(
callBack
instanceof
NameCallback
)
{
if
(
username
==
null
)
{
PasswordAuthentication
passAuth
=
Authenticator
.
requestPasswordAuthentication
(
hci
.
host
,
hci
.
addr
,
hci
.
port
,
hci
.
protocol
,
hci
.
prompt
,
hci
.
scheme
,
hci
.
url
,
hci
.
authType
);
username
=
passAuth
.
getUserName
();
password
=
passAuth
.
getPassword
();
}
NameCallback
nameCallback
=
(
NameCallback
)
callBack
;
nameCallback
.
setName
(
username
);
getAnswer
();
((
NameCallback
)
callBack
).
setName
(
username
);
}
else
if
(
callBack
instanceof
PasswordCallback
)
{
PasswordCallback
passwordCallback
=
(
PasswordCallback
)
callBack
;
if
(
password
==
null
)
{
PasswordAuthentication
passAuth
=
Authenticator
.
requestPasswordAuthentication
(
hci
.
host
,
hci
.
addr
,
hci
.
port
,
hci
.
protocol
,
hci
.
prompt
,
hci
.
scheme
,
hci
.
url
,
hci
.
authType
);
username
=
passAuth
.
getUserName
();
password
=
passAuth
.
getPassword
();
}
passwordCallback
.
setPassword
(
password
);
Arrays
.
fill
(
password
,
' '
);
getAnswer
();
((
PasswordCallback
)
callBack
).
setPassword
(
password
);
if
(
password
!=
null
)
Arrays
.
fill
(
password
,
' '
);
}
else
{
throw
new
UnsupportedCallbackException
(
callBack
,
"Call back not supported"
);
...
...
test/sun/security/krb5/auto/HttpNegotiateServer.java
浏览文件 @
95f4fb5c
/*
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2009
-2010
Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
...
...
@@ -23,8 +23,9 @@
/*
* @test
* @bug 6578647
* @bug 6578647
6829283
* @summary Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
* @summary HTTP/Negotiate: Authenticator triggered again when user cancels the first one
*/
import
com.sun.net.httpserver.Headers
;
...
...
@@ -35,6 +36,8 @@ import com.sun.net.httpserver.HttpServer;
import
com.sun.net.httpserver.HttpPrincipal
;
import
com.sun.security.auth.module.Krb5LoginModule
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.net.HttpURLConnection
;
...
...
@@ -79,6 +82,9 @@ public class HttpNegotiateServer {
// web page content
final
static
String
CONTENT
=
"Hello, World!"
;
// For 6829283, count how many times the Authenticator is called.
static
int
count
=
0
;
// URLs for web test, proxy test. The proxy server is not a real proxy
// since it fakes the same content for any URL. :)
final
static
URL
webUrl
,
proxyUrl
;
...
...
@@ -134,6 +140,17 @@ public class HttpNegotiateServer {
}
}
/**
* This Authenticator knows nothing
*/
static
class
KnowNothingAuthenticator
extends
java
.
net
.
Authenticator
{
@Override
public
PasswordAuthentication
getPasswordAuthentication
()
{
HttpNegotiateServer
.
count
++;
return
null
;
}
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
...
...
@@ -147,7 +164,6 @@ public class HttpNegotiateServer {
kdcp
.
addPrincipalRandKey
(
"krbtgt/"
+
REALM_PROXY
);
kdcp
.
addPrincipalRandKey
(
"HTTP/"
+
PROXY_HOST
);
KDC
.
writeMultiKtab
(
KRB5_TAB
,
kdcw
,
kdcp
);
KDC
.
saveConfig
(
KRB5_CONF
,
kdcw
,
kdcp
,
"default_keytab_name = "
+
KRB5_TAB
,
"[domain_realm]"
,
...
...
@@ -157,6 +173,19 @@ public class HttpNegotiateServer {
System
.
setProperty
(
"java.security.krb5.conf"
,
KRB5_CONF
);
Config
.
refresh
();
KDC
.
writeMultiKtab
(
KRB5_TAB
,
kdcw
,
kdcp
);
// Write a customized JAAS conf file, so that any kinit cache
// will be ignored.
System
.
setProperty
(
"java.security.auth.login.config"
,
OneKDC
.
JAAS_CONF
);
File
f
=
new
File
(
OneKDC
.
JAAS_CONF
);
FileOutputStream
fos
=
new
FileOutputStream
(
f
);
fos
.
write
((
"com.sun.security.jgss.krb5.initiate {\n"
+
" com.sun.security.auth.module.Krb5LoginModule required;\n};\n"
).
getBytes
());
fos
.
close
();
f
.
deleteOnExit
();
HttpServer
h1
=
httpd
(
WEB_PORT
,
"Negotiate"
,
false
,
"HTTP/"
+
WEB_HOST
+
"@"
+
REALM_WEB
,
KRB5_TAB
);
...
...
@@ -164,23 +193,21 @@ public class HttpNegotiateServer {
"HTTP/"
+
PROXY_HOST
+
"@"
+
REALM_PROXY
,
KRB5_TAB
);
try
{
BufferedReader
reader
;
java
.
net
.
Authenticator
.
setDefault
(
new
KnowAllAuthenticator
());
reader
=
new
BufferedReader
(
new
InputStreamReader
(
webUrl
.
openConnection
().
getInputStream
()));
if
(!
reader
.
readLine
().
equals
(
CONTENT
))
{
throw
new
RuntimeException
(
"Bad content"
);
Exception
e1
=
null
,
e2
=
null
;
try
{
test6578647
();
}
catch
(
Exception
e
)
{
e1
=
e
;
e
.
printStackTrace
();
}
reader
=
new
BufferedReader
(
new
InputStreamReader
(
proxyUrl
.
openConnection
(
new
Proxy
(
Proxy
.
Type
.
HTTP
,
new
InetSocketAddress
(
PROXY_HOST
,
PROXY_PORT
)))
.
getInputStream
()));
if
(
!
reader
.
readLine
().
equals
(
CONTENT
)
)
{
throw
new
RuntimeException
(
"
Bad content
"
);
try
{
test6829283
();
}
catch
(
Exception
e
)
{
e2
=
e
;
e
.
printStackTrace
();
}
if
(
e1
!=
null
||
e2
!=
null
)
{
throw
new
RuntimeException
(
"
Test error
"
);
}
}
finally
{
// Must stop. Seems there's no HttpServer.startAsDaemon()
...
...
@@ -189,6 +216,40 @@ public class HttpNegotiateServer {
}
}
static
void
test6578647
()
throws
Exception
{
BufferedReader
reader
;
java
.
net
.
Authenticator
.
setDefault
(
new
KnowAllAuthenticator
());
reader
=
new
BufferedReader
(
new
InputStreamReader
(
webUrl
.
openConnection
().
getInputStream
()));
if
(!
reader
.
readLine
().
equals
(
CONTENT
))
{
throw
new
RuntimeException
(
"Bad content"
);
}
reader
=
new
BufferedReader
(
new
InputStreamReader
(
proxyUrl
.
openConnection
(
new
Proxy
(
Proxy
.
Type
.
HTTP
,
new
InetSocketAddress
(
PROXY_HOST
,
PROXY_PORT
)))
.
getInputStream
()));
if
(!
reader
.
readLine
().
equals
(
CONTENT
))
{
throw
new
RuntimeException
(
"Bad content"
);
}
}
static
void
test6829283
()
throws
Exception
{
BufferedReader
reader
;
java
.
net
.
Authenticator
.
setDefault
(
new
KnowNothingAuthenticator
());
try
{
new
BufferedReader
(
new
InputStreamReader
(
webUrl
.
openConnection
().
getInputStream
()));
}
catch
(
IOException
ioe
)
{
// Will fail since no username and password is provided.
}
if
(
count
>
1
)
{
throw
new
RuntimeException
(
"Authenticator called twice"
);
}
}
/**
* Creates and starts an HTTP or proxy server that requires
* Negotiate authentication.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录