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