< prev index next >

src/java.base/share/classes/javax/crypto/JceSecurity.java

Print this page




  59     // value is failure cause Exception in error case
  60     private final static Map<Provider, Object> verificationResults =
  61             new IdentityHashMap<>();
  62 
  63     // Map<Provider,?> of the providers currently being verified
  64     private final static Map<Provider, Object> verifyingProviders =
  65             new IdentityHashMap<>();
  66 
  67     // Set the default value. May be changed in the static initializer.
  68     private static boolean isRestricted = true;
  69 
  70     /*
  71      * Don't let anyone instantiate this.
  72      */
  73     private JceSecurity() {
  74     }
  75 
  76     static {
  77         try {
  78             AccessController.doPrivileged(
  79                 new PrivilegedExceptionAction<Void> () {
  80                     @Override
  81                     public Void run() throws Exception {
  82                         setupJurisdictionPolicies();
  83                         return null;
  84                     }
  85                 }
  86             );
  87 
  88             isRestricted = defaultPolicy.implies(
  89                 CryptoAllPermission.INSTANCE) ? false : true;
  90         } catch (Exception e) {
  91             throw new SecurityException(
  92                     "Can not initialize cryptographic mechanism", e);
  93         }
  94     }
  95 
  96     static Instance getInstance(String type, Class<?> clazz, String algorithm,
  97             String provider) throws NoSuchAlgorithmException,
  98             NoSuchProviderException {
  99         Service s = GetInstance.getService(type, algorithm, provider);


 208     static {
 209         try {
 210             NULL_URL = new URL("http://null.sun.com/");
 211         } catch (Exception e) {
 212             throw new RuntimeException(e);
 213         }
 214     }
 215 
 216     // reference to a Map we use as a cache for codebases
 217     private static final Map<Class<?>, URL> codeBaseCacheRef =
 218             new WeakHashMap<>();
 219 
 220     /*
 221      * Returns the CodeBase for the given class.
 222      */
 223     static URL getCodeBase(final Class<?> clazz) {
 224         synchronized (codeBaseCacheRef) {
 225             URL url = codeBaseCacheRef.get(clazz);
 226             if (url == null) {
 227                 url = AccessController.doPrivileged(
 228                     new PrivilegedAction<URL>() {
 229                         @Override
 230                         public URL run() {
 231                             ProtectionDomain pd = clazz.getProtectionDomain();
 232                             if (pd != null) {
 233                                 CodeSource cs = pd.getCodeSource();
 234                                 if (cs != null) {
 235                                     return cs.getLocation();
 236                                 }
 237                             }
 238                             return NULL_URL;
 239                         }
 240                     });
 241                 codeBaseCacheRef.put(clazz, url);
 242             }
 243             return (url == NULL_URL) ? null : url;
 244         }
 245     }
 246 
 247     private static void setupJurisdictionPolicies() throws Exception {
 248         String javaHomeDir = System.getProperty("java.home");




  59     // value is failure cause Exception in error case
  60     private final static Map<Provider, Object> verificationResults =
  61             new IdentityHashMap<>();
  62 
  63     // Map<Provider,?> of the providers currently being verified
  64     private final static Map<Provider, Object> verifyingProviders =
  65             new IdentityHashMap<>();
  66 
  67     // Set the default value. May be changed in the static initializer.
  68     private static boolean isRestricted = true;
  69 
  70     /*
  71      * Don't let anyone instantiate this.
  72      */
  73     private JceSecurity() {
  74     }
  75 
  76     static {
  77         try {
  78             AccessController.doPrivileged(
  79                 new PrivilegedExceptionAction<> () {
  80                     @Override
  81                     public Void run() throws Exception {
  82                         setupJurisdictionPolicies();
  83                         return null;
  84                     }
  85                 }
  86             );
  87 
  88             isRestricted = defaultPolicy.implies(
  89                 CryptoAllPermission.INSTANCE) ? false : true;
  90         } catch (Exception e) {
  91             throw new SecurityException(
  92                     "Can not initialize cryptographic mechanism", e);
  93         }
  94     }
  95 
  96     static Instance getInstance(String type, Class<?> clazz, String algorithm,
  97             String provider) throws NoSuchAlgorithmException,
  98             NoSuchProviderException {
  99         Service s = GetInstance.getService(type, algorithm, provider);


 208     static {
 209         try {
 210             NULL_URL = new URL("http://null.sun.com/");
 211         } catch (Exception e) {
 212             throw new RuntimeException(e);
 213         }
 214     }
 215 
 216     // reference to a Map we use as a cache for codebases
 217     private static final Map<Class<?>, URL> codeBaseCacheRef =
 218             new WeakHashMap<>();
 219 
 220     /*
 221      * Returns the CodeBase for the given class.
 222      */
 223     static URL getCodeBase(final Class<?> clazz) {
 224         synchronized (codeBaseCacheRef) {
 225             URL url = codeBaseCacheRef.get(clazz);
 226             if (url == null) {
 227                 url = AccessController.doPrivileged(
 228                     new PrivilegedAction<>() {
 229                         @Override
 230                         public URL run() {
 231                             ProtectionDomain pd = clazz.getProtectionDomain();
 232                             if (pd != null) {
 233                                 CodeSource cs = pd.getCodeSource();
 234                                 if (cs != null) {
 235                                     return cs.getLocation();
 236                                 }
 237                             }
 238                             return NULL_URL;
 239                         }
 240                     });
 241                 codeBaseCacheRef.put(clazz, url);
 242             }
 243             return (url == NULL_URL) ? null : url;
 244         }
 245     }
 246 
 247     private static void setupJurisdictionPolicies() throws Exception {
 248         String javaHomeDir = System.getProperty("java.home");


< prev index next >