< prev index next >

src/java.base/share/classes/sun/security/ssl/ClientKeyExchangeService.java

Print this page
rev 14210 : 8154231: Simplify access to System properties from JDK code
Reviewed-by: rriggs


  33 import java.security.AccessControlContext;
  34 import java.security.AccessController;
  35 import java.security.Principal;
  36 import java.security.PrivilegedAction;
  37 import java.security.SecureRandom;
  38 import java.util.*;
  39 
  40 /**
  41  * Models a service that provides support for a particular client key exchange
  42  * mode. Currently used to implement Kerberos-related cipher suites.
  43  *
  44  * @since 9
  45  */
  46 public interface ClientKeyExchangeService {
  47 
  48     static class Loader {
  49         private static final Map<String,ClientKeyExchangeService>
  50                 providers = new HashMap<>();
  51 
  52         static {
  53             final String key = "java.home";
  54             String path = AccessController.doPrivileged(
  55                     new GetPropertyAction(key), null,
  56                     new PropertyPermission(key, "read"));
  57             ServiceLoader<ClientKeyExchangeService> sc =
  58                     AccessController.doPrivileged(
  59                             (PrivilegedAction<ServiceLoader<ClientKeyExchangeService>>)
  60                                     () -> ServiceLoader.loadInstalled(ClientKeyExchangeService.class),
  61                             null,
  62                             new FilePermission(new File(path, "-").toString(), "read"));
  63             Iterator<ClientKeyExchangeService> iter = sc.iterator();
  64             while (iter.hasNext()) {
  65                 ClientKeyExchangeService cs = iter.next();
  66                 for (String ex: cs.supported()) {
  67                     providers.put(ex, cs);
  68                 }
  69             }
  70         }
  71 
  72     }
  73 
  74     public static ClientKeyExchangeService find(String ex) {
  75         return Loader.providers.get(ex);
  76     }




  33 import java.security.AccessControlContext;
  34 import java.security.AccessController;
  35 import java.security.Principal;
  36 import java.security.PrivilegedAction;
  37 import java.security.SecureRandom;
  38 import java.util.*;
  39 
  40 /**
  41  * Models a service that provides support for a particular client key exchange
  42  * mode. Currently used to implement Kerberos-related cipher suites.
  43  *
  44  * @since 9
  45  */
  46 public interface ClientKeyExchangeService {
  47 
  48     static class Loader {
  49         private static final Map<String,ClientKeyExchangeService>
  50                 providers = new HashMap<>();
  51 
  52         static {
  53             String path = GetPropertyAction.getProperty("java.home");



  54             ServiceLoader<ClientKeyExchangeService> sc =
  55                     AccessController.doPrivileged(
  56                             (PrivilegedAction<ServiceLoader<ClientKeyExchangeService>>)
  57                                     () -> ServiceLoader.loadInstalled(ClientKeyExchangeService.class),
  58                             null,
  59                             new FilePermission(new File(path, "-").toString(), "read"));
  60             Iterator<ClientKeyExchangeService> iter = sc.iterator();
  61             while (iter.hasNext()) {
  62                 ClientKeyExchangeService cs = iter.next();
  63                 for (String ex: cs.supported()) {
  64                     providers.put(ex, cs);
  65                 }
  66             }
  67         }
  68 
  69     }
  70 
  71     public static ClientKeyExchangeService find(String ex) {
  72         return Loader.providers.get(ex);
  73     }


< prev index next >