From e9cc72e4ea0e6ba14d5bde89141aa3aaa8f03bd7 Mon Sep 17 00:00:00 2001 From: gluoh Date: Fri, 10 Jun 2022 03:10:18 +0000 Subject: [PATCH 01/10] fix(security): Fix build registeredClient clientId bug --- .../security/service/PigRemoteRegisteredClientRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/service/PigRemoteRegisteredClientRepository.java b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/service/PigRemoteRegisteredClientRepository.java index d6a9e2fc..4fe9e3a9 100644 --- a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/service/PigRemoteRegisteredClientRepository.java +++ b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/service/PigRemoteRegisteredClientRepository.java @@ -87,7 +87,7 @@ public class PigRemoteRegisteredClientRepository implements RegisteredClientRepo SysOauthClientDetails clientDetails = detailsR.getData(); RegisteredClient.Builder builder = RegisteredClient.withId(clientDetails.getClientId()) - .clientId(clientDetails.getClientSecret()) + .clientId(clientDetails.getClientId()) .clientSecret(SecurityConstants.NOOP + clientDetails.getClientSecret()) .clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC); From c482b04e06fbeafc4f7c788064112392d86f65b3 Mon Sep 17 00:00:00 2001 From: Lht Date: Wed, 15 Jun 2022 19:22:17 +0800 Subject: [PATCH 02/10] :arrow_up: Upgrading dependencies. close #I5C2Z6 UP hutool 5.8.3 --- README.md | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dc6047eb..a87e44ae 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ | Spring Cloud Alibaba | 2021.0.1.0 | | Spring Authorization Server | 0.3.0 | | Mybatis Plus | 3.5.2 | -| hutool | 5.8.2 | +| hutool | 5.8.3 | | Avue | 2.6.18 | ### 模块说明 diff --git a/pom.xml b/pom.xml index ce6293a1..032e2c83 100755 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ 1.8 2.6.7 0.3.0 - 5.8.2 + 5.8.3 3.5.1 2.2.2 2.3 From 0eb5598ea53f865ed0023487b57ba29cdfdb0076 Mon Sep 17 00:00:00 2001 From: lbw Date: Fri, 17 Jun 2022 22:02:31 +0800 Subject: [PATCH 03/10] =?UTF-8?q?:memo:=20Writing=20docs.=20README=20=20?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E6=98=BE=E7=A4=BA=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ffea315f..297e0ce7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@

- Build Status + Build Status Coverage Status Downloads @@ -27,6 +27,8 @@ ## 微信群 [禁广告] +![](https://minio.pigx.vip/oss/1648184189.png) + ## 快速开始 ### 核心依赖 @@ -104,12 +106,12 @@ cnpm install && cnpm run build:docker && cd docker && docker-compose up -d - - + + - - + +
@@ -120,7 +122,8 @@ cnpm install && cnpm run build:docker && cd docker && docker-compose up -d pig 开源软件遵循 [Apache 2.0 协议](https://www.apache.org/licenses/LICENSE-2.0.html)。 允许商业使用,但务必保留类作者、Copyright 信息。 -![](https://gitee.com/pig4cloud/oss/raw/master/2020-10-9/1602229452602-image.png) +![](https://minio.pigx.vip/oss/1655474288.jpg) + ### 其他说明 From 72337a7a13081eb176df3544c467a1b41215a4b8 Mon Sep 17 00:00:00 2001 From: lbw Date: Fri, 17 Jun 2022 22:03:09 +0800 Subject: [PATCH 04/10] =?UTF-8?q?:memo:=20Writing=20docs.=20README=20=20?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E6=98=BE=E7=A4=BA=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 297e0ce7..1c29be36 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,3 @@ pig 开源软件遵循 [Apache 2.0 协议](https://www.apache.org/licenses/LICEN 2. 欢迎提交 [issue](https://gitee.com/log4j/pig/issues),请写清楚遇到问题的原因、开发环境、复显步骤。 3. 联系作者 pig4cloud@qq.com - -[![Stargazers over time](https://whnb.wang/img/log4j/pig?e=604800)](https://whnb.wang/log4j/pig?e=604800) - From 0cc4db1553d186760f88b06b9f0f552d388f57d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=99=93=E4=BC=9F?= Date: Sat, 18 Jun 2022 13:04:19 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E8=87=B3=20org.springf?= =?UTF-8?q?ramework.security:spring-security-oauth2-authorization-server:0?= =?UTF-8?q?.3.1=EF=BC=8C=E4=BB=8E=E8=AF=A5=E7=89=88=E6=9C=AC=E5=BC=80?= =?UTF-8?q?=E5=A7=8B=EF=BC=8C=E6=94=AF=E6=8C=81=20JDK=208?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/spring-projects/spring-authorization-server/releases/tag/0.3.1 --- pig-common/pig-common-security/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pig-common/pig-common-security/pom.xml b/pig-common/pig-common-security/pom.xml index 69e082e1..3df9562f 100755 --- a/pig-common/pig-common-security/pom.xml +++ b/pig-common/pig-common-security/pom.xml @@ -56,7 +56,7 @@ spring-security-oauth2-jose - io.springboot.security + org.springframework.security spring-security-oauth2-authorization-server ${spring.authorization.version} diff --git a/pom.xml b/pom.xml index 032e2c83..f3535ac7 100755 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ 1.8 1.8 2.6.7 - 0.3.0 + 0.3.1 5.8.3 3.5.1 2.2.2 From dac823f400e9143cfbb142343f5d9a2b0bd10479 Mon Sep 17 00:00:00 2001 From: lbw Date: Sat, 18 Jun 2022 22:31:35 +0800 Subject: [PATCH 06/10] =?UTF-8?q?:bug:=20Fixing=20a=20bug.=20closed=20#I5B?= =?UTF-8?q?O47=20=E5=88=A0=E9=99=A4=E4=BB=A4=E7=89=8C=E6=8A=A55XX=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/pig4cloud/pig/auth/endpoint/PigTokenEndpoint.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pig-auth/src/main/java/com/pig4cloud/pig/auth/endpoint/PigTokenEndpoint.java b/pig-auth/src/main/java/com/pig4cloud/pig/auth/endpoint/PigTokenEndpoint.java index 7be59074..7be42f7a 100644 --- a/pig-auth/src/main/java/com/pig4cloud/pig/auth/endpoint/PigTokenEndpoint.java +++ b/pig-auth/src/main/java/com/pig4cloud/pig/auth/endpoint/PigTokenEndpoint.java @@ -166,6 +166,10 @@ public class PigTokenEndpoint { @DeleteMapping("/{token}") public R removeToken(@PathVariable("token") String token) { OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN); + if (authorization == null) { + return R.ok(); + } + OAuth2Authorization.Token accessToken = authorization.getAccessToken(); if (accessToken == null || StrUtil.isBlank(accessToken.getToken().getTokenValue())) { return R.ok(); From 7522417e1065a5cacb0eb7a84887f10577deeb91 Mon Sep 17 00:00:00 2001 From: lbw Date: Sat, 18 Jun 2022 22:32:22 +0800 Subject: [PATCH 07/10] :bug: Fixing a bug. closed #I5CO8Z resources ignore warings You are asking Spring Security to ignore Ant --- .../auth/config/WebSecurityConfiguration.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pig-auth/src/main/java/com/pig4cloud/pig/auth/config/WebSecurityConfiguration.java b/pig-auth/src/main/java/com/pig4cloud/pig/auth/config/WebSecurityConfiguration.java index a9542992..8e3e23b7 100755 --- a/pig-auth/src/main/java/com/pig4cloud/pig/auth/config/WebSecurityConfiguration.java +++ b/pig-auth/src/main/java/com/pig4cloud/pig/auth/config/WebSecurityConfiguration.java @@ -19,9 +19,9 @@ package com.pig4cloud.pig.auth.config; import com.pig4cloud.pig.auth.support.core.FormIdentityLoginConfigurer; import com.pig4cloud.pig.auth.support.core.PigDaoAuthenticationProvider; import org.springframework.context.annotation.Bean; +import org.springframework.core.annotation.Order; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer; import org.springframework.security.web.SecurityFilterChain; /** @@ -49,9 +49,21 @@ public class WebSecurityConfiguration { return http.build(); } + /** + * 暴露静态资源 + * + * https://github.com/spring-projects/spring-security/issues/10938 + * @param http + * @return + * @throws Exception + */ @Bean - public WebSecurityCustomizer webSecurityCustomizer() { - return (web) -> web.ignoring().antMatchers("/actuator/**", "/css/**", "/error"); + @Order(0) + SecurityFilterChain resources(HttpSecurity http) throws Exception { + http.requestMatchers((matchers) -> matchers.antMatchers("/actuator/**", "/css/**", "/error")) + .authorizeHttpRequests((authorize) -> authorize.anyRequest().permitAll()).requestCache().disable() + .securityContext().disable().sessionManagement().disable(); + return http.build(); } } From 812a6016ed15b485f7c66e78b03a24122140f1ef Mon Sep 17 00:00:00 2001 From: lbw Date: Sat, 18 Jun 2022 23:56:13 +0800 Subject: [PATCH 08/10] =?UTF-8?q?:zap:=20=E4=BC=98=E5=8C=96=E3=80=82=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96SAS=20=E5=AE=A2=E6=88=B7=E7=AB=AF=E8=AE=A4?= =?UTF-8?q?=E8=AF=81=E8=BF=87=E7=A8=8B=E4=B8=AD=E7=9A=84=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AuthorizationServerConfiguration.java | 6 +- .../pig/auth/endpoint/PigTokenEndpoint.java | 21 +- .../PigAuthenticationFailureEventHandler.java | 12 +- .../com/pig4cloud/pig/common/core/util/R.java | 2 +- .../pig/common/core/util/RetOps.java | 289 ++++++++++++++++++ .../PigRemoteRegisteredClientRepository.java | 10 +- .../security/util/OAuth2ErrorCodesExpand.java | 5 + .../security/util/OAuthClientException.java | 29 ++ 8 files changed, 349 insertions(+), 25 deletions(-) create mode 100644 pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/util/RetOps.java create mode 100644 pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/util/OAuthClientException.java diff --git a/pig-auth/src/main/java/com/pig4cloud/pig/auth/config/AuthorizationServerConfiguration.java b/pig-auth/src/main/java/com/pig4cloud/pig/auth/config/AuthorizationServerConfiguration.java index 79e7c290..77074ab6 100755 --- a/pig-auth/src/main/java/com/pig4cloud/pig/auth/config/AuthorizationServerConfiguration.java +++ b/pig-auth/src/main/java/com/pig4cloud/pig/auth/config/AuthorizationServerConfiguration.java @@ -69,8 +69,10 @@ public class AuthorizationServerConfiguration { tokenEndpoint.accessTokenRequestConverter(accessTokenRequestConverter()) // 注入自定义的授权认证Converter .accessTokenResponseHandler(new PigAuthenticationSuccessEventHandler()) // 登录成功处理器 .errorResponseHandler(new PigAuthenticationFailureEventHandler());// 登录失败处理器 - }).authorizationEndpoint( // 授权码端点个性化confirm页面 - authorizationEndpoint -> authorizationEndpoint.consentPage(SecurityConstants.CUSTOM_CONSENT_PAGE_URI))); + }).clientAuthentication(oAuth2ClientAuthenticationConfigurer -> // 个性化客户端认证 + oAuth2ClientAuthenticationConfigurer.errorResponseHandler(new PigAuthenticationFailureEventHandler()))// 处理客户端认证异常 + .authorizationEndpoint(authorizationEndpoint -> authorizationEndpoint// 授权码端点个性化confirm页面 + .consentPage(SecurityConstants.CUSTOM_CONSENT_PAGE_URI))); RequestMatcher endpointsMatcher = authorizationServerConfigurer.getEndpointsMatcher(); DefaultSecurityFilterChain securityFilterChain = http.requestMatcher(endpointsMatcher) diff --git a/pig-auth/src/main/java/com/pig4cloud/pig/auth/endpoint/PigTokenEndpoint.java b/pig-auth/src/main/java/com/pig4cloud/pig/auth/endpoint/PigTokenEndpoint.java index 7be42f7a..3c790de9 100644 --- a/pig-auth/src/main/java/com/pig4cloud/pig/auth/endpoint/PigTokenEndpoint.java +++ b/pig-auth/src/main/java/com/pig4cloud/pig/auth/endpoint/PigTokenEndpoint.java @@ -22,6 +22,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.pig4cloud.pig.admin.api.entity.SysOauthClientDetails; import com.pig4cloud.pig.admin.api.feign.RemoteClientDetailsService; import com.pig4cloud.pig.admin.api.vo.TokenVo; +import com.pig4cloud.pig.auth.support.handler.PigAuthenticationFailureEventHandler; import com.pig4cloud.pig.common.core.constant.CacheConstants; import com.pig4cloud.pig.common.core.constant.CommonConstants; import com.pig4cloud.pig.common.core.constant.SecurityConstants; @@ -44,18 +45,19 @@ import org.springframework.security.authentication.event.LogoutSuccessEvent; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.oauth2.core.OAuth2AccessToken; -import org.springframework.security.oauth2.core.OAuth2Error; import org.springframework.security.oauth2.core.OAuth2TokenType; import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse; import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames; import org.springframework.security.oauth2.core.http.converter.OAuth2AccessTokenResponseHttpMessageConverter; -import org.springframework.security.oauth2.core.http.converter.OAuth2ErrorHttpMessageConverter; import org.springframework.security.oauth2.server.authorization.OAuth2Authorization; import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService; +import org.springframework.security.oauth2.server.resource.InvalidBearerTokenException; +import org.springframework.security.web.authentication.AuthenticationFailureHandler; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.security.Principal; import java.util.List; @@ -75,7 +77,7 @@ public class PigTokenEndpoint { private final HttpMessageConverter accessTokenHttpResponseConverter = new OAuth2AccessTokenResponseHttpMessageConverter(); - private final HttpMessageConverter errorHttpResponseConverter = new OAuth2ErrorHttpMessageConverter(); + private final AuthenticationFailureHandler authenticationFailureHandler = new PigAuthenticationFailureEventHandler(); private final OAuth2AuthorizationService authorizationService; @@ -135,21 +137,20 @@ public class PigTokenEndpoint { */ @SneakyThrows @GetMapping("/check_token") - public void checkToken(String token, HttpServletResponse response) { + public void checkToken(String token, HttpServletResponse response, HttpServletRequest request) { ServletServerHttpResponse httpResponse = new ServletServerHttpResponse(response); if (StrUtil.isBlank(token)) { httpResponse.setStatusCode(HttpStatus.UNAUTHORIZED); - this.errorHttpResponseConverter.write(new OAuth2Error(OAuth2ErrorCodesExpand.TOKEN_MISSING), null, - httpResponse); + this.authenticationFailureHandler.onAuthenticationFailure(request, response, + new InvalidBearerTokenException(OAuth2ErrorCodesExpand.TOKEN_MISSING)); } OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN); // 如果令牌不存在 返回401 - if (authorization == null) { - httpResponse.setStatusCode(HttpStatus.UNAUTHORIZED); - this.errorHttpResponseConverter.write(new OAuth2Error(OAuth2ErrorCodesExpand.TOKEN_MISSING), null, - httpResponse); + if (authorization == null || authorization.getAccessToken() == null) { + this.authenticationFailureHandler.onAuthenticationFailure(request, response, + new InvalidBearerTokenException(OAuth2ErrorCodesExpand.INVALID_BEARER_TOKEN)); } Map claims = authorization.getAccessToken().getClaims(); diff --git a/pig-auth/src/main/java/com/pig4cloud/pig/auth/support/handler/PigAuthenticationFailureEventHandler.java b/pig-auth/src/main/java/com/pig4cloud/pig/auth/support/handler/PigAuthenticationFailureEventHandler.java index 65e10833..57efd6b9 100644 --- a/pig-auth/src/main/java/com/pig4cloud/pig/auth/support/handler/PigAuthenticationFailureEventHandler.java +++ b/pig-auth/src/main/java/com/pig4cloud/pig/auth/support/handler/PigAuthenticationFailureEventHandler.java @@ -29,8 +29,6 @@ import org.springframework.http.MediaType; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.http.server.ServletServerHttpResponse; import org.springframework.security.core.AuthenticationException; -import org.springframework.security.oauth2.core.OAuth2AuthenticationException; -import org.springframework.security.oauth2.core.OAuth2Error; import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames; import org.springframework.security.web.authentication.AuthenticationFailureHandler; @@ -73,15 +71,13 @@ public class PigAuthenticationFailureEventHandler implements AuthenticationFailu logVo.setUpdateBy(username); SpringContextHolder.publishEvent(new SysLogEvent(logVo)); // 写出错误信息 - sendErrorResponse(request, response, exception); + sendErrorResponse(response, exception); } - private void sendErrorResponse(HttpServletRequest request, HttpServletResponse response, - AuthenticationException exception) throws IOException { - OAuth2Error error = ((OAuth2AuthenticationException) exception).getError(); + private void sendErrorResponse(HttpServletResponse response, AuthenticationException exception) throws IOException { ServletServerHttpResponse httpResponse = new ServletServerHttpResponse(response); - httpResponse.setStatusCode(HttpStatus.BAD_REQUEST); - this.errorHttpResponseConverter.write(R.failed(error.getDescription()), MediaType.APPLICATION_JSON, + httpResponse.setStatusCode(HttpStatus.UNAUTHORIZED); + this.errorHttpResponseConverter.write(R.failed(exception.getLocalizedMessage()), MediaType.APPLICATION_JSON, httpResponse); } diff --git a/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/util/R.java b/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/util/R.java index 9e6425bd..7b79afa2 100755 --- a/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/util/R.java +++ b/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/util/R.java @@ -76,7 +76,7 @@ public class R implements Serializable { return restResult(data, CommonConstants.FAIL, msg); } - private static R restResult(T data, int code, String msg) { + public static R restResult(T data, int code, String msg) { R apiResult = new R<>(); apiResult.setCode(code); apiResult.setData(data); diff --git a/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/util/RetOps.java b/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/util/RetOps.java new file mode 100644 index 00000000..684d1a39 --- /dev/null +++ b/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/util/RetOps.java @@ -0,0 +1,289 @@ +/* + * + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + * + */ + +package com.pig4cloud.pig.common.core.util; + +import cn.hutool.core.util.ObjectUtil; +import com.pig4cloud.pig.common.core.constant.CommonConstants; + +import java.util.Arrays; +import java.util.Objects; +import java.util.Optional; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Predicate; + +/** + * 简化{@code R} 的访问操作,例子

+ * R result = R.ok(0);
+ * // 使用场景1: 链式操作: 断言然后消费
+ * RetOps.of(result)
+ * 		.assertCode(-1,r -> new RuntimeException("error "+r.getCode()))
+ * 		.assertDataNotEmpty(r -> new IllegalStateException("oops!"))
+ * 		.useData(System.out::println);
+ *
+ * // 使用场景2: 读取原始值(data),这里返回的是Optional
+ * RetOps.of(result).getData().orElse(null);
+ *
+ * // 使用场景3: 类型转换
+ * R s = RetOps.of(result)
+ *        .assertDataNotNull(r -> new IllegalStateException("nani??"))
+ *        .map(i -> Integer.toHexString(i))
+ *        .peek();
+ * 
+ * + * @author CJ (power4j@outlook.com) + * @date 2022/5/12 + * @since 4.4 + */ +public class RetOps { + + /** 状态码为成功 */ + public static final Predicate> CODE_SUCCESS = r -> CommonConstants.SUCCESS == r.getCode(); + + /** 数据有值 */ + public static final Predicate> HAS_DATA = r -> ObjectUtil.isNotEmpty(r.getData()); + + /** 数据有值,并且包含元素 */ + public static final Predicate> HAS_ELEMENT = r -> ObjectUtil.isNotEmpty(r.getData()); + + /** 状态码为成功并且有值 */ + public static final Predicate> DATA_AVAILABLE = CODE_SUCCESS.and(HAS_DATA); + + private final R original; + + // ~ 初始化 + // =================================================================================================== + + RetOps(R original) { + this.original = original; + } + + public static RetOps of(R original) { + return new RetOps<>(Objects.requireNonNull(original)); + } + + // ~ 杂项方法 + // =================================================================================================== + + /** + * 观察原始值 + * @return R + */ + public R peek() { + return original; + } + + /** + * 读取{@code code}的值 + * @return 返回code的值 + */ + public int getCode() { + return original.getCode(); + } + + /** + * 读取{@code data}的值 + * @return 返回 Optional 包装的data + */ + public Optional getData() { + return Optional.of(original.getData()); + } + + /** + * 有条件地读取{@code data}的值 + * @param predicate 断言函数 + * @return 返回 Optional 包装的data,如果断言失败返回empty + */ + public Optional getDataIf(Predicate> predicate) { + return predicate.test(original) ? getData() : Optional.empty(); + } + + /** + * 读取{@code msg}的值 + * @return 返回Optional包装的 msg + */ + public Optional getMsg() { + return Optional.of(original.getMsg()); + } + + /** + * 对{@code code}的值进行相等性测试 + * @param value 基准值 + * @return 返回ture表示相等 + */ + public boolean codeEquals(int value) { + return original.getCode() == value; + } + + /** + * 对{@code code}的值进行相等性测试 + * @param value 基准值 + * @return 返回ture表示不相等 + */ + public boolean codeNotEquals(int value) { + return !codeEquals(value); + } + + /** + * 是否成功 + * @return 返回ture表示成功 + * @see CommonConstants#SUCCESS + */ + public boolean isSuccess() { + return codeEquals(CommonConstants.SUCCESS); + } + + /** + * 是否失败 + * @return 返回ture表示失败 + */ + public boolean notSuccess() { + return !isSuccess(); + } + + // ~ 链式操作 + // =================================================================================================== + + /** + * 断言{@code code}的值 + * @param expect 预期的值 + * @param func 用户函数,负责创建异常对象 + * @param 异常类型 + * @return 返回实例,以便于继续进行链式操作 + * @throws Ex 断言失败时抛出 + */ + public RetOps assertCode(int expect, Function, ? extends Ex> func) + throws Ex { + if (codeNotEquals(expect)) { + throw func.apply(original); + } + return this; + } + + /** + * 断言成功 + * @param func 用户函数,负责创建异常对象 + * @param 异常类型 + * @return 返回实例,以便于继续进行链式操作 + * @throws Ex 断言失败时抛出 + */ + public RetOps assertSuccess(Function, ? extends Ex> func) throws Ex { + return assertCode(CommonConstants.SUCCESS, func); + } + + /** + * 断言业务数据有值 + * @param func 用户函数,负责创建异常对象 + * @param 异常类型 + * @return 返回实例,以便于继续进行链式操作 + * @throws Ex 断言失败时抛出 + */ + public RetOps assertDataNotNull(Function, ? extends Ex> func) throws Ex { + if (Objects.isNull(original.getData())) { + throw func.apply(original); + } + return this; + } + + /** + * 断言业务数据有值,并且包含元素 + * @param func 用户函数,负责创建异常对象 + * @param 异常类型 + * @return 返回实例,以便于继续进行链式操作 + * @throws Ex 断言失败时抛出 + */ + public RetOps assertDataNotEmpty(Function, ? extends Ex> func) throws Ex { + if (ObjectUtil.isNotEmpty(original.getData())) { + throw func.apply(original); + } + return this; + } + + /** + * 对业务数据(data)转换 + * @param mapper 业务数据转换函数 + * @param 数据类型 + * @return 返回新实例,以便于继续进行链式操作 + */ + public RetOps map(Function mapper) { + R result = R.restResult(mapper.apply(original.getData()), original.getCode(), original.getMsg()); + return of(result); + } + + /** + * 对业务数据(data)转换 + * @param predicate 断言函数 + * @param mapper 业务数据转换函数 + * @param 数据类型 + * @return 返回新实例,以便于继续进行链式操作 + * @see RetOps#CODE_SUCCESS + * @see RetOps#HAS_DATA + * @see RetOps#HAS_ELEMENT + * @see RetOps#DATA_AVAILABLE + */ + public RetOps mapIf(Predicate> predicate, Function mapper) { + R result = R.restResult(mapper.apply(original.getData()), original.getCode(), original.getMsg()); + return of(result); + } + + // ~ 数据消费 + // =================================================================================================== + + /** + * 消费数据,注意此方法保证数据可用 + * @param consumer 消费函数 + */ + public void useData(Consumer consumer) { + consumer.accept(original.getData()); + } + + /** + * 条件消费(错误代码匹配某个值) + * @param consumer 消费函数 + * @param codes 错误代码集合,匹配任意一个则调用消费函数 + */ + public void useDataOnCode(Consumer consumer, int... codes) { + useDataIf(o -> Arrays.stream(codes).filter(c -> original.getCode() == c).findFirst().isPresent(), consumer); + } + + /** + * 条件消费(错误代码表示成功) + * @param consumer 消费函数 + */ + public void useDataIfSuccess(Consumer consumer) { + useDataIf(CODE_SUCCESS, consumer); + } + + /** + * 条件消费 + * @param predicate 断言函数 + * @param consumer 消费函数,断言函数返回{@code true}时被调用 + * @see RetOps#CODE_SUCCESS + * @see RetOps#HAS_DATA + * @see RetOps#HAS_ELEMENT + * @see RetOps#DATA_AVAILABLE + */ + public void useDataIf(Predicate> predicate, Consumer consumer) { + if (predicate.test(original)) { + consumer.accept(original.getData()); + } + } + +} diff --git a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/service/PigRemoteRegisteredClientRepository.java b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/service/PigRemoteRegisteredClientRepository.java index 4fe9e3a9..10d1e9b6 100644 --- a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/service/PigRemoteRegisteredClientRepository.java +++ b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/service/PigRemoteRegisteredClientRepository.java @@ -5,7 +5,8 @@ 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.constant.SecurityConstants; -import com.pig4cloud.pig.common.core.util.R; +import com.pig4cloud.pig.common.core.util.RetOps; +import com.pig4cloud.pig.common.security.util.OAuthClientException; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import org.springframework.cache.annotation.Cacheable; @@ -82,9 +83,10 @@ public class PigRemoteRegisteredClientRepository implements RegisteredClientRepo @SneakyThrows @Cacheable(value = CacheConstants.CLIENT_DETAILS_KEY, key = "#clientId", unless = "#result == null") public RegisteredClient findByClientId(String clientId) { - R detailsR = clientDetailsService.getClientDetailsById(clientId, - SecurityConstants.FROM_IN); - SysOauthClientDetails clientDetails = detailsR.getData(); + + SysOauthClientDetails clientDetails = RetOps + .of(clientDetailsService.getClientDetailsById(clientId, SecurityConstants.FROM_IN)) + .assertDataNotNull(result -> new OAuthClientException("clientId 不合法")).getData().get(); RegisteredClient.Builder builder = RegisteredClient.withId(clientDetails.getClientId()) .clientId(clientDetails.getClientId()) diff --git a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/util/OAuth2ErrorCodesExpand.java b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/util/OAuth2ErrorCodesExpand.java index 69882d18..02065137 100644 --- a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/util/OAuth2ErrorCodesExpand.java +++ b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/util/OAuth2ErrorCodesExpand.java @@ -35,4 +35,9 @@ public interface OAuth2ErrorCodesExpand { /** 未知的登录异常 */ String UN_KNOW_LOGIN_ERROR = "un_know_login_error"; + /** + * 不合法的Token + */ + String INVALID_BEARER_TOKEN = "invalid_bearer_token"; + } diff --git a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/util/OAuthClientException.java b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/util/OAuthClientException.java new file mode 100644 index 00000000..ab7c8ddd --- /dev/null +++ b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/util/OAuthClientException.java @@ -0,0 +1,29 @@ +package com.pig4cloud.pig.common.security.util; + +import org.springframework.security.oauth2.core.OAuth2AuthenticationException; +import org.springframework.security.oauth2.core.OAuth2Error; + +/** + * @author lengleng + * @description OAuthClientException 异常信息 + */ +public class OAuthClientException extends OAuth2AuthenticationException { + + /** + * Constructs a ScopeException with the specified message. + * @param msg the detail message. + */ + public OAuthClientException(String msg) { + super(new OAuth2Error(msg), msg); + } + + /** + * Constructs a {@code ScopeException} with the specified message and root cause. + * @param msg the detail message. + * @param cause root cause + */ + public OAuthClientException(String msg, Throwable cause) { + super(new OAuth2Error(msg), cause); + } + +} From 3d9e0be72fac5c003e55a4c32d538dd7173414ce Mon Sep 17 00:00:00 2001 From: lbw Date: Mon, 20 Jun 2022 09:58:34 +0800 Subject: [PATCH 09/10] :bookmark: Releasing / Version tags. 3.5.1 --- .gitee/ISSUE_TEMPLATE.zh-CN.md | 4 +++- README.md | 2 +- pig-auth/pom.xml | 2 +- pig-common/pig-common-bom/pom.xml | 3 +-- pig-common/pig-common-core/pom.xml | 2 +- pig-common/pig-common-datasource/pom.xml | 2 +- pig-common/pig-common-feign/pom.xml | 2 +- pig-common/pig-common-job/pom.xml | 2 +- pig-common/pig-common-log/pom.xml | 2 +- pig-common/pig-common-mybatis/pom.xml | 2 +- pig-common/pig-common-seata/pom.xml | 2 +- pig-common/pig-common-security/pom.xml | 2 +- pig-common/pig-common-swagger/pom.xml | 2 +- pig-common/pom.xml | 2 +- pig-gateway/pom.xml | 2 +- pig-register/pom.xml | 2 +- pig-upms/pig-upms-api/pom.xml | 2 +- pig-upms/pig-upms-biz/pom.xml | 2 +- pig-upms/pom.xml | 2 +- pig-visual/pig-codegen/pom.xml | 2 +- pig-visual/pig-monitor/pom.xml | 2 +- pig-visual/pig-sentinel-dashboard/pom.xml | 2 +- pig-visual/pig-xxl-job-admin/pom.xml | 2 +- pig-visual/pom.xml | 2 +- pom.xml | 2 +- 25 files changed, 27 insertions(+), 26 deletions(-) diff --git a/.gitee/ISSUE_TEMPLATE.zh-CN.md b/.gitee/ISSUE_TEMPLATE.zh-CN.md index 96e01ee7..2a6494fb 100644 --- a/.gitee/ISSUE_TEMPLATE.zh-CN.md +++ b/.gitee/ISSUE_TEMPLATE.zh-CN.md @@ -1,6 +1,8 @@ ### 版本信息 -- pig版本: +- ⭐️ [4.x 版本点击这里提问,此处不回复](https://support.pig4cloud.com) + +- pig版本: - 是否修改包名: diff --git a/README.md b/README.md index 1c29be36..fe8aaa1e 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ cnpm install && cnpm run build:docker && cd docker && docker-compose up -d - + diff --git a/pig-auth/pom.xml b/pig-auth/pom.xml index ddc1f9ee..948eeece 100755 --- a/pig-auth/pom.xml +++ b/pig-auth/pom.xml @@ -21,7 +21,7 @@ com.pig4cloud pig - 3.5.0 + 3.5.1 pig-auth diff --git a/pig-common/pig-common-bom/pom.xml b/pig-common/pig-common-bom/pom.xml index 6cf25c50..7509700c 100644 --- a/pig-common/pig-common-bom/pom.xml +++ b/pig-common/pig-common-bom/pom.xml @@ -6,7 +6,7 @@ com.pig4cloud pig-common-bom - 3.5.0 + 3.5.1 pom pig-common-bom @@ -17,7 +17,6 @@ ${project.version} 2.7.0 UTF-8 - 2.1.8.RELEASE 2.17.1 1.8 1.8 diff --git a/pig-common/pig-common-core/pom.xml b/pig-common/pig-common-core/pom.xml index a45e51f3..df3e3542 100755 --- a/pig-common/pig-common-core/pom.xml +++ b/pig-common/pig-common-core/pom.xml @@ -21,7 +21,7 @@ com.pig4cloud pig-common - 3.5.0 + 3.5.1 pig-common-core diff --git a/pig-common/pig-common-datasource/pom.xml b/pig-common/pig-common-datasource/pom.xml index c33c2e6e..5f261b82 100644 --- a/pig-common/pig-common-datasource/pom.xml +++ b/pig-common/pig-common-datasource/pom.xml @@ -21,7 +21,7 @@ pig-common com.pig4cloud - 3.5.0 + 3.5.1 4.0.0 diff --git a/pig-common/pig-common-feign/pom.xml b/pig-common/pig-common-feign/pom.xml index 81430872..6cbbf0bd 100755 --- a/pig-common/pig-common-feign/pom.xml +++ b/pig-common/pig-common-feign/pom.xml @@ -21,7 +21,7 @@ com.pig4cloud pig-common - 3.5.0 + 3.5.1 4.0.0 diff --git a/pig-common/pig-common-job/pom.xml b/pig-common/pig-common-job/pom.xml index 2b5c7e8f..082873e9 100755 --- a/pig-common/pig-common-job/pom.xml +++ b/pig-common/pig-common-job/pom.xml @@ -23,7 +23,7 @@ com.pig4cloud pig-common - 3.5.0 + 3.5.1 pig-common-job diff --git a/pig-common/pig-common-log/pom.xml b/pig-common/pig-common-log/pom.xml index 05e27ec6..4437f631 100755 --- a/pig-common/pig-common-log/pom.xml +++ b/pig-common/pig-common-log/pom.xml @@ -21,7 +21,7 @@ com.pig4cloud pig-common - 3.5.0 + 3.5.1 pig-common-log diff --git a/pig-common/pig-common-mybatis/pom.xml b/pig-common/pig-common-mybatis/pom.xml index 50475ac9..0044ae7d 100755 --- a/pig-common/pig-common-mybatis/pom.xml +++ b/pig-common/pig-common-mybatis/pom.xml @@ -21,7 +21,7 @@ com.pig4cloud pig-common - 3.5.0 + 3.5.1 pig-common-mybatis diff --git a/pig-common/pig-common-seata/pom.xml b/pig-common/pig-common-seata/pom.xml index 822698fe..4568a316 100755 --- a/pig-common/pig-common-seata/pom.xml +++ b/pig-common/pig-common-seata/pom.xml @@ -23,7 +23,7 @@ com.pig4cloud pig-common - 3.5.0 + 3.5.1 pig-common-seata diff --git a/pig-common/pig-common-security/pom.xml b/pig-common/pig-common-security/pom.xml index 3df9562f..3c2f612c 100755 --- a/pig-common/pig-common-security/pom.xml +++ b/pig-common/pig-common-security/pom.xml @@ -21,7 +21,7 @@ com.pig4cloud pig-common - 3.5.0 + 3.5.1 pig-common-security diff --git a/pig-common/pig-common-swagger/pom.xml b/pig-common/pig-common-swagger/pom.xml index 2aac1d76..8273fd48 100644 --- a/pig-common/pig-common-swagger/pom.xml +++ b/pig-common/pig-common-swagger/pom.xml @@ -24,7 +24,7 @@ com.pig4cloud pig-common - 3.5.0 + 3.5.1 pig-common-swagger diff --git a/pig-common/pom.xml b/pig-common/pom.xml index 8dd15ad4..ad29a849 100755 --- a/pig-common/pom.xml +++ b/pig-common/pom.xml @@ -21,7 +21,7 @@ com.pig4cloud pig - 3.5.0 + 3.5.1 pig-common diff --git a/pig-gateway/pom.xml b/pig-gateway/pom.xml index 1ee14f2f..e7c70762 100755 --- a/pig-gateway/pom.xml +++ b/pig-gateway/pom.xml @@ -21,7 +21,7 @@ com.pig4cloud pig - 3.5.0 + 3.5.1 pig-gateway diff --git a/pig-register/pom.xml b/pig-register/pom.xml index 651bd2f7..0b8733a1 100755 --- a/pig-register/pom.xml +++ b/pig-register/pom.xml @@ -18,7 +18,7 @@ com.pig4cloud pig - 3.5.0 + 3.5.1 pig-register diff --git a/pig-upms/pig-upms-api/pom.xml b/pig-upms/pig-upms-api/pom.xml index 4ab56f9a..9608be8c 100755 --- a/pig-upms/pig-upms-api/pom.xml +++ b/pig-upms/pig-upms-api/pom.xml @@ -21,7 +21,7 @@ com.pig4cloud pig-upms - 3.5.0 + 3.5.1 pig-upms-api diff --git a/pig-upms/pig-upms-biz/pom.xml b/pig-upms/pig-upms-biz/pom.xml index 04bbbc0e..317ae706 100644 --- a/pig-upms/pig-upms-biz/pom.xml +++ b/pig-upms/pig-upms-biz/pom.xml @@ -21,7 +21,7 @@ com.pig4cloud pig-upms - 3.5.0 + 3.5.1 pig-upms-biz diff --git a/pig-upms/pom.xml b/pig-upms/pom.xml index 369509f4..1b4af4a8 100755 --- a/pig-upms/pom.xml +++ b/pig-upms/pom.xml @@ -21,7 +21,7 @@ com.pig4cloud pig - 3.5.0 + 3.5.1 pig-upms diff --git a/pig-visual/pig-codegen/pom.xml b/pig-visual/pig-codegen/pom.xml index aed74b6b..93a469e7 100755 --- a/pig-visual/pig-codegen/pom.xml +++ b/pig-visual/pig-codegen/pom.xml @@ -22,7 +22,7 @@ com.pig4cloud pig-visual - 3.5.0 + 3.5.1 pig-codegen diff --git a/pig-visual/pig-monitor/pom.xml b/pig-visual/pig-monitor/pom.xml index e0cba9f6..13632c21 100755 --- a/pig-visual/pig-monitor/pom.xml +++ b/pig-visual/pig-monitor/pom.xml @@ -21,7 +21,7 @@ com.pig4cloud pig-visual - 3.5.0 + 3.5.1 pig-monitor diff --git a/pig-visual/pig-sentinel-dashboard/pom.xml b/pig-visual/pig-sentinel-dashboard/pom.xml index 66e2e735..70f921b5 100755 --- a/pig-visual/pig-sentinel-dashboard/pom.xml +++ b/pig-visual/pig-sentinel-dashboard/pom.xml @@ -6,7 +6,7 @@ com.pig4cloud pig-visual - 3.5.0 + 3.5.1 pig-sentinel-dashboard diff --git a/pig-visual/pig-xxl-job-admin/pom.xml b/pig-visual/pig-xxl-job-admin/pom.xml index bfb91a71..4231a654 100644 --- a/pig-visual/pig-xxl-job-admin/pom.xml +++ b/pig-visual/pig-xxl-job-admin/pom.xml @@ -4,7 +4,7 @@ com.pig4cloud pig-visual - 3.5.0 + 3.5.1 pig-xxl-job-admin diff --git a/pig-visual/pom.xml b/pig-visual/pom.xml index 5c7db655..9ce4ca64 100755 --- a/pig-visual/pom.xml +++ b/pig-visual/pom.xml @@ -21,7 +21,7 @@ com.pig4cloud pig - 3.5.0 + 3.5.1 pig-visual diff --git a/pom.xml b/pom.xml index f3535ac7..da615d26 100755 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ com.pig4cloud pig ${project.artifactId} - 3.5.0 + 3.5.1 pom https://www.pig4cloud.com From dcb61e1a63ff32ebb2388955c622374b434ff2d6 Mon Sep 17 00:00:00 2001 From: lbw Date: Mon, 20 Jun 2022 11:19:57 +0800 Subject: [PATCH 10/10] =?UTF-8?q?:sparkles:=20Introducing=20new=20features?= =?UTF-8?q?.=20=E7=94=A8=E6=88=B7=E6=A0=A1=E9=AA=8C=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pig/common/core/exception/ErrorCodes.java | 5 ++++ .../resources/i18n/messages_zh_CN.properties | 29 ++++++++++--------- .../security/component/PermissionService.java | 1 + .../pig/admin/controller/UserController.java | 18 +++++++----- 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/exception/ErrorCodes.java b/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/exception/ErrorCodes.java index 36696ec2..4161e548 100644 --- a/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/exception/ErrorCodes.java +++ b/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/exception/ErrorCodes.java @@ -21,6 +21,11 @@ public interface ErrorCodes { /** * 用户已存在 */ + String SYS_USER_EXISTING = "sys.user.existing"; + + /** + * 用户名已存在 + */ String SYS_USER_USERNAME_EXISTING = "sys.user.username.existing"; /** diff --git a/pig-common/pig-common-core/src/main/resources/i18n/messages_zh_CN.properties b/pig-common/pig-common-core/src/main/resources/i18n/messages_zh_CN.properties index 4f8556ab..6812a666 100644 --- a/pig-common/pig-common-core/src/main/resources/i18n/messages_zh_CN.properties +++ b/pig-common/pig-common-core/src/main/resources/i18n/messages_zh_CN.properties @@ -1,23 +1,24 @@ -sys.user.update.passwordError=\u539f\u5bc6\u7801\u9519\u8bef\uff0c\u4fee\u6539\u5931\u8d25 -sys.user.query.error=\u83b7\u53d6\u5f53\u524d\u7528\u6237\u4fe1\u606f\u5931\u8d25 +sys.user.update.passwordError=\u539F\u5BC6\u7801\u9519\u8BEF\uFF0C\u4FEE\u6539\u5931\u8D25 +sys.user.query.error=\u83B7\u53D6\u5F53\u524D\u7528\u6237\u4FE1\u606F\u5931\u8D25 +sys.user.existing=\u7528\u6237\u5DF2\u5B58\u5728 sys.user.username.existing={0} \u7528\u6237\u540D\u5DF2\u5B58\u5728 -sys.user.userInfo.empty={0} \u7528\u6237\u4fe1\u606f\u4e3a\u7a7a +sys.user.userInfo.empty={0} \u7528\u6237\u4FE1\u606F\u4E3A\u7A7A -sys.dept.deptName.inexistence={0} \u90e8\u95e8\u540d\u79f0\u4e0d\u5b58\u5728 +sys.dept.deptName.inexistence={0} \u90E8\u95E8\u540D\u79F0\u4E0D\u5B58\u5728 -sys.post.postName.inexistence={0} \u5c97\u4f4d\u540d\u79f0\u4e0d\u5b58\u5728 -sys.post.nameOrCode.existing={0} {1} \u5c97\u4f4d\u540d\u6216\u5c97\u4f4d\u7f16\u7801\u5df2\u7ecf\u5b58\u5728 +sys.post.postName.inexistence={0} \u5C97\u4F4D\u540D\u79F0\u4E0D\u5B58\u5728 +sys.post.nameOrCode.existing={0} {1} \u5C97\u4F4D\u540D\u6216\u5C97\u4F4D\u7F16\u7801\u5DF2\u7ECF\u5B58\u5728 -sys.role.roleName.inexistence={0} \u89d2\u8272\u540d\u79f0\u4e0d\u5b58\u5728 -sys.role.nameOrCode.existing={0} {1} \u89d2\u8272\u540d\u6216\u89d2\u8272\u7f16\u7801\u5df2\u7ecf\u5b58\u5728 +sys.role.roleName.inexistence={0} \u89D2\u8272\u540D\u79F0\u4E0D\u5B58\u5728 +sys.role.nameOrCode.existing={0} {1} \u89D2\u8272\u540D\u6216\u89D2\u8272\u7F16\u7801\u5DF2\u7ECF\u5B58\u5728 -sys.param.delete.system=\u7cfb\u7edf\u5185\u7f6e\u53c2\u6570\u4e0d\u80fd\u5220\u9664 +sys.param.delete.system=\u7CFB\u7EDF\u5185\u7F6E\u53C2\u6570\u4E0D\u80FD\u5220\u9664 sys.param.config.error={0} \u7CFB\u7EDF\u53C2\u6570\u914D\u7F6E\u9519\u8BEF -sys.menu.delete.existing=\u83dc\u5355\u542b\u6709\u4e0b\u7ea7\u4e0d\u80fd\u5220\u9664 +sys.menu.delete.existing=\u83DC\u5355\u542B\u6709\u4E0B\u7EA7\u4E0D\u80FD\u5220\u9664 -sys.app.sms.often=\u9a8c\u8bc1\u7801\u53d1\u9001\u8fc7\u9891\u7e41 -sys.app.phone.unregistered={0} \u624b\u673a\u53f7\u672a\u6ce8\u518c +sys.app.sms.often=\u9A8C\u8BC1\u7801\u53D1\u9001\u8FC7\u9891\u7E41 +sys.app.phone.unregistered={0} \u624B\u673A\u53F7\u672A\u6CE8\u518C -sys.dict.delete.system=\u7cfb\u7edf\u5185\u7f6e\u5b57\u5178\u9879\u76ee\u4e0d\u80fd\u5220\u9664 -sys.dict.update.system=\u7cfb\u7edf\u5185\u7f6e\u5b57\u5178\u9879\u76ee\u4e0d\u80fd\u4fee\u6539 +sys.dict.delete.system=\u7CFB\u7EDF\u5185\u7F6E\u5B57\u5178\u9879\u76EE\u4E0D\u80FD\u5220\u9664 +sys.dict.update.system=\u7CFB\u7EDF\u5185\u7F6E\u5B57\u5178\u9879\u76EE\u4E0D\u80FD\u4FEE\u6539 diff --git a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PermissionService.java b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PermissionService.java index 00227c8e..fcf394a4 100755 --- a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PermissionService.java +++ b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PermissionService.java @@ -1,3 +1,4 @@ + /* * Copyright (c) 2020 pig4cloud Authors. All Rights Reserved. * diff --git a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/UserController.java b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/UserController.java index b1f2194d..7fc3c72e 100644 --- a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/UserController.java +++ b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/UserController.java @@ -16,6 +16,7 @@ package com.pig4cloud.pig.admin.controller; +import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -115,15 +116,18 @@ public class UserController { } /** - * 根据用户名查询用户信息 - * @param username 用户名 + * 判断用户是否存在 + * @param userDTO 查询条件 * @return */ - @GetMapping("/details/{username}") - public R user(@PathVariable String username) { - SysUser condition = new SysUser(); - condition.setUsername(username); - return R.ok(userService.getOne(new QueryWrapper<>(condition))); + @Inner(false) + @GetMapping("/check/exsit") + public R isExsit(UserDTO userDTO) { + List sysUserList = userService.list(new QueryWrapper<>(userDTO)); + if (CollUtil.isNotEmpty(sysUserList)) { + return R.ok(Boolean.TRUE, MsgUtils.getMessage(ErrorCodes.SYS_USER_EXISTING)); + } + return R.ok(Boolean.FALSE); } /**