001/*
002 * Copyright 2015-2017 UnboundID Corp.
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2015-2017 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 */
021package com.unboundid.ldap.sdk;
022
023
024
025import com.unboundid.asn1.ASN1OctetString;
026import com.unboundid.util.NotExtensible;
027import com.unboundid.util.NotMutable;
028import com.unboundid.util.ThreadSafety;
029import com.unboundid.util.ThreadSafetyLevel;
030
031
032
033/**
034 * This class defines an exception that can be thrown if the server sends a bind
035 * response with a result code other than {@link ResultCode#SUCCESS}, which
036 * indicates that the bind operation did not complete successfully.  This may be
037 * used to obtain access to any server SASL credentials contained in the
038 * non-successful bind result.
039 */
040@NotExtensible()
041@NotMutable()
042@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
043public class LDAPBindException
044       extends LDAPException
045{
046  /**
047   * The serial version UID for this serializable class.
048   */
049  private static final long serialVersionUID = 6545956074186731236L;
050
051
052
053  // The bind result for this exception.
054  private final BindResult bindResult;
055
056
057
058  /**
059   * Creates a new LDAP bind exception from the provided bind result.
060   *
061   * @param  bindResult  The bind result to use to create this exception.
062   */
063  public LDAPBindException(final BindResult bindResult)
064  {
065    super(bindResult);
066
067    this.bindResult = bindResult;
068  }
069
070
071
072  /**
073   * {@inheritDoc}
074   */
075  @Override()
076  public LDAPResult toLDAPResult()
077  {
078    return bindResult;
079  }
080
081
082
083  /**
084   * Retrieves the bind result that was returned by the server.
085   *
086   * @return  The bind result that was returned by the server.
087   */
088  public BindResult getBindResult()
089  {
090    return bindResult;
091  }
092
093
094
095  /**
096   * Retrieves the server SASL credentials included in the bind result, if any.
097   *
098   * @return  The server SASL credentials included in the bind result, or
099   *          {@code null} if the bind result did not include any server SASL
100   *          credentials.
101   */
102  public ASN1OctetString getServerSASLCredentials()
103  {
104    return bindResult.getServerSASLCredentials();
105  }
106}