jdk/test/java/lang/SecurityManager/CheckSecurityProvider.java
changeset 31270 e6470b24700d
parent 30506 1998a5644f50
child 39501 f971def61cb8
equal deleted inserted replaced
31269:14968253ce7e 31270:e6470b24700d
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @bug 6997010
    26  * @bug 6997010 7191662
    27  * @summary Consolidate java.security files into one file with modifications
    27  * @summary Consolidate java.security files into one file with modifications
       
    28  * @run main/othervm CheckSecurityProvider
    28  */
    29  */
    29 
    30 
    30 import java.security.Provider;
    31 import java.security.Provider;
    31 import java.security.Security;
    32 import java.security.Security;
    32 import java.util.ArrayList;
    33 import java.util.ArrayList;
    34 import java.util.List;
    35 import java.util.List;
    35 
    36 
    36 /*
    37 /*
    37  * The main benefit of this test is to catch merge errors or other types
    38  * The main benefit of this test is to catch merge errors or other types
    38  * of issues where one or more of the security providers are accidentally
    39  * of issues where one or more of the security providers are accidentally
    39  * removed. This is why the known security providers have to
    40  * removed. With the security manager enabled, this test can also catch
    40  * be explicitly listed below.
    41  * scenarios where the default permission policy needs to be updated.
    41  */
    42  */
    42 public class CheckSecurityProvider {
    43 public class CheckSecurityProvider {
    43     public static void main(String[] args) throws Exception {
    44     public static void main(String[] args) throws Exception {
       
    45         System.setSecurityManager(new SecurityManager());
    44 
    46 
    45         String os = System.getProperty("os.name");
    47         String os = System.getProperty("os.name");
    46 
       
    47         /*
    48         /*
    48          * This array should be updated whenever new security providers
    49          * This array should be updated whenever new security providers
    49          * are added to the the java.security file.
    50          * are added to the the java.security file.
    50          * NOTE: it should be in the same order as the java.security file
    51          * NOTE: it should be in the same order as the java.security file
    51          */
    52          */
    52 
    53 
    53         List<String> expected = new ArrayList<>();
    54         List<String> expected = new ArrayList<>();
    54 
    55 
       
    56         // NOTE: the ordering must match what's defined inside java.security
    55         if (os.equals("SunOS")) {
    57         if (os.equals("SunOS")) {
    56             if (!isOpenJDKOnly()) {
    58             expected.add("com.oracle.security.ucrypto.UcryptoProvider");
    57                 expected.add("com.oracle.security.ucrypto.UcryptoProvider");
       
    58             }
       
    59             expected.add("sun.security.pkcs11.SunPKCS11");
    59             expected.add("sun.security.pkcs11.SunPKCS11");
    60         }
    60         }
    61         expected.add("sun.security.provider.Sun");
    61         expected.add("sun.security.provider.Sun");
    62         expected.add("sun.security.rsa.SunRsaSign");
    62         expected.add("sun.security.rsa.SunRsaSign");
    63         expected.add("sun.security.ec.SunEC");
    63         expected.add("sun.security.ec.SunEC");
    66         expected.add("sun.security.jgss.SunProvider");
    66         expected.add("sun.security.jgss.SunProvider");
    67         expected.add("com.sun.security.sasl.Provider");
    67         expected.add("com.sun.security.sasl.Provider");
    68         expected.add("org.jcp.xml.dsig.internal.dom.XMLDSigRI");
    68         expected.add("org.jcp.xml.dsig.internal.dom.XMLDSigRI");
    69         expected.add("sun.security.smartcardio.SunPCSC");
    69         expected.add("sun.security.smartcardio.SunPCSC");
    70         expected.add("sun.security.provider.certpath.ldap.JdkLDAP");
    70         expected.add("sun.security.provider.certpath.ldap.JdkLDAP");
       
    71         expected.add("com.sun.security.sasl.gsskerb.JdkSASL");
    71         if (os.startsWith("Windows")) {
    72         if (os.startsWith("Windows")) {
    72             expected.add("sun.security.mscapi.SunMSCAPI");
    73             expected.add("sun.security.mscapi.SunMSCAPI");
    73         }
    74         }
    74         if (os.contains("OS X")) {
    75         if (os.contains("OS X")) {
    75             expected.add("apple.security.AppleProvider");
    76             expected.add("apple.security.AppleProvider");
       
    77         }
       
    78         if (!os.equals("SunOS")) {
       
    79             expected.add("sun.security.pkcs11.SunPKCS11");
    76         }
    80         }
    77 
    81 
    78         Iterator<String> iter = expected.iterator();
    82         Iterator<String> iter = expected.iterator();
    79         for (Provider p: Security.getProviders()) {
    83         for (Provider p: Security.getProviders()) {
    80             if (!iter.hasNext()) {
    84             if (!iter.hasNext()) {
    88         }
    92         }
    89         if (iter.hasNext()) {
    93         if (iter.hasNext()) {
    90             throw new Exception("More expected");
    94             throw new Exception("More expected");
    91         }
    95         }
    92     }
    96     }
    93 
       
    94     // Copied from CheckPackageAccess.java in the same directory
       
    95     private static boolean isOpenJDKOnly() {
       
    96         String prop = System.getProperty("java.runtime.name");
       
    97         return prop != null && prop.startsWith("OpenJDK");
       
    98     }
       
    99 }
    97 }