Package com.bastiaanjansen.jwt
Class JWT
- java.lang.Object
-
- com.bastiaanjansen.jwt.JWT
-
public final class JWT extends Object
This object represents a JSON Web Token- Author:
- Bastiaan Jansen
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJWT.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static JWTfromRawJWT(Algorithm algorithm, String jwt)Create a new JWT instance based on a raw JWTAlgorithmgetAlgorithm()HeadergetHeader()PayloadgetPayload()StringgetSignature()Stringsign()Create a new JWTvoidvalidate()Checks whether the JWT is valid or not with the default JWT validatorvoidvalidate(JWTValidator validator)Checks whether the JWT is valid or not with a custom validator
-
-
-
Constructor Detail
-
JWT
public JWT(Algorithm algorithm, Header header, Payload payload) throws JWTCreationException
- Throws:
JWTCreationException
-
-
Method Detail
-
getAlgorithm
public Algorithm getAlgorithm()
-
getPayload
public Payload getPayload()
-
getHeader
public Header getHeader()
-
getSignature
public String getSignature()
-
fromRawJWT
public static JWT fromRawJWT(Algorithm algorithm, String jwt) throws JWTDecodeException, JWTCreationException
Create a new JWT instance based on a raw JWT- Parameters:
algorithm- algorithm to use when signing JWTjwt- Raw JWT- Returns:
- Newly created JWT instance
- Throws:
JWTDecodeException- When the raw JWT could not be decodedJWTCreationException
-
validate
public void validate(JWTValidator validator) throws JWTValidationException
Checks whether the JWT is valid or not with a custom validator- Parameters:
validator- JWT Validator- Throws:
JWTValidationException- when JWT is not valid
-
validate
public void validate() throws JWTValidationExceptionChecks whether the JWT is valid or not with the default JWT validator- Throws:
JWTValidationException- when JWT is not valid
-
sign
public String sign() throws JWTCreationException
Create a new JWT- Returns:
- A new JWT
- Throws:
JWTCreationException- when JWT could not be created
-
-