Class TokenCredentials

java.lang.Object
one.jpro.platform.auth.core.jwt.TokenCredentials
All Implemented Interfaces:
Credentials

public class TokenCredentials extends Object implements Credentials
Credentials used by an AuthenticationProvider that requires tokens, such as OAuth2, to perform its authentication.
  • Constructor Details

    • TokenCredentials

      public TokenCredentials(@NotNull @NotNull String token)
      Creates a token credentials with the given token.
      Parameters:
      token - the token string
    • TokenCredentials

      public TokenCredentials(@NotNull @NotNull org.json.JSONObject json)
      Creates a token credentials from a json object.
      Parameters:
      json - the json object
      Throws:
      IllegalStateException - if the json object is null
    • TokenCredentials

      public TokenCredentials(@NotNull @NotNull User user)
      Creates a token credentials from a user object.

      This constructor should be called only if the user object is obtained from a AuthenticationProvider that uses tokens.

      Parameters:
      user - the user object
  • Method Details

    • fromJSON

      public static TokenCredentials fromJSON(String json)
      Creates a token credentials object with the given JSON formatted string.
      Parameters:
      json - the string representation of the JSON object holding the token credential's information.
    • toJSON

      public static String toJSON(TokenCredentials tokenCredentials)
      Convert the token credential information to JSON format and provides it as a string.
      Returns:
      a string in JSON format.
    • getToken

      @NotNull public @NotNull String getToken()
    • setToken

      public TokenCredentials setToken(@NotNull @NotNull String token)
    • getScopes

      @Nullable public @Nullable List<String> getScopes()
    • setScopes

      public TokenCredentials setScopes(List<String> scopes)
    • addScopes

      public TokenCredentials addScopes(String... scopes)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • validate

      public <V> void validate(V arg) throws CredentialValidationException
      Description copied from interface: Credentials
      Implementors should override this method to perform validation. An argument is allowed to allow custom validation.
      Specified by:
      validate in interface Credentials
      Type Parameters:
      V - the generic type of the argument
      Parameters:
      arg - optional argument or null.
      Throws:
      CredentialValidationException - when the validation fails
    • toJSON

      public org.json.JSONObject toJSON()
      Description copied from interface: Credentials
      Convert the credential information to JSON format.
      Specified by:
      toJSON in interface Credentials
      Returns:
      a JSON object.
    • toHttpAuthorization

      public String toHttpAuthorization()
      Description copied from interface: Credentials
      Encodes this credential as an HTTP Authorization https://tools.ietf.org/html/rfc7235.
      Specified by:
      toHttpAuthorization in interface Credentials
      Returns:
      HTTP header including scheme.
    • toString

      public String toString()
      Overrides:
      toString in class Object