Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
491c63a5
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看板
提交
491c63a5
编写于
6月 19, 2015
作者:
A
amjiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8050409: Test for JAAS getPrivateCredentials
Reviewed-by: weijun
上级
88c3bf1f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
108 addition
and
0 deletion
+108
-0
test/javax/security/auth/PrivateCredentialPermission/MoreThenOnePrincipals.java
...th/PrivateCredentialPermission/MoreThenOnePrincipals.java
+98
-0
test/javax/security/auth/PrivateCredentialPermission/MoreThenOnePrincipals.policy
.../PrivateCredentialPermission/MoreThenOnePrincipals.policy
+10
-0
未找到文件。
test/javax/security/auth/PrivateCredentialPermission/MoreThenOnePrincipals.java
0 → 100644
浏览文件 @
491c63a5
/*
* Copyright (c) 2015, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import
com.sun.security.auth.NTUserPrincipal
;
import
com.sun.security.auth.UnixPrincipal
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
javax.security.auth.Subject
;
import
org.testng.annotations.DataProvider
;
import
org.testng.annotations.Test
;
/*
* @test
* @bug 8050409
* @summary Tests with Subject.getPrivateCredentials to check permission checks with one or more principals.
* @run testng/othervm/policy=MoreThenOnePrincipals.policy MoreThenOnePrincipals
*/
public
class
MoreThenOnePrincipals
{
private
static
final
String
[]
CRED_VALUES
=
new
String
[]{
"testPrivateCredential-1"
,
"testPrivateCredentials-2"
};
private
static
final
HashSet
CREDS
=
new
HashSet
<>(
Arrays
.
asList
(
CRED_VALUES
));
/**
* Policy file grants access to the private Credential,belonging to a
* Subject with at least two associated Principals:"com.sun.security.auth
* .NTUserPrincipal", with the name,"NTUserPrincipal-1", and
* "com.sun.security.auth.UnixPrincipal", with the name, "UnixPrincipals-1".
*
* For test1 and test2, subjects are associated with none or only one of
* principals mentioned above, SecurityException is expected.
* For test 3 and test 4, subjects are associated with two or more
* Principals (above principals are included), no exception is expected.
*
*/
@Test
(
dataProvider
=
"Provider1"
,
expectedExceptions
=
SecurityException
.
class
)
public
void
test1
(
Subject
s
)
{
s
.
getPrivateCredentials
(
String
.
class
);
}
@Test
(
dataProvider
=
"Provider1"
,
expectedExceptions
=
SecurityException
.
class
)
public
void
test2
(
Subject
s
)
{
s
.
getPrivateCredentials
().
iterator
().
next
();
}
@Test
(
dataProvider
=
"Provider2"
)
public
void
test3
(
Subject
s
)
{
s
.
getPrivateCredentials
(
String
.
class
);
}
@Test
(
dataProvider
=
"Provider2"
)
public
void
test4
(
Subject
s
)
{
s
.
getPrivateCredentials
().
iterator
().
next
();
}
@DataProvider
public
Object
[][]
Provider1
()
{
Subject
s1
=
new
Subject
(
false
,
Collections
.
EMPTY_SET
,
Collections
.
EMPTY_SET
,
CREDS
);
s1
.
getPrincipals
().
add
(
new
NTUserPrincipal
(
"NTUserPrincipal-2"
));
Subject
s2
=
new
Subject
(
false
,
Collections
.
EMPTY_SET
,
Collections
.
EMPTY_SET
,
CREDS
);
s2
.
getPrincipals
().
add
(
new
NTUserPrincipal
(
"NTUserPrincipal-1"
));
return
new
Object
[][]{{
s1
},
{
s2
}};
}
@DataProvider
public
Object
[][]
Provider2
()
{
Subject
s3
=
new
Subject
(
false
,
Collections
.
EMPTY_SET
,
Collections
.
EMPTY_SET
,
CREDS
);
s3
.
getPrincipals
().
add
(
new
NTUserPrincipal
(
"NTUserPrincipal-1"
));
s3
.
getPrincipals
().
add
(
new
UnixPrincipal
(
"UnixPrincipals-1"
));
Subject
s4
=
new
Subject
(
false
,
Collections
.
EMPTY_SET
,
Collections
.
EMPTY_SET
,
CREDS
);
s4
.
getPrincipals
().
add
(
new
NTUserPrincipal
(
"NTUserPrincipal-1"
));
s4
.
getPrincipals
().
add
(
new
UnixPrincipal
(
"UnixPrincipals-1"
));
s4
.
getPrincipals
().
add
(
new
UnixPrincipal
(
"UnixPrincipals-2"
));
return
new
Object
[][]{{
s3
},
{
s4
}};
}
}
test/javax/security/auth/PrivateCredentialPermission/MoreThenOnePrincipals.policy
0 → 100644
浏览文件 @
491c63a5
grant{
// permissions for TestNG execution
permission java.io.FilePermission "*","read,write";
permission java.lang.RuntimePermission "accessDeclaredMembers";
permission java.util.PropertyPermission "*","read";
permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
// permissions for test itself
permission javax.security.auth.AuthPermission "modifyPrincipals";
permission javax.security.auth.PrivateCredentialPermission "* com.sun.security.auth.NTUserPrincipal \"NTUserPrincipal-1\" com.sun.security.auth.UnixPrincipal \"UnixPrincipals-1\"", "read";
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录