本文整理了Java中io.jsonwebtoken.Claims.setExpiration()
方法的一些代码示例,展示了Claims.setExpiration()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Claims.setExpiration()
方法的具体详情如下:
包路径:io.jsonwebtoken.Claims
类名称:Claims
方法名:setExpiration
暂无
代码示例来源:origin: jwtk/jjwt
@Override
public JwtParser requireExpiration(Date expiration) {
expectedClaims.setExpiration(expiration);
return this;
}
代码示例来源:origin: jwtk/jjwt
@Override
public JwtBuilder setExpiration(Date exp) {
if (exp != null) {
ensureClaims().setExpiration(exp);
} else {
if (this.claims != null) {
//noinspection ConstantConditions
this.claims.setExpiration(exp);
}
}
return this;
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void validate_token_does_not_refresh_session_when_disconnected_timeout_is_reached() {
UserDto user = db.users().insertUser();
addJwtCookie();
// Token was created 4 months ago, refreshed 4 minutes ago, and it expired in 5 minutes
Claims claims = createToken(user.getUuid(), NOW - (4L * 30 * 24 * 60 * 60 * 1000));
claims.setExpiration(new Date(NOW + 5 * 60 * 1000));
claims.put("lastRefreshTime", FOUR_MINUTES_AGO);
when(jwtSerializer.decode(JWT_TOKEN)).thenReturn(Optional.of(claims));
assertThat(underTest.validateToken(request, response).isPresent()).isFalse();
}
代码示例来源:origin: szerhusenBC/jwt-spring-security-demo
public String refreshToken(String token) {
final Date createdDate = clock.now();
final Date expirationDate = calculateExpirationDate(createdDate);
final Claims claims = getAllClaimsFromToken(token);
claims.setIssuedAt(createdDate);
claims.setExpiration(expirationDate);
return Jwts.builder()
.setClaims(claims)
.signWith(SignatureAlgorithm.HS512, secret)
.compact();
}
代码示例来源: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: io.jsonwebtoken/jjwt
@Override
public JwtParser requireExpiration(Date expiration) {
expectedClaims.setExpiration(expiration);
return this;
}
代码示例来源:origin: io.jsonwebtoken/jjwt-impl
@Override
public JwtParser requireExpiration(Date expiration) {
expectedClaims.setExpiration(expiration);
return this;
}
代码示例来源:origin: io.jsonwebtoken/jjwt-impl
@Override
public JwtBuilder setExpiration(Date exp) {
if (exp != null) {
ensureClaims().setExpiration(exp);
} else {
if (this.claims != null) {
//noinspection ConstantConditions
this.claims.setExpiration(exp);
}
}
return this;
}
代码示例来源:origin: io.jsonwebtoken/jjwt
@Override
public JwtBuilder setExpiration(Date exp) {
if (exp != null) {
ensureClaims().setExpiration(exp);
} else {
if (this.claims != null) {
//noinspection ConstantConditions
this.claims.setExpiration(exp);
}
}
return this;
}
代码示例来源:origin: craftingjava/springuni-particles
@Override
public String createJwtToken(Authentication authentication, int minutes) {
Claims claims = Jwts.claims()
.setId(String.valueOf(IdentityGenerator.generate()))
.setSubject(authentication.getName())
.setExpiration(new Date(currentTimeMillis() + minutes * 60 * 1000))
.setIssuedAt(new Date());
String authorities = authentication.getAuthorities()
.stream()
.map(GrantedAuthority::getAuthority)
.map(String::toUpperCase)
.collect(Collectors.joining(","));
claims.put(AUTHORITIES, authorities);
return Jwts.builder()
.setClaims(claims)
.signWith(HS512, secretkey)
.compact();
}
代码示例来源:origin: Jasig/uPortal
protected Claims createClaims(
Class<? extends ITokenizable> clazz, String username, Date expires) {
// Registered claims
final Claims rslt =
Jwts.claims()
.setIssuer(JWT_ISSUER)
.setSubject(username)
.setExpiration(expires)
.setIssuedAt(new Date())
.setId(UUID.randomUUID().toString());
// Deserialization class
rslt.put(JwtClaims.CLASS.getName(), clazz.getName());
return rslt;
}
代码示例来源:origin: craftingjava/springuni-particles
@Override
protected String encodeCookie(String[] cookieTokens) {
Claims claims = Jwts.claims()
.setId(cookieTokens[0])
.setSubject(cookieTokens[1])
.setExpiration(new Date(currentTimeMillis() + getTokenValiditySeconds() * 1000L))
.setIssuedAt(new Date());
return Jwts.builder()
.setClaims(claims)
.signWith(HS512, getKey())
.compact();
}
代码示例来源:origin: jloisel/securing-rest-api-spring-security
private String newToken(final Map<String, String> attributes, final int expiresInSec) {
final DateTime now = dates.now();
final Claims claims = Jwts
.claims()
.setIssuer(issuer)
.setIssuedAt(now.toDate());
if (expiresInSec > 0) {
final DateTime expiresAt = now.plusSeconds(expiresInSec);
claims.setExpiration(expiresAt.toDate());
}
claims.putAll(attributes);
return Jwts
.builder()
.setClaims(claims)
.signWith(HS256, secretKey)
.compressWith(COMPRESSION_CODEC)
.compact();
}
代码示例来源:origin: elunez/eladmin
public String refreshToken(String token) {
final Date createdDate = clock.now();
final Date expirationDate = calculateExpirationDate(createdDate);
final Claims claims = getAllClaimsFromToken(token);
claims.setIssuedAt(createdDate);
claims.setExpiration(expirationDate);
return Jwts.builder()
.setClaims(claims)
.signWith(SignatureAlgorithm.HS512, secret)
.compact();
}
代码示例来源:origin: liumapp/spring-security-mybatis-demo
public String refreshToken(String token) {
final Date createdDate = clock.now();
final Date expirationDate = calculateExpirationDate(createdDate);
final Claims claims = getAllClaimsFromToken(token);
claims.setIssuedAt(createdDate);
claims.setExpiration(expirationDate);
return Jwts.builder()
.setClaims(claims)
.signWith(SignatureAlgorithm.HS512, secret)
.compact();
}
代码示例来源:origin: yujunhao8831/spring-boot-start-current
public String refreshToken(String token) {
final Date createdDate = clock.now();
final Date expirationDate = calculateExpirationDate(createdDate);
final Claims claims = getAllClaimsFromToken(token);
claims.setIssuedAt(createdDate);
claims.setExpiration(expirationDate);
return Jwts.builder()
.setClaims(claims)
.signWith(SignatureAlgorithm.HS512, secret)
.compact();
}
代码示例来源:origin: pram/spring-react-boilerplate
public String refreshToken(String token) {
final Date createdDate = clock.now();
final Date expirationDate = calculateExpirationDate(createdDate);
final Claims claims = getAllClaimsFromToken(token);
claims.setIssuedAt(createdDate);
claims.setExpiration(expirationDate);
return Jwts.builder()
.setClaims(claims)
.signWith(SignatureAlgorithm.HS512, secret)
.compact();
}
代码示例来源:origin: lpsandaruwan/depli
public String refreshToken(String token) {
final Date createdDate = timeProvider.now();
final Date expirationDate = calculateExpirationDate(createdDate);
final Claims claims = getAllClaimsFromToken(token);
claims.setIssuedAt(createdDate);
claims.setExpiration(expirationDate);
return Jwts.builder()
.setClaims(claims)
.signWith(SignatureAlgorithm.HS512, secret)
.compact();
}
内容来源于网络,如有侵权,请联系作者删除!