class 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);
        }
    }

    public  JsonWebTokenAuthenticator(Key secretKey, SignatureAlgorithm algorithm);

}