001/* SaslServerFactory.java
002   Copyright (C) 2003, 2005, Free Software Foundation, Inc.
003
004This file is part of GNU Classpath.
005
006GNU Classpath is free software; you can redistribute it and/or modify
007it under the terms of the GNU General Public License as published by
008the Free Software Foundation; either version 2, or (at your option)
009any later version.
010
011GNU Classpath is distributed in the hope that it will be useful, but
012WITHOUT ANY WARRANTY; without even the implied warranty of
013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014General Public License for more details.
015
016You should have received a copy of the GNU General Public License
017along with GNU Classpath; see the file COPYING.  If not, write to the
018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
01902110-1301 USA.
020
021Linking this library statically or dynamically with other modules is
022making a combined work based on this library.  Thus, the terms and
023conditions of the GNU General Public License cover the whole
024combination.
025
026As a special exception, the copyright holders of this library give you
027permission to link this library with independent modules to produce an
028executable, regardless of the license terms of these independent
029modules, and to copy and distribute the resulting executable under
030terms of your choice, provided that you also meet, for each linked
031independent module, the terms and conditions of the license of that
032module.  An independent module is a module which is not derived from
033or based on this library.  If you modify this library, you may extend
034this exception to your version of the library, but you are not
035obligated to do so.  If you do not wish to do so, delete this
036exception statement from your version. */
037
038
039package javax.security.sasl;
040
041import java.util.Map;
042
043import javax.security.auth.callback.CallbackHandler;
044
045/**
046 * <p>An interface for creating instances of {@link SaslServer}. A class that
047 * implements this interface must be thread-safe and handle multiple
048 * simultaneous requests. It must also have a public constructor that accepts
049 * no arguments.</p>
050 *
051 * <p>This interface is not normally accessed directly by a server, which will
052 * use the {@link Sasl} static methods to create a {@link SaslServer} instance
053 * instead. However, a particular environment may provide and install a new or
054 * different <code>SaslServerFactory</code>.</p>
055 *
056 * @see SaslServer
057 * @see Sasl
058 *
059 * @since 1.5
060 */
061public interface SaslServerFactory
062{
063
064  /**
065   * Creates a {@link SaslServer} instance using the parameters supplied. It
066   * returns <code>null</code> if no {@link SaslServer} instance can be created
067   * using the parameters supplied. Throws {@link SaslException} if it cannot
068   * create a {@link SaslServer} because of an error.
069   *
070   * @param mechanism the non-null IANA-registered name of a SASL mechanism
071   * (e.g. "GSSAPI", "CRAM-MD5").
072   * @param protocol the non-null string name of the protocol for which the
073   * authentication is being performed (e.g. "ldap").
074   * @param serverName the non-null fully qualified host name of the server to
075   * authenticate to.
076   * @param props the possibly null set of properties used to select the SASL
077   * mechanism and to configure the authentication exchange of the selected
078   * mechanism. See the {@link Sasl} class for a list of standard properties.
079   * Other, possibly mechanism-specific, properties can be included. Properties
080   * not relevant to the selected mechanism are ignored.
081   * @param cbh the possibly null callback handler to used by the SASL
082   * mechanisms to get further information from the application/library to
083   * complete the authentication. For example, a SASL mechanism might require
084   * the authentication ID, password and realm from the caller. The
085   * authentication ID is requested by using a
086   * {@link javax.security.auth.callback.NameCallback}. The password is
087   * requested by using a {@link javax.security.auth.callback.PasswordCallback}.
088   * The realm is requested by using a {@link RealmChoiceCallback} if there is
089   * a list of realms to choose from, and by using a {@link RealmCallback} if
090   * the realm must be entered.
091   * @return a possibly null {@link SaslServer} created using the parameters
092   * supplied. If <code>null</code> is returned, it means that this factory
093   * cannot produce a {@link SaslServer} using the parameters supplied.
094   * @throws SaslException if a SaslServer instance cannot be created because
095   * of an error.
096   */
097  SaslServer createSaslServer(String mechanism, String protocol,
098                              String serverName, Map<String, ?> props,
099                              CallbackHandler cbh)
100    throws SaslException;
101
102  /**
103   * Returns an array of names of mechanisms that match the specified mechanism
104   * selection policies.
105   *
106   * @param props the possibly <code>null</code> set of properties used to
107   * specify the security policy of the SASL mechanisms. For example, if props
108   * contains the {@link Sasl#POLICY_NOPLAINTEXT} property with the value
109   * <code>"true"</code>, then the factory must not return any SASL mechanisms
110   * that are susceptible to simple plain passive attacks. See the {@link Sasl}
111   * class for a complete list of policy properties. Non-policy related
112   * properties, if present in props, are ignored.
113   * @return a non-null array containing IANA-registered SASL mechanism names.
114   */
115  String[] getMechanismNames(Map<String, ?> props);
116}