Class AuthUtil
- java.lang.Object
-
- com.inductiveautomation.ignition.gateway.auth.util.AuthUtil
-
public final class AuthUtil extends java.lang.ObjectUtility methods useful for Auth
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.jose4j.jwt.JwtClaimsdeserializeJwt(java.lang.String jwt)De-serialize from a compact and URL-safe JWTStringto aJwtClaimsobject.static java.lang.StringgenerateRandomBase64String(int entropyCountInBytes)Generates a random Base64-encoded String of "entropyCountInBytes" number of bytes.static java.lang.StringserializeJwt(org.jose4j.jwt.JwtClaims jwtClaims)Secure an arbitrary set of claims with a message authentication code (MAC) and return the data wrapped in JSON Web Token (JWT).
-
-
-
Method Detail
-
generateRandomBase64String
@Nonnull public static java.lang.String generateRandomBase64String(int entropyCountInBytes)
Generates a random Base64-encoded String of "entropyCountInBytes" number of bytes. Delegates toSecureRandomProviderfor 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:
Base64.getUrlEncoder(),Base64.Encoder.withoutPadding()
-
serializeJwt
public static java.lang.String serializeJwt(org.jose4j.jwt.JwtClaims jwtClaims) throws org.jose4j.lang.JoseExceptionSecure 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 arbitraryJwtClaimsto 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(java.lang.String jwt) throws org.jose4j.jwt.consumer.InvalidJwtExceptionDe-serialize from a compact and URL-safe JWTStringto aJwtClaimsobject. Throws anInvalidJwtExceptionif the JWT fails MAC verification against the secret key.- Parameters:
jwt- the JWT to de-serialize and verify- Returns:
- the de-serialized
JwtClaimswhich 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
-
-