Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/security/auth/PrivateCredentialPermission/MoreThenOnePrincipals.java
38854 views
1
/*
2
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import com.sun.security.auth.NTUserPrincipal;
25
import com.sun.security.auth.UnixPrincipal;
26
import java.util.Arrays;
27
import java.util.Collections;
28
import java.util.HashSet;
29
import javax.security.auth.Subject;
30
import org.testng.annotations.DataProvider;
31
import org.testng.annotations.Test;
32
33
/*
34
* @test
35
* @bug 8050409
36
* @summary Tests with Subject.getPrivateCredentials to check permission checks with one or more principals.
37
* @run testng/othervm/policy=MoreThenOnePrincipals.policy MoreThenOnePrincipals
38
*/
39
public class MoreThenOnePrincipals {
40
private static final String[] CRED_VALUES =
41
new String[]{"testPrivateCredential-1", "testPrivateCredentials-2"};
42
private static final HashSet CREDS = new HashSet<>(Arrays.asList(CRED_VALUES));
43
44
/**
45
* Policy file grants access to the private Credential,belonging to a
46
* Subject with at least two associated Principals:"com.sun.security.auth
47
* .NTUserPrincipal", with the name,"NTUserPrincipal-1", and
48
* "com.sun.security.auth.UnixPrincipal", with the name, "UnixPrincipals-1".
49
*
50
* For test1 and test2, subjects are associated with none or only one of
51
* principals mentioned above, SecurityException is expected.
52
* For test 3 and test 4, subjects are associated with two or more
53
* Principals (above principals are included), no exception is expected.
54
*
55
*/
56
57
@Test(dataProvider = "Provider1", expectedExceptions = SecurityException.class)
58
public void test1(Subject s) {
59
s.getPrivateCredentials(String.class);
60
}
61
62
@Test(dataProvider = "Provider1", expectedExceptions = SecurityException.class)
63
public void test2(Subject s) {
64
s.getPrivateCredentials().iterator().next();
65
}
66
67
@Test(dataProvider = "Provider2")
68
public void test3(Subject s) {
69
s.getPrivateCredentials(String.class);
70
}
71
72
@Test(dataProvider = "Provider2")
73
public void test4(Subject s) {
74
s.getPrivateCredentials().iterator().next();
75
}
76
77
@DataProvider
78
public Object[][] Provider1() {
79
Subject s1 = new Subject(false, Collections.EMPTY_SET, Collections.EMPTY_SET, CREDS);
80
s1.getPrincipals().add(new NTUserPrincipal("NTUserPrincipal-2"));
81
Subject s2 = new Subject(false, Collections.EMPTY_SET, Collections.EMPTY_SET, CREDS);
82
s2.getPrincipals().add(new NTUserPrincipal("NTUserPrincipal-1"));
83
return new Object[][]{{s1}, {s2}};
84
}
85
86
@DataProvider
87
public Object[][] Provider2() {
88
Subject s3 = new Subject(false, Collections.EMPTY_SET, Collections.EMPTY_SET, CREDS);
89
s3.getPrincipals().add(new NTUserPrincipal("NTUserPrincipal-1"));
90
s3.getPrincipals().add(new UnixPrincipal("UnixPrincipals-1"));
91
Subject s4 = new Subject(false, Collections.EMPTY_SET, Collections.EMPTY_SET, CREDS);
92
s4.getPrincipals().add(new NTUserPrincipal("NTUserPrincipal-1"));
93
s4.getPrincipals().add(new UnixPrincipal("UnixPrincipals-1"));
94
s4.getPrincipals().add(new UnixPrincipal("UnixPrincipals-2"));
95
return new Object[][]{{s3}, {s4}};
96
}
97
98
}
99
100