public class SignedToken extends Object
token := encoded-payload "." signature encoded-payload := BASE64(UTF8(payload)) signature := BASE64(HMAC-SHA256(encoded-payload, UTF8(secret))) payload := issuer "," subject "," not-before-time "," expiration-time "," issued-at-time "," messagewhere:
secret
- key used for signature validationissuer
- identifies principal that issued this tokensubject
- identifies subject of this tokennot-before-time
- time after which token will start to be validexpiration-time
- expiration time of the token, after which token will not be validissued-at-time
- time at which this token was issuedmessage
- any stringModifier and Type | Class and Description |
---|---|
static class |
SignedToken.Builder |
Modifier and Type | Field and Description |
---|---|
static String |
MAC_ALGORITHM
MAC algorithm used for signing is "HMAC-SHA256".
|
static String |
MAC_CHARSET
Charset used for string encoding is "UTF-8".
|
Modifier | Constructor and Description |
---|---|
protected |
SignedToken(String issuer,
String subject,
String message,
Instant notBefore,
Instant expiration,
Instant issuedAt,
String rawToken) |
public static final String MAC_ALGORITHM
public static final String MAC_CHARSET
public static SignedToken valueOf(String token)
public static SignedToken.Builder newBuilder()
public static SignedToken.Builder newBuilder(String issuer, String subject, Instant expiration)
public static SignedToken.Builder newBuilder(String issuer, String subject, TemporalAmount amount)
public String getIssuer()
public String getSubject()
public String getMessage()
public Instant getNotBefore()
public Instant getIssuedAt()
public Instant getExpiration()
public boolean isIssuedBefore(SignedToken token)
public String signToken(String secret)
@Deprecated public boolean verifyToken(String secret)
verifySignature(java.lang.String)
and verifyTime(java.time.Instant)
instead@Deprecated public boolean verifyToken(String secret, Instant now)
verifySignature(java.lang.String)
and verifyTime(java.time.Instant)
insteadpublic boolean verifySignature(String secret)
secret
- a secret to sign tokenpublic boolean verifyTime(Instant time)
time
- time to check if token is active atCopyright © 2023 Devexperts. All rights reserved.