當前位置: 首頁>>代碼示例>>Java>>正文


Java ExpiredJwtException類代碼示例

本文整理匯總了Java中io.jsonwebtoken.ExpiredJwtException的典型用法代碼示例。如果您正苦於以下問題:Java ExpiredJwtException類的具體用法?Java ExpiredJwtException怎麽用?Java ExpiredJwtException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ExpiredJwtException類屬於io.jsonwebtoken包,在下文中一共展示了ExpiredJwtException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: Verify

import io.jsonwebtoken.ExpiredJwtException; //導入依賴的package包/類
public static boolean Verify(String jwt, String type) throws Exception {
    
    try{
        Claims claims = Jwts.parser()
            .setSigningKey(DatatypeConverter.parseBase64Binary(Parameters.TOKENKEY))
            .parseClaimsJws(jwt).getBody();
        
        //verifica se o issuer é igual ao type
        return claims.getIssuer().equals(type);
        
    } catch (ExpiredJwtException | MalformedJwtException | SignatureException 
            | UnsupportedJwtException | IllegalArgumentException e) {
        System.out.println(e.getMessage());
        return false;
    }
}
 
開發者ID:Montanheiro,項目名稱:SistemaAlmoxarifado,代碼行數:17,代碼來源:Token.java

示例2: doFilter

import io.jsonwebtoken.ExpiredJwtException; //導入依賴的package包/類
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
    throws IOException, ServletException {
    try {
        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
        String jwt = resolveToken(httpServletRequest);
        if (StringUtils.hasText(jwt) && this.tokenProvider.validateToken(jwt)) {
            Authentication authentication = this.tokenProvider.getAuthentication(jwt);
            SecurityContextHolder.getContext().setAuthentication(authentication);
        }
        filterChain.doFilter(servletRequest, servletResponse);
    } catch (ExpiredJwtException eje) {
        log.info("Security exception for user {} - {}",
            eje.getClaims().getSubject(), eje.getMessage());

        log.trace("Security exception trace: {}", eje);
        ((HttpServletResponse) servletResponse).setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    }
}
 
開發者ID:oktadeveloper,項目名稱:jhipster-microservices-example,代碼行數:20,代碼來源:JWTFilter.java

示例3: doFilter

import io.jsonwebtoken.ExpiredJwtException; //導入依賴的package包/類
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
    throws IOException, ServletException {
    try {
        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
        String jwt = resolveToken(httpServletRequest);
        if (StringUtils.hasText(jwt)) {
            if (this.tokenProvider.validateToken(jwt)) {
                Authentication authentication = this.tokenProvider.getAuthentication(jwt);
                SecurityContextHolder.getContext().setAuthentication(authentication);
            }
        }
        filterChain.doFilter(servletRequest, servletResponse);
    } catch (ExpiredJwtException eje) {
        log.info("Security exception for user {} - {}", eje.getClaims().getSubject(), eje.getMessage());
        ((HttpServletResponse) servletResponse).setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    }
}
 
開發者ID:ElectronicArmory,項目名稱:Armory,代碼行數:19,代碼來源:JWTFilter.java

示例4: parseTokenFromBase64EncodedString

import io.jsonwebtoken.ExpiredJwtException; //導入依賴的package包/類
private Jws<Claims> parseTokenFromBase64EncodedString(final String base64EncodedToken) throws JwtException {
    try {
        return Jwts.parser().setSigningKeyResolver(new SigningKeyResolverAdapter() {
            @Override
            public byte[] resolveSigningKeyBytes(JwsHeader header, Claims claims) {
                final String identity = claims.getSubject();

                // Get the key based on the key id in the claims
                final String keyId = claims.get(KEY_ID_CLAIM, String.class);
                final Key key = keyService.getKey(keyId);

                // Ensure we were able to find a key that was previously issued by this key service for this user
                if (key == null || key.getKey() == null) {
                    throw new UnsupportedJwtException("Unable to determine signing key for " + identity + " [kid: " + keyId + "]");
                }

                return key.getKey().getBytes(StandardCharsets.UTF_8);
            }
        }).parseClaimsJws(base64EncodedToken);
    } catch (final MalformedJwtException | UnsupportedJwtException | SignatureException | ExpiredJwtException | IllegalArgumentException e) {
        // TODO: Exercise all exceptions to ensure none leak key material to logs
        final String errorMessage = "Unable to validate the access token.";
        throw new JwtException(errorMessage, e);
    }
}
 
開發者ID:apache,項目名稱:nifi-registry,代碼行數:26,代碼來源:JwtService.java

示例5: validateToken

import io.jsonwebtoken.ExpiredJwtException; //導入依賴的package包/類
/**
 * To validate the JWT token e.g Signature check, JWT claims check(expiration) etc
 *
 * @param token The JWT access tokens
 * @param context
 * @return the AuthenticationStatus to notify the container
 */
private AuthenticationStatus validateToken(String token, HttpMessageContext context) {
    try {
        if (tokenProvider.validateToken(token)) {
            JwtCredential credential = tokenProvider.getCredential(token);

            //fire an @Authenticated CDI event.
            authenticatedEvent.fire(new UserInfo(credential.getPrincipal(), credential.getAuthorities()));

            return context.notifyContainerAboutLogin(credential.getPrincipal(), credential.getAuthorities());
        }
        // if token invalid, response with unauthorized status
        return context.responseUnauthorized();
    } catch (ExpiredJwtException eje) {
        LOGGER.log(Level.INFO, "Security exception for user {0} - {1}", new String[]{eje.getClaims().getSubject(), eje.getMessage()});
        return context.responseUnauthorized();
    }
}
 
開發者ID:hantsy,項目名稱:javaee8-jaxrs-sample,代碼行數:25,代碼來源:JwtAuthenticationMechanism.java

示例6: dosomething

import io.jsonwebtoken.ExpiredJwtException; //導入依賴的package包/類
@Path("dosomething")
@POST
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public String dosomething(@FormParam(value = "token") String token) throws IOException {
	String result;
	
	try {
		 Claims claims = Jwts.parser()         
	       .setSigningKey(DatatypeConverter.parseBase64Binary(SECRECT))
	       .parseClaimsJws(token).getBody();
		 result = claims.getIssuer();
	}
	catch (ExpiredJwtException exception) {
		result = "expired";
	}
		    
    return result;
}
 
開發者ID:nphau,項目名稱:Angular2-OnlineCinema,代碼行數:19,代碼來源:AccountController.java

示例7: doFilter

import io.jsonwebtoken.ExpiredJwtException; //導入依賴的package包/類
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
	throws IOException, ServletException {
	try {
		HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
		String jwt = resolveToken(httpServletRequest);
		if (StringUtils.hasText(jwt)) {
			if (this.tokenProvider.validateToken(jwt)) {
				Authentication authentication = this.tokenProvider.getAuthentication(jwt);
				SecurityContextHolder.getContext().setAuthentication(authentication);
			}
		}
		filterChain.doFilter(servletRequest, servletResponse);
	} catch (ExpiredJwtException eje) {
		log.info("Security exception for user {} - {}", eje.getClaims().getSubject(), eje.getMessage());
		HttpServletResponse reponse = (HttpServletResponse) servletResponse;
		reponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Token expired (" + eje.getMessage() + ")");
	}
}
 
開發者ID:coinblesk,項目名稱:coinblesk-server,代碼行數:20,代碼來源:JWTFilter.java

示例8: expiredTokenCannotBeRefreshed

import io.jsonwebtoken.ExpiredJwtException; //導入依賴的package包/類
@Test(expected = ExpiredJwtException.class)
public void expiredTokenCannotBeRefreshed() throws Exception {
    when(timeProviderMock.now())
            .thenReturn(DateUtil.yesterday());
    String token = createToken();
    jwtTokenUtil.canTokenBeRefreshed(token, DateUtil.tomorrow());
}
 
開發者ID:adriano-fonseca,項目名稱:rest-api-jwt-spring-security,代碼行數:8,代碼來源:JwtTokenUtilTest.java

示例9: parseToken

import io.jsonwebtoken.ExpiredJwtException; //導入依賴的package包/類
private JwtAuthenticatedUser parseToken(String token) {
    JwtAuthenticatedUser user = null;
    try {
        Claims body = Jwts.parser()
                .setSigningKey(secret)
                .parseClaimsJws(token)
                .getBody();
        user = new JwtAuthenticatedUser(body.getSubject(), Arrays.asList(body.get(ROLE_KEY).toString().split(ROLE_DELIMITER)));
    } catch (ExpiredJwtException e) {
        LOGGER.warn("Error token expired", e);
    }
    return user;
}
 
開發者ID:TraineeSIIp,項目名稱:PepSIIrup-2017,代碼行數:14,代碼來源:TokenAuthenticationService.java

示例10: parseToken

import io.jsonwebtoken.ExpiredJwtException; //導入依賴的package包/類
private Jws<Claims> parseToken(final String token) {
    if (token != null) {
        try {
            return Jwts.parser().setSigningKey(secretKey).parseClaimsJws(token);
        } catch (ExpiredJwtException | UnsupportedJwtException | MalformedJwtException
                | SignatureException | IllegalArgumentException e) {
            return null;
        }
    }
    return null;
}
 
開發者ID:vlsidlyarevich,項目名稱:Spring-Boot-MongoDB-JWT,代碼行數:12,代碼來源:JsonWebTokenAuthenticationService.java

示例11: testGenerateTokenExpired

import io.jsonwebtoken.ExpiredJwtException; //導入依賴的package包/類
@Test(expected=ExpiredJwtException.class)
public void testGenerateTokenExpired() {
    String token = tokenHelper.generateToken("fanjin");
    Jwts.parser()
        .setSigningKey("mySecret")
        .parseClaimsJws(token)
        .getBody();
}
 
開發者ID:bfwg,項目名稱:angular-spring-starter,代碼行數:9,代碼來源:TokenHelperTest.java

示例12: parseClaims

import io.jsonwebtoken.ExpiredJwtException; //導入依賴的package包/類
/**
 * Parses and validates JWT Token signature.
 * 
 * @throws BadCredentialsException
 * @throws JwtExpiredTokenException
 * 
 */
public Jws<Claims> parseClaims(String signingKey) {
    try {
        return Jwts.parser().setSigningKey(signingKey).parseClaimsJws(this.token);
    } catch (UnsupportedJwtException | MalformedJwtException | IllegalArgumentException | SignatureException ex) {
        logger.error("Invalid JWT Token", ex);
        throw new BadCredentialsException("Invalid JWT token: ", ex);
    } catch (ExpiredJwtException expiredEx) {
        logger.info("JWT Token is expired", expiredEx);
        throw new JwtExpiredTokenException(this, "JWT Token expired", expiredEx);
    }
}
 
開發者ID:Apereo-Learning-Analytics-Initiative,項目名稱:OpenLRW,代碼行數:19,代碼來源:RawAccessJwtToken.java

示例13: authenticateIfTokenExpirationFinishedTest

import io.jsonwebtoken.ExpiredJwtException; //導入依賴的package包/類
@Test(expected = ExpiredJwtException.class)
public void authenticateIfTokenExpirationFinishedTest() {
    final User user = createUser();
    String token = tokenService.generate(user.getUsername(), user.getPassword()).getToken();
    token = modifyTokenExpirationTime(token);

    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader(authHeaderName, token);

    final Authentication authentication = tokenService.authenticate(request);

    assertNull(authentication);
}
 
開發者ID:akraskovski,項目名稱:product-management-system,代碼行數:14,代碼來源:TokenServiceTest.java

示例14: validate

import io.jsonwebtoken.ExpiredJwtException; //導入依賴的package包/類
@Override
public CredentialValidationResult validate(RememberMeCredential rememberMeCredential) {
    try {
        if (tokenProvider.validateToken(rememberMeCredential.getToken())) {
            JwtCredential credential = tokenProvider.getCredential(rememberMeCredential.getToken());
            return new CredentialValidationResult(credential.getPrincipal(), credential.getAuthorities());
        }
        // if token invalid, response with invalid result status
        return INVALID_RESULT;
    } catch (ExpiredJwtException eje) {
        LOGGER.log(Level.INFO, "Security exception for user {0} - {1}", new Object[]{eje.getClaims().getSubject(), eje.getMessage()});
        return INVALID_RESULT;
    }
}
 
開發者ID:hantsy,項目名稱:javaee8-jaxrs-sample,代碼行數:15,代碼來源:JwtRememberMeIdentityStore.java

示例15: parseClaims

import io.jsonwebtoken.ExpiredJwtException; //導入依賴的package包/類
/**
 * Parses and validates JWT Token signature.
 *
 * @throws BadCredentialsException
 * @throws JwtExpiredTokenException
 *
 */
public Jws<Claims> parseClaims(String signingKey) {
  try {
    return Jwts.parser().setSigningKey(signingKey).parseClaimsJws(this.token);
  } catch (UnsupportedJwtException | MalformedJwtException | IllegalArgumentException | SignatureException ex) {
    logger.error("Invalid JWT Token", ex);
    throw new BadCredentialsException("Invalid JWT token: ", ex);
  } catch (ExpiredJwtException expiredEx) {
    logger.info("JWT Token is expired", expiredEx);
    throw new JwtExpiredTokenException(this, "JWT Token expired", expiredEx);
  }
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:19,代碼來源:RawAccessJwtToken.java


注:本文中的io.jsonwebtoken.ExpiredJwtException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。