< prev index next >

test/jdk/java/lang/SecurityManager/CheckSecurityProvider.java

Print this page
rev 59105 : imported patch corelibs


  41  * of issues where one or more of the security providers are accidentally
  42  * removed. With the security manager enabled, this test can also catch
  43  * scenarios where the default permission policy needs to be updated.
  44  */
  45 public class CheckSecurityProvider {
  46     public static void main(String[] args) throws Exception {
  47         ModuleLayer layer = ModuleLayer.boot();
  48 
  49         System.setSecurityManager(new SecurityManager());
  50 
  51         String os = System.getProperty("os.name");
  52         /*
  53          * This array should be updated whenever new security providers
  54          * are added to the the java.security file.
  55          * NOTE: it should be in the same order as the java.security file
  56          */
  57 
  58         List<String> expected = new ArrayList<>();
  59 
  60         // NOTE: the ordering must match what's defined inside java.security
  61         if (os.equals("SunOS")) {
  62             layer.findModule("jdk.crypto.ucrypto")
  63                 .ifPresent(m -> expected.add("com.oracle.security.ucrypto.UcryptoProvider"));
  64             layer.findModule("jdk.crypto.cryptoki")
  65                 .ifPresent(m -> expected.add("sun.security.pkcs11.SunPKCS11"));
  66         }
  67         expected.add("sun.security.provider.Sun");
  68         expected.add("sun.security.rsa.SunRsaSign");
  69         layer.findModule("jdk.crypto.ec")
  70             .ifPresent(m -> expected.add("sun.security.ec.SunEC"));
  71         expected.add("sun.security.ssl.SunJSSE");
  72         expected.add("com.sun.crypto.provider.SunJCE");
  73         layer.findModule("jdk.security.jgss")
  74             .ifPresent(m -> expected.add("sun.security.jgss.SunProvider"));
  75         layer.findModule("java.security.sasl")
  76             .ifPresent(m -> expected.add("com.sun.security.sasl.Provider"));
  77         layer.findModule("java.xml.crypto")
  78             .ifPresent(m -> expected.add("org.jcp.xml.dsig.internal.dom.XMLDSigRI"));
  79         layer.findModule("java.smartcardio")
  80             .ifPresent(m -> expected.add("sun.security.smartcardio.SunPCSC"));
  81         layer.findModule("java.naming")
  82             .ifPresent(m -> expected.add("sun.security.provider.certpath.ldap.JdkLDAP"));
  83         layer.findModule("jdk.security.jgss")
  84             .ifPresent(m -> expected.add("com.sun.security.sasl.gsskerb.JdkSASL"));
  85         if (os.startsWith("Windows")) {
  86             layer.findModule("jdk.crypto.mscapi")
  87                 .ifPresent(m -> expected.add("sun.security.mscapi.SunMSCAPI"));
  88         }
  89         if (os.contains("OS X")) {
  90             expected.add("apple.security.AppleProvider");
  91         }
  92         if (!os.equals("SunOS")) {
  93             layer.findModule("jdk.crypto.cryptoki")
  94                 .ifPresent(m -> expected.add("sun.security.pkcs11.SunPKCS11"));
  95         }
  96 
  97         List<String> actual = Stream.of(Security.getProviders())
  98             .map(p -> p.getClass().getName())
  99             .collect(Collectors.toList());
 100 
 101         System.out.println("Expected providers:");
 102         expected.stream().forEach(System.out::println);
 103         System.out.println("Actual providers:");
 104         actual.stream().forEach(System.out::println);
 105 
 106         if (expected.size() != actual.size()) {
 107             throw new Exception("Unexpected provider count. "
 108                 + "Expected: " + expected.size() + ". Actual: " + actual.size());
 109         }
 110         Iterator<String> iter = expected.iterator();
 111         for (String p: actual) {
 112             String nextExpected = iter.next();
 113             if (!nextExpected.equals(p)) {
 114                 throw new Exception("Expected " + nextExpected + ", actual " + p);
 115             }


  41  * of issues where one or more of the security providers are accidentally
  42  * removed. With the security manager enabled, this test can also catch
  43  * scenarios where the default permission policy needs to be updated.
  44  */
  45 public class CheckSecurityProvider {
  46     public static void main(String[] args) throws Exception {
  47         ModuleLayer layer = ModuleLayer.boot();
  48 
  49         System.setSecurityManager(new SecurityManager());
  50 
  51         String os = System.getProperty("os.name");
  52         /*
  53          * This array should be updated whenever new security providers
  54          * are added to the the java.security file.
  55          * NOTE: it should be in the same order as the java.security file
  56          */
  57 
  58         List<String> expected = new ArrayList<>();
  59 
  60         // NOTE: the ordering must match what's defined inside java.security






  61         expected.add("sun.security.provider.Sun");
  62         expected.add("sun.security.rsa.SunRsaSign");
  63         layer.findModule("jdk.crypto.ec")
  64             .ifPresent(m -> expected.add("sun.security.ec.SunEC"));
  65         expected.add("sun.security.ssl.SunJSSE");
  66         expected.add("com.sun.crypto.provider.SunJCE");
  67         layer.findModule("jdk.security.jgss")
  68             .ifPresent(m -> expected.add("sun.security.jgss.SunProvider"));
  69         layer.findModule("java.security.sasl")
  70             .ifPresent(m -> expected.add("com.sun.security.sasl.Provider"));
  71         layer.findModule("java.xml.crypto")
  72             .ifPresent(m -> expected.add("org.jcp.xml.dsig.internal.dom.XMLDSigRI"));
  73         layer.findModule("java.smartcardio")
  74             .ifPresent(m -> expected.add("sun.security.smartcardio.SunPCSC"));
  75         layer.findModule("java.naming")
  76             .ifPresent(m -> expected.add("sun.security.provider.certpath.ldap.JdkLDAP"));
  77         layer.findModule("jdk.security.jgss")
  78             .ifPresent(m -> expected.add("com.sun.security.sasl.gsskerb.JdkSASL"));
  79         if (os.startsWith("Windows")) {
  80             layer.findModule("jdk.crypto.mscapi")
  81                 .ifPresent(m -> expected.add("sun.security.mscapi.SunMSCAPI"));
  82         }
  83         if (os.contains("OS X")) {
  84             expected.add("apple.security.AppleProvider");
  85         }

  86         layer.findModule("jdk.crypto.cryptoki")
  87             .ifPresent(m -> expected.add("sun.security.pkcs11.SunPKCS11"));

  88 
  89         List<String> actual = Stream.of(Security.getProviders())
  90             .map(p -> p.getClass().getName())
  91             .collect(Collectors.toList());
  92 
  93         System.out.println("Expected providers:");
  94         expected.stream().forEach(System.out::println);
  95         System.out.println("Actual providers:");
  96         actual.stream().forEach(System.out::println);
  97 
  98         if (expected.size() != actual.size()) {
  99             throw new Exception("Unexpected provider count. "
 100                 + "Expected: " + expected.size() + ". Actual: " + actual.size());
 101         }
 102         Iterator<String> iter = expected.iterator();
 103         for (String p: actual) {
 104             String nextExpected = iter.next();
 105             if (!nextExpected.equals(p)) {
 106                 throw new Exception("Expected " + nextExpected + ", actual " + p);
 107             }
< prev index next >