TRX hace 1 año
padre
commit
f5900d9d7e

+ 3 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/login/LoginCommonModel.java

@@ -44,4 +44,7 @@ public class LoginCommonModel {
 
     @Schema(description = "用户权限列表")
     private Set<String> auths;
+
+    @Schema(description = "权限字符串")
+    private String permiss;
 }

+ 13 - 6
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/org/IndexService.java

@@ -27,6 +27,7 @@ import com.zhongshu.card.server.core.service.base.RedisService;
 import com.zhongshu.card.server.core.service.setting.PlatFormConfigInfoService;
 import com.zhongshu.card.server.core.service.user.RoleServiceImpl;
 import com.zhongshu.card.server.core.service.user.UserAccountServiceImpl;
+import com.zhongshu.card.server.core.util.AesUtils;
 import com.zhongshu.card.server.core.util.CommonUtil;
 import com.zhongshu.card.server.core.util.wx.WechatCUtil;
 import jakarta.servlet.http.HttpServletRequest;
@@ -243,7 +244,16 @@ public class IndexService {
         stopWatch.start("3");
         // 用户所有的权限
         Set<String> auth = roleServiceImpl.getUserAllAuths(userAccount.getUserId());
+        String aesStr = "";
+        if (auth != null && !auth.isEmpty()) {
+            try {
+                aesStr = AesUtils.encrypt(String.join(",", auth), "lIllIIIllIIIllIl");
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
         commonModel.setAuths(auth);
+        commonModel.setPermiss(aesStr);
         stopWatch.stop();
         log.info(stopWatch.prettyPrint());
 
@@ -316,8 +326,7 @@ public class IndexService {
         if (ObjectUtils.isEmpty(organization)) {
             return ResultContent.buildFail(String.format("平台未初始化,请联系管理员"));
         }
-        if (organization.getState() == OrganizationState.Locked ||
-                organization.getState() == OrganizationState.Frozen) {
+        if (organization.getState() == OrganizationState.Locked || organization.getState() == OrganizationState.Frozen) {
             return ResultContent.buildFail(String.format("平台已被锁定,不能登录"));
         }
         UserAccount userAccount = userCountDao.findTopByLoginName(phone);
@@ -475,8 +484,7 @@ public class IndexService {
             return ResultContent.buildSuccess(resultContent.getContent());
         } else {
             // 记录登录失败信息
-            userLoginFailRecordDao.save(UserLoginFailRecord.builder().userName(phone)
-                    .ttl(new Date(dbHelper.getTime() + lockTime)).build());
+            userLoginFailRecordDao.save(UserLoginFailRecord.builder().userName(phone).ttl(new Date(dbHelper.getTime() + lockTime)).build());
             String msg = resultContent.getMsg();
             if (StringUtils.isEmpty(msg)) {
                 msg = "账号或密码不正确.";
@@ -509,8 +517,7 @@ public class IndexService {
      * @return
      */
     public ResultContent loginOut() {
-        com.github.microservice.auth.client.content.ResultContent<Long> resultContent =
-                userService.logoutFromToken(authHelper.getUserToken());
+        com.github.microservice.auth.client.content.ResultContent<Long> resultContent = userService.logoutFromToken(authHelper.getUserToken());
         if (resultContent.getState() == ResultState.Success) {
         } else {
             return ResultContent.buildFail(resultContent.getMsg());

+ 24 - 14
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/user/RoleServiceImpl.java

@@ -463,7 +463,8 @@ public class RoleServiceImpl extends SuperService {
         if (ObjectUtils.isEmpty(userAccount)) {
             return auth;
         }
-        List<OrganizationUser> organizationUsers = organizationUserDao.findByUserAndAuthType(userAccount, AuthType.Platform);
+//        List<OrganizationUser> organizationUsers = organizationUserDao.findByUserAndAuthType(userAccount, AuthType.Platform);
+        List<OrganizationUser> organizationUsers = organizationUserDao.findByUserId(userAccount.getUserId());
         if (ObjectUtils.isEmpty(organizationUsers)) {
             return auth;
         }
@@ -471,22 +472,31 @@ public class RoleServiceImpl extends SuperService {
             Organization organization = organizationUser.getOrganization();
             String oid = organization.getOid();
 
-            var roleGroupModels = roleService.listRoleGroupFromOrganizationUser(oid, userId).getContent();
-            if (!CollectionUtils.isEmpty(roleGroupModels)) {
-                roleGroupModels.stream().forEach(roleGroup -> {
-                    if (!CollectionUtils.isEmpty(roleGroup.getRoleId())) {
-                        roleGroup.getRoleId().stream().forEach(it -> {
-                            var role = roleService.getRole(it).getContent();
-                            if (role != null && !CollectionUtils.isEmpty(role.getAuth())) {
-                                auth.addAll(role.getAuth());
-                            }
-                        });
+            List<Role> roles = organizationUser.getRoles();
+
+//            var roleGroupModels = roleService.listRoleGroupFromOrganizationUser(oid, userId).getContent();
+//            if (!CollectionUtils.isEmpty(roleGroupModels)) {
+//                roleGroupModels.stream().forEach(roleGroup -> {
+//                    if (!CollectionUtils.isEmpty(roleGroup.getRoleId())) {
+//                        roleGroup.getRoleId().stream().forEach(it -> {
+//                            var role = roleService.getRole(it).getContent();
+//                            if (role != null && !CollectionUtils.isEmpty(role.getAuth())) {
+//                                auth.addAll(role.getAuth());
+//                            }
+//                        });
+//                    }
+//                });
+//            }
+
+
+            if (ObjectUtils.isNotEmpty(roles)) {
+                roles.stream().forEach(tempRole -> {
+                    var role = roleService.getRole(tempRole.getRoleId()).getContent();
+                    if (role != null && !CollectionUtils.isEmpty(role.getAuth())) {
+                        auth.addAll(role.getAuth());
                     }
                 });
-            }
 
-            List<Role> roles = organizationUser.getRoles();
-            if (ObjectUtils.isNotEmpty(roles)) {
                 List<Role> _list = roles.stream().filter(it -> {
                     return it.getIsAdmin();
                 }).collect(Collectors.toList());

+ 18 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/util/AesUtils.java

@@ -6,6 +6,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.bouncycastle.jce.provider.BouncyCastleProvider;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.crypto.Cipher;
 import javax.crypto.Mac;
 import javax.crypto.spec.SecretKeySpec;
 import java.io.ByteArrayOutputStream;
@@ -32,6 +33,23 @@ public class AesUtils {
         return toHexString(md.digest());
     }
 
+    public static String encrypt(String data, String SECRET_KEY) throws Exception {
+        Cipher cipher = Cipher.getInstance("AES");
+        SecretKeySpec secretKeySpec = new SecretKeySpec(SECRET_KEY.getBytes(), "AES");
+        cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
+        byte[] encryptedBytes = cipher.doFinal(data.getBytes());
+        String str = new String(encryptedBytes, "utf-8");
+
+        Cipher cipher1 = Cipher.getInstance("AES");
+        SecretKeySpec secretKeySpec1 = new SecretKeySpec(SECRET_KEY.getBytes(), "AES");
+        cipher1.init(Cipher.DECRYPT_MODE, secretKeySpec1);
+        byte[] encryptedBytes1 = cipher1.doFinal(encryptedBytes);
+        String str1 = new String(encryptedBytes1);
+        log.info("==: {}", str1);
+
+        return new String(Base64.getEncoder().encode(encryptedBytes));
+    }
+
     @SneakyThrows
     public static String signMacSHA256(String str, String key) {
         Mac mac = Mac.getInstance("HmacSHA256");