Java 类io.jsonwebtoken.PrematureJwtException 实例源码

项目:services-in-one    文件:JwtAuthenticationProvider.java   
@Override
public Authentication authenticate(Authentication authentication) {
    log.debug("Authenticating: {}", authentication);
    try {
        final String token = authentication.getCredentials().toString();
        final Claims claims = jwtParser.parseClaimsJws(token).getBody();
        checkClaims(claims);
        return new JwtToken(token, claims);
    } catch (ExpiredJwtException | MalformedJwtException | PrematureJwtException | SignatureException | UnsupportedJwtException e) {
        log.warn("{}", e);
        throw new BadCredentialsException(e.getMessage(), e);
    }
}
项目:services-in-one    文件:JwtAuthenticationProviderTest.java   
@Test
public void testAuthenticatePrematureJwtException() throws Exception {
    final String token = "token";
    doReturn(token).when(authentication).getCredentials();
    doThrow(new PrematureJwtException(null, null, null)).when(jwtParser).parseClaimsJws(anyString());

    exception.expect(BadCredentialsException.class);
    exception.expectCause(is(instanceOf(PrematureJwtException.class)));

    jwtAuthenticationProvider.authenticate(authentication);
}
项目:apiman-plugins    文件:JWTPolicy.java   
private Map<String, Object> validateJwt(String token, ApiRequest request, JWTPolicyBean config)
        throws ExpiredJwtException, PrematureJwtException, MalformedJwtException, SignatureException, InvalidClaimException {
    JwtParser parser = Jwts.parser()
            .setSigningKey(config.getSigningKey())
            .setAllowedClockSkewSeconds(config.getAllowedClockSkew());

    // Set all claims
    config.getRequiredClaims().stream() // TODO add type variable to allow dates, etc
        .forEach(requiredClaim -> parser.require(requiredClaim.getClaimName(), requiredClaim.getClaimValue()));

    return parser.parse(token, new ConfigCheckingJwtHandler(config));
}
项目:apiman-plugins    文件:PolicyFailureFactory.java   
public PolicyFailure jwtPremature(IPolicyContext context, PrematureJwtException e) {
    return createAuthenticationPolicyFailure(context, AUTH_JWT_PREMATURE,
            e.getLocalizedMessage());
}