Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
2a626bde
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看板
提交
2a626bde
编写于
7月 09, 2013
作者:
C
coffeys
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8019979: Replace CheckPackageAccess test with better one from closed repo
Reviewed-by: mullan
上级
381e10cf
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
115 addition
and
13 deletion
+115
-13
test/java/lang/SecurityManager/CheckPackageAccess.java
test/java/lang/SecurityManager/CheckPackageAccess.java
+115
-13
未找到文件。
test/java/lang/SecurityManager/CheckPackageAccess.java
浏览文件 @
2a626bde
...
...
@@ -22,31 +22,133 @@
*/
/*
* @test
* @bug 7146431 8000450
* @summary Test that internal packages cannot be accessed
* @test
* @bug 6741606 7146431 8000450
* @summary Make sure all restricted packages listed in the package.access
* property in the java.security file are blocked
* @run main/othervm CheckPackageAccess
*/
import
java.security.Security
;
import
java.util.Collections
;
import
java.util.Arrays
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.StringTokenizer
;
/*
* The main benefit of this test is to catch merge errors or other types
* of issues where one or more of the packages are accidentally
* removed. This is why the packages that are known to be restricted have to
* be explicitly listed below.
*/
public
class
CheckPackageAccess
{
/*
* This array should be updated whenever new packages are added to the
* package.access property in the java.security file
*/
private
static
final
String
[]
packages
=
{
"sun."
,
"com.sun.corba.se.impl."
,
"com.sun.xml.internal."
,
"com.sun.imageio."
,
"com.sun.istack.internal."
,
"com.sun.jmx."
,
"com.sun.proxy."
,
"com.sun.org.apache.bcel.internal."
,
"com.sun.org.apache.regexp.internal."
,
"com.sun.org.apache.xerces.internal."
,
"com.sun.org.apache.xpath.internal."
,
"com.sun.org.apache.xalan.internal.extensions."
,
"com.sun.org.apache.xalan.internal.lib."
,
"com.sun.org.apache.xalan.internal.res."
,
"com.sun.org.apache.xalan.internal.templates."
,
"com.sun.org.apache.xalan.internal.utils."
,
"com.sun.org.apache.xalan.internal.xslt."
,
"com.sun.org.apache.xalan.internal.xsltc.cmdline."
,
"com.sun.org.apache.xalan.internal.xsltc.compiler."
,
"com.sun.org.apache.xalan.internal.xsltc.trax."
,
"com.sun.org.apache.xalan.internal.xsltc.util."
,
"com.sun.org.apache.xml.internal.res."
,
"com.sun.org.apache.xml.internal.security."
,
"com.sun.org.apache.xml.internal.serializer.utils."
,
"com.sun.org.apache.xml.internal.utils."
,
"com.sun.org.glassfish."
,
"com.oracle.xmlns.internal."
,
"com.oracle.webservices.internal."
,
"oracle.jrockit.jfr."
,
"org.jcp.xml.dsig.internal."
,
"jdk.internal."
,
"jdk.nashorn.internal."
,
"jdk.nashorn.tools."
};
public
static
void
main
(
String
[]
args
)
throws
Exception
{
List
<
String
>
pkgs
=
new
ArrayList
<>(
Arrays
.
asList
(
packages
));
String
osName
=
System
.
getProperty
(
"os.name"
);
if
(
osName
.
contains
(
"OS X"
))
{
pkgs
.
add
(
"apple."
);
// add apple package for OS X
}
else
if
(
osName
.
startsWith
(
"Windows"
))
{
pkgs
.
add
(
"com.sun.java.accessibility."
);
}
List
<
String
>
jspkgs
=
getPackages
(
Security
.
getProperty
(
"package.access"
));
// Sort to ensure lists are comparable
Collections
.
sort
(
pkgs
);
Collections
.
sort
(
jspkgs
);
if
(!
pkgs
.
equals
(
jspkgs
))
{
for
(
String
p
:
pkgs
)
if
(!
jspkgs
.
contains
(
p
))
System
.
out
.
println
(
"In golden set, but not in j.s file: "
+
p
);
for
(
String
p
:
jspkgs
)
if
(!
pkgs
.
contains
(
p
))
System
.
out
.
println
(
"In j.s file, but not in golden set: "
+
p
);
String
[]
pkgs
=
new
String
[]
{
"com.sun.corba.se.impl."
,
"com.sun.org.apache.xerces.internal.utils."
,
"com.sun.org.apache.xalan.internal.utils."
};
SecurityManager
sm
=
new
SecurityManager
();
System
.
setSecurityManager
(
sm
);
for
(
String
pkg
:
pkgs
)
{
System
.
out
.
println
(
"Checking package access for "
+
pkg
);
throw
new
RuntimeException
(
"restricted packages are not "
+
"consistent with java.security file"
);
}
System
.
setSecurityManager
(
new
SecurityManager
());
SecurityManager
sm
=
System
.
getSecurityManager
();
for
(
String
pkg
:
packages
)
{
String
subpkg
=
pkg
+
"foo"
;
try
{
sm
.
checkPackageAccess
(
pkg
);
throw
new
Exception
(
"Expected PackageAccess SecurityException not thrown"
);
throw
new
RuntimeException
(
"Able to access "
+
pkg
+
" package"
);
}
catch
(
SecurityException
se
)
{
}
try
{
sm
.
checkPackageAccess
(
subpkg
);
throw
new
RuntimeException
(
"Able to access "
+
subpkg
+
" package"
);
}
catch
(
SecurityException
se
)
{
}
try
{
sm
.
checkPackageDefinition
(
pkg
);
throw
new
Exception
(
"Expected PackageDefinition SecurityException not thrown"
);
throw
new
RuntimeException
(
"Able to define class in "
+
pkg
+
" package"
);
}
catch
(
SecurityException
se
)
{
}
try
{
sm
.
checkPackageDefinition
(
subpkg
);
throw
new
RuntimeException
(
"Able to define class in "
+
subpkg
+
" package"
);
}
catch
(
SecurityException
se
)
{
}
}
System
.
out
.
println
(
"Test passed"
);
}
private
static
List
<
String
>
getPackages
(
String
p
)
{
List
<
String
>
packages
=
new
ArrayList
<>();
if
(
p
!=
null
&&
!
p
.
equals
(
""
))
{
StringTokenizer
tok
=
new
StringTokenizer
(
p
,
","
);
while
(
tok
.
hasMoreElements
())
{
String
s
=
tok
.
nextToken
().
trim
();
packages
.
add
(
s
);
}
}
return
packages
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录