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


Java Claims.getExpiration方法代碼示例

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


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

示例1: of

import io.jsonwebtoken.Claims; //導入方法依賴的package包/類
/**
 * Factory method for creating a new {@code {@link JwtAuthenticationToken}}.
 * @param claims JWT claims
 * @return a JwtAuthenticationToken
 */
public static JwtAuthenticationToken of(Claims claims) {
  long userId = Long.valueOf(claims.getSubject());

  Collection<GrantedAuthority> authorities =
      Arrays.stream(String.valueOf(claims.get(AUTHORITIES)).split(","))
          .map(String::trim)
          .filter(StringUtils::hasText)
          .map(String::toUpperCase)
          .map(SimpleGrantedAuthority::new)
          .collect(Collectors.toSet());

  JwtAuthenticationToken jwtAuthenticationToken = new JwtAuthenticationToken(userId, authorities);

  Date now = new Date();
  Date expiration = claims.getExpiration();
  Date notBefore = Optional.ofNullable(claims.getNotBefore()).orElse(now);
  jwtAuthenticationToken.setAuthenticated(now.after(notBefore) && now.before(expiration));

  return jwtAuthenticationToken;
}
 
開發者ID:springuni,項目名稱:springuni-particles,代碼行數:26,代碼來源:JwtAuthenticationToken.java

示例2: parseAndValidate

import io.jsonwebtoken.Claims; //導入方法依賴的package包/類
public AuthTokenDetails parseAndValidate(String token) {
    AuthTokenDetails authTokenDetails = null;
    try {
        Claims claims = Jwts.parser().setSigningKey(getSecretKey())
                .parseClaimsJws(token)
                .getBody();
        String userId = claims.getSubject();
        String username = (String) claims.get("username");
        List<String> roleNames = (List) claims.get("roleNames");
        Date expirationDate = claims.getExpiration();

        authTokenDetails = new AuthTokenDetails();
        authTokenDetails.setId(Long.valueOf(userId));
        authTokenDetails.setUsername(username);
        authTokenDetails.setRoleNames(roleNames);
        authTokenDetails.setExpirationDate(expirationDate);
    } catch (JwtException ex) {
        logger.error(ex.getMessage(), ex);
    }
    return authTokenDetails;
}
 
開發者ID:jeikerxiao,項目名稱:SpringBootStudy,代碼行數:22,代碼來源:JsonWebTokenUtility.java

示例3: getExpirationDateFromToken

import io.jsonwebtoken.Claims; //導入方法依賴的package包/類
public Date getExpirationDateFromToken(String token) {
    Date expiration;
    try {
        final Claims claims = getClaimsFromToken(token);
        expiration = claims.getExpiration();
    } catch (Exception e) {
        expiration = null;
    }
    return expiration;
}
 
開發者ID:rodrigues882013,項目名稱:springboot-rest-api-skeleton,代碼行數:11,代碼來源:JwtTokenUtil.java

示例4: getExpirationDateFromToken

import io.jsonwebtoken.Claims; //導入方法依賴的package包/類
private Date getExpirationDateFromToken(String token) {
    Date expiration;
    try {
        final Claims claims = getClaimsFromToken(token);
        expiration = claims.getExpiration();
    } catch (Exception e) {
        expiration = null;
    }
    return expiration;
}
 
開發者ID:DigAg,項目名稱:digag-server,代碼行數:11,代碼來源:JwtTokenUtil.java

示例5: getExpirationDateFromTokenClaims

import io.jsonwebtoken.Claims; //導入方法依賴的package包/類
Date getExpirationDateFromTokenClaims(Claims claims) throws JwtAuthenticationException {
    try {
        return claims.getExpiration();
    } catch (Exception e) {
        final String errorMsg = "Failed to extract expiration claim from token!";
        LOG.error(errorMsg, e);
        throw new JwtAuthenticationException(errorMsg, e);
    }
}
 
開發者ID:gazbert,項目名稱:bxbot-ui-server,代碼行數:10,代碼來源:JwtUtils.java

示例6: getExpirationDateFromToken

import io.jsonwebtoken.Claims; //導入方法依賴的package包/類
/**
 * 得到token過期時間
 *
 * @param token
 * @return
 */
public Date getExpirationDateFromToken ( String token ) {
	Date expiration;
	try {
		final Claims claims = getClaimsFromToken( token );
		expiration = claims.getExpiration();
	} catch ( Exception e ) {
		expiration = null;
	}
	return expiration;
}
 
開發者ID:yujunhao8831,項目名稱:spring-boot-start-current,代碼行數:17,代碼來源:JwtTokenUtil.java

示例7: getExpirationDateFromToken

import io.jsonwebtoken.Claims; //導入方法依賴的package包/類
/**
 * Retorna a data de expiração de um token JWT.
 * 
 * @param token
 * @return Date
 */
public Date getExpirationDateFromToken(String token) {
	Date expiration;
	try {
		Claims claims = getClaimsFromToken(token);
		expiration = claims.getExpiration();
	} catch (Exception e) {
		expiration = null;
	}
	return expiration;
}
 
開發者ID:m4rciosouza,項目名稱:ponto-inteligente-api,代碼行數:17,代碼來源:JwtTokenUtil.java

示例8: getUsEx

import io.jsonwebtoken.Claims; //導入方法依賴的package包/類
public Pair<String, Date> getUsEx(String token) {
    Claims body = getBody(token);
    if (body != null) {
        return new Pair<>(body.getSubject(), body.getExpiration());
    }
    return null;
}
 
開發者ID:Clcanny,項目名稱:MicroServiceDemo,代碼行數:8,代碼來源:JwtTokenUtil.java

示例9: isTokenExpired

import io.jsonwebtoken.Claims; //導入方法依賴的package包/類
/**
 * 有效期是否期滿,過期為true
 *
 * @param token
 * @param secretKey
 * @return
 */
public static Boolean isTokenExpired(String token, String secretKey) throws JwtException {
    Claims claims = getClaims(token, secretKey);
    Date expiration = claims.getExpiration();
    return expiration.before(new Date());
}
 
開發者ID:lupindong,項目名稱:xq_seckill_microservice,代碼行數:13,代碼來源:JwtTokenUtil.java


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