Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
f6fbd30c
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看板
提交
f6fbd30c
编写于
4月 06, 2010
作者:
C
chegar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6648001: Cancelling HTTP authentication causes subsequent deadlocks
Reviewed-by: michaelm
上级
20f8f3ee
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
188 addition
and
18 deletion
+188
-18
src/share/classes/sun/net/www/protocol/http/AuthenticationInfo.java
...classes/sun/net/www/protocol/http/AuthenticationInfo.java
+16
-7
src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java
.../classes/sun/net/www/protocol/http/HttpURLConnection.java
+12
-11
test/java/net/Authenticator/Deadlock.java
test/java/net/Authenticator/Deadlock.java
+160
-0
未找到文件。
src/share/classes/sun/net/www/protocol/http/AuthenticationInfo.java
浏览文件 @
f6fbd30c
...
@@ -270,13 +270,17 @@ public abstract class AuthenticationInfo extends AuthCacheValue implements Clone
...
@@ -270,13 +270,17 @@ public abstract class AuthenticationInfo extends AuthCacheValue implements Clone
* In this case we do not use the path because the protection space
* In this case we do not use the path because the protection space
* is identified by the host:port:realm only
* is identified by the host:port:realm only
*/
*/
static
AuthenticationInfo
getServerAuth
(
URL
url
,
String
realm
,
AuthScheme
scheme
)
{
static
String
getServerAuthKey
(
URL
url
,
String
realm
,
AuthScheme
scheme
)
{
int
port
=
url
.
getPort
();
int
port
=
url
.
getPort
();
if
(
port
==
-
1
)
{
if
(
port
==
-
1
)
{
port
=
url
.
getDefaultPort
();
port
=
url
.
getDefaultPort
();
}
}
String
key
=
SERVER_AUTHENTICATION
+
":"
+
scheme
+
":"
+
url
.
getProtocol
().
toLowerCase
()
String
key
=
SERVER_AUTHENTICATION
+
":"
+
scheme
+
":"
+
url
.
getProtocol
().
toLowerCase
()
+
":"
+
url
.
getHost
().
toLowerCase
()
+
":"
+
port
+
":"
+
realm
;
+
":"
+
url
.
getHost
().
toLowerCase
()
+
":"
+
port
+
":"
+
realm
;
return
key
;
}
static
AuthenticationInfo
getServerAuth
(
String
key
)
{
AuthenticationInfo
cached
=
getAuth
(
key
,
null
);
AuthenticationInfo
cached
=
getAuth
(
key
,
null
);
if
((
cached
==
null
)
&&
requestIsInProgress
(
key
))
{
if
((
cached
==
null
)
&&
requestIsInProgress
(
key
))
{
/* check the cache again, it might contain an entry */
/* check the cache again, it might contain an entry */
...
@@ -314,9 +318,13 @@ public abstract class AuthenticationInfo extends AuthCacheValue implements Clone
...
@@ -314,9 +318,13 @@ public abstract class AuthenticationInfo extends AuthCacheValue implements Clone
* Used in response to a challenge. Note, the protocol field is always
* Used in response to a challenge. Note, the protocol field is always
* blank for proxies.
* blank for proxies.
*/
*/
static
AuthenticationInfo
getProxyAuth
(
String
host
,
int
port
,
String
realm
,
AuthScheme
scheme
)
{
static
String
getProxyAuthKey
(
String
host
,
int
port
,
String
realm
,
AuthScheme
scheme
)
{
String
key
=
PROXY_AUTHENTICATION
+
":"
+
scheme
+
"::"
+
host
.
toLowerCase
()
String
key
=
PROXY_AUTHENTICATION
+
":"
+
scheme
+
"::"
+
host
.
toLowerCase
()
+
":"
+
port
+
":"
+
realm
;
+
":"
+
port
+
":"
+
realm
;
return
key
;
}
static
AuthenticationInfo
getProxyAuth
(
String
key
)
{
AuthenticationInfo
cached
=
(
AuthenticationInfo
)
cache
.
get
(
key
,
null
);
AuthenticationInfo
cached
=
(
AuthenticationInfo
)
cache
.
get
(
key
,
null
);
if
((
cached
==
null
)
&&
requestIsInProgress
(
key
))
{
if
((
cached
==
null
)
&&
requestIsInProgress
(
key
))
{
/* check the cache again, it might contain an entry */
/* check the cache again, it might contain an entry */
...
@@ -330,19 +338,20 @@ public abstract class AuthenticationInfo extends AuthCacheValue implements Clone
...
@@ -330,19 +338,20 @@ public abstract class AuthenticationInfo extends AuthCacheValue implements Clone
* Add this authentication to the cache
* Add this authentication to the cache
*/
*/
void
addToCache
()
{
void
addToCache
()
{
cache
.
put
(
cacheKey
(
true
),
this
);
String
key
=
cacheKey
(
true
);
cache
.
put
(
key
,
this
);
if
(
supportsPreemptiveAuthorization
())
{
if
(
supportsPreemptiveAuthorization
())
{
cache
.
put
(
cacheKey
(
false
),
this
);
cache
.
put
(
cacheKey
(
false
),
this
);
}
}
endAuthRequest
();
endAuthRequest
(
key
);
}
}
void
endAuthRequest
(
)
{
static
void
endAuthRequest
(
String
key
)
{
if
(!
serializeAuth
)
{
if
(!
serializeAuth
)
{
return
;
return
;
}
}
synchronized
(
requests
)
{
synchronized
(
requests
)
{
requestCompleted
(
cacheKey
(
true
)
);
requestCompleted
(
key
);
}
}
}
}
...
...
src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java
浏览文件 @
f6fbd30c
...
@@ -249,6 +249,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
...
@@ -249,6 +249,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
boolean
isUserServerAuth
;
boolean
isUserServerAuth
;
boolean
isUserProxyAuth
;
boolean
isUserProxyAuth
;
String
serverAuthKey
,
proxyAuthKey
;
/* Progress source */
/* Progress source */
protected
ProgressSource
pi
;
protected
ProgressSource
pi
;
...
@@ -1503,11 +1505,11 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
...
@@ -1503,11 +1505,11 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
}
}
throw
e
;
throw
e
;
}
finally
{
}
finally
{
if
(
respCode
==
HTTP_PROXY_AUTH
&&
proxyAuthentication
!=
null
)
{
if
(
proxyAuthKey
!=
null
)
{
proxyAuthentication
.
endAuthRequest
(
);
AuthenticationInfo
.
endAuthRequest
(
proxyAuthKey
);
}
}
else
if
(
respCode
==
HTTP_UNAUTHORIZED
&&
serverAuthentication
!=
null
)
{
if
(
serverAuthKey
!=
null
)
{
serverAuthentication
.
endAuthRequest
(
);
AuthenticationInfo
.
endAuthRequest
(
serverAuthKey
);
}
}
}
}
}
}
...
@@ -1720,8 +1722,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
...
@@ -1720,8 +1722,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
statusLine
+
"\""
);
statusLine
+
"\""
);
}
}
}
finally
{
}
finally
{
if
(
respCode
==
HTTP_PROXY_AUTH
&&
proxyAuthentication
!=
null
)
{
if
(
proxyAuthKey
!=
null
)
{
proxyAuthentication
.
endAuthRequest
(
);
AuthenticationInfo
.
endAuthRequest
(
proxyAuthKey
);
}
}
}
}
...
@@ -1837,10 +1839,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
...
@@ -1837,10 +1839,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
if
(
realm
==
null
)
if
(
realm
==
null
)
realm
=
""
;
realm
=
""
;
ret
=
AuthenticationInfo
.
getProxyAuth
(
host
,
proxyAuthKey
=
AuthenticationInfo
.
getProxyAuthKey
(
host
,
port
,
realm
,
authScheme
);
port
,
ret
=
AuthenticationInfo
.
getProxyAuth
(
proxyAuthKey
);
realm
,
authScheme
);
if
(
ret
==
null
)
{
if
(
ret
==
null
)
{
switch
(
authScheme
)
{
switch
(
authScheme
)
{
case
BASIC:
case
BASIC:
...
@@ -1981,7 +1981,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
...
@@ -1981,7 +1981,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
domain
=
p
.
findValue
(
"domain"
);
domain
=
p
.
findValue
(
"domain"
);
if
(
realm
==
null
)
if
(
realm
==
null
)
realm
=
""
;
realm
=
""
;
ret
=
AuthenticationInfo
.
getServerAuth
(
url
,
realm
,
authScheme
);
serverAuthKey
=
AuthenticationInfo
.
getServerAuthKey
(
url
,
realm
,
authScheme
);
ret
=
AuthenticationInfo
.
getServerAuth
(
serverAuthKey
);
InetAddress
addr
=
null
;
InetAddress
addr
=
null
;
if
(
ret
==
null
)
{
if
(
ret
==
null
)
{
try
{
try
{
...
...
test/java/net/Authenticator/Deadlock.java
0 → 100644
浏览文件 @
f6fbd30c
/*
* Copyright 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @test
* @bug 6648001
* @run main/othervm/timeout=20 -ea:sun.net.www.protocol.http.AuthenticationInfo -Dhttp.auth.serializeRequests=true Deadlock
* @summary cancelling HTTP authentication causes deadlock
*/
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ExecutorService
;
import
java.io.InputStream
;
import
java.io.IOException
;
import
java.net.HttpURLConnection
;
import
java.net.InetSocketAddress
;
import
java.net.PasswordAuthentication
;
import
java.net.URL
;
import
com.sun.net.httpserver.BasicAuthenticator
;
import
com.sun.net.httpserver.Headers
;
import
com.sun.net.httpserver.HttpContext
;
import
com.sun.net.httpserver.HttpExchange
;
import
com.sun.net.httpserver.HttpHandler
;
import
com.sun.net.httpserver.HttpPrincipal
;
import
com.sun.net.httpserver.HttpServer
;
public
class
Deadlock
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
Handler
handler
=
new
Handler
();
InetSocketAddress
addr
=
new
InetSocketAddress
(
0
);
HttpServer
server
=
HttpServer
.
create
(
addr
,
0
);
HttpContext
ctx
=
server
.
createContext
(
"/test"
,
handler
);
BasicAuthenticator
a
=
new
BasicAuthenticator
(
"foobar@test.realm"
)
{
@Override
public
boolean
checkCredentials
(
String
username
,
String
pw
)
{
return
"fred"
.
equals
(
username
)
&&
pw
.
charAt
(
0
)
==
'x'
;
}
};
ctx
.
setAuthenticator
(
a
);
ExecutorService
executor
=
Executors
.
newCachedThreadPool
();
server
.
setExecutor
(
executor
);
server
.
start
();
java
.
net
.
Authenticator
.
setDefault
(
new
MyAuthenticator
());
System
.
out
.
print
(
"Deadlock: "
);
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
Runner
t
=
new
Runner
(
server
,
i
);
t
.
start
();
t
.
join
();
}
server
.
stop
(
2
);
executor
.
shutdown
();
if
(
error
)
{
throw
new
RuntimeException
(
"test failed error"
);
}
if
(
count
!=
2
)
{
throw
new
RuntimeException
(
"test failed count = "
+
count
);
}
System
.
out
.
println
(
"OK"
);
}
static
class
Runner
extends
Thread
{
HttpServer
server
;
int
i
;
Runner
(
HttpServer
s
,
int
i
)
{
server
=
s
;
this
.
i
=
i
;
}
@Override
public
void
run
()
{
URL
url
;
HttpURLConnection
urlc
;
try
{
url
=
new
URL
(
"http://localhost:"
+
server
.
getAddress
().
getPort
()+
"/test/foo.html"
);
urlc
=
(
HttpURLConnection
)
url
.
openConnection
();
}
catch
(
IOException
e
)
{
error
=
true
;
return
;
}
InputStream
is
=
null
;
try
{
is
=
urlc
.
getInputStream
();
while
(
is
.
read
()!=
-
1
)
{}
}
catch
(
IOException
e
)
{
if
(
i
==
1
)
error
=
true
;
}
finally
{
if
(
is
!=
null
)
try
{
is
.
close
();
}
catch
(
IOException
e
)
{}
}
}
}
public
static
boolean
error
=
false
;
public
static
int
count
=
0
;
static
class
MyAuthenticator
extends
java
.
net
.
Authenticator
{
@Override
public
PasswordAuthentication
getPasswordAuthentication
()
{
PasswordAuthentication
pw
;
if
(!
getRequestingPrompt
().
equals
(
"foobar@test.realm"
))
{
Deadlock
.
error
=
true
;
}
if
(
count
==
0
)
{
pw
=
null
;
}
else
{
pw
=
new
PasswordAuthentication
(
"fred"
,
"xyz"
.
toCharArray
());
}
count
++;
return
pw
;
}
}
static
class
Handler
implements
HttpHandler
{
int
invocation
=
1
;
@Override
public
void
handle
(
HttpExchange
t
)
throws
IOException
{
InputStream
is
=
t
.
getRequestBody
();
Headers
map
=
t
.
getRequestHeaders
();
Headers
rmap
=
t
.
getResponseHeaders
();
while
(
is
.
read
()
!=
-
1
);
is
.
close
();
t
.
sendResponseHeaders
(
200
,
-
1
);
HttpPrincipal
p
=
t
.
getPrincipal
();
if
(!
p
.
getUsername
().
equals
(
"fred"
))
{
error
=
true
;
}
if
(!
p
.
getRealm
().
equals
(
"foobar@test.realm"
))
{
error
=
true
;
}
t
.
close
();
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录