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        private static final long serialVersionUID = 2520352130331160789L;
041        
042        
043        /**
044         * Creates a new minimal typeless access token with the specified 
045         * value. The optional lifetime and scope are left undefined.
046         *
047         * @param value The access token value. Must not be {@code null} or
048         *              empty string.
049         */
050        public TypelessAccessToken(final String value) {
051        
052                super(AccessTokenType.UNKNOWN, value);
053        }
054
055
056        /**
057         * Operation not supported.
058         * 
059         * @throws UnsupportedOperationException Serialisation is not 
060         *                                       supported.
061         */
062        @Override
063        public JSONObject toJSONObject() {
064
065                throw new UnsupportedOperationException("Serialization not supported");
066        }
067        
068        
069        /**
070         * Operation not supported.
071         * 
072         * @throws UnsupportedOperationException Serialisation is not 
073         *                                       supported.
074         */
075        @Override
076        public String toAuthorizationHeader() {
077
078                throw new UnsupportedOperationException("Serialization not supported");
079        }
080        
081        
082        @Override
083        public boolean equals(final Object object) {
084        
085                return object instanceof AccessToken &&
086                       this.toString().equals(object.toString());
087        }
088}