1. /*
  2. * @(#)LDAPCertStoreParameters.java 1.8 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.security.cert;
  8. /**
  9. * Parameters used as input for the LDAP <code>CertStore</code> algorithm.
  10. * <p>
  11. * This class is used to provide necessary configuration parameters (server
  12. * name and port number) to implementations of the LDAP <code>CertStore</code>
  13. * algorithm.
  14. * <p>
  15. * <b>Concurrent Access</b>
  16. * <p>
  17. * Unless otherwise specified, the methods defined in this class are not
  18. * thread-safe. Multiple threads that need to access a single
  19. * object concurrently should synchronize amongst themselves and
  20. * provide the necessary locking. Multiple threads each manipulating
  21. * separate objects need not synchronize.
  22. *
  23. * @version 1.8 12/19/03
  24. * @since 1.4
  25. * @author Steve Hanna
  26. * @see CertStore
  27. */
  28. public class LDAPCertStoreParameters implements CertStoreParameters {
  29. private static final int LDAP_DEFAULT_PORT = 389;
  30. /**
  31. * the port number of the LDAP server
  32. */
  33. private int port;
  34. /**
  35. * the DNS name of the LDAP server
  36. */
  37. private String serverName;
  38. /**
  39. * Creates an instance of <code>LDAPCertStoreParameters</code> with the
  40. * specified parameter values.
  41. *
  42. * @param serverName the DNS name of the LDAP server
  43. * @param port the port number of the LDAP server
  44. * @exception NullPointerException if <code>serverName</code> is
  45. * <code>null</code>
  46. */
  47. public LDAPCertStoreParameters(String serverName, int port) {
  48. if (serverName == null)
  49. throw new NullPointerException();
  50. this.serverName = serverName;
  51. this.port = port;
  52. }
  53. /**
  54. * Creates an instance of <code>LDAPCertStoreParameters</code> with the
  55. * specified server name and a default port of 389.
  56. *
  57. * @param serverName the DNS name of the LDAP server
  58. * @exception NullPointerException if <code>serverName</code> is
  59. * <code>null</code>
  60. */
  61. public LDAPCertStoreParameters(String serverName) {
  62. this(serverName, LDAP_DEFAULT_PORT);
  63. }
  64. /**
  65. * Creates an instance of <code>LDAPCertStoreParameters</code> with the
  66. * default parameter values (server name "localhost", port 389).
  67. */
  68. public LDAPCertStoreParameters() {
  69. this("localhost", LDAP_DEFAULT_PORT);
  70. }
  71. /**
  72. * Returns the DNS name of the LDAP server.
  73. *
  74. * @return the name (not <code>null</code>)
  75. */
  76. public String getServerName() {
  77. return serverName;
  78. }
  79. /**
  80. * Returns the port number of the LDAP server.
  81. *
  82. * @return the port number
  83. */
  84. public int getPort() {
  85. return port;
  86. }
  87. /**
  88. * Returns a copy of this object. Changes to the copy will not affect
  89. * the original and vice versa.
  90. * <p>
  91. * Note: this method currently performs a shallow copy of the object
  92. * (simply calls <code>Object.clone()</code>). This may be changed in a
  93. * future revision to perform a deep copy if new parameters are added
  94. * that should not be shared.
  95. *
  96. * @return the copy
  97. */
  98. public Object clone() {
  99. try {
  100. return super.clone();
  101. } catch (CloneNotSupportedException e) {
  102. /* Cannot happen */
  103. throw new InternalError(e.toString());
  104. }
  105. }
  106. /**
  107. * Returns a formatted string describing the parameters.
  108. *
  109. * @return a formatted string describing the parameters
  110. */
  111. public String toString() {
  112. StringBuffer sb = new StringBuffer();
  113. sb.append("LDAPCertStoreParameters: [\n");
  114. sb.append(" serverName: " + serverName + "\n");
  115. sb.append(" port: " + port + "\n");
  116. sb.append("]");
  117. return sb.toString();
  118. }
  119. }