lyfO_o
2022-07-01 165b3cfcd8e604e70192865b9dcb3a12f3306e3b
safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/security/TokenAuthenticationFilter.java
@@ -3,6 +3,7 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gkhy.safePlatform.account.rpc.apimodel.UserAccountService;
import com.gkhy.safePlatform.commons.co.CacheAuthority;
import com.gkhy.safePlatform.commons.co.CacheUser;
import com.gkhy.safePlatform.commons.enums.RedisKeyEnum;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
@@ -54,11 +55,7 @@
        } catch (BusinessException e) {
            // 返回异常
            this.writeJSON(req, resp, new ResultVO<>(e.getError()));
        } catch (Exception e) {
            e.printStackTrace();
            this.writeJSON(req, resp, new ResultVO<>(ResultCodes.SERVER_ERROR));
        }
    }
@@ -93,13 +90,15 @@
                // 3.redis获取权限
                String authoritiesKey = RedisKeyEnum.authKey(RedisKeyEnum.AUTH_AUTHORITIES, userId);
                String oo = userAccountService.getValueByKeyFromRedis(authoritiesKey);
                List<GrantedAuthority> authorities;
                List<GrantedAuthority> authorities = new ArrayList<>();
                // 4.redis中是否存在
                if (oo != null) {
                    // 5.存在
                    authorities = JSONArray.parseArray(oo, GrantedAuthority.class);
                    List<CacheAuthority> cacheAuthorities = JSONArray.parseArray(oo, CacheAuthority.class);
                    for (CacheAuthority cacheAuthority: cacheAuthorities) {
                        authorities.add(new SimpleGrantedAuthority(cacheAuthority.getAuthority()));
                    }
                }else {
                    authorities = new ArrayList<>();
                    // 6.不存在=>数据库查询
                    String roleCode = userAccountService.getUserRoleCodeByUserId(userId);
                    // role