Package com.nimbusds.oauth2.sdk.device
Class UserCode
- java.lang.Object
-
- com.nimbusds.oauth2.sdk.id.Identifier
-
- com.nimbusds.oauth2.sdk.device.UserCode
-
- All Implemented Interfaces:
Serializable,Comparable<Identifier>,net.minidev.json.JSONAware
@Immutable public final class UserCode extends Identifier
User code.Related specifications:
- OAuth 2.0 Device Authorization Grant (draft-ietf-oauth-device-flow-15)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringDIGIT_CHAR_SETstatic StringLETTER_CHAR_SET-
Fields inherited from class com.nimbusds.oauth2.sdk.id.Identifier
DEFAULT_BYTE_LENGTH, secureRandom
-
-
Constructor Summary
Constructors Constructor Description UserCode()Creates a new user code with a randomly generated value with 8 characters fromLETTER_CHAR_SET, in the formWDJB-MJHT.UserCode(String value)Creates a new user code with the specified value and theLETTER_CHAR_SET.UserCode(String charset, int length)Creates a new user code with a randomly generated value from the specified charset and length.UserCode(String value, String charset)Creates a new user code with the specified value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(Identifier other)booleanequals(Object object)StringgetCharset()Returns the character set used by thisUserCode.StringgetStrippedValue()Returns the value with all invalid characters removed.inthashCode()static StringstripIllegalChars(String value, String charset)Removes all characters fromvaluethat are not incharset.-
Methods inherited from class com.nimbusds.oauth2.sdk.id.Identifier
getValue, toJSONString, toString, toStringList
-
-
-
-
Field Detail
-
LETTER_CHAR_SET
public static final String LETTER_CHAR_SET
- See Also:
- Constant Field Values
-
DIGIT_CHAR_SET
public static final String DIGIT_CHAR_SET
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
UserCode
public UserCode(String value, String charset)
Creates a new user code with the specified value.- Parameters:
value- The code value. Must not benullor empty string.charset- The character set used by the identifier. The identifier can only contain characters from this set. Ifnull, all characters are allowed.
-
UserCode
public UserCode(String value)
Creates a new user code with the specified value and theLETTER_CHAR_SET.- Parameters:
value- The code value. Must not benullor empty string.
-
UserCode
public UserCode()
Creates a new user code with a randomly generated value with 8 characters fromLETTER_CHAR_SET, in the formWDJB-MJHT.
-
-
Method Detail
-
getCharset
public String getCharset()
Returns the character set used by thisUserCode.- Returns:
- The character set, or
nullif unspecified.
-
getStrippedValue
public String getStrippedValue()
Returns the value with all invalid characters removed.- Returns:
- The value with all invalid characters removed.
-
compareTo
public int compareTo(Identifier other)
- Specified by:
compareToin interfaceComparable<Identifier>- Overrides:
compareToin classIdentifier
-
hashCode
public int hashCode()
- Overrides:
hashCodein classIdentifier
-
equals
public boolean equals(Object object)
- Overrides:
equalsin classIdentifier
-
stripIllegalChars
public static String stripIllegalChars(String value, String charset)
Removes all characters fromvaluethat are not incharset.- Parameters:
value- The code value.charset- The allowed characters invalue. Ifnullall characters are retained.- Returns:
- The
valuewith all invalid characters removed.
-
-