public class AuthToken extends Object implements Serializable
AuthToken
class represents an authorization token and encapsulates information about the authorization
scheme and its associated value.
An AuthToken consists of the following components:
Modifier and Type | Field and Description |
---|---|
static String |
BASIC_SCHEME |
static String |
BEARER_SCHEME |
Modifier and Type | Method and Description |
---|---|
static AuthToken |
createBasicToken(String userPassword)
Constructs an
AuthToken with the specified username and password per RFC2617. |
static AuthToken |
createBasicToken(String user,
String password)
Constructs an
AuthToken with the specified username and password per RFC2617. |
static AuthToken |
createBasicTokenOrNull(String user,
String password)
Constructs an
AuthToken with the specified username and password per RFC2617. |
static AuthToken |
createBearerToken(String token)
Constructs an
AuthToken with the specified bearer token per RFC6750. |
static AuthToken |
createBearerTokenOrNull(String token)
Constructs an
AuthToken with the specified bearer token per RFC6750. |
static AuthToken |
createCustomToken(String scheme,
String value)
Constructs an
AuthToken with a custom scheme and value. |
boolean |
equals(Object o) |
String |
getHttpAuthorization()
Returns the HTTP authorization header value.
|
String |
getPassword()
Returns the password or
null if it is not known or applicable. |
String |
getScheme()
Returns the authentication scheme.
|
String |
getUser()
Returns the username or
null if it is not known or applicable. |
String |
getValue()
Returns the access token for RFC6750 or the Base64-encoded "username:password" for RFC2617.
|
int |
hashCode() |
String |
toString() |
static AuthToken |
valueOf(String string)
Constructs an
AuthToken from the specified string. |
public static final String BASIC_SCHEME
public static final String BEARER_SCHEME
public static AuthToken valueOf(String string)
AuthToken
from the specified string.string
- the string with space-separated scheme and valueAuthToken
NullPointerException
- if the specified string is nullInvalidFormatException
- if the string is malformed, or if the scheme is "Basic" but the format does not comply with RFC2617toString()
public static AuthToken createBasicToken(String userPassword)
AuthToken
with the specified username and password per RFC2617.
Username and password can be empty.userPassword
- the string containing the username and password in the format "username:password"AuthToken
NullPointerException
- if the userPassword is nullInvalidFormatException
- if the userPassword is malformedpublic static AuthToken createBasicToken(String user, String password)
AuthToken
with the specified username and password per RFC2617.
Username and password can be empty.user
- the usernamepassword
- the passwordAuthToken
NullPointerException
- if either the username or password is nullpublic static AuthToken createBasicTokenOrNull(String user, String password)
AuthToken
with the specified username and password per RFC2617.
If both the username and password are empty or null
, returns null
.user
- the usernamepassword
- the passwordAuthToken
or null
public static AuthToken createBearerToken(String token)
AuthToken
with the specified bearer token per RFC6750.token
- the access tokenAuthToken
NullPointerException
- if the token is nullInvalidFormatException
- if the token is emptypublic static AuthToken createBearerTokenOrNull(String token)
AuthToken
with the specified bearer token per RFC6750.token
- the access tokenAuthToken
or null
public static AuthToken createCustomToken(String scheme, String value)
AuthToken
with a custom scheme and value.scheme
- the custom schemevalue
- the custom valueAuthToken
NullPointerException
- if either the scheme or value is nullInvalidFormatException
- if the scheme or value is emptypublic String getHttpAuthorization()
public String getUser()
null
if it is not known or applicable.null
if not known or applicablepublic String getPassword()
null
if it is not known or applicable.null
if not known or applicablepublic String getScheme()
public String getValue()
Copyright © 2002–2025 Devexperts LLC. All rights reserved.