001/*
002 * oauth2-oidc-sdk
003 *
004 * Copyright 2012-2016, Connect2id Ltd and contributors.
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use
007 * this file except in compliance with the License. You may obtain a copy of the
008 * License at
009 *
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software distributed
013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
015 * specific language governing permissions and limitations under the License.
016 */
017
018package com.nimbusds.oauth2.sdk.token;
019
020
021import net.minidev.json.JSONObject;
022
023import net.jcip.annotations.Immutable;
024
025
026/**
027 * Typeless access token, cannot be serialised. Intended to represent parsed
028 * access tokens which type cannot be inferred.
029 *
030 * <p>Related specifications:
031 *
032 * <ul>
033 *     <li>OAuth 2.0 (RFC 6749), sections 1.4 and 5.1.
034 * </ul>
035 */
036@Immutable
037public class TypelessAccessToken extends AccessToken {
038
039        
040        /**
041         * Creates a new minimal typeless access token with the specified 
042         * value. The optional lifetime and scope are left undefined.
043         *
044         * @param value The access token value. Must not be {@code null} or
045         *              empty string.
046         */
047        public TypelessAccessToken(final String value) {
048        
049                super(AccessTokenType.UNKNOWN, value);
050        }
051
052
053        /**
054         * Operation not supported.
055         * 
056         * @throws UnsupportedOperationException Serialisation is not 
057         *                                       supported.
058         */
059        @Override
060        public JSONObject toJSONObject() {
061
062                throw new UnsupportedOperationException("Serialization not supported");
063        }
064        
065        
066        /**
067         * Operation not supported.
068         * 
069         * @throws UnsupportedOperationException Serialisation is not 
070         *                                       supported.
071         */
072        @Override
073        public String toAuthorizationHeader() {
074
075                throw new UnsupportedOperationException("Serialization not supported");
076        }
077        
078        
079        @Override
080        public boolean equals(final Object object) {
081        
082                return object instanceof AccessToken &&
083                       this.toString().equals(object.toString());
084        }
085}