java.lang.Object
com.inductiveautomation.ignition.gateway.auth.util.AuthUtil

public final class AuthUtil extends Object
Utility methods useful for Auth
  • Method Details

    • generateRandomBase64String

      @Nonnull public static String generateRandomBase64String(int entropyCountInBytes)
      Generates a random Base64-encoded String of "entropyCountInBytes" number of bytes. Delegates to SecureRandomProvider for generating a secure random byte array. This Base64 encoded string is safe for use in URLs.
      Parameters:
      entropyCountInBytes - Number of bytes of randomness to generate (must be greater than 0)
      Returns:
      The random Base64-encoded String of bytes
      See Also:
    • serializeJwt

      public static String serializeJwt(org.jose4j.jwt.JwtClaims jwtClaims) throws org.jose4j.lang.JoseException

      Secure an arbitrary set of claims with a message authentication code (MAC) and return the data wrapped in JSON Web Token (JWT). The resulting JWT will be serialized in its compact URL-safe form.

      Note: secret keys will vary each time the server is restarted. The JWT may be verified using deserializeJwt(String).

      Parameters:
      jwtClaims - the arbitrary JwtClaims to include in the JWT
      Returns:
      the JWT with the claims included in compact URL-safe form
      Throws:
      org.jose4j.lang.JoseException - if there is an unexpected problem serializing the JWT
    • deserializeJwt

      public static org.jose4j.jwt.JwtClaims deserializeJwt(String jwt) throws org.jose4j.jwt.consumer.InvalidJwtException
      De-serialize from a compact and URL-safe JWT String to a JwtClaims object. Throws an InvalidJwtException if the JWT fails MAC verification against the secret key.
      Parameters:
      jwt - the JWT to de-serialize and verify
      Returns:
      the de-serialized JwtClaims which may be trusted since MAC verification was performed and it was determined that the payload was generated from this server (authenticated) and was not tampered with (integrity protection)
      Throws:
      org.jose4j.jwt.consumer.InvalidJwtException - if the JWT fails MAC verification against the secret key