Просмотр исходного кода

用户登录Token添加factoryId绑定,请求解绑得到factoryId的信息

v_HuilingDeng 3 лет назад
Родитель
Сommit
044f0e31ef

+ 5 - 0
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/infrastructure/interceptor/TokenInterceptor.java

@@ -20,6 +20,7 @@ import javax.servlet.http.HttpServletResponse;
 import java.lang.reflect.Method;
 import java.text.MessageFormat;
 import java.util.Map;
+import java.util.Objects;
 import java.util.concurrent.TimeUnit;
 
 import static com.abi.qms.platform.infrastructure.constant.RedisKey.TOKEN_KEY;
@@ -74,10 +75,14 @@ public class TokenInterceptor implements HandlerInterceptor {
             redisClient.expire(redisTokenKey,2, TimeUnit.HOURS);
             String userName = userMap.get("userName").asString();
             String roleCode = userMap.get("roleCode").asString();
+            Long factoryId = userMap.get("factoryId").asLong();
             UserInfo userInfo = new UserInfo();
             userInfo.setId(Long.valueOf(userId));
             userInfo.setUserName(userName);
             userInfo.setRoleCode(roleCode);
+            if(Objects.nonNull(factoryId)) {
+                userInfo.setFactoryId(factoryId);
+            }
             UserUtil.setUser(userInfo);
         } catch (JWTDecodeException j) {
             throw new BusinessException(401,"用户认证失败");

+ 1 - 0
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/infrastructure/util/JwtTokenUtils.java

@@ -63,6 +63,7 @@ public class JwtTokenUtils{
                     .withClaim("userId",user.getId())
                     .withClaim("userName",user.getUserName())
                     .withClaim("roleCode",user.getRoleCode())
+                    .withClaim("factoryId",user.getFactoryId())
                     .withClaim("roles","")
                     .sign(Algorithm.RSA512((RSAPublicKey)globalRsaKeyMap.get(RSA_PUBLIC_KEY),
                             (RSAPrivateKey)globalRsaKeyMap.get(RSA_PRIVATE_KEY)));