1 /* 2 * Copyright (c) 2000, 2015, 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 26 package java.security.cert; 27 28 /** 29 * Parameters used as input for the LDAP {@code CertStore} algorithm. 30 * <p> 31 * This class is used to provide necessary configuration parameters (server 32 * name and port number) to implementations of the LDAP {@code CertStore} 33 * algorithm. However, if you are retrieving certificates or CRLs from 34 * an ldap URI as specified by RFC 5280, use the 35 * {@link java.security.cert.URICertStoreParameters URICertStoreParameters} 36 * instead as the URI may contain additional information such as the 37 * distinguished name that will help the LDAP CertStore find the specific 38 * certificates and CRLs. 39 * <p> 40 * <b>Concurrent Access</b> 41 * <p> 42 * Unless otherwise specified, the methods defined in this class are not 43 * thread-safe. Multiple threads that need to access a single 44 * object concurrently should synchronize amongst themselves and 45 * provide the necessary locking. Multiple threads each manipulating 46 * separate objects need not synchronize. 47 * 48 * @since 1.4 49 * @author Steve Hanna 50 * @see CertStore 51 */ 52 public class LDAPCertStoreParameters implements CertStoreParameters { 53 54 private static final int LDAP_DEFAULT_PORT = 389; 55 56 /** 57 * the port number of the LDAP server 58 */ 59 private int port; 60 61 /** 62 * the DNS name of the LDAP server 63 */ 64 private String serverName; 65 66 /** 67 * Creates an instance of {@code LDAPCertStoreParameters} with the 68 * specified parameter values. 69 * 70 * @param serverName the DNS name of the LDAP server 71 * @param port the port number of the LDAP server 72 * @exception NullPointerException if {@code serverName} is 73 * {@code null} 74 */ LDAPCertStoreParameters(String serverName, int port)75 public LDAPCertStoreParameters(String serverName, int port) { 76 if (serverName == null) 77 throw new NullPointerException(); 78 this.serverName = serverName; 79 this.port = port; 80 } 81 82 /** 83 * Creates an instance of {@code LDAPCertStoreParameters} with the 84 * specified server name and a default port of 389. 85 * 86 * @param serverName the DNS name of the LDAP server 87 * @exception NullPointerException if {@code serverName} is 88 * {@code null} 89 */ LDAPCertStoreParameters(String serverName)90 public LDAPCertStoreParameters(String serverName) { 91 this(serverName, LDAP_DEFAULT_PORT); 92 } 93 94 /** 95 * Creates an instance of {@code LDAPCertStoreParameters} with the 96 * default parameter values (server name "localhost", port 389). 97 */ LDAPCertStoreParameters()98 public LDAPCertStoreParameters() { 99 this("localhost", LDAP_DEFAULT_PORT); 100 } 101 102 /** 103 * Returns the DNS name of the LDAP server. 104 * 105 * @return the name (not {@code null}) 106 */ getServerName()107 public String getServerName() { 108 return serverName; 109 } 110 111 /** 112 * Returns the port number of the LDAP server. 113 * 114 * @return the port number 115 */ getPort()116 public int getPort() { 117 return port; 118 } 119 120 /** 121 * Returns a copy of this object. Changes to the copy will not affect 122 * the original and vice versa. 123 * <p> 124 * Note: this method currently performs a shallow copy of the object 125 * (simply calls {@code Object.clone()}). This may be changed in a 126 * future revision to perform a deep copy if new parameters are added 127 * that should not be shared. 128 * 129 * @return the copy 130 */ clone()131 public Object clone() { 132 try { 133 return super.clone(); 134 } catch (CloneNotSupportedException e) { 135 /* Cannot happen */ 136 throw new InternalError(e.toString(), e); 137 } 138 } 139 140 /** 141 * Returns a formatted string describing the parameters. 142 * 143 * @return a formatted string describing the parameters 144 */ toString()145 public String toString() { 146 StringBuilder sb = new StringBuilder(); 147 sb.append("LDAPCertStoreParameters: [\n"); 148 149 sb.append(" serverName: " + serverName + "\n"); 150 sb.append(" port: " + port + "\n"); 151 sb.append("]"); 152 return sb.toString(); 153 } 154 } 155