1/* 2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 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 26package sun.security.provider.certpath.ldap; 27 28import java.util.HashMap; 29import java.util.List; 30import java.security.*; 31import java.security.cert.CertStoreParameters; 32import static sun.security.util.SecurityConstants.PROVIDER_VER; 33 34/** 35 * Provider class for the JdkLDAP provider. 36 * Supports LDAP cert store. 37 * 38 * @since 9 39 */ 40public final class JdkLDAP extends Provider { 41 42 private static final long serialVersionUID = -2279741232933606418L; 43 44 private static final class ProviderService extends Provider.Service { 45 ProviderService(Provider p, String type, String algo, String cn, 46 List<String> aliases, HashMap<String, String> attrs) { 47 super(p, type, algo, cn, aliases, attrs); 48 } 49 50 @Override 51 public Object newInstance(Object ctrParamObj) 52 throws NoSuchAlgorithmException { 53 String type = getType(); 54 String algo = getAlgorithm(); 55 if (type.equals("CertStore") && algo.equals("LDAP")) { 56 if (ctrParamObj != null && 57 !(ctrParamObj instanceof CertStoreParameters)) { 58 throw new InvalidParameterException 59 ("constructorParameter must be instanceof CertStoreParameters"); 60 } 61 try { 62 return new LDAPCertStore((CertStoreParameters) ctrParamObj); 63 } catch (Exception ex) { 64 throw new NoSuchAlgorithmException("Error constructing " + 65 type + " for " + algo + " using JdkLDAP", ex); 66 } 67 } 68 throw new ProviderException("No impl for " + algo + " " + type); 69 } 70 } 71 72 public JdkLDAP() { 73 super("JdkLDAP", PROVIDER_VER, "JdkLDAP Provider (implements LDAP CertStore)"); 74 75 final Provider p = this; 76 AccessController.doPrivileged(new PrivilegedAction<Void>() { 77 public Void run() { 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(p, "CertStore", 87 "LDAP", "sun.security.provider.certpath.ldap.LDAPCertStore", 88 null, attrs)); 89 return null; 90 } 91 }); 92 } 93} 94