本文整理匯總了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());
}