Java Code Examples for io.jsonwebtoken.JwtException#getMessage()
The following examples show how to use
io.jsonwebtoken.JwtException#getMessage() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JwtIdentityProvider.java From nifi-registry with Apache License 2.0 | 6 votes |
@Override public AuthenticationResponse authenticate(AuthenticationRequest authenticationRequest) throws InvalidCredentialsException, IdentityAccessException { if (authenticationRequest == null) { logger.info("Cannot authenticate null authenticationRequest, returning null."); return null; } final Object credentials = authenticationRequest.getCredentials(); String jwtAuthToken = credentials != null && credentials instanceof String ? (String) credentials : null; if (credentials == null) { logger.info("JWT not found in authenticationRequest credentials, returning null."); return null; } try { final String jwtPrincipal = jwtService.getAuthenticationFromToken(jwtAuthToken); return new AuthenticationResponse(jwtPrincipal, jwtPrincipal, expiration, issuer); } catch (JwtException e) { throw new InvalidAuthenticationException(e.getMessage(), e); } }
Example 2
Source File: JwtAuthenticationProvider.java From localization_nifi with Apache License 2.0 | 5 votes |
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { final JwtAuthenticationRequestToken request = (JwtAuthenticationRequestToken) authentication; try { final String jwtPrincipal = jwtService.getAuthenticationFromToken(request.getToken()); final NiFiUser user = new StandardNiFiUser(mapIdentity(jwtPrincipal), request.getClientAddress()); return new NiFiAuthenticationToken(new NiFiUserDetails(user)); } catch (JwtException e) { throw new InvalidAuthenticationException(e.getMessage(), e); } }
Example 3
Source File: AuthenticationProviderToken.java From pulsar with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private Jwt<?, Claims> authenticateToken(final String token) throws AuthenticationException { try { Jwt<?, Claims> jwt = Jwts.parser() .setSigningKey(validationKey) .parse(token); if (audienceClaim != null) { Object object = jwt.getBody().get(audienceClaim); if (object == null) { throw new JwtException("Found null Audience in token, for claimed field: " + audienceClaim); } if (object instanceof List) { List<String> audiences = (List<String>) object; // audience not contains this broker, throw exception. if (!audiences.stream().anyMatch(audienceInToken -> audienceInToken.equals(audience))) { throw new AuthenticationException("Audiences in token: [" + String.join(", ", audiences) + "] not contains this broker: " + audience); } } else if (object instanceof String) { if (!object.equals(audience)) { throw new AuthenticationException("Audiences in token: [" + object + "] not contains this broker: " + audience); } } else { // should not reach here. throw new AuthenticationException("Audiences in token is not in expected format: " + object); } } return jwt; } catch (JwtException e) { throw new AuthenticationException("Failed to authentication token: " + e.getMessage()); } }
Example 4
Source File: JwtAuthenticationProvider.java From nifi with Apache License 2.0 | 5 votes |
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { final JwtAuthenticationRequestToken request = (JwtAuthenticationRequestToken) authentication; try { final String jwtPrincipal = jwtService.getAuthenticationFromToken(request.getToken()); final String mappedIdentity = mapIdentity(jwtPrincipal); final NiFiUser user = new Builder().identity(mappedIdentity).groups(getUserGroups(mappedIdentity)).clientAddress(request.getClientAddress()).build(); return new NiFiAuthenticationToken(new NiFiUserDetails(user)); } catch (JwtException e) { throw new InvalidAuthenticationException(e.getMessage(), e); } }