001    /*
002     * Copyright 2011-2016 UnboundID Corp.
003     * All Rights Reserved.
004     */
005    /*
006     * Copyright (C) 2011-2016 UnboundID Corp.
007     *
008     * This program is free software; you can redistribute it and/or modify
009     * it under the terms of the GNU General Public License (GPLv2 only)
010     * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011     * as published by the Free Software Foundation.
012     *
013     * This program is distributed in the hope that it will be useful,
014     * but WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016     * GNU General Public License for more details.
017     *
018     * You should have received a copy of the GNU General Public License
019     * along with this program; if not, see <http://www.gnu.org/licenses>.
020     */
021    package com.unboundid.ldap.listener;
022    
023    
024    
025    import java.util.List;
026    
027    import com.unboundid.asn1.ASN1OctetString;
028    import com.unboundid.ldap.sdk.BindResult;
029    import com.unboundid.ldap.sdk.Control;
030    import com.unboundid.ldap.sdk.DN;
031    import com.unboundid.util.Extensible;
032    import com.unboundid.util.ThreadSafety;
033    import com.unboundid.util.ThreadSafetyLevel;
034    
035    
036    
037    /**
038     * This class defines an API that may be used to provide support for a specified
039     * SASL mechanism in the in-memory directory server.
040     */
041    @Extensible()
042    @ThreadSafety(level=ThreadSafetyLevel.INTERFACE_NOT_THREADSAFE)
043    public abstract class InMemorySASLBindHandler
044    {
045      /**
046       * Retrieves the name of the SASL mechanism supported by this bind handler.
047       *
048       * @return  The name of the SASL mechanism supported by this bind handler.
049       */
050      public abstract String getSASLMechanismName();
051    
052    
053    
054      /**
055       * Performs the appropriate processing for a SASL bind request with the
056       * provided information.
057       * <BR><BR>
058       * If the bind processing is successful, then this method should also call
059       * {@link InMemoryRequestHandler#setAuthenticatedDN(DN)} on the provided
060       * request handler instance to set the identity of the authenticated user.
061       * <BR><BR>
062       * If the associated SASL mechanism requires multiple stages of processing
063       * and it is necessary to store and retrieve state information to use in other
064       * stages of the bind processing, then the map returned by the
065       * {@link InMemoryRequestHandler#getConnectionState()} method should be used
066       * for this purpose.
067       *
068       * @param  handler      The in-memory request handler that accepted the bind
069       *                      request.
070       * @param  messageID    The message ID for the LDAP message that the client
071       *                      used to send the request.
072       * @param  bindDN       The bind DN provided by the client.
073       * @param  credentials  The SASL credentials provided by the client, or
074       *                      {@code null} if there were none.
075       * @param  controls     The request controls provided by the client.
076       *
077       * @return  The result that should be returned to the client in response to
078       *          the provided request.
079       */
080      public abstract BindResult processSASLBind(
081                                      final InMemoryRequestHandler handler,
082                                      final int messageID, final DN bindDN,
083                                      final ASN1OctetString credentials,
084                                      final List<Control> controls);
085    
086    
087    
088      /**
089       * Retrieves a string representation of this SASL bind handler.
090       *
091       * @return  A string representation of this SASL bind handler.
092       */
093      @Override()
094      public String toString()
095      {
096        return "InMemorySASLBindHandler(mechanismName='" + getSASLMechanismName() +
097             ')';
098      }
099    }