Class ClaimsSet
- java.lang.Object
-
- com.nimbusds.openid.connect.sdk.claims.ClaimsSet
-
- All Implemented Interfaces:
net.minidev.json.JSONAware
- Direct Known Subclasses:
Address,Birthplace,IDTokenClaimsSet,LogoutTokenClaimsSet,PersonClaims
public class ClaimsSet extends Object implements net.minidev.json.JSONAware
Claims set with basic getters and setters, serialisable to a JSON object.
-
-
Field Summary
Fields Modifier and Type Field Description static StringAUD_CLAIM_NAMEThe audience claim name.protected net.minidev.json.JSONObjectclaimsThe JSON object representation of the claims set.static StringISS_CLAIM_NAMEThe issuer claim name.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description List<Audience>getAudience()Gets the audience.BooleangetBooleanClaim(String name)Gets a boolean-based claim.ObjectgetClaim(String name)Gets a claim.<T> TgetClaim(String name, Class<T> clazz)Gets a claim that casts to the specified class.DategetDateClaim(String name)Gets a date / time based claim, represented as the number of seconds from 1970-01-01T0:0:0Z as measured in UTC until the date / time.javax.mail.internet.InternetAddressgetEmailClaim(String name)Deprecated.IssuergetIssuer()Gets the issuer.<T> Map<com.nimbusds.langtag.LangTag,T>getLangTaggedClaim(String name, Class<T> clazz)Returns a map of all instances, including language-tagged, of a claim with the specified base name.NumbergetNumberClaim(String name)Gets a number-based claim.static Set<String>getStandardClaimNames()Gets the names of the standard top-level claims.StringgetStringClaim(String name)Gets a string-based claim.StringgetStringClaim(String name, com.nimbusds.langtag.LangTag langTag)Gets a string-based claim with an optional language tag.List<String>getStringListClaim(String name)Gets a string list based claim.URIgetURIClaim(String name)Gets an URI string based claim.URLgetURLClaim(String name)Gets an URL string based claim.voidputAll(ClaimsSet other)Puts all claims from the specified other claims set.voidputAll(Map<String,Object> claims)Puts all claims from the specified map.voidsetAudience(Audience aud)Sets the audience.voidsetAudience(List<Audience> audList)Sets the audience list.voidsetClaim(String name, Object value)Sets a claim.voidsetClaim(String name, Object value, com.nimbusds.langtag.LangTag langTag)Sets a claim with an optional language tag.voidsetDateClaim(String name, Date value)Sets a date / time based claim, represented as the number of seconds from 1970-01-01T0:0:0Z as measured in UTC until the date / time.voidsetEmailClaim(String name, javax.mail.internet.InternetAddress value)Deprecated.voidsetIssuer(Issuer iss)Sets the issuer.voidsetURIClaim(String name, URI value)Sets an URI string based claim.voidsetURLClaim(String name, URL value)Sets an URL string based claim.net.minidev.json.JSONObjecttoJSONObject()Gets the JSON object representation of this claims set.StringtoJSONString()com.nimbusds.jwt.JWTClaimsSettoJWTClaimsSet()Gets the JSON Web Token (JWT) claims set for this claim set.
-
-
-
Field Detail
-
ISS_CLAIM_NAME
public static final String ISS_CLAIM_NAME
The issuer claim name.- See Also:
- Constant Field Values
-
AUD_CLAIM_NAME
public static final String AUD_CLAIM_NAME
The audience claim name.- See Also:
- Constant Field Values
-
claims
protected final net.minidev.json.JSONObject claims
The JSON object representation of the claims set.
-
-
Method Detail
-
getStandardClaimNames
public static Set<String> getStandardClaimNames()
Gets the names of the standard top-level claims.- Returns:
- The names of the standard top-level claims (read-only set).
-
putAll
public void putAll(ClaimsSet other)
Puts all claims from the specified other claims set.- Parameters:
other- The other claims set. Must not benull.
-
putAll
public void putAll(Map<String,Object> claims)
Puts all claims from the specified map.- Parameters:
claims- The claims to put. Must not benull.
-
getClaim
public Object getClaim(String name)
Gets a claim.- Parameters:
name- The claim name. Must not benull.- Returns:
- The claim value,
nullif not specified.
-
getClaim
public <T> T getClaim(String name, Class<T> clazz)
Gets a claim that casts to the specified class.- Parameters:
name- The claim name. Must not benull.clazz- The Java class that the claim value should cast to. Must not benull.- Returns:
- The claim value,
nullif not specified or casting failed.
-
getLangTaggedClaim
public <T> Map<com.nimbusds.langtag.LangTag,T> getLangTaggedClaim(String name, Class<T> clazz)
Returns a map of all instances, including language-tagged, of a claim with the specified base name.Example JSON serialised claims set:
{ "month" : "January", "month#de" : "Januar" "month#es" : "enero", "month#it" : "gennaio" }The "month" claim instances as java.util.Map:
null = "January" (no language tag) "de" = "Januar" "es" = "enero" "it" = "gennaio"
- Parameters:
name- The claim name. Must not benull.clazz- The Java class that the claim values should cast to. Must not benull.- Returns:
- The matching language-tagged claim values, empty map if
none. A
nullkey indicates the value has no language tag (corresponds to the base name).
-
setClaim
public void setClaim(String name, Object value)
Sets a claim.- Parameters:
name- The claim name, with an optional language tag. Must not benull.value- The claim value. Should serialise to a JSON entity. Ifnullany existing claim with the same name will be removed.
-
setClaim
public void setClaim(String name, Object value, com.nimbusds.langtag.LangTag langTag)
Sets a claim with an optional language tag.- Parameters:
name- The claim name. Must not benull.value- The claim value. Should serialise to a JSON entity. Ifnullany existing claim with the same name and language tag (if any) will be removed.langTag- The language tag of the claim value,nullif not tagged.
-
getStringClaim
public String getStringClaim(String name)
Gets a string-based claim.- Parameters:
name- The claim name. Must not benull.- Returns:
- The claim value,
nullif not specified or casting failed.
-
getStringClaim
public String getStringClaim(String name, com.nimbusds.langtag.LangTag langTag)
Gets a string-based claim with an optional language tag.- Parameters:
name- The claim name. Must not benull.langTag- The language tag of the claim value,nullto get the non-tagged value.- Returns:
- The claim value,
nullif not specified or casting failed.
-
getBooleanClaim
public Boolean getBooleanClaim(String name)
Gets a boolean-based claim.- Parameters:
name- The claim name. Must not benull.- Returns:
- The claim value,
nullif not specified or casting failed.
-
getNumberClaim
public Number getNumberClaim(String name)
Gets a number-based claim.- Parameters:
name- The claim name. Must not benull.- Returns:
- The claim value,
nullif not specified or casting failed.
-
getURLClaim
public URL getURLClaim(String name)
Gets an URL string based claim.- Parameters:
name- The claim name. Must not benull.- Returns:
- The claim value,
nullif not specified or parsing failed.
-
setURLClaim
public void setURLClaim(String name, URL value)
Sets an URL string based claim.- Parameters:
name- The claim name. Must not benull.value- The claim value. Ifnullany existing claim with the same name will be removed.
-
getURIClaim
public URI getURIClaim(String name)
Gets an URI string based claim.- Parameters:
name- The claim name. Must not benull.- Returns:
- The claim value,
nullif not specified or parsing failed.
-
setURIClaim
public void setURIClaim(String name, URI value)
Sets an URI string based claim.- Parameters:
name- The claim name. Must not benull.value- The claim value. Ifnullany existing claim with the same name will be removed.
-
getEmailClaim
@Deprecated public javax.mail.internet.InternetAddress getEmailClaim(String name)
Deprecated.Gets an email string based claim.- Parameters:
name- The claim name. Must not benull.- Returns:
- The claim value,
nullif not specified or parsing failed.
-
setEmailClaim
@Deprecated public void setEmailClaim(String name, javax.mail.internet.InternetAddress value)
Deprecated.Sets an email string based claim.- Parameters:
name- The claim name. Must not benull.value- The claim value. Ifnullany existing claim with the same name will be removed.
-
getDateClaim
public Date getDateClaim(String name)
Gets a date / time based claim, represented as the number of seconds from 1970-01-01T0:0:0Z as measured in UTC until the date / time.- Parameters:
name- The claim name. Must not benull.- Returns:
- The claim value,
nullif not specified or parsing failed.
-
setDateClaim
public void setDateClaim(String name, Date value)
Sets a date / time based claim, represented as the number of seconds from 1970-01-01T0:0:0Z as measured in UTC until the date / time.- Parameters:
name- The claim name. Must not benull.value- The claim value. Ifnullany existing claim with the same name will be removed.
-
getStringListClaim
public List<String> getStringListClaim(String name)
Gets a string list based claim.- Parameters:
name- The claim name. Must not benull.- Returns:
- The claim value,
nullif not specified or parsing failed.
-
getIssuer
public Issuer getIssuer()
Gets the issuer. Corresponds to theissclaim.- Returns:
- The issuer,
nullif not specified.
-
setIssuer
public void setIssuer(Issuer iss)
Sets the issuer. Corresponds to theissclaim.- Parameters:
iss- The issuer,nullif not specified.
-
getAudience
public List<Audience> getAudience()
Gets the audience. Corresponds to theaudclaim.- Returns:
- The audience list,
nullif not specified.
-
setAudience
public void setAudience(Audience aud)
Sets the audience. Corresponds to theaudclaim.- Parameters:
aud- The audience,nullif not specified.
-
setAudience
public void setAudience(List<Audience> audList)
Sets the audience list. Corresponds to theaudclaim.- Parameters:
audList- The audience list,nullif not specified.
-
toJSONObject
public net.minidev.json.JSONObject toJSONObject()
Gets the JSON object representation of this claims set.Example:
{ "country" : "USA", "country#en" : "USA", "country#de_DE" : "Vereinigte Staaten", "country#fr_FR" : "Etats Unis" }- Returns:
- The JSON object representation.
-
toJSONString
public String toJSONString()
- Specified by:
toJSONStringin interfacenet.minidev.json.JSONAware
-
toJWTClaimsSet
public com.nimbusds.jwt.JWTClaimsSet toJWTClaimsSet() throws ParseException
Gets the JSON Web Token (JWT) claims set for this claim set.- Returns:
- The JWT claims set.
- Throws:
ParseException- If the conversion to a JWT claims set fails.
-
-