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 (RFC 8628)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
DIGIT_CHAR_SET
static String
LETTER_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 int
compareTo(Identifier other)
boolean
equals(Object object)
String
getCharset()
Returns the character set used by thisUserCode
.String
getStrippedValue()
Returns the value with all invalid characters removed.int
hashCode()
static String
stripIllegalChars(String value, String charset)
Removes all characters fromvalue
that 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 benull
or 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 benull
or 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
.
-
UserCode
public UserCode(String charset, int length)
Creates a new user code with a randomly generated value from the specified charset and length. A dash is added every 4 characters.- Parameters:
charset
- The character set used by the identifier. The identifier will contain characters from this set. Must not benull
or empty string.length
- The length of the value to generate.
-
-
Method Detail
-
getCharset
public String getCharset()
Returns the character set used by thisUserCode
.- Returns:
- The character set, or
null
if 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:
compareTo
in interfaceComparable<Identifier>
- Overrides:
compareTo
in classIdentifier
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classIdentifier
-
equals
public boolean equals(Object object)
- Overrides:
equals
in classIdentifier
-
stripIllegalChars
public static String stripIllegalChars(String value, String charset)
Removes all characters fromvalue
that are not incharset
.- Parameters:
value
- The code value.charset
- The allowed characters invalue
. Ifnull
all characters are retained.- Returns:
- The
value
with all invalid characters removed.
-
-