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
010 * docs/licenses/cddl.txt
011 * or http://www.opensource.org/licenses/cddl1.php.
012 * See the License for the specific language governing permissions
013 * and limitations under the License.
014 *
015 * When distributing Covered Code, include this CDDL HEADER in each
016 * file and include the License file at
017 * docs/licenses/cddl.txt.  If applicable,
018 * add the following below this CDDL HEADER, with the fields enclosed
019 * by brackets "[]" replaced with your own identifying information:
020 *      Portions Copyright [yyyy] [name of copyright owner]
021 *
022 * CDDL HEADER END
023 *
024 *
025 *      Copyright 2011-2016 UnboundID Corp.
026 */
027
028package com.unboundid.directory.sdk.http.types;
029
030/**
031 * Exception used to indicate authentication failed with an external identity
032 * provider while performing the OAuth 2 flow.
033 */
034public class OAuth2AuthenticationException extends AuthenticationException
035{
036  private static final long serialVersionUID = -5607773387618172057L;
037
038  private final String preservedState;
039
040  /**
041   * Constructs an {@code OAuth2AuthenticationException} with the specified
042   * message and no root cause.
043   *
044   * @param message the detail message
045   * @param preservedState the state preserved during the OAuth 2 flow or
046   *                       {@code null} if not available.
047   */
048  public OAuth2AuthenticationException(final String message,
049                                       final String preservedState)
050  {
051    super(message);
052    this.preservedState = preservedState;
053  }
054
055  /**
056   * Constructs an {@code OAuth2AuthenticationException} with the specified
057   * message and root cause.
058   *
059   * @param message the detail message
060   * @param cause the root cause
061   * @param preservedState the state preserved during the OAuth 2 flow or
062   *                       {@code null} if not available.
063   */
064  public OAuth2AuthenticationException(final String message,
065                                       final Throwable cause,
066                                       final String preservedState)
067  {
068    super(message, cause);
069    this.preservedState = preservedState;
070  }
071
072  /**
073   * Retrieves the state preserved during the OAuth 2 flow.
074   *
075   * @return the state preserved during the OAuth 2 flow or {@code null} if
076   *         not available.
077   */
078  public String getPreservedState()
079  {
080    return preservedState;
081  }
082
083  /**
084   * {@inheritDoc}
085   */
086  @Override
087  public String getErrorCode()
088  {
089    return OAUTH2_ERROR;
090  }
091}