Search in sources :

Example 1 with ClaimSet

use of com.auth0.jwt.ClaimSet in project nextprot-api by calipho-sib.

the class JWTCodecImpl method encodeJWT.

@Override
public String encodeJWT(Map<String, Object> properties, int expiration) {
    String payload, token;
    try {
        JwtSigner jwtSigner = new JwtSigner();
        payload = new ObjectMapper().writeValueAsString(properties);
        ClaimSet claimSet = new ClaimSet();
        claimSet.setExp(expiration);
        token = jwtSigner.encode(Algorithm.HS256, payload, "payload", new String(Base64.decodeBase64(clientSecret)), claimSet);
    } catch (JsonProcessingException e) {
        throw new SecurityException(e);
    } catch (Exception e) {
        throw new SecurityException(e);
    }
    return token;
}
Also used : JwtSigner(com.auth0.jwt.JwtSigner) ClaimSet(com.auth0.jwt.ClaimSet) NextprotSecurityException(org.nextprot.api.security.service.exception.NextprotSecurityException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SignatureException(java.security.SignatureException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NextprotSecurityException(org.nextprot.api.security.service.exception.NextprotSecurityException) InvalidKeyException(java.security.InvalidKeyException)

Aggregations

ClaimSet (com.auth0.jwt.ClaimSet)1 JwtSigner (com.auth0.jwt.JwtSigner)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SignatureException (java.security.SignatureException)1 NextprotSecurityException (org.nextprot.api.security.service.exception.NextprotSecurityException)1