use of com.auth0.json.mgmt.Token in project seckill by yt-King.
the class JWTUtils method isExpire.
/**
* 判断过期
* @param token
* @return
*/
public static boolean isExpire(String token) {
DecodedJWT jwt = null;
jwt = JWT.decode(token);
return System.currentTimeMillis() > jwt.getExpiresAt().getTime();
}
use of com.auth0.json.mgmt.Token in project iesi by metadew.
the class JwtService method generateAuthenticationResponse.
public AuthenticationResponse generateAuthenticationResponse(Authentication authentication) {
Algorithm algorithm = Algorithm.HMAC256(secret);
LocalDateTime now = LocalDateTime.now(clock);
LocalDateTime expiresAt = now.plus(accessTokenExpiryDate, ChronoUnit.SECONDS);
String token = JWT.create().withIssuer(ISSUER).withSubject(authentication.getName()).withIssuedAt(Timestamp.valueOf(now)).withExpiresAt(Timestamp.valueOf(expiresAt)).withClaim("uuid", ((IesiUserDetails) authentication.getPrincipal()).getId().toString()).sign(algorithm);
UserDto userDto = userService.get(((IesiUserDetails) authentication.getPrincipal()).getId()).orElseThrow(() -> new UsernameNotFoundException(String.format("Cannot find user %s (%s)", ((IesiUserDetails) authentication.getPrincipal()).getId().toString(), ((IesiUserDetails) authentication.getPrincipal()).getUsername())));
return new AuthenticationResponse(token, ChronoUnit.SECONDS.between(now, expiresAt), userDto.getRoles());
}
use of com.auth0.json.mgmt.Token in project code by lastwhispers.
the class UserController method login.
/**
* http://localhost:8080/user/login?username=admin&password=123456
*
* @param username
* @param password
* @return
*/
@GetMapping("/login")
public String login(@RequestParam String username, @RequestParam String password) {
Algorithm algorithm = Algorithm.HMAC256(JWT_KEY);
String token = JWT.create().withClaim(CURRENT_USER, username).withClaim(UID, 1).withExpiresAt(new Date(System.currentTimeMillis() + 3600000)).sign(algorithm);
return token;
}
use of com.auth0.json.mgmt.Token in project jobs by damingerdai.
the class JWTUtil method sign.
/**
* 生成签名,5min后过期
* @param username 用户名
* @param secret 用户的密码
* @return 加密的token
*/
public static String sign(String username, String secret) {
Date date = new Date(System.currentTimeMillis() + EXPIRE_TIME);
Algorithm algorithm = Algorithm.HMAC256(secret);
// 附带username信息
return JWT.create().withClaim("username", username).withExpiresAt(date).sign(algorithm);
}
use of com.auth0.json.mgmt.Token in project jobs by damingerdai.
the class JwtTool method verifyToken.
public static boolean verifyToken(String token, String secret) {
try {
Algorithm algorithm = Algorithm.HMAC256(secret);
var verifier = JWT.require(algorithm).build();
var jwt = verifier.verify(token);
return true;
} catch (Exception ex) {
ex.printStackTrace();
return false;
}
}
Aggregations