author | alanb |
Fri, 07 Apr 2017 08:05:54 +0000 | |
changeset 44545 | 83b611b88ac8 |
parent 38949 | efeb06a73871 |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
38454
f196252337c7
8157469: DefaultProviderList.java fails with no provider class apple.security.AppleProvider found
rhalade
parents:
36511
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
36511 | 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 |
|
38949
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
26 |
* @bug 7191662 8157469 8157489 |
36511 | 27 |
* @summary Ensure non-java.base providers can be found by ServiceLoader |
28 |
* @author Valerie Peng |
|
29 |
*/ |
|
30 |
||
38454
f196252337c7
8157469: DefaultProviderList.java fails with no provider class apple.security.AppleProvider found
rhalade
parents:
36511
diff
changeset
|
31 |
import java.security.Provider; |
f196252337c7
8157469: DefaultProviderList.java fails with no provider class apple.security.AppleProvider found
rhalade
parents:
36511
diff
changeset
|
32 |
import java.security.Security; |
f196252337c7
8157469: DefaultProviderList.java fails with no provider class apple.security.AppleProvider found
rhalade
parents:
36511
diff
changeset
|
33 |
import java.util.Arrays; |
f196252337c7
8157469: DefaultProviderList.java fails with no provider class apple.security.AppleProvider found
rhalade
parents:
36511
diff
changeset
|
34 |
import java.util.Iterator; |
f196252337c7
8157469: DefaultProviderList.java fails with no provider class apple.security.AppleProvider found
rhalade
parents:
36511
diff
changeset
|
35 |
import java.util.ServiceLoader; |
36511 | 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; |
|
38949
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
46 |
|
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
47 |
Module baseMod = Object.class.getModule(); |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
48 |
|
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
49 |
// Test#1: check that all non-base security providers can be found |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
50 |
// through ServiceLoader |
36511 | 51 |
for (Provider p : defaultProvs) { |
52 |
String pName = p.getName(); |
|
38949
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
53 |
Class pClass = p.getClass(); |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
54 |
|
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
55 |
if (pClass.getModule() != baseMod) { |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
56 |
String pClassName = pClass.getName(); |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
57 |
Iterator<Provider> provIter = sl.iterator(); |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
58 |
boolean found = false; |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
59 |
while (provIter.hasNext()) { |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
60 |
Provider pFromSL = provIter.next(); |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
61 |
|
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
62 |
// check for match by class name because PKCS11 provider |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
63 |
// will have a different name after being configured. |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
64 |
if (pFromSL.getClass().getName().equals(pClassName)) { |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
65 |
found = true; |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
66 |
System.out.println("SL found provider " + pName); |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
67 |
break; |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
68 |
} |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
69 |
} |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
70 |
if (!found) { |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
71 |
failed = true; |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
72 |
System.out.println("Error: SL cannot find provider " + |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
73 |
pName); |
36511 | 74 |
} |
75 |
} |
|
38949
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
76 |
} |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
77 |
|
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
78 |
// Test#2: check that all security providers found through ServiceLoader |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
79 |
// are not from base module |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
80 |
Iterator<Provider> provIter = sl.iterator(); |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
81 |
while (provIter.hasNext()) { |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
82 |
Provider pFromSL = provIter.next(); |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
83 |
if (pFromSL.getClass().getModule() == baseMod) { |
36511 | 84 |
failed = true; |
38949
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
85 |
System.out.println("Error: base provider " + |
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
86 |
pFromSL.getName() + " loaded by SL"); |
36511 | 87 |
} |
88 |
} |
|
38949
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
89 |
|
36511 | 90 |
if (!failed) { |
91 |
System.out.println("Test Passed"); |
|
92 |
} else { |
|
38949
efeb06a73871
8157489: AppleProvider in java.base/macosx/classes/module-info.java.extra
valeriep
parents:
38454
diff
changeset
|
93 |
throw new Exception("One or more tests failed"); |
36511 | 94 |
} |
95 |
} |
|
96 |
} |