本文整理了Java中io.jsonwebtoken.Claims.getExpiration()
方法的一些代码示例,展示了Claims.getExpiration()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Claims.getExpiration()
方法的具体详情如下:
包路径:io.jsonwebtoken.Claims
类名称:Claims
方法名:getExpiration
[英]Returns the JWT exp
(expiration) timestamp or null if not present.
A JWT obtained after this timestamp should not be used.
[中]返回JWTexp
(过期)时间戳,如果不存在,则返回null。
不应使用在此时间戳之后获得的JWT。
代码示例来源:origin: macrozheng/mall
/**
* 从token中获取过期时间
*/
private Date getExpiredDateFromToken(String token) {
Claims claims = getClaimsFromToken(token);
return claims.getExpiration();
}
代码示例来源:origin: stylefeng/Guns
/**
* 获取jwt失效时间
*/
public static Date getExpirationDateFromToken(String token) {
return getClaimFromToken(token).getExpiration();
}
代码示例来源:origin: hs-web/hsweb-framework
try {
Claims claims = parseJWT(headerToken);
if (claims.getExpiration().getTime() <= System.currentTimeMillis()) {
代码示例来源:origin: SonarSource/sonarqube
Optional<Claims> decode(String token) {
checkIsStarted();
Claims claims = null;
try {
claims = Jwts.parser()
.setSigningKey(secretKey)
.parseClaimsJws(token)
.getBody();
requireNonNull(claims.getId(), "Token id hasn't been found");
requireNonNull(claims.getSubject(), "Token subject hasn't been found");
requireNonNull(claims.getExpiration(), "Token expiration date hasn't been found");
requireNonNull(claims.getIssuedAt(), "Token creation date hasn't been found");
return Optional.of(claims);
} catch (ExpiredJwtException | SignatureException e) {
return Optional.empty();
} catch (Exception e) {
throw AuthenticationException.newBuilder()
.setSource(Source.jwt())
.setLogin(claims == null ? null : claims.getSubject())
.setMessage(e.getMessage())
.build();
}
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void decode_token() {
setSecretKey(A_SECRET_KEY);
underTest.start();
Date now = new Date();
String token = underTest.encode(new JwtSession(USER_LOGIN, 20 * 60));
Claims claims = underTest.decode(token).get();
assertThat(claims.getId()).isNotEmpty();
assertThat(claims.getSubject()).isEqualTo(USER_LOGIN);
assertThat(claims.getExpiration()).isNotNull();
assertThat(claims.getIssuedAt()).isNotNull();
// Check expiration date it set to more than 19 minutes in the future
assertThat(claims.getExpiration()).isAfterOrEqualsTo(new Date(now.getTime() + 19 * 60 * 1000));
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void generate_token_with_expiration_date() {
setSecretKey(A_SECRET_KEY);
underTest.start();
Date now = new Date();
long expirationTimeInSeconds = 10L;
String token = underTest.encode(new JwtSession(USER_LOGIN, expirationTimeInSeconds));
assertThat(token).isNotEmpty();
Claims claims = underTest.decode(token).get();
assertThat(claims.getExpiration().getTime()).isGreaterThanOrEqualTo(now.getTime() + expirationTimeInSeconds * 1000L - 1000L);
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void generate_token_with_big_expiration_date() {
setSecretKey(A_SECRET_KEY);
underTest.start();
Date now = new Date();
long oneYearInSeconds = 12 * 30 * 24 * 60 * 60L;
String token = underTest.encode(new JwtSession(USER_LOGIN, oneYearInSeconds));
assertThat(token).isNotEmpty();
Claims claims = underTest.decode(token).get();
// Check expiration date it set to one year in the future
assertThat(claims.getExpiration().getTime()).isGreaterThanOrEqualTo(now.getTime() + oneYearInSeconds * 1000L - 1000L);
}
代码示例来源:origin: jwtk/jjwt
Date exp = claims.getExpiration();
if (exp != null) {
代码示例来源:origin: SonarSource/sonarqube
@Test
public void refresh_token() {
setSecretKey(A_SECRET_KEY);
underTest.start();
Date now = new Date();
Date createdAt = DateUtils.parseDate("2016-01-01");
// Expired in 10 minutes
Date expiredAt = new Date(now.getTime() + 10 * 60 * 1000);
Claims token = new DefaultClaims()
.setId("id")
.setSubject("subject")
.setIssuer("sonarqube")
.setIssuedAt(createdAt)
.setExpiration(expiredAt);
token.put("key", "value");
// Refresh the token with a higher expiration time
String encodedToken = underTest.refresh(token, 20 * 60);
Claims result = underTest.decode(encodedToken).get();
assertThat(result.getId()).isEqualTo("id");
assertThat(result.getSubject()).isEqualTo("subject");
assertThat(result.getIssuer()).isEqualTo("sonarqube");
assertThat(result.getIssuedAt()).isEqualTo(createdAt);
assertThat(result.get("key")).isEqualTo("value");
// Expiration date has been changed
assertThat(result.getExpiration()).isNotEqualTo(expiredAt)
.isAfterOrEqualsTo(new Date(now.getTime() + 19 * 1000));
}
代码示例来源:origin: zhangxd1989/springboot-dubbox
/**
* 获取过期时间
*
* @param token Token
* @return Date
*/
public Date getExpiredFromToken(String token) {
Claims claims = getClaimsFromToken(token);
return claims != null ? claims.getExpiration() : null;
}
代码示例来源:origin: eclipse/hono
@SuppressWarnings("rawtypes")
@Override
public Key resolveSigningKey(final JwsHeader header, final Claims claims) {
final Date exp = claims.getExpiration();
if (exp != null) {
result.set(exp);
}
return DUMMY_KEY;
}
}).parse(token);
代码示例来源:origin: org.eclipse.hono/hono-core
@SuppressWarnings("rawtypes")
@Override
public Key resolveSigningKey(final JwsHeader header, final Claims claims) {
final Date exp = claims.getExpiration();
if (exp != null) {
result.set(exp);
}
return DUMMY_KEY;
}
}).parse(token);
代码示例来源:origin: cassiomolin/jersey-jwt
/**
* Extract the expiration date from the token claims.
*
* @param claims
* @return Expiration date of the JWT token
*/
private ZonedDateTime extractExpirationDateFromClaims(@NotNull Claims claims) {
return ZonedDateTime.ofInstant(claims.getExpiration().toInstant(), ZoneId.systemDefault());
}
代码示例来源:origin: cassiomolin/jersey-jwt-springsecurity
/**
* Extract the expiration date from the token claims.
*
* @param claims
* @return Expiration date of the JWT token
*/
private ZonedDateTime extractExpirationDateFromClaims(@NotNull Claims claims) {
return ZonedDateTime.ofInstant(claims.getExpiration().toInstant(), ZoneId.systemDefault());
}
代码示例来源:origin: org.eclipse.hono/hono-service-base
@Override
public Instant getExpirationTime() {
return expandedToken.getBody().getExpiration().toInstant();
}
}
代码示例来源:origin: jonsychen/rest-security-demo
public Date getExpirationDateFromToken(String token) {
Date expiration;
try {
final Claims claims = getClaimsFromToken(token);
expiration = claims.getExpiration();
} catch (Exception e) {
expiration = null;
}
return expiration;
}
代码示例来源:origin: Caratacus/Crown
/**
* 获取jwt失效时间
*/
public static Date getExpiration(String token) {
return getClaim(token).getExpiration();
}
代码示例来源:origin: qiurunze123/GEEKQ-CM
/**
* 获取jwt失效时间
*/
public Date getExpirationDateFromToken(String token) {
return getClaimFromToken(token).getExpiration();
}
代码示例来源:origin: qiurunze123/GEEKQ-CM
/**
* 获取jwt失效时间
*/
public Date getExpirationDateFromToken(String token) {
return getClaimFromToken(token).getExpiration();
}
代码示例来源:origin: getheimdall/heimdall
/**
* Get expiration {@link LocalDateTime} from token.
*
* @param token The token
* @param privateKey The privateKey used to generate token
* @return The expiration {@link LocalDateTime}
* @throws HeimdallException If token expired
*/
public static LocalDateTime recoverDateExpirationFromToken(String token, String privateKey) throws HeimdallException {
Claims claims = getClaimsFromTheToken(token, encodePrivateKey(privateKey));
return claims.getExpiration().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
}
内容来源于网络,如有侵权,请联系作者删除!