Class JWTSecret
java.lang.Object
org.gcube.common.security.secrets.Secret
org.gcube.common.security.secrets.JWTSecret
- Direct Known Subclasses:
UmaTokenSecret
public class JWTSecret
extends org.gcube.common.security.secrets.Secret
A JSON Web Token issued by the D4Science IAM, e.g. the bearer token a service receives in the
Authorization header. Its Context is its audience, which must be a single value.
The token is valid only when it is issued by one of the trusted IAM realms
(setTrustedIssuers(Collection)) and its signature is verified with the key of that realm.
The issuer is checked before any connection, so a token naming another realm is rejected without
contacting it. Whoever hosts the code sets the trusted realms (SmartGears sets the realm of the
container); while none is set, every token is rejected.
- Author:
- Luca Frosini (ISTI - CNR)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intPriority of the secrets based on the tokens of the IAM. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringReturns the encoded token.org.gcube.common.security.OwnergetOwner()Returns the IAM realms whose tokens are accepted.booleanbooleanisValid()Tells whether the token is issued by a trusted IAM realm and its signature is verified with the key of that realm.intpriority()static voidsetTrustedIssuers(Collection<String> issuers) Sets the IAM realms whose tokens are accepted, for the whole JVM.
-
Field Details
-
KEYCLOAK_BASED_SECRET_PRIORITY
public static final int KEYCLOAK_BASED_SECRET_PRIORITYPriority of the secrets based on the tokens of the IAM.- See Also:
-
-
Constructor Details
-
JWTSecret
Creates the secret of an encoded token.- Parameters:
encodedToken- the encoded JWT
-
-
Method Details
-
setTrustedIssuers
Sets the IAM realms whose tokens are accepted, for the whole JVM.- Parameters:
issuers- the base URLs of the realms, as in theissclaim of their tokens, e.g.https://accounts.d4science.org/auth/realms/d4science; a trailing slash is ignored
-
getTrustedIssuers
Returns the IAM realms whose tokens are accepted.- Returns:
- the base URLs of the realms, without trailing slash; empty when none is set
-
priority
public int priority()- Specified by:
priorityin classorg.gcube.common.security.secrets.Secret
-
getOwner
public org.gcube.common.security.Owner getOwner()- Specified by:
getOwnerin classorg.gcube.common.security.secrets.Secret
-
getContext
- Specified by:
getContextin classorg.gcube.common.security.secrets.Secret
-
getHTTPAuthorizationHeaders
- Specified by:
getHTTPAuthorizationHeadersin classorg.gcube.common.security.secrets.Secret
-
getEncodedToken
Returns the encoded token.- Returns:
- the encoded JWT
-
isExpired
public boolean isExpired()- Specified by:
isExpiredin classorg.gcube.common.security.secrets.Secret
-
isValid
public boolean isValid()Tells whether the token is issued by a trusted IAM realm and its signature is verified with the key of that realm. The expiration is not checked here: seeisExpired().- Specified by:
isValidin classorg.gcube.common.security.secrets.Secret- Returns:
truewhen the token is valid
-