lyfO_o
2022-07-16 108ed1c548b7dc17ce47dcadea80e4c42a2f29e7
safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/security/TokenAuthenticationFilter.java
@@ -4,8 +4,8 @@
import com.alibaba.fastjson.JSONObject;
import com.gkhy.safePlatform.account.rpc.apimodel.AccountAuthService;
import com.gkhy.safePlatform.account.rpc.apimodel.AccountAuthService;
import com.gkhy.safePlatform.commons.co.CacheAuthority;
import com.gkhy.safePlatform.commons.co.CacheUser;
import com.gkhy.safePlatform.commons.co.ContextCacheAuthority;
import com.gkhy.safePlatform.commons.co.ContextCacheUser;
import com.gkhy.safePlatform.commons.enums.RedisKeyEnum;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.exception.BusinessException;
@@ -86,9 +86,9 @@
                throw new BusinessException(ResultCodes.CLIENT_CREDENTIALS_TOKEN_INVALID);
            }else{
                Long userId = Long.valueOf(loginUserId);
                CacheUser cacheUser = JSONObject.parseObject(o.toString(), CacheUser.class);
                assert userId.equals(cacheUser.getUserId());
                if ( !authToken.equals(cacheUser.getAccessToken())) {
                ContextCacheUser contextCacheUser = JSONObject.parseObject(o.toString(), ContextCacheUser.class);
                assert userId.equals(contextCacheUser.getUid());
                if ( !authToken.equals(contextCacheUser.getAccessToken())) {
                    throw new BusinessException(ResultCodes.CLIENT_CREDENTIALS_TOKEN_INVALID);
                }
@@ -99,8 +99,8 @@
                // 4.redis中是否存在
                if (oo != null) {
                    // 5.存在
                    List<CacheAuthority> cacheAuthorities = JSONArray.parseArray(oo.toString(), CacheAuthority.class);
                    for (CacheAuthority cacheAuthority: cacheAuthorities) {
                    List<ContextCacheAuthority> cacheAuthorities = JSONArray.parseArray(oo.toString(), ContextCacheAuthority.class);
                    for (ContextCacheAuthority cacheAuthority: cacheAuthorities) {
                        authorities.add(new SimpleGrantedAuthority(cacheAuthority.getAuthority()));
                    }
                }else {
@@ -146,7 +146,7 @@
                }
                // security对象中存入登陆者信息
                return new UsernamePasswordAuthenticationToken(userId,authToken,authorities);
                return new UsernamePasswordAuthenticationToken(contextCacheUser,authToken,authorities);
            }