From fc7e7cb977ea831e4dea8bf608824927dfc78ccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Fri, 8 Mar 2019 22:34:42 +0800 Subject: [PATCH] =?UTF-8?q?:bookmark:=20Releasing=20/=20Version=20tags.2.1?= =?UTF-8?q?.0=20=20=E5=8C=85=E8=A3=85spring=20security=20oauth2=20?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=BB=86=E8=8A=82=EF=BC=8C=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E6=B3=A8=E8=A7=A3=E6=8E=A5=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .editorconfig | 4 +- README.md | 14 +- pig-auth/pom.xml | 6 +- .../PigAuthenticationFailureEvenHandler.java | 4 +- .../PigAuthenticationSuccessEventHandler.java | 4 +- pig-common/pig-common-core/pom.xml | 2 +- .../config/FilterIgnorePropertiesConfig.java | 4 +- .../core/constant/SecurityConstants.java | 12 +- .../src/main/resources/logback-spring.xml | 91 +++++------ pig-common/pig-common-log/pom.xml | 6 +- pig-common/pig-common-security/pom.xml | 6 +- .../annotation/EnablePigResourceServer.java | 21 ++- .../BaseResourceServerConfigurerAdapter.java | 144 ------------------ .../PigResourceServerAutoConfiguration.java | 51 +++++++ .../PigResourceServerConfigurerAdapter.java | 81 ++++++++++ .../PigSecurityBeanDefinitionRegistrar.java | 50 ++++++ .../PigUserAuthenticationConverter.java | 91 +++++++++++ .../feign/PigFeignClientConfiguration.java | 2 +- ...ractAuthenticationFailureEvenHandler.java} | 2 +- ...actAuthenticationSuccessEventHandler.java} | 2 +- .../main/resources/META-INF/spring.factories | 6 - pig-common/pom.xml | 2 +- pig-config/pom.xml | 2 +- .../main/resources/config/pig-gateway-dev.yml | 64 ++++---- .../src/main/resources/logback-spring.xml | 91 +++++------ pig-eureka/pom.xml | 2 +- .../src/main/resources/logback-spring.xml | 91 +++++------ pig-gateway/pom.xml | 4 +- .../filter/ValidateCodeGatewayFilter.java | 8 +- pig-upms/pig-upms-api/pom.xml | 4 +- .../pig/admin/api/entity/SysLog.java | 1 - .../admin/api/feign/RemoteUserService.java | 2 +- .../RemoteLogServiceFallbackFactory.java | 2 +- .../RemoteTokenServiceFallbackFactory.java | 2 +- .../RemoteUserServiceFallbackFactory.java | 2 +- .../RemoteTokenServiceFallbackImpl.java | 1 - pig-upms/pig-upms-biz/pom.xml | 8 +- .../pig/admin/PigAdminApplication.java | 2 + .../pig/admin/controller/MenuController.java | 16 +- .../pig/admin/controller/UserController.java | 4 +- .../service/impl/SysMenuServiceImpl.java | 10 +- .../main/resources/mapper/SysUserMapper.xml | 24 +-- pig-upms/pom.xml | 2 +- pig-visual/pig-codegen/pom.xml | 8 +- .../pig/codegen/PigCodeGenApplication.java | 4 +- .../config/ResourceServerConfigurer.java | 45 ------ .../controller/SysGeneratorController.java | 2 +- .../codegen/service/SysGeneratorService.java | 1 + .../service/impl/SysGeneratorServiceImpl.java | 4 +- .../pig4cloud/pig/codegen/util/GenUtils.java | 2 +- .../src/main/resources/generator.properties | 6 - .../resources/mapper/SysGeneratorMapper.xml | 5 +- pig-visual/pig-monitor/pom.xml | 2 +- pig-visual/pig-zipkin/pom.xml | 6 +- .../pig/zipkin/PigZipkinApplication.java | 1 + pig-visual/pom.xml | 2 +- pom.xml | 4 +- 57 files changed, 561 insertions(+), 478 deletions(-) rename pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/config/ResourceServerConfigurer.java => pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/annotation/EnablePigResourceServer.java (61%) mode change 100755 => 100644 delete mode 100755 pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/BaseResourceServerConfigurerAdapter.java create mode 100644 pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PigResourceServerAutoConfiguration.java create mode 100644 pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PigResourceServerConfigurerAdapter.java create mode 100644 pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PigSecurityBeanDefinitionRegistrar.java create mode 100644 pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PigUserAuthenticationConverter.java rename pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/handler/{AuthenticationFailureEvenHandler.java => AbstractAuthenticationFailureEvenHandler.java} (92%) rename pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/handler/{AuthenticationSuccessEventHandler.java => AbstractAuthenticationSuccessEventHandler.java} (92%) delete mode 100755 pig-visual/pig-codegen/src/main/java/com/pig4cloud/pig/codegen/config/ResourceServerConfigurer.java diff --git a/.editorconfig b/.editorconfig index afff4db4..46b4828d 100755 --- a/.editorconfig +++ b/.editorconfig @@ -9,11 +9,11 @@ end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true -[*.{java,xml}] +[*.{java, xml}] indent_style = tab indent_size = 4 -[*.{yml,json}] +[*.{yml, json}] indent_style = space indent_size = 2 diff --git a/README.md b/README.md index 6ec5a102..02c5d6e7 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,10 @@ 依赖 | 版本 ---|--- Spring Boot | 2.0.8.RELEASE -Spring Cloud | Finchley.SR2 +Spring Cloud | Finchley.SR3 Spring Security OAuth2 | 2.3.3 -Mybatis Plus | 3.0.6 -hutool | 4.3.3 +Mybatis Plus | 3.1.0 +hutool | 4.5.0 Avue | 1.5.0 @@ -66,11 +66,7 @@ pig ![](http://a.pigx.top/20190201155120.png) -#### 鸣谢 +#### 关注我们 -avue [@smallwei](https://avue.top) -mica-auto [@dreamlu](https://dreamlu.net) -bladex [@smallc](http://bladex.vip) -mybatis-plus [@青苗](http://mp.baomidou.com) -hutool [@路小磊](https://dreamlu.net) +![](http://pic.pigx.top/20190308224043_luIWau_Screenshot.jpeg) diff --git a/pig-auth/pom.xml b/pig-auth/pom.xml index eec333c6..876b863e 100755 --- a/pig-auth/pom.xml +++ b/pig-auth/pom.xml @@ -21,7 +21,7 @@ com.pig4cloud pig - 2.0.3 + 2.1.0 pig-auth @@ -39,13 +39,13 @@ com.pig4cloud pig-upms-api - 2.0.3 + 2.1.0 com.pig4cloud pig-common-security - 2.0.3 + 2.1.0 diff --git a/pig-auth/src/main/java/com/pig4cloud/pig/auth/handler/PigAuthenticationFailureEvenHandler.java b/pig-auth/src/main/java/com/pig4cloud/pig/auth/handler/PigAuthenticationFailureEvenHandler.java index ddea22e7..3fae37b6 100755 --- a/pig-auth/src/main/java/com/pig4cloud/pig/auth/handler/PigAuthenticationFailureEvenHandler.java +++ b/pig-auth/src/main/java/com/pig4cloud/pig/auth/handler/PigAuthenticationFailureEvenHandler.java @@ -16,7 +16,7 @@ package com.pig4cloud.pig.auth.handler; -import com.pig4cloud.pig.common.security.handler.AuthenticationFailureEvenHandler; +import com.pig4cloud.pig.common.security.handler.AbstractAuthenticationFailureEvenHandler; import lombok.extern.slf4j.Slf4j; import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; @@ -28,7 +28,7 @@ import org.springframework.stereotype.Component; */ @Slf4j @Component -public class PigAuthenticationFailureEvenHandler extends AuthenticationFailureEvenHandler { +public class PigAuthenticationFailureEvenHandler extends AbstractAuthenticationFailureEvenHandler { /** * 处理登录失败方法 diff --git a/pig-auth/src/main/java/com/pig4cloud/pig/auth/handler/PigAuthenticationSuccessEventHandler.java b/pig-auth/src/main/java/com/pig4cloud/pig/auth/handler/PigAuthenticationSuccessEventHandler.java index 65771954..68e6b5ac 100755 --- a/pig-auth/src/main/java/com/pig4cloud/pig/auth/handler/PigAuthenticationSuccessEventHandler.java +++ b/pig-auth/src/main/java/com/pig4cloud/pig/auth/handler/PigAuthenticationSuccessEventHandler.java @@ -16,7 +16,7 @@ package com.pig4cloud.pig.auth.handler; -import com.pig4cloud.pig.common.security.handler.AuthenticationSuccessEventHandler; +import com.pig4cloud.pig.common.security.handler.AbstractAuthenticationSuccessEventHandler; import lombok.extern.slf4j.Slf4j; import org.springframework.security.core.Authentication; import org.springframework.stereotype.Component; @@ -27,7 +27,7 @@ import org.springframework.stereotype.Component; */ @Slf4j @Component -public class PigAuthenticationSuccessEventHandler extends AuthenticationSuccessEventHandler { +public class PigAuthenticationSuccessEventHandler extends AbstractAuthenticationSuccessEventHandler { /** * 处理登录成功方法 diff --git a/pig-common/pig-common-core/pom.xml b/pig-common/pig-common-core/pom.xml index 7706345d..9f05decb 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 - 2.0.3 + 2.1.0 pig-common-core diff --git a/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/config/FilterIgnorePropertiesConfig.java b/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/config/FilterIgnorePropertiesConfig.java index e372f2e4..6a481094 100755 --- a/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/config/FilterIgnorePropertiesConfig.java +++ b/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/config/FilterIgnorePropertiesConfig.java @@ -42,10 +42,10 @@ public class FilterIgnorePropertiesConfig { private List clients = new ArrayList<>(); /** * 放行url,放行的url不再被安全框架拦截 - */ + */ private List urls = new ArrayList<>(); /** * 不聚合swagger */ - private List swaggerProviders =new ArrayList<>(); + private List swaggerProviders = new ArrayList<>(); } diff --git a/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/constant/SecurityConstants.java b/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/constant/SecurityConstants.java index c47f23b1..eac115d2 100755 --- a/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/constant/SecurityConstants.java +++ b/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/constant/SecurityConstants.java @@ -67,13 +67,7 @@ public interface SecurityConstants { /** * oauth 客户端信息 */ - String CLIENT_DETAILS_KEY = PROJECT_PREFIX+OAUTH_PREFIX+"client:details"; - - /** - * 微信获取OPENID - */ - String WX_AUTHORIZATION_CODE_URL = "https://api.weixin.qq.com/sns/oauth2/access_token" + - "?appid=%s&secret=%s&code=%s&grant_type=authorization_code"; + String CLIENT_DETAILS_KEY = PROJECT_PREFIX + OAUTH_PREFIX + "client:details"; /** * {bcrypt} 加密的特征码 @@ -102,4 +96,8 @@ public interface SecurityConstants { */ String DEFAULT_SELECT_STATEMENT = BASE_FIND_STATEMENT + " where client_id = ?"; + /*** + * 资源服务器默认bean名称 + */ + String RESOURCE_SERVER_CONFIGURER = "resourceServerConfigurerAdapter"; } diff --git a/pig-common/pig-common-core/src/main/resources/logback-spring.xml b/pig-common/pig-common-core/src/main/resources/logback-spring.xml index 70ea9fa5..6a4d7b1c 100755 --- a/pig-common/pig-common-core/src/main/resources/logback-spring.xml +++ b/pig-common/pig-common-core/src/main/resources/logback-spring.xml @@ -16,56 +16,57 @@ --> - - + + + value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/> - - + + - - - - ${CONSOLE_LOG_PATTERN} - - + converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/> + + + + ${CONSOLE_LOG_PATTERN} + + - - - ${log.path}/debug.log - - ${log.path}/%d{yyyy-MM, aux}/debug.%d{yyyy-MM-dd}.%i.log.gz - 50MB - 30 - - - %date [%thread] %-5level [%logger{50}] %file:%line - %msg%n - - + + + ${log.path}/debug.log + + ${log.path}/%d{yyyy-MM, aux}/debug.%d{yyyy-MM-dd}.%i.log.gz + 50MB + 30 + + + %date [%thread] %-5level [%logger{50}] %file:%line - %msg%n + + - - - ${log.path}/error.log - - ${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz - 50MB - 30 - - - %date [%thread] %-5level [%logger{50}] %file:%line - %msg%n - - - ERROR - - + + + ${log.path}/error.log + + ${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz + 50MB + 30 + + + %date [%thread] %-5level [%logger{50}] %file:%line - %msg%n + + + ERROR + + - - - - - - + + + + + + diff --git a/pig-common/pig-common-log/pom.xml b/pig-common/pig-common-log/pom.xml index 9a71013b..44705020 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 - 2.0.3 + 2.1.0 pig-common-log @@ -35,13 +35,13 @@ com.pig4cloud pig-common-core - 2.0.3 + 2.1.0 com.pig4cloud pig-upms-api - 2.0.3 + 2.1.0 diff --git a/pig-common/pig-common-security/pom.xml b/pig-common/pig-common-security/pom.xml index 62dfcef2..d622d2d8 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 - 2.0.3 + 2.1.0 pig-common-security @@ -35,7 +35,7 @@ com.pig4cloud pig-common-core - 2.0.3 + 2.1.0 @@ -46,7 +46,7 @@ com.pig4cloud pig-upms-api - 2.0.3 + 2.1.0 diff --git a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/config/ResourceServerConfigurer.java b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/annotation/EnablePigResourceServer.java old mode 100755 new mode 100644 similarity index 61% rename from pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/config/ResourceServerConfigurer.java rename to pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/annotation/EnablePigResourceServer.java index 76d4fb08..c6c5caa6 --- a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/config/ResourceServerConfigurer.java +++ b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/annotation/EnablePigResourceServer.java @@ -14,20 +14,29 @@ * limitations under the License. */ -package com.pig4cloud.pig.admin.config; +package com.pig4cloud.pig.common.security.annotation; -import com.pig4cloud.pig.common.security.component.BaseResourceServerConfigurerAdapter; -import org.springframework.context.annotation.Configuration; +import com.pig4cloud.pig.common.security.component.PigResourceServerAutoConfiguration; +import com.pig4cloud.pig.common.security.component.PigSecurityBeanDefinitionRegistrar; +import org.springframework.context.annotation.Import; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; +import java.lang.annotation.*; + /** * @author lengleng - * @date 2019/2/1 + * @date 2019/03/08 + *

+ * 资源服务注解 */ -@Configuration +@Documented +@Inherited @EnableResourceServer +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) @EnableGlobalMethodSecurity(prePostEnabled = true) -public class ResourceServerConfigurer extends BaseResourceServerConfigurerAdapter { +@Import({PigResourceServerAutoConfiguration.class, PigSecurityBeanDefinitionRegistrar.class}) +public @interface EnablePigResourceServer { } diff --git a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/BaseResourceServerConfigurerAdapter.java b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/BaseResourceServerConfigurerAdapter.java deleted file mode 100755 index 050ea408..00000000 --- a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/BaseResourceServerConfigurerAdapter.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (c) 2019-2020, 冷冷 (wangiegie@gmail.com). - *

- * Licensed under the GNU Lesser General Public License 3.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.gnu.org/licenses/lgpl.html - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.pig4cloud.pig.common.security.component; - -import com.pig4cloud.pig.common.core.config.FilterIgnorePropertiesConfig; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cloud.client.loadbalancer.LoadBalanced; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Primary; -import org.springframework.http.HttpStatus; -import org.springframework.http.client.ClientHttpResponse; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer; -import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; -import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer; -import org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter; -import org.springframework.security.oauth2.provider.token.DefaultUserAuthenticationConverter; -import org.springframework.security.oauth2.provider.token.RemoteTokenServices; -import org.springframework.web.client.DefaultResponseErrorHandler; -import org.springframework.web.client.RestTemplate; - -import java.io.IOException; - -/** - * @author lengleng - * @date 2019/2/1 - *

- * 1. 支持remoteTokenServices 负载均衡 - * 2. 支持 获取用户全部信息 - */ -public abstract class BaseResourceServerConfigurerAdapter extends ResourceServerConfigurerAdapter { - @Autowired - protected ResourceAuthExceptionEntryPoint resourceAuthExceptionEntryPoint; - @Autowired - protected PigAccessDeniedHandler pigAccessDeniedHandler; - @Autowired - protected RemoteTokenServices remoteTokenServices; - @Autowired - protected UserDetailsService userDetailsService; - @Autowired - private FilterIgnorePropertiesConfig filterIgnorePropertiesConfig; - - - /** - * 默认的配置,对外暴露 - * - * @param http - * @throws Exception - */ - @Override - public void configure(HttpSecurity http) throws Exception{ - //允许使用iframe 嵌套,避免swagger-ui 不被加载的问题 - http.headers().frameOptions().disable(); - ExpressionUrlAuthorizationConfigurer - .ExpressionInterceptUrlRegistry registry = http - .authorizeRequests(); - filterIgnorePropertiesConfig.getUrls() - .forEach(url -> registry.antMatchers(url).permitAll()); - registry.anyRequest().authenticated() - .and().csrf().disable(); - } - - /** - * 提供子类重写 - *

- * 1. 不重写,默认支持获取雍熙 - * 2. 重写notGetUser,提供性能 - *

- * see codegen ResourceServerConfigurer - * - * @param resources - */ - @Override - public void configure(ResourceServerSecurityConfigurer resources) { - canGetUser(resources); - } - - @Bean - @Primary - @LoadBalanced - public RestTemplate lbRestTemplate() { - RestTemplate restTemplate = new RestTemplate(); - restTemplate.setErrorHandler(new DefaultResponseErrorHandler() { - @Override - public void handleError(ClientHttpResponse response) throws IOException { - if (response.getRawStatusCode() != HttpStatus.BAD_REQUEST.value()) { - super.handleError(response); - } - } - }); - return restTemplate; - } - /** - * 不获取用户详细 只有用户名 - * - * @param resources - */ - protected void notGetUser(ResourceServerSecurityConfigurer resources) { - DefaultAccessTokenConverter accessTokenConverter = new DefaultAccessTokenConverter(); - DefaultUserAuthenticationConverter userTokenConverter = new DefaultUserAuthenticationConverter(); - accessTokenConverter.setUserTokenConverter(userTokenConverter); - - remoteTokenServices.setRestTemplate(lbRestTemplate()); - remoteTokenServices.setAccessTokenConverter(accessTokenConverter); - resources.authenticationEntryPoint(resourceAuthExceptionEntryPoint) - .accessDeniedHandler(pigAccessDeniedHandler) - .tokenServices(remoteTokenServices); - } - - - /** - * 上下文中获取用户全部信息,两次调用userDetailsService,影响性能 - * - * @param resources - */ - private void canGetUser(ResourceServerSecurityConfigurer resources) { - DefaultAccessTokenConverter accessTokenConverter = new DefaultAccessTokenConverter(); - DefaultUserAuthenticationConverter userTokenConverter = new DefaultUserAuthenticationConverter(); - userTokenConverter.setUserDetailsService(userDetailsService); - accessTokenConverter.setUserTokenConverter(userTokenConverter); - - remoteTokenServices.setRestTemplate(lbRestTemplate()); - remoteTokenServices.setAccessTokenConverter(accessTokenConverter); - resources.authenticationEntryPoint(resourceAuthExceptionEntryPoint) - .accessDeniedHandler(pigAccessDeniedHandler) - .tokenServices(remoteTokenServices); - } - -} diff --git a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PigResourceServerAutoConfiguration.java b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PigResourceServerAutoConfiguration.java new file mode 100644 index 00000000..2f775024 --- /dev/null +++ b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PigResourceServerAutoConfiguration.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2019-2020, 冷冷 (wangiegie@gmail.com). + *

+ * Licensed under the GNU Lesser General Public License 3.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://www.gnu.org/licenses/lgpl.html + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.pig4cloud.pig.common.security.component; + +import org.springframework.cloud.client.loadbalancer.LoadBalanced; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Primary; +import org.springframework.http.HttpStatus; +import org.springframework.http.client.ClientHttpResponse; +import org.springframework.web.client.DefaultResponseErrorHandler; +import org.springframework.web.client.RestTemplate; + +import java.io.IOException; + +/** + * @author lengleng + * @date 2019/03/08 + */ +@ComponentScan("com.pig4cloud.pig.common.security") +public class PigResourceServerAutoConfiguration { + @Bean + @Primary + @LoadBalanced + public RestTemplate lbRestTemplate() { + RestTemplate restTemplate = new RestTemplate(); + restTemplate.setErrorHandler(new DefaultResponseErrorHandler() { + @Override + public void handleError(ClientHttpResponse response) throws IOException { + if (response.getRawStatusCode() != HttpStatus.BAD_REQUEST.value()) { + super.handleError(response); + } + } + }); + return restTemplate; + } +} diff --git a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PigResourceServerConfigurerAdapter.java b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PigResourceServerConfigurerAdapter.java new file mode 100644 index 00000000..c7cc30d4 --- /dev/null +++ b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PigResourceServerConfigurerAdapter.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2019-2020, 冷冷 (wangiegie@gmail.com). + *

+ * Licensed under the GNU Lesser General Public License 3.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://www.gnu.org/licenses/lgpl.html + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.pig4cloud.pig.common.security.component; + +import com.pig4cloud.pig.common.core.config.FilterIgnorePropertiesConfig; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer; +import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; +import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer; +import org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter; +import org.springframework.security.oauth2.provider.token.RemoteTokenServices; +import org.springframework.security.oauth2.provider.token.UserAuthenticationConverter; +import org.springframework.web.client.RestTemplate; + +/** + * @author lengleng + * @date 2019/03/08 + * + *

+ * 1. 支持remoteTokenServices 负载均衡 + * 2. 支持 获取用户全部信息 + */ +@Slf4j +public class PigResourceServerConfigurerAdapter extends ResourceServerConfigurerAdapter { + @Autowired + protected ResourceAuthExceptionEntryPoint resourceAuthExceptionEntryPoint; + @Autowired + protected RemoteTokenServices remoteTokenServices; + @Autowired + private FilterIgnorePropertiesConfig ignorePropertiesConfig; + @Autowired + private RestTemplate lbRestTemplate; + + /** + * 默认的配置,对外暴露 + * + * @param httpSecurity + */ + @Override + @SneakyThrows + public void configure(HttpSecurity httpSecurity) { + //允许使用iframe 嵌套,避免swagger-ui 不被加载的问题 + httpSecurity.headers().frameOptions().disable(); + ExpressionUrlAuthorizationConfigurer + .ExpressionInterceptUrlRegistry registry = httpSecurity + .authorizeRequests(); + ignorePropertiesConfig.getUrls() + .forEach(url -> registry.antMatchers(url).permitAll()); + registry.anyRequest().authenticated() + .and().csrf().disable(); + } + + @Override + public void configure(ResourceServerSecurityConfigurer resources) { + DefaultAccessTokenConverter accessTokenConverter = new DefaultAccessTokenConverter(); + UserAuthenticationConverter userTokenConverter = new PigUserAuthenticationConverter(); + accessTokenConverter.setUserTokenConverter(userTokenConverter); + + remoteTokenServices.setRestTemplate(lbRestTemplate); + remoteTokenServices.setAccessTokenConverter(accessTokenConverter); + resources.authenticationEntryPoint(resourceAuthExceptionEntryPoint) + .tokenServices(remoteTokenServices); + } +} diff --git a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PigSecurityBeanDefinitionRegistrar.java b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PigSecurityBeanDefinitionRegistrar.java new file mode 100644 index 00000000..7f9a4446 --- /dev/null +++ b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PigSecurityBeanDefinitionRegistrar.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2019-2020, 冷冷 (wangiegie@gmail.com). + *

+ * Licensed under the GNU Lesser General Public License 3.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://www.gnu.org/licenses/lgpl.html + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.pig4cloud.pig.common.security.component; + +import com.pig4cloud.pig.common.core.constant.SecurityConstants; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.beans.factory.support.GenericBeanDefinition; +import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; +import org.springframework.core.type.AnnotationMetadata; + +/** + * @author lengleng + * @date 2019/03/08 + */ +@Slf4j +public class PigSecurityBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar { + /** + * 根据注解值动态注入资源服务器的相关属性 + * + * @param metadata 注解信息 + * @param registry 注册器 + */ + @Override + public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) { + if (registry.isBeanNameInUse(SecurityConstants.RESOURCE_SERVER_CONFIGURER)) { + log.warn("本地存在资源服务器配置,覆盖默认配置:" + SecurityConstants.RESOURCE_SERVER_CONFIGURER); + return; + } + + GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); + beanDefinition.setBeanClass(PigResourceServerConfigurerAdapter.class); + registry.registerBeanDefinition(SecurityConstants.RESOURCE_SERVER_CONFIGURER, beanDefinition); + + } +} diff --git a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PigUserAuthenticationConverter.java b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PigUserAuthenticationConverter.java new file mode 100644 index 00000000..fe16b27f --- /dev/null +++ b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PigUserAuthenticationConverter.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2019-2020, 冷冷 (wangiegie@gmail.com). + *

+ * Licensed under the GNU Lesser General Public License 3.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://www.gnu.org/licenses/lgpl.html + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.pig4cloud.pig.common.security.component; + +import com.pig4cloud.pig.common.security.service.PigUser; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.AuthorityUtils; +import org.springframework.security.oauth2.provider.token.UserAuthenticationConverter; +import org.springframework.util.StringUtils; + +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * @author lengleng + * @date 2019-03-07 + *

+ * 根据checktoken 的结果转化用户信息 + */ +public class PigUserAuthenticationConverter implements UserAuthenticationConverter { + private static final String USER_ID = "user_id"; + private static final String DEPT_ID = "dept_id"; + private static final String TENANT_ID = "tenant_id"; + private static final String N_A = "N/A"; + + /** + * Extract information about the user to be used in an access token (i.e. for resource servers). + * + * @param authentication an authentication representing a user + * @return a map of key values representing the unique information about the user + */ + @Override + public Map convertUserAuthentication(Authentication authentication) { + Map response = new LinkedHashMap<>(); + response.put(USERNAME, authentication.getName()); + if (authentication.getAuthorities() != null && !authentication.getAuthorities().isEmpty()) { + response.put(AUTHORITIES, AuthorityUtils.authorityListToSet(authentication.getAuthorities())); + } + return response; + } + + /** + * Inverse of {@link #convertUserAuthentication(Authentication)}. Extracts an Authentication from a map. + * + * @param map a map of user information + * @return an Authentication representing the user or null if there is none + */ + @Override + public Authentication extractAuthentication(Map map) { + if (map.containsKey(USERNAME)) { + Collection authorities = getAuthorities(map); + + String username = (String) map.get(USERNAME); + Integer id = (Integer) map.get(USER_ID); + Integer deptId = (Integer) map.get(DEPT_ID); + PigUser user = new PigUser(id, deptId, username, N_A, true + , true, true, true, authorities); + return new UsernamePasswordAuthenticationToken(user, N_A, authorities); + } + return null; + } + + private Collection getAuthorities(Map map) { + Object authorities = map.get(AUTHORITIES); + if (authorities instanceof String) { + return AuthorityUtils.commaSeparatedStringToAuthorityList((String) authorities); + } + if (authorities instanceof Collection) { + return AuthorityUtils.commaSeparatedStringToAuthorityList(StringUtils + .collectionToCommaDelimitedString((Collection) authorities)); + } + throw new IllegalArgumentException("Authorities must be either a String or a Collection"); + } +} diff --git a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/feign/PigFeignClientConfiguration.java b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/feign/PigFeignClientConfiguration.java index 6c1acc95..f00c5632 100755 --- a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/feign/PigFeignClientConfiguration.java +++ b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/feign/PigFeignClientConfiguration.java @@ -39,6 +39,6 @@ public class PigFeignClientConfiguration { public RequestInterceptor oauth2FeignRequestInterceptor(OAuth2ClientContext oAuth2ClientContext, OAuth2ProtectedResourceDetails resource, AccessTokenContextRelay accessTokenContextRelay) { - return new PigFeignClientInterceptor(oAuth2ClientContext, resource,accessTokenContextRelay); + return new PigFeignClientInterceptor(oAuth2ClientContext, resource, accessTokenContextRelay); } } diff --git a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/handler/AuthenticationFailureEvenHandler.java b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/handler/AbstractAuthenticationFailureEvenHandler.java similarity index 92% rename from pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/handler/AuthenticationFailureEvenHandler.java rename to pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/handler/AbstractAuthenticationFailureEvenHandler.java index 634af6c2..90314934 100755 --- a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/handler/AuthenticationFailureEvenHandler.java +++ b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/handler/AbstractAuthenticationFailureEvenHandler.java @@ -26,7 +26,7 @@ import org.springframework.security.core.AuthenticationException; * @date 2019/2/1 * 认证失败事件处理器 */ -public abstract class AuthenticationFailureEvenHandler implements ApplicationListener { +public abstract class AbstractAuthenticationFailureEvenHandler implements ApplicationListener { /** * Handle an application event. diff --git a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/handler/AuthenticationSuccessEventHandler.java b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/handler/AbstractAuthenticationSuccessEventHandler.java similarity index 92% rename from pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/handler/AuthenticationSuccessEventHandler.java rename to pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/handler/AbstractAuthenticationSuccessEventHandler.java index 7443f5e7..64e66c91 100755 --- a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/handler/AuthenticationSuccessEventHandler.java +++ b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/handler/AbstractAuthenticationSuccessEventHandler.java @@ -26,7 +26,7 @@ import org.springframework.security.core.Authentication; * @date 2019/2/1 * 认证成功事件处理器 */ -public abstract class AuthenticationSuccessEventHandler implements ApplicationListener { +public abstract class AbstractAuthenticationSuccessEventHandler implements ApplicationListener { /** * Handle an application event. * diff --git a/pig-common/pig-common-security/src/main/resources/META-INF/spring.factories b/pig-common/pig-common-security/src/main/resources/META-INF/spring.factories index a162c5ad..55beb731 100755 --- a/pig-common/pig-common-security/src/main/resources/META-INF/spring.factories +++ b/pig-common/pig-common-security/src/main/resources/META-INF/spring.factories @@ -1,8 +1,2 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - com.pig4cloud.pig.common.security.component.PermissionService,\ - com.pig4cloud.pig.common.security.component.PigAccessDeniedHandler,\ - com.pig4cloud.pig.common.security.component.PigSecurityInnerAspect,\ - com.pig4cloud.pig.common.security.component.ResourceAuthExceptionEntryPoint,\ - com.pig4cloud.pig.common.security.component.PigResourceServerTokenRelayAutoConfiguration,\ - com.pig4cloud.pig.common.security.feign.PigFeignClientConfiguration,\ com.pig4cloud.pig.common.security.service.PigUserDetailsServiceImpl diff --git a/pig-common/pom.xml b/pig-common/pom.xml index 80cf7772..b1a3654d 100755 --- a/pig-common/pom.xml +++ b/pig-common/pom.xml @@ -21,7 +21,7 @@ com.pig4cloud pig - 2.0.3 + 2.1.0 pig-common diff --git a/pig-config/pom.xml b/pig-config/pom.xml index cbf121cf..ea045a84 100755 --- a/pig-config/pom.xml +++ b/pig-config/pom.xml @@ -21,7 +21,7 @@ com.pig4cloud pig - 2.0.3 + 2.1.0 pig-config diff --git a/pig-config/src/main/resources/config/pig-gateway-dev.yml b/pig-config/src/main/resources/config/pig-gateway-dev.yml index e2ef1d04..0762e0d7 100755 --- a/pig-config/src/main/resources/config/pig-gateway-dev.yml +++ b/pig-config/src/main/resources/config/pig-gateway-dev.yml @@ -4,38 +4,38 @@ spring: locator: enabled: true routes: - # 认证中心 - - id: pig-auth - uri: lb://pig-auth - predicates: - - Path=/auth/** - filters: - # 验证码处理 - - ValidateCodeGatewayFilter - # 前端密码解密 - - PasswordDecoderFilter - #UPMS 模块 - - id: pig-upms - uri: lb://pig-upms - predicates: - - Path=/admin/** - filters: - # 限流配置 - - name: RequestRateLimiter - args: - key-resolver: '#{@remoteAddrKeyResolver}' - redis-rate-limiter.replenishRate: 10 - redis-rate-limiter.burstCapacity: 20 - # 降级配置 - - name: Hystrix - args: - name: default - fallbackUri: 'forward:/fallback' - # 代码生成模块 - - id: pig-codegen - uri: lb://pig-codegen - predicates: - - Path=/gen/** + # 认证中心 + - id: pig-auth + uri: lb://pig-auth + predicates: + - Path=/auth/** + filters: + # 验证码处理 + - ValidateCodeGatewayFilter + # 前端密码解密 + - PasswordDecoderFilter + #UPMS 模块 + - id: pig-upms + uri: lb://pig-upms + predicates: + - Path=/admin/** + filters: + # 限流配置 + - name: RequestRateLimiter + args: + key-resolver: '#{@remoteAddrKeyResolver}' + redis-rate-limiter.replenishRate: 10 + redis-rate-limiter.burstCapacity: 20 + # 降级配置 + - name: Hystrix + args: + name: default + fallbackUri: 'forward:/fallback' + # 代码生成模块 + - id: pig-codegen + uri: lb://pig-codegen + predicates: + - Path=/gen/** security: diff --git a/pig-config/src/main/resources/logback-spring.xml b/pig-config/src/main/resources/logback-spring.xml index 70ea9fa5..6a4d7b1c 100755 --- a/pig-config/src/main/resources/logback-spring.xml +++ b/pig-config/src/main/resources/logback-spring.xml @@ -16,56 +16,57 @@ --> - - + + + value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/> - - + + - - - - ${CONSOLE_LOG_PATTERN} - - + converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/> + + + + ${CONSOLE_LOG_PATTERN} + + - - - ${log.path}/debug.log - - ${log.path}/%d{yyyy-MM, aux}/debug.%d{yyyy-MM-dd}.%i.log.gz - 50MB - 30 - - - %date [%thread] %-5level [%logger{50}] %file:%line - %msg%n - - + + + ${log.path}/debug.log + + ${log.path}/%d{yyyy-MM, aux}/debug.%d{yyyy-MM-dd}.%i.log.gz + 50MB + 30 + + + %date [%thread] %-5level [%logger{50}] %file:%line - %msg%n + + - - - ${log.path}/error.log - - ${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz - 50MB - 30 - - - %date [%thread] %-5level [%logger{50}] %file:%line - %msg%n - - - ERROR - - + + + ${log.path}/error.log + + ${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz + 50MB + 30 + + + %date [%thread] %-5level [%logger{50}] %file:%line - %msg%n + + + ERROR + + - - - - - - + + + + + + diff --git a/pig-eureka/pom.xml b/pig-eureka/pom.xml index 140a0a3e..f0b98091 100755 --- a/pig-eureka/pom.xml +++ b/pig-eureka/pom.xml @@ -21,7 +21,7 @@ com.pig4cloud pig - 2.0.3 + 2.1.0 pig-eureka diff --git a/pig-eureka/src/main/resources/logback-spring.xml b/pig-eureka/src/main/resources/logback-spring.xml index fd3233e9..6a4d7b1c 100755 --- a/pig-eureka/src/main/resources/logback-spring.xml +++ b/pig-eureka/src/main/resources/logback-spring.xml @@ -16,56 +16,57 @@ --> - - + + + value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/> - - + + - - - - ${CONSOLE_LOG_PATTERN} - - + converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/> + + + + ${CONSOLE_LOG_PATTERN} + + - - - ${log.path}/debug.log - - ${log.path}/%d{yyyy-MM, aux}/debug.%d{yyyy-MM-dd}.%i.log.gz - 50MB - 30 - - - %date [%thread] %-5level [%logger{50}] %file:%line - %msg%n - - + + + ${log.path}/debug.log + + ${log.path}/%d{yyyy-MM, aux}/debug.%d{yyyy-MM-dd}.%i.log.gz + 50MB + 30 + + + %date [%thread] %-5level [%logger{50}] %file:%line - %msg%n + + - - - ${log.path}/error.log - - ${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz - 50MB - 30 - - - %date [%thread] %-5level [%logger{50}] %file:%line - %msg%n - - - ERROR - - + + + ${log.path}/error.log + + ${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz + 50MB + 30 + + + %date [%thread] %-5level [%logger{50}] %file:%line - %msg%n + + + ERROR + + - - - - - - + + + + + + diff --git a/pig-gateway/pom.xml b/pig-gateway/pom.xml index 5d8dc35b..b1cc983d 100755 --- a/pig-gateway/pom.xml +++ b/pig-gateway/pom.xml @@ -21,7 +21,7 @@ com.pig4cloud pig - 2.0.3 + 2.1.0 pig-gateway @@ -54,7 +54,7 @@ com.pig4cloud pig-common-core - 2.0.3 + 2.1.0 diff --git a/pig-gateway/src/main/java/com/pig4cloud/pig/gateway/filter/ValidateCodeGatewayFilter.java b/pig-gateway/src/main/java/com/pig4cloud/pig/gateway/filter/ValidateCodeGatewayFilter.java index ea336eac..4d1f9c33 100644 --- a/pig-gateway/src/main/java/com/pig4cloud/pig/gateway/filter/ValidateCodeGatewayFilter.java +++ b/pig-gateway/src/main/java/com/pig4cloud/pig/gateway/filter/ValidateCodeGatewayFilter.java @@ -57,7 +57,7 @@ public class ValidateCodeGatewayFilter extends AbstractGatewayFilterFactory { // 不是登录请求,直接向下执行 if (!StrUtil.containsAnyIgnoreCase(request.getURI().getPath() - , SecurityConstants.OAUTH_TOKEN_URL)) { + , SecurityConstants.OAUTH_TOKEN_URL)) { return chain.filter(exchange); } @@ -81,9 +81,9 @@ public class ValidateCodeGatewayFilter extends AbstractGatewayFilterFactory { response.setStatusCode(HttpStatus.PRECONDITION_REQUIRED); try { return response.writeWith(Mono.just(response.bufferFactory() - .wrap(objectMapper.writeValueAsBytes( - R.builder().msg(e.getMessage()) - .code(CommonConstants.FAIL).build())))); + .wrap(objectMapper.writeValueAsBytes( + R.builder().msg(e.getMessage()) + .code(CommonConstants.FAIL).build())))); } catch (JsonProcessingException e1) { log.error("对象输出异常", e1); } diff --git a/pig-upms/pig-upms-api/pom.xml b/pig-upms/pig-upms-api/pom.xml index fdbf7365..1e56b8f6 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 - 2.0.3 + 2.1.0 pig-upms-api @@ -35,7 +35,7 @@ com.pig4cloud pig-common-core - 2.0.3 + 2.1.0 diff --git a/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/entity/SysLog.java b/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/entity/SysLog.java index 7b5e221c..0cd404bc 100644 --- a/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/entity/SysLog.java +++ b/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/entity/SysLog.java @@ -107,5 +107,4 @@ public class SysLog implements Serializable { private String delFlag; - } diff --git a/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/feign/RemoteUserService.java b/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/feign/RemoteUserService.java index d6f3dd9e..eeeb4da9 100755 --- a/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/feign/RemoteUserService.java +++ b/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/feign/RemoteUserService.java @@ -16,8 +16,8 @@ package com.pig4cloud.pig.admin.api.feign; -import com.pig4cloud.pig.admin.api.feign.factory.RemoteUserServiceFallbackFactory; import com.pig4cloud.pig.admin.api.dto.UserInfo; +import com.pig4cloud.pig.admin.api.feign.factory.RemoteUserServiceFallbackFactory; import com.pig4cloud.pig.common.core.constant.SecurityConstants; import com.pig4cloud.pig.common.core.constant.ServiceNameConstants; import com.pig4cloud.pig.common.core.util.R; diff --git a/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/feign/factory/RemoteLogServiceFallbackFactory.java b/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/feign/factory/RemoteLogServiceFallbackFactory.java index 1f408fa8..d327913f 100755 --- a/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/feign/factory/RemoteLogServiceFallbackFactory.java +++ b/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/feign/factory/RemoteLogServiceFallbackFactory.java @@ -16,8 +16,8 @@ package com.pig4cloud.pig.admin.api.feign.factory; -import com.pig4cloud.pig.admin.api.feign.fallback.RemoteLogServiceFallbackImpl; import com.pig4cloud.pig.admin.api.feign.RemoteLogService; +import com.pig4cloud.pig.admin.api.feign.fallback.RemoteLogServiceFallbackImpl; import feign.hystrix.FallbackFactory; import org.springframework.stereotype.Component; diff --git a/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/feign/factory/RemoteTokenServiceFallbackFactory.java b/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/feign/factory/RemoteTokenServiceFallbackFactory.java index 4139fbe0..a48b5801 100755 --- a/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/feign/factory/RemoteTokenServiceFallbackFactory.java +++ b/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/feign/factory/RemoteTokenServiceFallbackFactory.java @@ -16,8 +16,8 @@ package com.pig4cloud.pig.admin.api.feign.factory; -import com.pig4cloud.pig.admin.api.feign.fallback.RemoteTokenServiceFallbackImpl; import com.pig4cloud.pig.admin.api.feign.RemoteTokenService; +import com.pig4cloud.pig.admin.api.feign.fallback.RemoteTokenServiceFallbackImpl; import feign.hystrix.FallbackFactory; import org.springframework.stereotype.Component; diff --git a/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/feign/factory/RemoteUserServiceFallbackFactory.java b/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/feign/factory/RemoteUserServiceFallbackFactory.java index 78d99110..41a08f25 100755 --- a/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/feign/factory/RemoteUserServiceFallbackFactory.java +++ b/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/feign/factory/RemoteUserServiceFallbackFactory.java @@ -16,8 +16,8 @@ package com.pig4cloud.pig.admin.api.feign.factory; -import com.pig4cloud.pig.admin.api.feign.fallback.RemoteUserServiceFallbackImpl; import com.pig4cloud.pig.admin.api.feign.RemoteUserService; +import com.pig4cloud.pig.admin.api.feign.fallback.RemoteUserServiceFallbackImpl; import feign.hystrix.FallbackFactory; import org.springframework.stereotype.Component; diff --git a/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/feign/fallback/RemoteTokenServiceFallbackImpl.java b/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/feign/fallback/RemoteTokenServiceFallbackImpl.java index 8593a79f..7b06567c 100755 --- a/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/feign/fallback/RemoteTokenServiceFallbackImpl.java +++ b/pig-upms/pig-upms-api/src/main/java/com/pig4cloud/pig/admin/api/feign/fallback/RemoteTokenServiceFallbackImpl.java @@ -51,7 +51,6 @@ public class RemoteTokenServiceFallbackImpl implements RemoteTokenService { /** * 删除token * - * * @param s * @param id * @return diff --git a/pig-upms/pig-upms-biz/pom.xml b/pig-upms/pig-upms-biz/pom.xml index 2f595a3b..4f153c9a 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 - 2.0.3 + 2.1.0 pig-upms-biz @@ -34,19 +34,19 @@ com.pig4cloud pig-upms-api - 2.0.3 + 2.1.0 com.pig4cloud pig-common-security - 2.0.3 + 2.1.0 com.pig4cloud pig-common-log - 2.0.3 + 2.1.0 diff --git a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/PigAdminApplication.java b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/PigAdminApplication.java index e8fce4a9..d4400469 100644 --- a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/PigAdminApplication.java +++ b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/PigAdminApplication.java @@ -18,6 +18,7 @@ package com.pig4cloud.pig.admin; import com.pig4cloud.pig.common.security.annotation.EnablePigFeignClients; +import com.pig4cloud.pig.common.security.annotation.EnablePigResourceServer; import org.springframework.boot.SpringApplication; import org.springframework.cloud.client.SpringCloudApplication; @@ -26,6 +27,7 @@ import org.springframework.cloud.client.SpringCloudApplication; * @date 2018年06月21日 * 用户统一管理系统 */ +@EnablePigResourceServer @EnablePigFeignClients @SpringCloudApplication public class PigAdminApplication { diff --git a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/MenuController.java b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/MenuController.java index f1bc65c4..dbdaa5f8 100644 --- a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/MenuController.java +++ b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/MenuController.java @@ -57,12 +57,12 @@ public class MenuController { // 获取符合条件的菜单 Set all = new HashSet<>(); SecurityUtils.getRoles() - .forEach(roleId -> all.addAll(sysMenuService.getMenuByRoleId(roleId))); + .forEach(roleId -> all.addAll(sysMenuService.getMenuByRoleId(roleId))); List menuTreeList = all.stream() - .filter(menuVo -> CommonConstants.MENU.equals(menuVo.getType())) - .map(MenuTree::new) - .sorted(Comparator.comparingInt(MenuTree::getSort)) - .collect(Collectors.toList()); + .filter(menuVo -> CommonConstants.MENU.equals(menuVo.getType())) + .map(MenuTree::new) + .sorted(Comparator.comparingInt(MenuTree::getSort)) + .collect(Collectors.toList()); return new R<>(TreeUtil.buildByLoop(menuTreeList, -1)); } @@ -85,9 +85,9 @@ public class MenuController { @GetMapping("/tree/{roleId}") public List getRoleTree(@PathVariable Integer roleId) { return sysMenuService.getMenuByRoleId(roleId) - .stream() - .map(MenuVO::getMenuId) - .collect(Collectors.toList()); + .stream() + .map(MenuVO::getMenuId) + .collect(Collectors.toList()); } /** 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 fca456ef..187ca7d4 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 @@ -51,7 +51,7 @@ public class UserController { public R info() { String username = SecurityUtils.getUser().getUsername(); SysUser user = userService.getOne(Wrappers.query() - .lambda().eq(SysUser::getUsername, username)); + .lambda().eq(SysUser::getUsername, username)); if (user == null) { return new R<>(Boolean.FALSE, "获取当前用户信息失败"); } @@ -67,7 +67,7 @@ public class UserController { @GetMapping("/info/{username}") public R info(@PathVariable String username) { SysUser user = userService.getOne(Wrappers.query() - .lambda().eq(SysUser::getUsername, username)); + .lambda().eq(SysUser::getUsername, username)); if (user == null) { return new R<>(Boolean.FALSE, String.format("用户信息为空 %s", username)); } diff --git a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysMenuServiceImpl.java b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysMenuServiceImpl.java index fa43edbd..c958965c 100644 --- a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysMenuServiceImpl.java +++ b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysMenuServiceImpl.java @@ -60,16 +60,16 @@ public class SysMenuServiceImpl extends ServiceImpl impl public R removeMenuById(Integer id) { // 查询父节点为当前节点的节点 List menuList = this.list(Wrappers.query() - .lambda().eq(SysMenu::getParentId, id)); + .lambda().eq(SysMenu::getParentId, id)); if (CollUtil.isNotEmpty(menuList)) { return R.builder() - .code(CommonConstants.FAIL) - .msg("菜单含有下级不能删除").build(); + .code(CommonConstants.FAIL) + .msg("菜单含有下级不能删除").build(); } sysRoleMenuMapper - .delete(Wrappers.query() - .lambda().eq(SysRoleMenu::getMenuId, id)); + .delete(Wrappers.query() + .lambda().eq(SysRoleMenu::getMenuId, id)); //删除当前菜单及其子菜单 return new R(this.removeById(id)); diff --git a/pig-upms/pig-upms-biz/src/main/resources/mapper/SysUserMapper.xml b/pig-upms/pig-upms-biz/src/main/resources/mapper/SysUserMapper.xml index 893b33e5..8573f821 100644 --- a/pig-upms/pig-upms-biz/src/main/resources/mapper/SysUserMapper.xml +++ b/pig-upms/pig-upms-biz/src/main/resources/mapper/SysUserMapper.xml @@ -112,25 +112,25 @@ + SELECT + + FROM + sys_user AS `user` + LEFT JOIN sys_user_role AS ur ON ur.user_id = `user`.user_id + LEFT JOIN sys_role AS r ON r.role_id = ur.role_id + LEFT JOIN sys_dept AS d ON d.dept_id = `user`.dept_id + WHERE + `user`.user_id = #{id} + - select table_name tableName, engine, table_comment tableComment, create_time createTime from information_schema.tables - where table_schema = (select database()) + select table_name tableName, engine, table_comment tableComment, create_time createTime from + information_schema.tables + where table_schema = (select database()) and table_name like concat('%', #{tableName}, '%') diff --git a/pig-visual/pig-monitor/pom.xml b/pig-visual/pig-monitor/pom.xml index 59f2e1c2..e6e89d34 100755 --- a/pig-visual/pig-monitor/pom.xml +++ b/pig-visual/pig-monitor/pom.xml @@ -21,7 +21,7 @@ com.pig4cloud pig-visual - 2.0.3 + 2.1.0 pig-monitor diff --git a/pig-visual/pig-zipkin/pom.xml b/pig-visual/pig-zipkin/pom.xml index 895c2a07..865e7a21 100644 --- a/pig-visual/pig-zipkin/pom.xml +++ b/pig-visual/pig-zipkin/pom.xml @@ -1,11 +1,11 @@ - pig-visual com.pig4cloud - 2.0.3 + 2.1.0 4.0.0 diff --git a/pig-visual/pig-zipkin/src/main/java/com/pig4cloud/pig/zipkin/PigZipkinApplication.java b/pig-visual/pig-zipkin/src/main/java/com/pig4cloud/pig/zipkin/PigZipkinApplication.java index 51caec1b..92a4aec8 100644 --- a/pig-visual/pig-zipkin/src/main/java/com/pig4cloud/pig/zipkin/PigZipkinApplication.java +++ b/pig-visual/pig-zipkin/src/main/java/com/pig4cloud/pig/zipkin/PigZipkinApplication.java @@ -20,6 +20,7 @@ public class PigZipkinApplication { public static void main(String[] args) { SpringApplication.run(PigZipkinApplication.class, args); } + @Bean public MySQLStorage mySQLStorage(DataSource datasource) { return MySQLStorage.builder().datasource(datasource).executor(Runnable::run).build(); diff --git a/pig-visual/pom.xml b/pig-visual/pom.xml index 8bb6a7bd..c50ccb33 100755 --- a/pig-visual/pom.xml +++ b/pig-visual/pom.xml @@ -21,7 +21,7 @@ com.pig4cloud pig - 2.0.3 + 2.1.0 pig-visual diff --git a/pom.xml b/pom.xml index 8338d5f7..05cf0068 100755 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ com.pig4cloud pig - 2.0.3 + 2.1.0 ${project.artifactId} pom https://www.pig4cloud.com @@ -33,7 +33,7 @@ UTF-8 1.8 1.8 - 2.0.4 + 2.0.5 4.5.0 3.1.0 0.0.9