diff --git a/pigx-common/pigx-common-gateway/src/main/java/com/pig4cloud/pigx/common/gateway/configuration/GlobalExceptionConfiguration.java b/pigx-common/pigx-common-gateway/src/main/java/com/pig4cloud/pigx/common/gateway/configuration/GlobalExceptionConfiguration.java index 060a87276..01d241d7e 100644 --- a/pigx-common/pigx-common-gateway/src/main/java/com/pig4cloud/pigx/common/gateway/configuration/GlobalExceptionConfiguration.java +++ b/pigx-common/pigx-common-gateway/src/main/java/com/pig4cloud/pigx/common/gateway/configuration/GlobalExceptionConfiguration.java @@ -47,7 +47,7 @@ public class GlobalExceptionConfiguration implements ErrorWebExceptionHandler { return response.writeWith(Mono.fromSupplier(() -> { DataBufferFactory bufferFactory = response.bufferFactory(); try { - log.error("Error rquest :{} Error Spring Cloud Gateway : {}", exchange.getRequest().getPath(), + log.error("Error request :{} Error Spring Cloud Gateway : {}", exchange.getRequest().getPath(), ex.getMessage()); return bufferFactory.wrap(objectMapper.writeValueAsBytes(R.failed(ex.getMessage()))); } diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxTocDefaultUserDetailsServiceImpl.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxTocDefaultUserDetailsServiceImpl.java index 0fd55f2b1..32d01feaf 100755 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxTocDefaultUserDetailsServiceImpl.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxTocDefaultUserDetailsServiceImpl.java @@ -57,27 +57,23 @@ public class PigxTocDefaultUserDetailsServiceImpl implements PigxUserDetailsServ /** * 用户密码登录 + * * @param username 用户密码登录 * @return */ @Override @SneakyThrows public UserDetails loadUserByUsername(String username) { - if (!remoteAppUserServiceOptional.isPresent()) { - throw new UnsupportedOperationException(); - } - Cache cache = cacheManager.getCache(CacheConstants.USER_DETAILS_MINI); - if (cache != null && cache.get(username) != null) { - return cache.get(username, PigxUser.class); + if (Objects.nonNull(cache) && Objects.nonNull(cache.get(username))) { + AppUserInfo appUserInfo = cache.get(username, AppUserInfo.class); + return getUserDetailsAppUser(R.ok(appUserInfo)); } - R info = remoteAppUserServiceOptional.get().info(username); - UserDetails userDetailsAppUser = this.getUserDetailsAppUser(info); - if (cache != null) { - cache.put(username, userDetailsAppUser); - } - return userDetailsAppUser; + R result = remoteAppUserServiceOptional.get().info(username); + Optional userInfoOptional = RetOps.of(result).getData(); + userInfoOptional.ifPresent(userInfo -> Objects.requireNonNull(cache).put(username, userInfo)); + return getUserDetailsAppUser(result); } @Override @@ -88,7 +84,7 @@ public class PigxTocDefaultUserDetailsServiceImpl implements PigxUserDetailsServ UserDetails getUserDetailsAppUser(R result) { // @formatter:off return RetOps.of(result) - .assertSuccess(r -> new OAuth2AuthenticationException(new OAuth2Error(OAuth2ErrorCodes.SERVER_ERROR, "用户信息获取失败",null))) + .assertSuccess(r -> new OAuth2AuthenticationException(new OAuth2Error(OAuth2ErrorCodes.SERVER_ERROR, "用户信息获取失败",null))) .getData() .map(this::convertUserDetailsAppUser) .orElseThrow(() -> new UsernameNotFoundException("用户不存在")); @@ -97,6 +93,7 @@ public class PigxTocDefaultUserDetailsServiceImpl implements PigxUserDetailsServ /** * UserInfo 转 UserDetails + * * @param info * @return 返回UserDetails对象 */ @@ -110,7 +107,7 @@ public class PigxTocDefaultUserDetailsServiceImpl implements PigxUserDetailsServ } Collection authorities = AuthorityUtils - .createAuthorityList(dbAuthsSet.toArray(new String[0])); + .createAuthorityList(dbAuthsSet.toArray(new String[0])); AppUser user = info.getAppUser(); // 构造security用户 @@ -127,7 +124,8 @@ public class PigxTocDefaultUserDetailsServiceImpl implements PigxUserDetailsServ /** * 支持所有的 mobile 类型 - * @param clientId 目标客户端 + * + * @param clientId 目标客户端 * @param grantType 授权类型 * @return true/false */