Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/security/auth/PrivateCredentialPermission/MoreThenOnePrincipals.java
41153 views
1
/*
2
* Copyright (c) 2015, 2017, 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
* @modules jdk.security.auth
37
* @summary Tests with Subject.getPrivateCredentials to check permission checks with one or more principals.
38
* @run testng/othervm/policy=MoreThenOnePrincipals.policy MoreThenOnePrincipals
39
*/
40
public class MoreThenOnePrincipals {
41
private static final String[] CRED_VALUES =
42
new String[]{"testPrivateCredential-1", "testPrivateCredentials-2"};
43
private static final HashSet CREDS = new HashSet<>(Arrays.asList(CRED_VALUES));
44
45
/**
46
* Policy file grants access to the private Credential,belonging to a
47
* Subject with at least two associated Principals:"com.sun.security.auth
48
* .NTUserPrincipal", with the name,"NTUserPrincipal-1", and
49
* "com.sun.security.auth.UnixPrincipal", with the name, "UnixPrincipals-1".
50
*
51
* For test1 and test2, subjects are associated with none or only one of
52
* principals mentioned above, SecurityException is expected.
53
* For test 3 and test 4, subjects are associated with two or more
54
* Principals (above principals are included), no exception is expected.
55
*
56
*/
57
58
@Test(dataProvider = "Provider1", expectedExceptions = SecurityException.class)
59
public void test1(Subject s) {
60
s.getPrivateCredentials(String.class);
61
}
62
63
@Test(dataProvider = "Provider1", expectedExceptions = SecurityException.class)
64
public void test2(Subject s) {
65
s.getPrivateCredentials().iterator().next();
66
}
67
68
@Test(dataProvider = "Provider2")
69
public void test3(Subject s) {
70
s.getPrivateCredentials(String.class);
71
}
72
73
@Test(dataProvider = "Provider2")
74
public void test4(Subject s) {
75
s.getPrivateCredentials().iterator().next();
76
}
77
78
@DataProvider
79
public Object[][] Provider1() {
80
Subject s1 = new Subject(false, Collections.EMPTY_SET, Collections.EMPTY_SET, CREDS);
81
s1.getPrincipals().add(new NTUserPrincipal("NTUserPrincipal-2"));
82
Subject s2 = new Subject(false, Collections.EMPTY_SET, Collections.EMPTY_SET, CREDS);
83
s2.getPrincipals().add(new NTUserPrincipal("NTUserPrincipal-1"));
84
return new Object[][]{{s1}, {s2}};
85
}
86
87
@DataProvider
88
public Object[][] Provider2() {
89
Subject s3 = new Subject(false, Collections.EMPTY_SET, Collections.EMPTY_SET, CREDS);
90
s3.getPrincipals().add(new NTUserPrincipal("NTUserPrincipal-1"));
91
s3.getPrincipals().add(new UnixPrincipal("UnixPrincipals-1"));
92
Subject s4 = new Subject(false, Collections.EMPTY_SET, Collections.EMPTY_SET, CREDS);
93
s4.getPrincipals().add(new NTUserPrincipal("NTUserPrincipal-1"));
94
s4.getPrincipals().add(new UnixPrincipal("UnixPrincipals-1"));
95
s4.getPrincipals().add(new UnixPrincipal("UnixPrincipals-2"));
96
return new Object[][]{{s3}, {s4}};
97
}
98
99
}
100
101