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-2014 UnboundID Corp.
026     */
027    
028    package com.unboundid.directory.sdk.http.types;
029    
030    import java.util.Map;
031    import java.util.TreeMap;
032    
033    /**
034     * Base abstract class for all exceptions that result in a HTTP authentication
035     * failure.
036     */
037    public abstract class AuthenticationException extends Exception
038    {
039      /**
040       * Error code used to indicate registration failed because the user account
041       * conflicts with an already existing one.
042       */
043      public static final String RESOURCE_CONFLICT = "resource_conflict";
044    
045      /**
046       * Error code used to indicate authentication failed because policy
047       * denied one or more attributes in the registration data.
048       */
049      public static final String ATTRIBUTE_CREATE_DENIED =
050          "attribute_create_denied";
051    
052      /**
053       * Error code used to indicate authentication failed because registration
054       * request included an invalid registration data.
055       */
056      public static final String INVALID_RESOURCE = "invalid_resource";
057    
058      /**
059       * Error code used to indicate authentication failed because the provided
060       * credentials are not valid.
061       */
062      public static final String BAD_CREDENTIALS = "bad_credentials";
063    
064      /**
065       * Error code used to indicate authentication failed because the user's
066       * credentials have expired.
067       */
068      public static final String CREDENTIALS_EXPIRED = "credentials_expired";
069    
070      /**
071       * Error code used to indicate authentication failed because invalid identity
072       * provider is specified.
073       */
074      public static final String INVALID_IDENTITY_PROVIDER =
075          "invalid_identity_provider";
076    
077      /**
078       * Error code used to indicate authentication failed because the request
079       * included an invalid client ID.
080       */
081      public static final String INVALID_CLIENT = "invalid_client";
082    
083      /**
084       * Error code used to indicate authentication failed because the request
085       * is invalid.
086       */
087      public static final String INVALID_REQUEST = "invalid_request";
088    
089      /**
090       * Error code used to indicate authentication failed due to a internal
091       * error.
092       */
093      public static final String INTERNAL_ERROR = "internal_error";
094    
095      /**
096       * Error code used to indicate authentication failed because the user account
097       * is disabled.
098       */
099      public static final String USER_DISABLED = "user_disabled";
100    
101      /**
102       * Error code used to indicate authentication failed because the user
103       * account is locked.
104       */
105      public static final String USER_LOCKED = "user_locked";
106    
107      /**
108       * Error code used to indicate authentication failed with an external identity
109       * provider while performing the OAuth 2 flow.
110       */
111      public static final String OAUTH2_ERROR = "oauth2_error";
112    
113      private static final long serialVersionUID = 7386070808689343226L;
114    
115      private final Map<String, Object> additionalInformation =
116          new TreeMap<String, Object>();
117    
118      /**
119       * Constructs an {@code AuthenticationException} with the specified message
120       * and no root cause.
121       *
122       * @param message the detail message
123       */
124      public AuthenticationException(final String message)
125      {
126        super(message);
127      }
128    
129      /**
130       * Constructs an {@code AuthenticationException} with the specified message
131       * and root cause.
132       *
133       * @param message the detail message
134       * @param cause the root cause
135       */
136      public AuthenticationException(final String message,
137                                     final Throwable cause)
138      {
139        super(message, cause);
140      }
141    
142      /**
143       * Get any additional information about this exception.
144       *
145       * @return Any additional information, or null.
146       */
147      public Map<String, Object> getAdditionalInformation()
148      {
149        return this.additionalInformation;
150      }
151    
152      /**
153       * Add a piece of additional information about this exception.
154       *
155       * @param key The key.
156       * @param value The value.
157       */
158      public void addAdditionalInformation(final String key,
159                                           final Object value)
160      {
161        this.additionalInformation.put(key, value);
162      }
163    
164      /**
165       * Retrieve the error code associated with this exception.
166       *
167       * @return The error code associated with this exception.
168       */
169      public abstract String getErrorCode();
170    }