Java Code Examples for com.auth0.jwt.interfaces.JWTVerifier#verify()

The following examples show how to use com.auth0.jwt.interfaces.JWTVerifier#verify() . 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: JwtAuthenticationServiceImpl.java    From alibaba-rsocket-broker with Apache License 2.0 6 votes vote down vote up
@Override
public @Nullable NamedPrincipal auth(String jwtToken) {
    int tokenHashCode = jwtToken.hashCode();
    NamedPrincipal principal = jwtVerifyCache.getIfPresent(tokenHashCode);
    if (principal == null) {
        for (JWTVerifier verifier : verifiers) {
            try {
                DecodedJWT decodedJWT = verifier.verify(jwtToken);
                principal = new NamedPrincipal(decodedJWT.getSubject());
                jwtVerifyCache.put(tokenHashCode, principal);
                break;
            } catch (JWTVerificationException ignore) {

            }
        }
    }
    return principal;
}
 
Example 2
Source File: AuthenticationServiceJwtImpl.java    From alibaba-rsocket-broker with Apache License 2.0 6 votes vote down vote up
@Override
@Nullable
public RSocketAppPrincipal auth(String type, String credentials) {
    int tokenHashCode = credentials.hashCode();
    RSocketAppPrincipal principal = jwtVerifyCache.getIfPresent(tokenHashCode);
    for (JWTVerifier verifier : verifiers) {
        try {
            principal = new JwtPrincipal(verifier.verify(credentials), credentials);
            jwtVerifyCache.put(tokenHashCode, principal);
            break;
        } catch (JWTVerificationException ignore) {

        }
    }
    return principal;
}
 
Example 3
Source File: JWTAuthentication.java    From codeway_service with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 解析基础信息,返回解码后的JWT
 * @param jwtStr jwt
 * @return DecodedJWT
 */
private static DecodedJWT parse(String jwtStr) {
	Algorithm algorithm = null;
	try {
		algorithm = Algorithm.HMAC256(SECRET);
	} catch (IllegalArgumentException ex) {
		throw new RuntimeException(ex);
	}
	JWTVerifier verifier = JWT.require(algorithm).withIssuer(ISSUER).build();
	return verifier.verify(jwtStr);
}
 
Example 4
Source File: JWTAuthentication.java    From codeway_service with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 解析基础信息,返回解码后的JWT
 * @param jwtStr jwt
 * @return DecodedJWT
 */
private static DecodedJWT parse(String jwtStr) {
	Algorithm algorithm = null;
	try {
		algorithm = Algorithm.HMAC256(SECRET);
	} catch (IllegalArgumentException ex) {
		throw new RuntimeException(ex);
	}
	JWTVerifier verifier = JWT.require(algorithm).withIssuer(ISSUER).build();
	return verifier.verify(jwtStr);
}