本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}