From bf5de1dd2e24a2d5c4ebbfe0518260daaf7dee9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9C=E5=8D=81=E4=B8=80=E7=8B=BC?= Date: Tue, 27 Aug 2024 13:46:29 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=BA=A0=E6=AD=A3=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E9=87=8C=E7=9A=84=E8=8B=B1=E6=96=87=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit rquest 改成 request,原来rquest会引起代码扫描提示 --- .../gateway/configuration/GlobalExceptionConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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()))); } From 9a4216193566979b63291cd053441c56d694ef10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= <2270033969@qq.com> Date: Wed, 28 Aug 2024 17:45:03 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(app):=20=E3=80=90=E7=B4=A7=E6=80=A5?= =?UTF-8?q?=E7=B4=A7=E6=80=A5=E3=80=91=20APP=E7=99=BB=E5=BD=95=E5=BA=8F?= =?UTF-8?q?=E5=88=97=E5=8C=96=E9=94=99=E8=AF=AF=E5=AF=BC=E8=87=B4=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PigxTocDefaultUserDetailsServiceImpl.java | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) 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 */