1. /*
  2. * @(#)SaslClientFactory.java 1.15 04/05/05
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.security.sasl;
  8. import java.util.Map;
  9. import javax.security.auth.callback.CallbackHandler;
  10. /**
  11. * An interface for creating instances of <tt>SaslClient</tt>.
  12. * A class that implements this interface
  13. * must be thread-safe and handle multiple simultaneous
  14. * requests. It must also have a public constructor that accepts no
  15. * argument.
  16. *<p>
  17. * This interface is not normally accessed directly by a client, which will use the
  18. * <tt>Sasl</tt> static methods
  19. * instead. However, a particular environment may provide and install a
  20. * new or different <tt>SaslClientFactory</tt>.
  21. *
  22. * @since 1.5
  23. *
  24. * @see SaslClient
  25. * @see Sasl
  26. *
  27. * @author Rosanna Lee
  28. * @author Rob Weltman
  29. */
  30. public abstract interface SaslClientFactory {
  31. /**
  32. * Creates a SaslClient using the parameters supplied.
  33. *
  34. * @param mechanisms The non-null list of mechanism names to try. Each is the
  35. * IANA-registered name of a SASL mechanism. (e.g. "GSSAPI", "CRAM-MD5").
  36. * @param authorizationId The possibly null protocol-dependent
  37. * identification to be used for authorization.
  38. * If null or empty, the server derives an authorization
  39. * ID from the client's authentication credentials.
  40. * When the SASL authentication completes successfully,
  41. * the specified entity is granted access.
  42. * @param protocol The non-null string name of the protocol for which
  43. * the authentication is being performed (e.g., "ldap").
  44. * @param serverName The non-null fully qualified host name
  45. * of the server to authenticate to.
  46. * @param props The possibly null set of properties used to select the SASL
  47. * mechanism and to configure the authentication exchange of the selected
  48. * mechanism. See the <tt>Sasl</tt> class for a list of standard properties.
  49. * Other, possibly mechanism-specific, properties can be included.
  50. * Properties not relevant to the selected mechanism are ignored.
  51. *
  52. * @param cbh The possibly null callback handler to used by the SASL
  53. * mechanisms to get further information from the application/library
  54. * to complete the authentication. For example, a SASL mechanism might
  55. * require the authentication ID, password and realm from the caller.
  56. * The authentication ID is requested by using a <tt>NameCallback</tt>.
  57. * The password is requested by using a <tt>PasswordCallback</tt>.
  58. * The realm is requested by using a <tt>RealmChoiceCallback</tt> if there is a list
  59. * of realms to choose from, and by using a <tt>RealmCallback</tt> if
  60. * the realm must be entered.
  61. *
  62. *@return A possibly null <tt>SaslClient</tt> created using the parameters
  63. * supplied. If null, this factory cannot produce a <tt>SaslClient</tt>
  64. * using the parameters supplied.
  65. *@exception SaslException If cannot create a <tt>SaslClient</tt> because
  66. * of an error.
  67. */
  68. public abstract SaslClient createSaslClient(
  69. String[] mechanisms,
  70. String authorizationId,
  71. String protocol,
  72. String serverName,
  73. Map<String,?> props,
  74. CallbackHandler cbh) throws SaslException;
  75. /**
  76. * Returns an array of names of mechanisms that match the specified
  77. * mechanism selection policies.
  78. * @param props The possibly null set of properties used to specify the
  79. * security policy of the SASL mechanisms. For example, if <tt>props</tt>
  80. * contains the <tt>Sasl.POLICY_NOPLAINTEXT</tt> property with the value
  81. * <tt>"true"</tt>, then the factory must not return any SASL mechanisms
  82. * that are susceptible to simple plain passive attacks.
  83. * See the <tt>Sasl</tt> class for a complete list of policy properties.
  84. * Non-policy related properties, if present in <tt>props</tt>, are ignored.
  85. * @return A non-null array containing a IANA-registered SASL mechanism names.
  86. */
  87. public abstract String[] getMechanismNames(Map<String,?> props);
  88. }