001    package com.nimbusds.oauth2.sdk;
002    
003    
004    import net.jcip.annotations.Immutable;
005    
006    import com.nimbusds.oauth2.sdk.id.Identifier;
007    
008    
009    /**
010     * Authorisation code. A maximum authorization code lifetime of 10 minutes is 
011     * recommended. This class is immutable.
012     *
013     * <p>Related specifications:
014     *
015     * <ul>
016     *     <li>OAuth 2.0 (RFC 6749), section 1.3.1.
017     * </ul>
018     *
019     * @author Vladimir Dzhuvinov
020     */
021    @Immutable
022    public final class AuthorizationCode extends Identifier {
023    
024    
025            /**
026             * Creates a new authorisation code with the specified value.
027             *
028             * @param value The code value. Must not be {@code null} or empty 
029             *              string.
030             */
031            public AuthorizationCode(final String value) {
032            
033                    super(value);
034            }
035    
036    
037            /**
038             * Creates a new authorisation code with a randomly generated value of 
039             * the specified length. The value will be made up of mixed-case 
040             * alphanumeric ASCII characters.
041             *
042             * @param length The number of characters. Must be a positive integer.
043             */
044            public AuthorizationCode(final int length) {
045            
046                    super(length);
047            }
048            
049            
050            /**
051             * Creates a new authorisation code with a randomly generated value. 
052             * The value will be made up of 32 mixed-case alphanumeric ASCII 
053             * characters.
054             */
055            public AuthorizationCode() {
056    
057                    super();
058            }
059            
060            
061            @Override
062            public boolean equals(final Object object) {
063            
064                    return object != null && 
065                           object instanceof AuthorizationCode && 
066                           this.toString().equals(object.toString());
067            }
068    }