Package org.wildfly.security.http.oidc
Class JsonWebToken
- java.lang.Object
-
- org.wildfly.security.http.oidc.JsonWebToken
-
- Direct Known Subclasses:
AccessToken
,IDToken
public class JsonWebToken extends Object
Representation of a JSON Web Token, as per RFC 7519.- Author:
- Farah Juma
-
-
Field Summary
Fields Modifier and Type Field Description static String
EMAIL
static String
EXP
static String
FAMILY_NAME
static String
GIVEN_NAME
static String
IAT
private org.jose4j.jwt.JwtClaims
jwtClaims
static String
MIDDLE_NAME
static String
NAME
static String
NBF
static String
NICKNAME
static String
PREFERRED_USERNAME
static String
SUB
-
Constructor Summary
Constructors Constructor Description JsonWebToken(org.jose4j.jwt.JwtClaims jwtClaims)
Construct a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description List<String>
getAudience()
Get the audience claim.Set<String>
getClaimNames()
Get the claim names.Object
getClaimValue(String claimName)
Get the value of the given claim.<T> T
getClaimValue(String claimName, Class<T> type)
Get the value of the given claim.(package private) Long
getClaimValueAsLong(String claimName)
String
getClaimValueAsString(String claimName)
Get the value of the given claim.private static int
getCurrentTimeInSeconds()
String
getEmail()
Get the email claim.Long
getExpiration()
Get the expiration claim.String
getFamilyName()
Get the family name claim.String
getGivenName()
Get the given name claim.String
getID()
Get the ID claim.Long
getIssuedAt()
Get the issued at claim.String
getIssuer()
Get the issuer claim.String
getMiddleName()
Get the middle name claim.String
getName()
Get the name claim.String
getNickName()
Get the nick name claim.Long
getNotBefore()
Get the not before claim.String
getPreferredUsername()
Get the preferred username claim.String
getPrincipalName(OidcClientConfiguration deployment)
Get the principal name.List<String>
getStringListClaimValue(String claimName)
Get the value of the given claim as a string list.String
getSubject()
Get the subject claim.boolean
hasClaim(String claimName)
Return whether this token has the given claim.boolean
isActive()
Checks that the token is not expired and isn't prior to the not before time.boolean
isExpired()
Return whether this JWT is expired.boolean
isNotBefore()
Return whether the current time is greater than or equal to the value of the not before claim.static jakarta.json.JsonObject
replaceMap(Map<String,Object> map)
private static jakarta.json.JsonArray
toJsonArray(Collection<?> collection)
static jakarta.json.JsonValue
wrapValue(Object value)
-
-
-
Field Detail
-
EMAIL
public static final String EMAIL
- See Also:
- Constant Field Values
-
EXP
public static final String EXP
- See Also:
- Constant Field Values
-
FAMILY_NAME
public static final String FAMILY_NAME
- See Also:
- Constant Field Values
-
GIVEN_NAME
public static final String GIVEN_NAME
- See Also:
- Constant Field Values
-
IAT
public static final String IAT
- See Also:
- Constant Field Values
-
MIDDLE_NAME
public static final String MIDDLE_NAME
- See Also:
- Constant Field Values
-
NAME
public static final String NAME
- See Also:
- Constant Field Values
-
NICKNAME
public static final String NICKNAME
- See Also:
- Constant Field Values
-
NBF
public static final String NBF
- See Also:
- Constant Field Values
-
PREFERRED_USERNAME
public static final String PREFERRED_USERNAME
- See Also:
- Constant Field Values
-
SUB
public static final String SUB
- See Also:
- Constant Field Values
-
jwtClaims
private final org.jose4j.jwt.JwtClaims jwtClaims
-
-
Method Detail
-
getIssuer
public String getIssuer()
Get the issuer claim.- Returns:
- the issuer claim
- Throws:
IllegalArgumentException
- if the issuer claim is malformed
-
getSubject
public String getSubject()
Get the subject claim.- Returns:
- the subject claim
- Throws:
IllegalArgumentException
- if the subject claim is malformed
-
getAudience
public List<String> getAudience()
Get the audience claim.- Returns:
- the audience claim
- Throws:
IllegalArgumentException
- if the audience claim is malformed
-
getExpiration
public Long getExpiration()
Get the expiration claim.- Returns:
- the expiration claim
- Throws:
IllegalArgumentException
- if the expiration claim is malformed
-
isExpired
public boolean isExpired()
Return whether this JWT is expired.- Returns:
true
if this JWT is expired andfalse
otherwise- Throws:
IllegalArgumentException
- if the issuer claim is malformed
-
getNotBefore
public Long getNotBefore()
Get the not before claim.- Returns:
- the not before claim
- Throws:
IllegalArgumentException
- if the not before claim is malformed
-
isNotBefore
public boolean isNotBefore()
Return whether the current time is greater than or equal to the value of the not before claim.- Returns:
true
if the not before claim is null or if the current time is greater than or equal to the value of the not before claim andfalse
otherwise- Throws:
IllegalArgumentException
- if the not before claim is malformed
-
isActive
public boolean isActive()
Checks that the token is not expired and isn't prior to the not before time.- Returns:
true
if the token is active andfalse
otherwise
-
getIssuedAt
public Long getIssuedAt()
Get the issued at claim.- Returns:
- the issued at claim
- Throws:
IllegalArgumentException
- if the issued at claim is malformed
-
getID
public String getID()
Get the ID claim.- Returns:
- the ID claim
- Throws:
IllegalArgumentException
- if the ID claim is malformed
-
hasClaim
public boolean hasClaim(String claimName)
Return whether this token has the given claim.- Parameters:
claimName
- the claim name to check- Returns:
true
if this token has the given claim andfalse
otherwise
-
getClaimValue
public Object getClaimValue(String claimName)
Get the value of the given claim.- Parameters:
claimName
- the claim to retrieve- Returns:
- the value of the given claim
-
getClaimValue
public <T> T getClaimValue(String claimName, Class<T> type)
Get the value of the given claim.- Type Parameters:
T
- the type of the value- Parameters:
claimName
- the claim to retrievetype
- the type that should be returned- Returns:
- the value of the given claim
- Throws:
IllegalArgumentException
- if the claim is malformed
-
getClaimValueAsString
public String getClaimValueAsString(String claimName)
Get the value of the given claim.- Parameters:
claimName
- the claim to retrieve- Returns:
- the value of the given claim as a string
-
getStringListClaimValue
public List<String> getStringListClaimValue(String claimName)
Get the value of the given claim as a string list.- Parameters:
claimName
- the claim to retrieve- Returns:
- the value of the given claim as a string list
-
getName
public String getName()
Get the name claim.- Returns:
- the name claim
-
getPrincipalName
public String getPrincipalName(OidcClientConfiguration deployment)
Get the principal name.- Parameters:
deployment
- the OIDC client configuration that should be used to determine the principal- Returns:
- the principal name
-
getGivenName
public String getGivenName()
Get the given name claim.- Returns:
- the given name claim
-
getFamilyName
public String getFamilyName()
Get the family name claim.- Returns:
- the family name claim
-
getMiddleName
public String getMiddleName()
Get the middle name claim.- Returns:
- the middle name claim
-
getNickName
public String getNickName()
Get the nick name claim.- Returns:
- the nick name claim
-
getPreferredUsername
public String getPreferredUsername()
Get the preferred username claim.- Returns:
- the preferred username claim
-
getEmail
public String getEmail()
Get the email claim.- Returns:
- the email claim
-
getCurrentTimeInSeconds
private static int getCurrentTimeInSeconds()
-
wrapValue
public static jakarta.json.JsonValue wrapValue(Object value)
-
toJsonArray
private static jakarta.json.JsonArray toJsonArray(Collection<?> collection)
-
-