001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2009 Sun Microsystems, Inc.
025 *      Portions copyright 2012 ForgeRock AS.
026 */
027
028package org.forgerock.opendj.ldap.responses;
029
030import java.util.List;
031
032import org.forgerock.opendj.ldap.ByteString;
033import org.forgerock.opendj.ldap.DecodeException;
034import org.forgerock.opendj.ldap.DecodeOptions;
035import org.forgerock.opendj.ldap.ResultCode;
036import org.forgerock.opendj.ldap.controls.Control;
037import org.forgerock.opendj.ldap.controls.ControlDecoder;
038
039/**
040 * A Bind result indicates the status of the client's request for
041 * authentication.
042 * <p>
043 * A successful Bind operation is indicated by a Bind result with a result code
044 * set to {@link ResultCode#SUCCESS} and can be determined by invoking the
045 * {@link #isSuccess} method.
046 * <p>
047 * The server SASL credentials field is used as part of a SASL-defined bind
048 * mechanism to allow the client to authenticate the server to which it is
049 * communicating, or to perform "challenge-response" authentication. If the
050 * client bound using a form of simple authentication, or the SASL mechanism
051 * does not require the server to return information to the client, then this
052 * field shall not be included in the Bind result.
053 * <p>
054 * If the server requires the client to send a new SASL Bind request in order to
055 * continue the authentication process then the result code is set to
056 * {@link ResultCode#SASL_BIND_IN_PROGRESS} and can be determined by invoking
057 * the {@link #isSASLBindInProgress} method.
058 */
059public interface BindResult extends Result {
060
061    @Override
062    BindResult addControl(Control control);
063
064    @Override
065    BindResult addReferralURI(String uri);
066
067    @Override
068    Throwable getCause();
069
070    @Override
071    <C extends Control> C getControl(ControlDecoder<C> decoder, DecodeOptions options)
072            throws DecodeException;
073
074    @Override
075    List<Control> getControls();
076
077    @Override
078    String getDiagnosticMessage();
079
080    @Override
081    String getMatchedDN();
082
083    @Override
084    List<String> getReferralURIs();
085
086    @Override
087    ResultCode getResultCode();
088
089    /**
090     * Returns the server SASL credentials associated with this bind result.
091     *
092     * @return The server SASL credentials, or {@code null} indicating that none
093     *         was provided.
094     */
095    ByteString getServerSASLCredentials();
096
097    @Override
098    boolean isReferral();
099
100    /**
101     * Indicates whether or not the server requires the client to send a new
102     * SASL Bind request with the same SASL mechanism in order to continue the
103     * authentication process. This typically occurs during multi-stage
104     * (challenge response) authentication.
105     * <p>
106     * Specifically, this method returns {@code true} if the result code is
107     * equal to {@link ResultCode#SASL_BIND_IN_PROGRESS}.
108     *
109     * @return {@code true} if the server requires the client to send a new SASL
110     *         Bind request, otherwise {@code false}.
111     */
112    boolean isSASLBindInProgress();
113
114    @Override
115    boolean isSuccess();
116
117    @Override
118    BindResult setCause(Throwable cause);
119
120    @Override
121    BindResult setDiagnosticMessage(String message);
122
123    @Override
124    BindResult setMatchedDN(String dn);
125
126    @Override
127    BindResult setResultCode(ResultCode resultCode);
128
129    /**
130     * Sets the server SASL credentials associated with this bind result.
131     *
132     * @param credentials
133     *            The server SASL credentials associated with this bind result,
134     *            which may be {@code null} indicating that none was provided.
135     * @return This bind result.
136     * @throws UnsupportedOperationException
137     *             If this bind result does not permit the server SASL
138     *             credentials to be set.
139     */
140    BindResult setServerSASLCredentials(ByteString credentials);
141
142}