author | alanb |
Fri, 07 Apr 2017 08:05:54 +0000 | |
changeset 44545 | 83b611b88ac8 |
parent 43248 | 5e15de85a1a0 |
permissions | -rw-r--r-- |
25974
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
1 |
/* |
43248
5e15de85a1a0
8172527: Rename jdk.crypto.token to jdk.crypto.cryptoki
ascarpino
parents:
42693
diff
changeset
|
2 |
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. |
25974
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
4 |
* |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
8 |
* |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
13 |
* accompanied this code). |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
14 |
* |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
18 |
* |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
21 |
* questions. |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
22 |
*/ |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
23 |
|
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
24 |
/* |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
25 |
* @test |
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30506
diff
changeset
|
26 |
* @bug 6997010 7191662 |
25974
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
27 |
* @summary Consolidate java.security files into one file with modifications |
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30506
diff
changeset
|
28 |
* @run main/othervm CheckSecurityProvider |
25974
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
29 |
*/ |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
30 |
|
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
31 |
import java.security.Provider; |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
32 |
import java.security.Security; |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
33 |
import java.util.ArrayList; |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
34 |
import java.util.Iterator; |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
35 |
import java.util.List; |
39501
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
36 |
import java.util.stream.Collectors; |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
37 |
import java.util.stream.Stream; |
25974
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
38 |
|
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
39 |
/* |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
40 |
* The main benefit of this test is to catch merge errors or other types |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
41 |
* of issues where one or more of the security providers are accidentally |
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30506
diff
changeset
|
42 |
* removed. With the security manager enabled, this test can also catch |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30506
diff
changeset
|
43 |
* scenarios where the default permission policy needs to be updated. |
25974
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
44 |
*/ |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
45 |
public class CheckSecurityProvider { |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
46 |
public static void main(String[] args) throws Exception { |
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
43248
diff
changeset
|
47 |
ModuleLayer layer = ModuleLayer.boot(); |
39501
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
48 |
|
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30506
diff
changeset
|
49 |
System.setSecurityManager(new SecurityManager()); |
25974
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
50 |
|
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
51 |
String os = System.getProperty("os.name"); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
52 |
/* |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
53 |
* This array should be updated whenever new security providers |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
54 |
* are added to the the java.security file. |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
55 |
* NOTE: it should be in the same order as the java.security file |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
56 |
*/ |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
57 |
|
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
58 |
List<String> expected = new ArrayList<>(); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
59 |
|
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30506
diff
changeset
|
60 |
// NOTE: the ordering must match what's defined inside java.security |
25974
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
61 |
if (os.equals("SunOS")) { |
39501
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
62 |
layer.findModule("jdk.crypto.ucrypto") |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
63 |
.ifPresent(m -> expected.add("com.oracle.security.ucrypto.UcryptoProvider")); |
43248
5e15de85a1a0
8172527: Rename jdk.crypto.token to jdk.crypto.cryptoki
ascarpino
parents:
42693
diff
changeset
|
64 |
layer.findModule("jdk.crypto.cryptoki") |
39501
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
65 |
.ifPresent(m -> expected.add("sun.security.pkcs11.SunPKCS11")); |
25974
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
66 |
} |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
67 |
expected.add("sun.security.provider.Sun"); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
68 |
expected.add("sun.security.rsa.SunRsaSign"); |
39501
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
69 |
layer.findModule("jdk.crypto.ec") |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
70 |
.ifPresent(m -> expected.add("sun.security.ec.SunEC")); |
25974
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
71 |
expected.add("com.sun.net.ssl.internal.ssl.Provider"); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
72 |
expected.add("com.sun.crypto.provider.SunJCE"); |
39501
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
73 |
layer.findModule("jdk.security.jgss") |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
74 |
.ifPresent(m -> expected.add("sun.security.jgss.SunProvider")); |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
75 |
layer.findModule("java.security.sasl") |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
76 |
.ifPresent(m -> expected.add("com.sun.security.sasl.Provider")); |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
77 |
layer.findModule("java.xml.crypto") |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
78 |
.ifPresent(m -> expected.add("org.jcp.xml.dsig.internal.dom.XMLDSigRI")); |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
79 |
layer.findModule("java.smartcardio") |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
80 |
.ifPresent(m -> expected.add("sun.security.smartcardio.SunPCSC")); |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
81 |
layer.findModule("java.naming") |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
82 |
.ifPresent(m -> expected.add("sun.security.provider.certpath.ldap.JdkLDAP")); |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
83 |
layer.findModule("jdk.security.jgss") |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
84 |
.ifPresent(m -> expected.add("com.sun.security.sasl.gsskerb.JdkSASL")); |
25974
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
85 |
if (os.startsWith("Windows")) { |
39501
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
86 |
layer.findModule("jdk.crypto.mscapi") |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
87 |
.ifPresent(m -> expected.add("sun.security.mscapi.SunMSCAPI")); |
25974
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
88 |
} |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
89 |
if (os.contains("OS X")) { |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
90 |
expected.add("apple.security.AppleProvider"); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
91 |
} |
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30506
diff
changeset
|
92 |
if (!os.equals("SunOS")) { |
43248
5e15de85a1a0
8172527: Rename jdk.crypto.token to jdk.crypto.cryptoki
ascarpino
parents:
42693
diff
changeset
|
93 |
layer.findModule("jdk.crypto.cryptoki") |
39501
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
94 |
.ifPresent(m -> expected.add("sun.security.pkcs11.SunPKCS11")); |
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30506
diff
changeset
|
95 |
} |
25974
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
96 |
|
39501
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
97 |
List<String> actual = Stream.of(Security.getProviders()) |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
98 |
.map(p -> p.getClass().getName()) |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
99 |
.collect(Collectors.toList()); |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
100 |
|
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
101 |
System.out.println("Expected providers:"); |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
102 |
expected.stream().forEach(System.out::println); |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
103 |
System.out.println("Actual providers:"); |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
104 |
actual.stream().forEach(System.out::println); |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
105 |
|
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
106 |
if (expected.size() != actual.size()) { |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
107 |
throw new Exception("Unexpected provider count. " |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
108 |
+ "Expected: " + expected.size() + ". Actual: " + actual.size()); |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
109 |
} |
25974
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
110 |
Iterator<String> iter = expected.iterator(); |
39501
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
111 |
for (String p: actual) { |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
112 |
String nextExpected = iter.next(); |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
113 |
if (!nextExpected.equals(p)) { |
f971def61cb8
8158670: Fix @modules in java/lang/SecurityManager/CheckSecurityProvider.java
shurailine
parents:
31270
diff
changeset
|
114 |
throw new Exception("Expected " + nextExpected + ", actual " + p); |
25974
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
115 |
} |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
116 |
} |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
117 |
} |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
118 |
} |