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 {@link Scope} token. This class is immutable. 011 * 012 * @author Vladimir Dzhuvinov 013 * @version $version$ (2013-01-21) 014 */ 015 @Immutable 016 public class ScopeToken extends Identifier { 017 018 019 /** 020 * Enumeration of the {@link ScopeToken scope token} requirements 021 * for application-specific authorisation requests. 022 */ 023 public static enum Requirement { 024 025 /** 026 * The token must be present in the {@link Scope} parameter. 027 */ 028 REQUIRED, 029 030 031 /** 032 * The token may be optionally included in the {@link Scope} 033 * parameter. 034 */ 035 OPTIONAL 036 } 037 038 039 /** 040 * Optional requirement. 041 */ 042 private final ScopeToken.Requirement requirement; 043 044 045 /** 046 * Creates a new scope token with the specified value. The requirement 047 * is not specified. 048 * 049 * @param value The scope token value. Must not be {@code null} or 050 * empty string. 051 */ 052 public ScopeToken(final String value) { 053 054 this(value, null); 055 } 056 057 058 /** 059 * Creates a new scope token with the specified value and optional 060 * requirement. 061 * 062 * @param value The scope token value. Must not be {@code null} 063 * or empty string. 064 * @param requirement The requirement, {@code null} if not specified. 065 */ 066 public ScopeToken(final String value, final ScopeToken.Requirement requirement) { 067 068 super(value); 069 070 this.requirement = requirement; 071 } 072 073 074 /** 075 * Gets the requirement of this scope token. 076 * 077 * @return The requirement, {@code null} if not specified. 078 */ 079 public Requirement getRequirement() { 080 081 return requirement; 082 } 083 084 085 @Override 086 public boolean equals(final Object object) { 087 088 return object != null && 089 object instanceof ScopeToken && 090 this.toString().equals(object.toString()); 091 } 092 }