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 StringEMAILstatic StringEXPstatic StringFAMILY_NAMEstatic StringGIVEN_NAMEstatic StringIATprivate org.jose4j.jwt.JwtClaimsjwtClaimsstatic StringMIDDLE_NAMEstatic StringNAMEstatic StringNBFstatic StringNICKNAMEstatic StringPREFERRED_USERNAMEstatic StringSUB
-
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.ObjectgetClaimValue(String claimName)Get the value of the given claim.<T> TgetClaimValue(String claimName, Class<T> type)Get the value of the given claim.(package private) LonggetClaimValueAsLong(String claimName)StringgetClaimValueAsString(String claimName)Get the value of the given claim.private static intgetCurrentTimeInSeconds()StringgetEmail()Get the email claim.LonggetExpiration()Get the expiration claim.StringgetFamilyName()Get the family name claim.StringgetGivenName()Get the given name claim.StringgetID()Get the ID claim.LonggetIssuedAt()Get the issued at claim.StringgetIssuer()Get the issuer claim.StringgetMiddleName()Get the middle name claim.StringgetName()Get the name claim.StringgetNickName()Get the nick name claim.LonggetNotBefore()Get the not before claim.StringgetPreferredUsername()Get the preferred username claim.StringgetPrincipalName(OidcClientConfiguration deployment)Get the principal name.List<String>getStringListClaimValue(String claimName)Get the value of the given claim as a string list.StringgetSubject()Get the subject claim.booleanhasClaim(String claimName)Return whether this token has the given claim.booleanisActive()Checks that the token is not expired and isn't prior to the not before time.booleanisExpired()Return whether this JWT is expired.booleanisNotBefore()Return whether the current time is greater than or equal to the value of the not before claim.static jakarta.json.JsonObjectreplaceMap(Map<String,Object> map)private static jakarta.json.JsonArraytoJsonArray(Collection<?> collection)static jakarta.json.JsonValuewrapValue(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:
trueif this JWT is expired andfalseotherwise- 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:
trueif the not before claim is null or if the current time is greater than or equal to the value of the not before claim andfalseotherwise- 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:
trueif the token is active andfalseotherwise
-
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:
trueif this token has the given claim andfalseotherwise
-
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)
-
-