|
|
|
|
@ -6,10 +6,10 @@ import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import egovframework.com.cmm.LoginVO;
|
|
|
|
|
import egovframework.com.cmm.service.EgovProperties;
|
|
|
|
|
import io.jsonwebtoken.Claims;
|
|
|
|
|
import io.jsonwebtoken.Jwts;
|
|
|
|
|
import io.jsonwebtoken.SignatureAlgorithm;
|
|
|
|
|
@ -24,8 +24,7 @@ public class EgovJwtTokenUtil implements Serializable{
|
|
|
|
|
//public static final long JWT_TOKEN_VALIDITY = 24 * 60 * 60; //하루
|
|
|
|
|
public static final long JWT_TOKEN_VALIDITY = (long) ((1 * 60 * 60) / 60) * 60; //토큰의 유효시간 설정, 기본 60분
|
|
|
|
|
|
|
|
|
|
@Value("egovframe")
|
|
|
|
|
private String secret;
|
|
|
|
|
public static final String SECRET_KEY = EgovProperties.getProperty("Globals.jwt.secret");
|
|
|
|
|
|
|
|
|
|
//retrieve username from jwt token
|
|
|
|
|
public String getUsernameFromToken(String token) {
|
|
|
|
|
@ -44,8 +43,8 @@ public class EgovJwtTokenUtil implements Serializable{
|
|
|
|
|
|
|
|
|
|
//for retrieveing any information from token we will need the secret key
|
|
|
|
|
public Claims getAllClaimsFromToken(String token) {
|
|
|
|
|
log.debug("===>>> secret = "+secret);
|
|
|
|
|
return Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody();
|
|
|
|
|
log.debug("===>>> secret = "+SECRET_KEY);
|
|
|
|
|
return Jwts.parser().setSigningKey(SECRET_KEY).parseClaimsJws(token).getBody();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//check if the token has expired
|
|
|
|
|
@ -70,10 +69,10 @@ public class EgovJwtTokenUtil implements Serializable{
|
|
|
|
|
//3. According to JWS Compact Serialization(https://tools.ietf.org/html/draft-ietf-jose-json-web-signature-41#section-3.1)
|
|
|
|
|
// compaction of the JWT to a URL-safe string
|
|
|
|
|
private String doGenerateToken(Map<String, Object> claims, String subject) {
|
|
|
|
|
log.debug("===>>> secret = "+secret);
|
|
|
|
|
log.debug("===>>> secret = "+SECRET_KEY);
|
|
|
|
|
return Jwts.builder().setClaims(claims).setSubject(subject).setIssuedAt(new Date(System.currentTimeMillis()))
|
|
|
|
|
.setExpiration(new Date(System.currentTimeMillis() + JWT_TOKEN_VALIDITY * 1000))
|
|
|
|
|
.signWith(SignatureAlgorithm.HS512, secret).compact();
|
|
|
|
|
.signWith(SignatureAlgorithm.HS512, SECRET_KEY).compact();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//validate token
|
|
|
|
|
|