Forráskód Böngészése

去除角色用户相关信息

lyhzzz 3 éve
szülő
commit
8858eeb36c

+ 17 - 0
platform-common/src/main/java/com/platform/service/impl/ZhiHouseService.java

@@ -279,4 +279,21 @@ public class ZhiHouseService {
         CurrentUserLoginVo user = (CurrentUserLoginVo) responseEntity.getBody().getMessage();
         return user;
     }
+
+    public List<String> getAllPerms(Long userId) {
+        Map<String, Object> mp = new HashMap<>();
+        if(userId!=null){
+            mp.put("userId",userId);
+        }
+        String url = zhiHouseHost + "api/shop/getAllPerms";
+        ResponseEntity<ReturnDTO>  responseEntity = restTemplate.postForEntity(url, mp,ReturnDTO.class);
+        if(responseEntity.getStatusCode()!= HttpStatus.OK){
+            throw new CommonBaseException(ResultCodeEnum.D100);
+        }
+        if (responseEntity.getBody().getCode() != 200) {
+            throw new CommonBaseException(ResultCodeEnum.D100,responseEntity.getBody().getError());
+        }
+        List<String> list = (List<String>) responseEntity.getBody().getMessage();
+        return list;
+    }
 }

+ 25 - 36
platform-common/src/main/java/com/platform/shiro/UserRealm.java

@@ -1,5 +1,6 @@
 package com.platform.shiro;
 
+import com.alibaba.fastjson.JSON;
 import com.auth0.jwt.JWT;
 import com.alibaba.fastjson.JSONObject;
 import com.platform.cache.J2CacheUtils;
@@ -7,10 +8,13 @@ import com.platform.shiro.jwt.JwtToken;
 import com.platform.service.impl.ZhiHouseService;
 import com.platform.utils.Constant;
 import com.platform.utils.JwtUtil;
+import com.platform.utils.LettuceRedisClientUtils;
 import com.platform.vos.CurrentUserLoginVo;
 import com.platform.vos.TbUser;
 import io.jsonwebtoken.Claims;
 import lombok.extern.slf4j.Slf4j;
+import net.oschina.j2cache.redis.RedisUtils;
+import org.apache.commons.lang.StringEscapeUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.shiro.SecurityUtils;
 import org.apache.shiro.authc.*;
@@ -49,41 +53,29 @@ public class UserRealm extends AuthorizingRealm {
      */
     @Override
     protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
-//        SysUserEntity user = (SysUserEntity) principals.getPrimaryPrincipal();
-//        Long userId = user.getUserId();
-//
-////        Claims claims = JwtUtil.parseJWT(principals.toString());
-////        Long userId = Long.valueOf(claims.get("id", String.class));
-//
-//        SysUserEntity user = (SysUserEntity) principals.getPrimaryPrincipal();
-//
-//        List<String> permsList;
-//
-//        //系统管理员,拥有最高权限
-//        if (userId == Constant.SUPER_ADMIN) {
-//            if (user.getUserId() == Constant.SUPER_ADMIN) {
-//                List<SysMenuEntity> menuList = sysMenuDao.queryList(new HashMap<>());
-//                permsList = new ArrayList<>(menuList.size());
-//                for (SysMenuEntity menu : menuList) {
-//                    permsList.add(menu.getPerms());
-//                }
-//            } else {
-//                permsList = sysUserDao.queryAllPerms(userId);
-//                permsList = sysUserDao.queryAllPerms(user.getUserId());
-//            }
-//            //用户权限列表
-//            Set<String> permsSet = new HashSet<String>();
-//            if (permsList != null && permsList.size() != 0) {
-//                for (String perms : permsList) {
-//                    if (StringUtils.isBlank(perms)) {
-//                        continue;
-//                    }
-//                    permsSet.addAll(Arrays.asList(perms.trim().split(",")));
-//                }
-//            }
+        TbUser user = (TbUser) principals.getPrimaryPrincipal();
+        Long userId = user.getId();
+        Set<String> permsSet = new HashSet<String>();
+        List<String> permsList;
 
+        //系统管理员,拥有最高权限
+
+        if (userId == Constant.SUPER_ADMIN) {
+            permsList = zhiHouseService.getAllPerms(null);
+        } else {
+            permsList = zhiHouseService.getAllPerms(userId);
+        }
+        //用户权限列表
+        if (permsList != null && permsList.size() != 0) {
+            for (String perms : permsList) {
+                if (StringUtils.isBlank(perms)) {
+                    continue;
+                }
+                permsSet.addAll(Arrays.asList(perms.trim().split(",")));
+            }
+        }
         SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
-        //info.setStringPermissions(permsSet);
+        info.setStringPermissions(permsSet);
         return info;
     }
 
@@ -96,9 +88,6 @@ public class UserRealm extends AuthorizingRealm {
         String token = (String) auth.getCredentials();
         Claims claims = JwtUtil.parseJWT(token);
         String userId = claims.get("id", String.class);
-        String username = claims.get("username", String.class);
-        String password = claims.get("password", String.class);
-
         //查询用户信息
         TbUser userEntity = zhiHouseService.getByUserId(Long.valueOf(userId));