001    /*
002     * Copyright 2012 UnboundID Corp.
003     *
004     * This program is free software; you can redistribute it and/or modify
005     * it under the terms of the GNU General Public License (GPLv2 only)
006     * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
007     * as published by the Free Software Foundation.
008     *
009     * This program is distributed in the hope that it will be useful,
010     * but WITHOUT ANY WARRANTY; without even the implied warranty of
011     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012     * GNU General Public License for more details.
013     *
014     * You should have received a copy of the GNU General Public License
015     * along with this program; if not, see <http://www.gnu.org/licenses>.
016     */
017    package com.unboundid.scim.sdk;
018    
019    /**
020     * This class is a holder for OAuth token types.
021     */
022    public class OAuthToken {
023      /**
024       * This enum defines the supported set of OAuth token types.
025       */
026      public enum Type {
027        /**
028         * OAuth 1.0 token type.
029         */
030        OAuth,
031        /**
032         * OAuth bearer token type.
033         */
034        Bearer
035      }
036    
037      /**
038       * The OAuth token type.
039       */
040      private volatile Type type;
041    
042      /**
043       * The OAuth token value.
044       */
045      private volatile String tokenValue;
046    
047      /**
048       * Constructs a fully initialized OAuthToken of the Bearer variety.
049       * @param tokenValue The OAuth token value.
050       */
051      public OAuthToken(final String tokenValue) {
052        this(Type.Bearer, tokenValue);
053      }
054    
055      /**
056       * Constructs a fully initialized OAuthToken.
057       * @param type The token Type.
058       * @param tokenValue The OAuth token value.
059       */
060      public OAuthToken(final Type type, final String tokenValue) {
061        this.type=type;
062        this.tokenValue=tokenValue;
063      }
064    
065      /**
066       * Returns the token type.
067       * @return  Get the token type.
068       */
069      public Type getType() {
070        return type;
071      }
072    
073      /**
074       * Returns the token value.
075       * @return Get the token value.
076       */
077      public String getTokenValue() {
078        return tokenValue;
079      }
080    
081      /**
082       * Returns a formatted representation of the token type and value for use as
083       * an Authorization header value.
084       * @return the token type and value in HTTP header value form.
085       */
086      public String getFormattedValue() {
087        return getType().name() + " " + getTokenValue();
088      }
089    }