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