Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/security/Provider/DefaultProviderList.java
41149 views
1
/*
2
* Copyright (c) 2015, 2016, 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 7191662 8157469 8157489
27
* @summary Ensure non-java.base providers can be found by ServiceLoader
28
* @author Valerie Peng
29
*/
30
31
import java.security.Provider;
32
import java.security.Security;
33
import java.util.Arrays;
34
import java.util.Iterator;
35
import java.util.ServiceLoader;
36
37
public class DefaultProviderList {
38
39
public static void main(String[] args) throws Exception {
40
Provider[] defaultProvs = Security.getProviders();
41
System.out.println("Providers: " + Arrays.asList(defaultProvs));
42
System.out.println();
43
44
ServiceLoader<Provider> sl = ServiceLoader.load(Provider.class);
45
boolean failed = false;
46
47
Module baseMod = Object.class.getModule();
48
49
// Test#1: check that all non-base security providers can be found
50
// through ServiceLoader
51
for (Provider p : defaultProvs) {
52
String pName = p.getName();
53
Class pClass = p.getClass();
54
55
if (pClass.getModule() != baseMod) {
56
String pClassName = pClass.getName();
57
Iterator<Provider> provIter = sl.iterator();
58
boolean found = false;
59
while (provIter.hasNext()) {
60
Provider pFromSL = provIter.next();
61
62
// check for match by class name because PKCS11 provider
63
// will have a different name after being configured.
64
if (pFromSL.getClass().getName().equals(pClassName)) {
65
found = true;
66
System.out.println("SL found provider " + pName);
67
break;
68
}
69
}
70
if (!found) {
71
failed = true;
72
System.out.println("Error: SL cannot find provider " +
73
pName);
74
}
75
}
76
}
77
78
// Test#2: check that all security providers found through ServiceLoader
79
// are not from base module
80
Iterator<Provider> provIter = sl.iterator();
81
while (provIter.hasNext()) {
82
Provider pFromSL = provIter.next();
83
if (pFromSL.getClass().getModule() == baseMod) {
84
failed = true;
85
System.out.println("Error: base provider " +
86
pFromSL.getName() + " loaded by SL");
87
}
88
}
89
90
if (!failed) {
91
System.out.println("Test Passed");
92
} else {
93
throw new Exception("One or more tests failed");
94
}
95
}
96
}
97
98