diff --git a/pig-auth/src/main/java/com/pig4cloud/pig/auth/support/SaOAuth2ClientDataLoaderImpl.java b/pig-auth/src/main/java/com/pig4cloud/pig/auth/support/SaOAuth2ClientDataLoaderImpl.java index 2efb0027..7cc0b263 100644 --- a/pig-auth/src/main/java/com/pig4cloud/pig/auth/support/SaOAuth2ClientDataLoaderImpl.java +++ b/pig-auth/src/main/java/com/pig4cloud/pig/auth/support/SaOAuth2ClientDataLoaderImpl.java @@ -5,9 +5,11 @@ import cn.dev33.satoken.oauth2.data.model.loader.SaClientModel; import cn.hutool.core.util.StrUtil; import com.pig4cloud.pig.admin.api.entity.SysOauthClientDetails; import com.pig4cloud.pig.admin.api.feign.RemoteClientDetailsService; +import com.pig4cloud.pig.common.core.constant.CacheConstants; import com.pig4cloud.pig.common.core.util.R; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import java.util.Arrays; @@ -33,6 +35,7 @@ public class SaOAuth2ClientDataLoaderImpl implements SaOAuth2DataLoader { * @return ClientModel */ @Override + @Cacheable(value = CacheConstants.CLIENT_DETAILS_KEY, key = "#clientId", unless = "#result == null") public SaClientModel getClientModel(String clientId) { R clientDetailsById = remoteClientDetailsService.getClientDetailsById(clientId); diff --git a/pig-common/pig-common-bom/pom.xml b/pig-common/pig-common-bom/pom.xml index 00d20762..111e5406 100644 --- a/pig-common/pig-common-bom/pom.xml +++ b/pig-common/pig-common-bom/pom.xml @@ -176,6 +176,14 @@ pom import + + + cn.dev33 + sa-token-bom + ${sa-token.version} + pom + import + org.springframework.boot diff --git a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/util/SecurityUtils.java b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/util/SecurityUtils.java index 043b1565..0b9ea456 100755 --- a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/util/SecurityUtils.java +++ b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/util/SecurityUtils.java @@ -44,10 +44,6 @@ public class SecurityUtils { */ public PigUser getUser() { Object loginId = StpUtil.getLoginId(); - if (ObjectUtil.isNull(loginId)) { - return null; - } - String username = loginId.toString(); Cache cache = SpringUtil.getBean(CacheManager.class).getCache(CacheConstants.USER_DETAILS); PigUser pigUser = getCachedPigUser(cache, username); @@ -65,10 +61,6 @@ public class SecurityUtils { */ public List getRoles() { Object loginId = StpUtil.getLoginId(); - if (ObjectUtil.isNull(loginId)) { - return null; - } - String username = loginId.toString(); Cache cache = SpringUtil.getBean(CacheManager.class).getCache(CacheConstants.USER_DETAILS); List roles = getCachedRoles(cache, username);