@Test(expected = AuthenticationException.class) public void testAuthenticateThrowsIfProvidedAnInvalidString() throws AuthenticationException { final JsonWebTokenAuthenticator authenticator = createValidAuthenticatorInstance(); final String invalidString = TestHelpers.generateRandomString(); authenticator.authenticate(invalidString); }
@Override public Optional<Principal> authenticate(String s) throws NullPointerException, AuthenticationException { Objects.requireNonNull(s); try { final Jws<Claims> claims = Jwts.parser().setSigningKey(this.secretKey).parseClaimsJws(s); final String username = claims.getBody().getSubject(); final Principal principal = new PrincipalImpl(username); return Optional.of(principal); } catch (MalformedJwtException ex) { throw new AuthenticationException("The provided json web token was malformed.", ex); } catch (SignatureException ex) { throw new AuthenticationException("The provided json web token failed signature validation tests.", ex); } }
JsonWebTokenAuthenticator implements Authenticator<String, Principal> { @Override public Optional<Principal> authenticate(String s) throws NullPointerException, AuthenticationException { Objects.requireNonNull(s); try { final Jws<Claims> claims = Jwts.parser().setSigningKey(this.secretKey).parseClaimsJws(s); final String username = claims.getBody().getSubject(); final Principal principal = new PrincipalImpl(username); return Optional.of(principal); } catch (MalformedJwtException ex) { throw new AuthenticationException("The provided json web token was malformed.", ex); } catch (SignatureException ex) { throw new AuthenticationException("The provided json web token failed signature validation tests.", ex); } } }
JsonWebTokenAuthenticator implements Authenticator<String, Principal> { @Override public Optional<Principal> authenticate(String s) throws NullPointerException, AuthenticationException { Objects.requireNonNull(s); try { final Jws<Claims> claims = Jwts.parser().setSigningKey(this.secretKey).parseClaimsJws(s); final String username = claims.getBody().getSubject(); final Principal principal = new PrincipalImpl(username); return Optional.of(principal); } catch (MalformedJwtException ex) { throw new AuthenticationException("The provided json web token was malformed.", ex); } catch (SignatureException ex) { throw new AuthenticationException("The provided json web token failed signature validation tests.", ex); } } JsonWebTokenAuthenticator(Key secretKey, SignatureAlgorithm algorithm); }
JsonWebTokenAuthenticator implements Authenticator<String, Principal> { @Override public Optional<Principal> authenticate(String s) throws NullPointerException, AuthenticationException { Objects.requireNonNull(s); try { final Jws<Claims> claims = Jwts.parser().setSigningKey(this.secretKey).parseClaimsJws(s); final String username = claims.getBody().getSubject(); final Principal principal = new PrincipalImpl(username); return Optional.of(principal); } catch (MalformedJwtException ex) { throw new AuthenticationException("The provided json web token was malformed.", ex); } catch (SignatureException ex) { throw new AuthenticationException("The provided json web token failed signature validation tests.", ex); } } JsonWebTokenAuthenticator(Key secretKey, SignatureAlgorithm algorithm); static String createJwtToken(SignatureAlgorithm alg, Key secretKey, Principal principal); @Override Optional<Principal> authenticate(String s); String createJwtToken(Principal principal); }
JsonWebTokenAuthenticator implements Authenticator<String, Principal> { @Override public Optional<Principal> authenticate(String s) throws NullPointerException, AuthenticationException { Objects.requireNonNull(s); try { final Jws<Claims> claims = Jwts.parser().setSigningKey(this.secretKey).parseClaimsJws(s); final String username = claims.getBody().getSubject(); final Principal principal = new PrincipalImpl(username); return Optional.of(principal); } catch (MalformedJwtException ex) { throw new AuthenticationException("The provided json web token was malformed.", ex); } catch (SignatureException ex) { throw new AuthenticationException("The provided json web token failed signature validation tests.", ex); } } JsonWebTokenAuthenticator(Key secretKey, SignatureAlgorithm algorithm); static String createJwtToken(SignatureAlgorithm alg, Key secretKey, Principal principal); @Override Optional<Principal> authenticate(String s); String createJwtToken(Principal principal);  }