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;
019
020
021import net.jcip.annotations.Immutable;
022
023import com.nimbusds.oauth2.sdk.id.Identifier;
024
025
026/**
027 * Authorisation code. A maximum authorization code lifetime of 10 minutes is 
028 * recommended.
029 *
030 * <p>Related specifications:
031 *
032 * <ul>
033 *     <li>OAuth 2.0 (RFC 6749), section 1.3.1.
034 * </ul>
035 */
036@Immutable
037public final class AuthorizationCode extends Identifier {
038        
039        
040        private static final long serialVersionUID = 8793105384344282267L;
041        
042        
043        /**
044         * Creates a new authorisation code with the specified value.
045         *
046         * @param value The code value. Must not be {@code null} or empty 
047         *              string.
048         */
049        public AuthorizationCode(final String value) {
050        
051                super(value);
052        }
053
054
055        /**
056         * Creates a new authorisation code with a randomly generated value of 
057         * the specified byte length, Base64URL-encoded.
058         *
059         * @param byteLength The byte length of the value to generate. Must be
060         *                   greater than one.
061         */
062        public AuthorizationCode(final int byteLength) {
063        
064                super(byteLength);
065        }
066        
067        
068        /**
069         * Creates a new authorisation code with a randomly generated 256-bit 
070         * (32-byte) value, Base64URL-encoded.
071         */
072        public AuthorizationCode() {
073
074                super();
075        }
076        
077        
078        @Override
079        public boolean equals(final Object object) {
080        
081                return object instanceof AuthorizationCode &&
082                       this.toString().equals(object.toString());
083        }
084}