Class JwtWrapper

java.lang.Object
dev.galasa.framework.api.common.JwtWrapper

public class JwtWrapper extends Object
  • Field Details

    • decodedJwt

      protected com.auth0.jwt.interfaces.DecodedJWT decodedJwt
  • Constructor Details

    • JwtWrapper

      public JwtWrapper(javax.servlet.http.HttpServletRequest req)
    • JwtWrapper

      public JwtWrapper(javax.servlet.http.HttpServletRequest req, Environment env)
    • JwtWrapper

      public JwtWrapper(String jwt, Environment env)
  • Method Details

    • decodeJwt

      public com.auth0.jwt.interfaces.DecodedJWT decodeJwt(@NotNull @NotNull String jwt)
    • getSubject

      public String 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

      public String getUsername() throws InternalServletException
      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