src/java.naming/share/classes/sun/security/provider/certpath/ldap/JdkLDAP.java

Print this page
7191662: JCE providers should be located via ServiceLoader


  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.security.provider.certpath.ldap;
  27 
  28 import java.util.HashMap;
  29 import java.util.List;
  30 import java.security.Provider;
  31 import java.security.NoSuchAlgorithmException;
  32 import java.security.InvalidParameterException;
  33 import java.security.InvalidAlgorithmParameterException;
  34 import java.security.ProviderException;
  35 import java.security.cert.CertStoreParameters;
  36 
  37 /**
  38  * Provider class for the JdkLDAP provider.
  39  * Supports LDAP cert store.
  40  *
  41  * @since   1.9
  42  */
  43 public final class JdkLDAP extends Provider {
  44 
  45     private static final long serialVersionUID = -2279741232933606418L;
  46 
  47     private static final class ProviderService extends Provider.Service {
  48         ProviderService(Provider p, String type, String algo, String cn,
  49             List<String> aliases, HashMap<String, String> attrs) {
  50             super(p, type, algo, cn, aliases, attrs);
  51         }
  52 
  53         @Override
  54         public Object newInstance(Object ctrParamObj)


  58             if (type.equals("CertStore") && algo.equals("LDAP")) {
  59                 if (ctrParamObj != null &&
  60                     !(ctrParamObj instanceof CertStoreParameters)) {
  61                     throw new InvalidParameterException
  62                     ("constructorParameter must be instanceof CertStoreParameters");
  63                 }
  64                 try {
  65                     return new LDAPCertStore((CertStoreParameters) ctrParamObj);
  66                 } catch (Exception ex) {
  67                     throw new NoSuchAlgorithmException("Error constructing " +
  68                         type + " for " + algo + " using JdkLDAP", ex);
  69                 }
  70             }
  71             throw new ProviderException("No impl for " + algo + " " + type);
  72         }
  73     }
  74 
  75     public JdkLDAP() {
  76         super("JdkLDAP", 1.9d, "JdkLDAP Provider (implements LDAP CertStore)");
  77 



  78         HashMap<String, String> attrs = new HashMap<>(2);
  79         attrs.put("LDAPSchema", "RFC2587");
  80         attrs.put("ImplementedIn", "Software");
  81 
  82         /*
  83          * CertStore
  84          * attrs: LDAPSchema, ImplementedIn
  85          */
  86         putService(new ProviderService(this, "CertStore",
  87             "LDAP", "sun.security.provider.certpath.ldap.LDAPCertStore",
  88             null, attrs));

  89     }


  90 }


  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.security.provider.certpath.ldap;
  27 
  28 import java.util.HashMap;
  29 import java.util.List;
  30 import java.security.*;




  31 import java.security.cert.CertStoreParameters;
  32 
  33 /**
  34  * Provider class for the JdkLDAP provider.
  35  * Supports LDAP cert store.
  36  *
  37  * @since   1.9
  38  */
  39 public final class JdkLDAP extends Provider {
  40 
  41     private static final long serialVersionUID = -2279741232933606418L;
  42 
  43     private static final class ProviderService extends Provider.Service {
  44         ProviderService(Provider p, String type, String algo, String cn,
  45             List<String> aliases, HashMap<String, String> attrs) {
  46             super(p, type, algo, cn, aliases, attrs);
  47         }
  48 
  49         @Override
  50         public Object newInstance(Object ctrParamObj)


  54             if (type.equals("CertStore") && algo.equals("LDAP")) {
  55                 if (ctrParamObj != null &&
  56                     !(ctrParamObj instanceof CertStoreParameters)) {
  57                     throw new InvalidParameterException
  58                     ("constructorParameter must be instanceof CertStoreParameters");
  59                 }
  60                 try {
  61                     return new LDAPCertStore((CertStoreParameters) ctrParamObj);
  62                 } catch (Exception ex) {
  63                     throw new NoSuchAlgorithmException("Error constructing " +
  64                         type + " for " + algo + " using JdkLDAP", ex);
  65                 }
  66             }
  67             throw new ProviderException("No impl for " + algo + " " + type);
  68         }
  69     }
  70 
  71     public JdkLDAP() {
  72         super("JdkLDAP", 1.9d, "JdkLDAP Provider (implements LDAP CertStore)");
  73 
  74         final Provider p = this;
  75         AccessController.doPrivileged(new PrivilegedAction<Void>() {
  76             public Void run() {
  77                 HashMap<String, String> attrs = new HashMap<>(2);
  78                 attrs.put("LDAPSchema", "RFC2587");
  79                 attrs.put("ImplementedIn", "Software");
  80 
  81                 /*
  82                  * CertStore
  83                  * attrs: LDAPSchema, ImplementedIn
  84                  */
  85                 putService(new ProviderService(p, "CertStore",
  86                            "LDAP", "sun.security.provider.certpath.ldap.LDAPCertStore",
  87                            null, attrs));
  88                 return null;
  89             }
  90         });
  91     }
  92 }