|
|
@@ -17,6 +17,7 @@ public class JwtUtil {
|
|
|
public static final String SHIRO_USER_NAME = "username";
|
|
|
public static final String SHIRO_USER_ID = "userId";
|
|
|
public static final String SHIRO_FTY_ID = "ftyId";
|
|
|
+ public static final String SHIRO_FTY_CODE = "ftyCode";
|
|
|
public static final String SHIRO_CLIENT_ID = "clientId";
|
|
|
public static final String SHIRO_APP_CODE = "appCode";
|
|
|
public static final String SHIRO_USER_SALT = "salt";
|
|
|
@@ -59,7 +60,7 @@ public class JwtUtil {
|
|
|
* @param request
|
|
|
* @return
|
|
|
*/
|
|
|
- public static String getDecryptToken(HttpServletRequest request,String AESKey) {
|
|
|
+ public static String getDecryptToken(HttpServletRequest request, String AESKey) {
|
|
|
String token = "";
|
|
|
try {
|
|
|
// 构建 OAuth2 资源请求
|
|
|
@@ -74,9 +75,9 @@ public class JwtUtil {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获得token中的信息无需secret解密也能获得
|
|
|
- *
|
|
|
- * @return token中包含的用户名
|
|
|
+ * @desc : 获取token中UserName
|
|
|
+ * @author : 周兴
|
|
|
+ * @date : 2023/2/26 16:32
|
|
|
*/
|
|
|
public static String getUserName(String token) {
|
|
|
try {
|
|
|
@@ -88,6 +89,11 @@ public class JwtUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @desc : 获取token中UserId
|
|
|
+ * @author : 周兴
|
|
|
+ * @date : 2023/2/26 16:32
|
|
|
+ */
|
|
|
public static String getUserId(String token) {
|
|
|
try {
|
|
|
DecodedJWT jwt = JWT.decode(token);
|
|
|
@@ -98,7 +104,12 @@ public class JwtUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static String getCompanyId(String token) {
|
|
|
+ /**
|
|
|
+ * @desc : 获取token中FtyId
|
|
|
+ * @author : 周兴
|
|
|
+ * @date : 2023/2/26 16:32
|
|
|
+ */
|
|
|
+ public static String getFtyId(String token) {
|
|
|
try {
|
|
|
DecodedJWT jwt = JWT.decode(token);
|
|
|
return jwt.getClaim(SHIRO_FTY_ID).asString();
|
|
|
@@ -108,6 +119,26 @@ public class JwtUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @desc : 获取token中FtyCode
|
|
|
+ * @author : 周兴
|
|
|
+ * @date : 2023/2/26 16:32
|
|
|
+ */
|
|
|
+ public static String getFtyCode(String token) {
|
|
|
+ try {
|
|
|
+ DecodedJWT jwt = JWT.decode(token);
|
|
|
+ return jwt.getClaim(SHIRO_FTY_CODE).asString();
|
|
|
+ } catch (JWTDecodeException e) {
|
|
|
+ log.error("error:{}", e.getMessage());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 获取token中Lang
|
|
|
+ * @author : 周兴
|
|
|
+ * @date : 2023/2/26 16:32
|
|
|
+ */
|
|
|
public static String getLang(String token) {
|
|
|
try {
|
|
|
DecodedJWT jwt = JWT.decode(token);
|
|
|
@@ -145,7 +176,7 @@ public class JwtUtil {
|
|
|
* @param salt 盐值
|
|
|
* @return 加密的token
|
|
|
*/
|
|
|
- public static String sign(String username, String userId, String appCode, String clientId, String salt,String ftyId,String lang) {
|
|
|
+ public static String sign(String username, String userId, String appCode, String clientId, String salt, String ftyId, String ftyCode, String lang) {
|
|
|
Date expireDate = new Date(System.currentTimeMillis() + OauthConstants.EXPIRES_IN);
|
|
|
//加盐值
|
|
|
Algorithm algorithm = Algorithm.HMAC256(salt);
|
|
|
@@ -154,6 +185,7 @@ public class JwtUtil {
|
|
|
.withClaim(SHIRO_USER_NAME, username)
|
|
|
.withClaim(SHIRO_USER_ID, userId)
|
|
|
.withClaim(SHIRO_FTY_ID, ftyId)
|
|
|
+ .withClaim(SHIRO_FTY_CODE, ftyCode)
|
|
|
.withClaim(SHIRO_APP_CODE, appCode)
|
|
|
.withClaim(SHIRO_CLIENT_ID, clientId)
|
|
|
.withClaim(SHIRO_USER_SALT, salt)
|
|
|
@@ -174,7 +206,7 @@ public class JwtUtil {
|
|
|
.sign(algorithm);
|
|
|
}
|
|
|
|
|
|
- public static String sign(String username, String userId, String appCode, String clientId, String salt, String grantType,String ftyId,String lang) {
|
|
|
+ public static String sign(String username, String userId, String appCode, String clientId, String salt, String grantType, String ftyId, String ftyCode, String lang) {
|
|
|
Date expireDate = new Date(System.currentTimeMillis() + OauthConstants.EXPIRES_IN);
|
|
|
//加盐值
|
|
|
Algorithm algorithm = Algorithm.HMAC256(salt);
|
|
|
@@ -183,6 +215,7 @@ public class JwtUtil {
|
|
|
.withClaim(SHIRO_USER_NAME, username)
|
|
|
.withClaim(SHIRO_USER_ID, userId)
|
|
|
.withClaim(SHIRO_FTY_ID, ftyId)
|
|
|
+ .withClaim(SHIRO_FTY_CODE, ftyCode)
|
|
|
.withClaim(SHIRO_APP_CODE, appCode)
|
|
|
.withClaim(SHIRO_CLIENT_ID, clientId)
|
|
|
.withClaim(SHIRO_USER_SALT, salt)
|
|
|
@@ -204,7 +237,7 @@ public class JwtUtil {
|
|
|
.sign(algorithm);
|
|
|
}
|
|
|
|
|
|
- public static String sign(String username, String clientId, String salt,String ftyId,String lang) {
|
|
|
+ public static String sign(String username, String clientId, String salt, String ftyId, String ftyCode, String lang) {
|
|
|
Date expireDate = new Date(System.currentTimeMillis() + OauthConstants.EXPIRES_IN);
|
|
|
//加盐值
|
|
|
Algorithm algorithm = Algorithm.HMAC256(salt);
|
|
|
@@ -212,6 +245,7 @@ public class JwtUtil {
|
|
|
return JWT.create()
|
|
|
.withClaim(SHIRO_USER_NAME, username)
|
|
|
.withClaim(SHIRO_FTY_ID, ftyId)
|
|
|
+ .withClaim(SHIRO_FTY_CODE, ftyCode)
|
|
|
.withClaim(SHIRO_CLIENT_ID, clientId)
|
|
|
.withClaim(SHIRO_USER_SALT, salt)
|
|
|
.withClaim(SHIRO_APP_LANG, lang)
|