Search in sources :

Example 1 with Jwt

use of io.jsonwebtoken.Jwt in project jjwt by jwtk.

the class DefaultJwtParser method parse.

@Override
public <T> T parse(String compact, JwtHandler<T> handler) throws ExpiredJwtException, MalformedJwtException, SignatureException {
    Assert.notNull(handler, "JwtHandler argument cannot be null.");
    Assert.hasText(compact, "JWT String argument cannot be null or empty.");
    Jwt jwt = parse(compact);
    if (jwt instanceof Jws) {
        Jws jws = (Jws) jwt;
        Object body = jws.getBody();
        if (body instanceof Claims) {
            return handler.onClaimsJws((Jws<Claims>) jws);
        } else {
            return handler.onPlaintextJws((Jws<String>) jws);
        }
    } else {
        Object body = jwt.getBody();
        if (body instanceof Claims) {
            return handler.onClaimsJwt((Jwt<Header, Claims>) jwt);
        } else {
            return handler.onPlaintextJwt((Jwt<Header, String>) jwt);
        }
    }
}
Also used : Claims(io.jsonwebtoken.Claims) Header(io.jsonwebtoken.Header) JwsHeader(io.jsonwebtoken.JwsHeader) Jwt(io.jsonwebtoken.Jwt) Jws(io.jsonwebtoken.Jws)

Aggregations

Claims (io.jsonwebtoken.Claims)1 Header (io.jsonwebtoken.Header)1 Jws (io.jsonwebtoken.Jws)1 JwsHeader (io.jsonwebtoken.JwsHeader)1 Jwt (io.jsonwebtoken.Jwt)1