Package dev.galasa.framework.api.common
Class JwtWrapper
java.lang.Object
dev.galasa.framework.api.common.JwtWrapper
-
Field Summary
-
Constructor Summary
ConstructorDescriptionJwtWrapper
(String jwt, Environment env) JwtWrapper
(javax.servlet.http.HttpServletRequest req) JwtWrapper
(javax.servlet.http.HttpServletRequest req, Environment env) -
Method Summary
Modifier and TypeMethodDescriptioncom.auth0.jwt.interfaces.DecodedJWT
static String
getBearerTokenFromAuthHeader
(javax.servlet.http.HttpServletRequest servletRequest) Gets a JSON Web Token (JWT) from a given request's Authorization header, returning null if it does not have one.Get the value of the "sub" claim from the decoded JWTGets the username from a request's JWT, throwing an exception if a username could not be retrieved from the supplied JWT claims.
-
Field Details
-
decodedJwt
protected com.auth0.jwt.interfaces.DecodedJWT decodedJwt
-
-
Constructor Details
-
JwtWrapper
public JwtWrapper(javax.servlet.http.HttpServletRequest req) -
JwtWrapper
-
JwtWrapper
-
-
Method Details
-
decodeJwt
-
getSubject
Get the value of the "sub" claim from the decoded JWT- Returns:
- the value associated with the decoded JWT's "sub" claim
-
getBearerTokenFromAuthHeader
public static String getBearerTokenFromAuthHeader(javax.servlet.http.HttpServletRequest servletRequest) Gets a JSON Web Token (JWT) from a given request's Authorization header, returning null if it does not have one.- Parameters:
servletRequest
- the request to retrieve a JWT from- Returns:
- the JWT stored in the request's "Authorization" header, or null
-
getUsername
Gets the username from a request's JWT, throwing an exception if a username could not be retrieved from the supplied JWT claims.- Returns:
- the username retrieved from a claim in the JWT
- Throws:
InternalServletException
- if no JWT claims could be used to get a username or no JWT was set
-