当前位置: 首页>>代码示例>>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;未经允许,请勿转载。