public final class AuthenticationToken extends Credential
AuthenticationToken()
Modifier and Type | Class and Description |
---|---|
static class |
AuthenticationToken.AuthenticationTokenHolder |
credentialStatus, credentialStatusUpdateTime, credentialUpdateTime
Constructor and Description |
---|
AuthenticationToken(org.joda.time.DateTime credentialUpdateTime,
CredentialStatus credentialStatus,
org.joda.time.DateTime credentialStatusUpdateTime,
org.joda.time.DateTime expiry,
String tokenHash,
String salt)
Create an authentication token.
|
AuthenticationToken(org.joda.time.DateTime credentialUpdateTime,
org.joda.time.DateTime expiry,
String tokenHash,
String salt)
Create an authentication token.
|
AuthenticationToken(org.joda.time.DateTime credentialUpdateTime,
org.joda.time.Duration lifetime,
String tokenHash,
String salt)
Convenience constructor to create a token with an expiry time specified as a duration relative to creation time.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canEqual(Object obj) |
boolean |
equals(Object obj) |
static AuthenticationToken.AuthenticationTokenHolder |
generateAuthenticationToken()
Generates a new authentication token.
|
org.joda.time.DateTime |
getExpiry()
Expiry time.
|
String |
getSalt()
Salt used to hash the token (string).
|
String |
getTokenHash()
Hashed token (string).
|
int |
hashCode() |
boolean |
isValidAt(org.joda.time.DateTime time)
Return if the token is still valid, given a reference time.
|
AuthenticationToken |
withCredentialStatus(CredentialStatus credentialStatus)
Setter for
Credential.getCredentialUpdateTime() . |
AuthenticationToken |
withCredentialStatusUpdateTime(org.joda.time.DateTime credentialStatusUpdateTime)
Setter for
Credential.getCredentialStatusUpdateTime() . |
AuthenticationToken |
withCredentialUpdateTime(org.joda.time.DateTime credentialUpdateTime)
Setter for
Credential.getCredentialUpdateTime() . |
AuthenticationToken |
withExpiry(org.joda.time.DateTime expiry)
Setter for
getExpiry() . |
AuthenticationToken |
withPlaintextToken(String plaintextToken)
Sets a hashed token by hashing the given
plaintextToken with the existing salt. |
AuthenticationToken |
withSalt(String salt)
Setter for
getSalt() . |
AuthenticationToken |
withTokenHash(String tokenHash)
Setter for
getTokenHash() . |
getCredentialStatus, getCredentialStatusUpdateTime, getCredentialUpdateTime, hashCodeSuper, toJson, toString
public AuthenticationToken(@Nonnull org.joda.time.DateTime credentialUpdateTime, @Nonnull CredentialStatus credentialStatus, @Nonnull org.joda.time.DateTime credentialStatusUpdateTime, @Nonnull org.joda.time.DateTime expiry, @Nonnull String tokenHash, @Nonnull String salt)
credentialUpdateTime
- Credential update time.credentialStatus
- Credential status.credentialStatusUpdateTime
- Credential status update time.expiry
- Expiry time (token is valid until and including this time).tokenHash
- Hashed authentication token. Cannot be empty. Must be a hex-encoded string (see
HexString.getHexByteArray(String)
for further requirements on
hex-encoded values). A good value would be, for example, new
Uid().toHexString().salt
- The salt used to hash this authentication token. Cannot be null
, but
can be the empty string. If not empty, must be a hex-encoded string (see HexString.getHexByteArray(String)
for further requirements on non-empty salt
values).public AuthenticationToken(@Nonnull org.joda.time.DateTime credentialUpdateTime, @Nonnull org.joda.time.DateTime expiry, @Nonnull String tokenHash, @Nonnull String salt)
credentialUpdateTime
- Credential update time.expiry
- Expiry time (token is valid until and including this time).tokenHash
- Hashed authentication token. Cannot be empty. Must be a hex-encoded string (see
HexString.getHexByteArray(String)
for further requirements on hex-encoded
values). A good value would be, for example, new Uid().toHexString().salt
- The salt used to hash this authentication token. Cannot be null
, but can be
the empty string. If not empty, must be a hex-encoded string (see HexString.getHexByteArray(String)
for further requirements on non-empty salt
values).public AuthenticationToken(@Nonnull org.joda.time.DateTime credentialUpdateTime, @Nonnull org.joda.time.Duration lifetime, @Nonnull String tokenHash, @Nonnull String salt)
credentialUpdateTime
- Credential update time.lifetime
- Lifetime, counted from 'created'.tokenHash
- Hashed authentication token. Cannot be empty. Must be a hex-encoded string (see
HexString.getHexByteArray(String)
for further requirements on hex-encoded
values). A good value would be, for example, new Uid().toHexString().salt
- The salt used to hash this authentication token. Cannot be null
, but can be
the empty string. If not empty, must be a hex-encoded string (see HexString.getHexByteArray(String)
for further requirements on non-empty salt
values).@Nonnull public static AuthenticationToken.AuthenticationTokenHolder generateAuthenticationToken()
holder object
that contains both the newly created
AuthenticationToken
as well as the token in plaintext that was used in this AuthenticationToken
.
The expiration date of this token will be set approximately 100 years into the future.AuthenticationToken
as well as the plaintext
token.@Nonnull public org.joda.time.DateTime getExpiry()
@Nonnull public String getTokenHash()
@Nonnull public String getSalt()
@Nonnull public AuthenticationToken withExpiry(@Nonnull org.joda.time.DateTime expiry)
getExpiry()
.expiry
- Expiry time.@Nonnull public AuthenticationToken withTokenHash(@Nonnull String tokenHash)
getTokenHash()
.tokenHash
- Hashed token. Must be a hex-encoded string (see HexString.getHexByteArray(String)
for
further requirements on hex-encoded values).@Nonnull public AuthenticationToken withPlaintextToken(@Nonnull String plaintextToken)
plaintextToken
with the existing salt.plaintextToken
- Plaintext token.@Nonnull public AuthenticationToken withSalt(@Nonnull String salt)
getSalt()
.salt
- Salt used to hash the token. Cannot be null
, but can be the empty string. If not empty, must
be a hex-encoded string (see HexString.getHexByteArray(String)
for further requirements on
non-empty salt values).@Nonnull public AuthenticationToken withCredentialUpdateTime(@Nonnull org.joda.time.DateTime credentialUpdateTime)
Credential
Credential.getCredentialUpdateTime()
.withCredentialUpdateTime
in class Credential
credentialUpdateTime
- Update time of the credential.@Nonnull public AuthenticationToken withCredentialStatus(@Nonnull CredentialStatus credentialStatus)
Credential
Credential.getCredentialUpdateTime()
.withCredentialStatus
in class Credential
credentialStatus
- Update time of the credential.@Nonnull public AuthenticationToken withCredentialStatusUpdateTime(@Nonnull org.joda.time.DateTime credentialStatusUpdateTime)
Credential
Credential.getCredentialStatusUpdateTime()
.withCredentialStatusUpdateTime
in class Credential
credentialStatusUpdateTime
- Status update time of the credential.public boolean isValidAt(@Nonnull org.joda.time.DateTime time)
false
is returned, no matter what the reference time is.time
- Reference time (usually 'now').true
if the token is valid at the reference time.public boolean canEqual(@Nonnull Object obj)
canEqual
in class Credential
public boolean equals(@Nullable Object obj)
equals
in class Credential
public int hashCode()
hashCode
in class Credential
Copyright © 2018 TomTom International BV. All rights reserved.