@Override public JwtToken authenticate(Authentication authentication) throws AuthenticationException { JwtToken token = (JwtToken) authentication; if (token.getPrincipal() instanceof String) { try { Claims claims = Jwts.parser() .setSigningKey(secret) .parseClaimsJws((String) token.getPrincipal()) .getBody(); UserDetails user = handler.parseClaims(claims); return new JwtToken(user, claims, user.getAuthorities()); } catch (ClaimJwtException ex) { throw new BadCredentialsException("JWT error", ex); } } else { return null; } }
public PolicyFailure invalidClaim(IPolicyContext context, ClaimJwtException e) { return createAuthenticationPolicyFailure(context, AUTH_JWT_CLAIM_FAILURE, e.getLocalizedMessage()); }