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