|
@@ -12,11 +12,13 @@ import cn.reghao.jutil.web.ServletUtil;
|
|
|
import cn.reghao.tnb.account.app.model.vo.AccountToken;
|
|
import cn.reghao.tnb.account.app.model.vo.AccountToken;
|
|
|
import cn.reghao.tnb.account.app.security.form.AccountAuthToken;
|
|
import cn.reghao.tnb.account.app.security.form.AccountAuthToken;
|
|
|
import cn.reghao.tnb.account.app.service.PubkeyService;
|
|
import cn.reghao.tnb.account.app.service.PubkeyService;
|
|
|
-import cn.reghao.tnb.account.app.util.JwtUtil;
|
|
|
|
|
|
|
+import cn.reghao.tnb.account.app.util.AuthConverter;
|
|
|
|
|
+import cn.reghao.jutil.auth.JwtUtil;
|
|
|
import cn.reghao.tnb.account.app.redis.RedisKeys;
|
|
import cn.reghao.tnb.account.app.redis.RedisKeys;
|
|
|
-import cn.reghao.tnb.account.app.model.vo.RefreshPayload;
|
|
|
|
|
|
|
+import cn.reghao.jutil.auth.model.RefreshPayload;
|
|
|
import cn.reghao.tnb.account.app.redis.ds.RedisString;
|
|
import cn.reghao.tnb.account.app.redis.ds.RedisString;
|
|
|
import cn.reghao.tnb.account.app.redis.ds.RedisStringObject;
|
|
import cn.reghao.tnb.account.app.redis.ds.RedisStringObject;
|
|
|
|
|
+import cn.reghao.jutil.auth.model.JwtPayload;
|
|
|
import cn.reghao.tnb.common.util.ConstantId;
|
|
import cn.reghao.tnb.common.util.ConstantId;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
|
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
|
@@ -30,6 +32,7 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.servlet.http.Cookie;
|
|
import javax.servlet.http.Cookie;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
|
+import java.security.PrivateKey;
|
|
|
import java.security.interfaces.RSAPrivateKey;
|
|
import java.security.interfaces.RSAPrivateKey;
|
|
|
import java.security.interfaces.RSAPublicKey;
|
|
import java.security.interfaces.RSAPublicKey;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -77,15 +80,16 @@ public class AccountTokenServiceImpl implements AccountTokenService {
|
|
|
long accessExpireIn = 1000L*3600*24*7;
|
|
long accessExpireIn = 1000L*3600*24*7;
|
|
|
long accessExpireAt = System.currentTimeMillis() + accessExpireIn;
|
|
long accessExpireAt = System.currentTimeMillis() + accessExpireIn;
|
|
|
String accessToken = "";
|
|
String accessToken = "";
|
|
|
|
|
+ JwtPayload jwtPayload = AuthConverter.getJwtPayload(authToken);
|
|
|
if (signKeyPrivate != null) {
|
|
if (signKeyPrivate != null) {
|
|
|
- accessToken = JwtUtil.createAccessToken(authToken, userId, accessExpireAt, signKeyPrivate);
|
|
|
|
|
|
|
+ accessToken = JwtUtil.createAccessToken(jwtPayload, accessExpireAt, signKeyPrivate);
|
|
|
} else {
|
|
} else {
|
|
|
- accessToken = JwtUtil.createAccessToken(authToken, userId, accessExpireAt, signKeyRandom);
|
|
|
|
|
|
|
+ accessToken = JwtUtil.createAccessToken(jwtPayload, accessExpireAt, signKeyRandom);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
long refreshExpireIn = accessExpireIn*4;
|
|
long refreshExpireIn = accessExpireIn*4;
|
|
|
long refreshExpireAt = System.currentTimeMillis() + refreshExpireIn;
|
|
long refreshExpireAt = System.currentTimeMillis() + refreshExpireIn;
|
|
|
- String refreshToken = JwtUtil.createRefreshToken(authToken, refreshExpireAt, signKeyRandom);
|
|
|
|
|
|
|
+ String refreshToken = JwtUtil.createRefreshToken(jwtPayload, refreshExpireAt, signKeyRandom);
|
|
|
|
|
|
|
|
if (signKeyPrivate == null) {
|
|
if (signKeyPrivate == null) {
|
|
|
redisString.setWithTimeout(RedisKeys.getAccessSignKeyKey(accessToken), signKeyRandom, accessExpireIn);
|
|
redisString.setWithTimeout(RedisKeys.getAccessSignKeyKey(accessToken), signKeyRandom, accessExpireIn);
|
|
@@ -99,6 +103,10 @@ public class AccountTokenServiceImpl implements AccountTokenService {
|
|
|
return new AccountToken(accessToken, accessExpireAt, refreshToken, refreshExpireAt);
|
|
return new AccountToken(accessToken, accessExpireAt, refreshToken, refreshExpireAt);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private JwtPayload getJwtPayload(AccountAuthToken accountAuthToken, String signKey, PrivateKey privateKey) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public void refreshToken(long userId, String loginId) {
|
|
public void refreshToken(long userId, String loginId) {
|
|
|
log.info("令牌刷新尚未实现");
|
|
log.info("令牌刷新尚未实现");
|
|
|
}
|
|
}
|
|
@@ -292,15 +300,17 @@ public class AccountTokenServiceImpl implements AccountTokenService {
|
|
|
String savedSignKey = redisString.get(RedisKeys.getJwtSignKey("pubkey"));
|
|
String savedSignKey = redisString.get(RedisKeys.getJwtSignKey("pubkey"));
|
|
|
RSAPublicKey rsaPublicKey = RsaCryptor.getRSAPublicKey(savedSignKey);
|
|
RSAPublicKey rsaPublicKey = RsaCryptor.getRSAPublicKey(savedSignKey);
|
|
|
try {
|
|
try {
|
|
|
- AccountAuthToken userAuthToken = JwtUtil.getAuthentication(token, rsaPublicKey);
|
|
|
|
|
- if (userAuthToken != null) {
|
|
|
|
|
|
|
+ JwtPayload jwtPayload = JwtUtil.getJwtPayload(token, rsaPublicKey);
|
|
|
|
|
+ if (jwtPayload != null) {
|
|
|
|
|
+ AccountAuthToken userAuthToken = AuthConverter.getAccountAuthToken(jwtPayload);
|
|
|
long userId = userAuthToken.getUserId();
|
|
long userId = userAuthToken.getUserId();
|
|
|
String loginId = userAuthToken.getLoginId();
|
|
String loginId = userAuthToken.getLoginId();
|
|
|
String redisKey = RedisKeys.getAuthTokenKey(userId, loginId);
|
|
String redisKey = RedisKeys.getAuthTokenKey(userId, loginId);
|
|
|
boolean online = redisOps.exists(redisKey);
|
|
boolean online = redisOps.exists(redisKey);
|
|
|
return online ? userAuthToken : null;
|
|
return online ? userAuthToken : null;
|
|
|
}
|
|
}
|
|
|
- } catch (Exception ignore) {
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
return null;
|
|
@@ -313,7 +323,7 @@ public class AccountTokenServiceImpl implements AccountTokenService {
|
|
|
throw new Exception("refresh-token 已过期");
|
|
throw new Exception("refresh-token 已过期");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- RefreshPayload refreshPayload = JwtUtil.parseRefreshToken(refreshToken, signKey);
|
|
|
|
|
|
|
+ RefreshPayload refreshPayload = JwtUtil.getRefreshPayload(refreshToken, signKey);
|
|
|
int plat = refreshPayload.getPlat();
|
|
int plat = refreshPayload.getPlat();
|
|
|
String loginId = refreshPayload.getLoginId();
|
|
String loginId = refreshPayload.getLoginId();
|
|
|
long userId = refreshPayload.getUserId();
|
|
long userId = refreshPayload.getUserId();
|