Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/security/UnresolvedPermission/AccessorMethods.java
41149 views
1
/*
2
* Copyright (c) 2003, 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
/*
25
* @test
26
* @bug 4765281
27
* @summary provide accessor methods for UnresolvedPermission
28
*/
29
30
import java.io.*;
31
import java.security.UnresolvedPermission;
32
import java.security.cert.*;
33
34
public class AccessorMethods {
35
36
private static final String SIGNER1 = "AccessorMethods.signer1";
37
private static final String SIGNER2 = "AccessorMethods.signer2";
38
private static final String CA = "AccessorMethods.ca";
39
40
public static void main(String[] args) throws Exception {
41
42
// set CA cert in chain
43
File f = new File(System.getProperty("test.src", "."), CA);
44
FileInputStream fis = new FileInputStream(f);
45
CertificateFactory fac = CertificateFactory.getInstance("X.509");
46
Certificate cacert = fac.generateCertificate(fis);
47
Certificate[] signercerts = new Certificate[4];
48
signercerts[1] = cacert;
49
signercerts[3] = cacert;
50
51
// set signer certs
52
f = new File(System.getProperty("test.src", "."), SIGNER1);
53
fis = new FileInputStream(f);
54
Certificate signer1 = fac.generateCertificate(fis);
55
signercerts[0] = signer1;
56
57
f = new File(System.getProperty("test.src", "."), SIGNER2);
58
fis = new FileInputStream(f);
59
Certificate signer2 = fac.generateCertificate(fis);
60
signercerts[2] = signer2;
61
62
UnresolvedPermission up = new UnresolvedPermission
63
("type", "name", "actions", signercerts);
64
if (!up.getUnresolvedType().equals("type") ||
65
!up.getUnresolvedName().equals("name") ||
66
!up.getUnresolvedActions().equals("actions")) {
67
throw new SecurityException("Test 1 Failed");
68
}
69
70
Certificate[] certs = up.getUnresolvedCerts();
71
if (certs == null || certs.length != 2) {
72
throw new SecurityException("Test 2 Failed");
73
}
74
75
boolean foundSigner1 = false;
76
boolean foundSigner2 = false;
77
if (certs[0].equals(signer1) || certs[1].equals(signer1)) {
78
foundSigner1 = true;
79
}
80
if (certs[0].equals(signer2) || certs[1].equals(signer2)) {
81
foundSigner2 = true;
82
}
83
if (!foundSigner1 || !foundSigner2) {
84
throw new SecurityException("Test 3 Failed");
85
}
86
}
87
}
88
89