From bc84aa37d22b7d757419256378b6f3d44af709a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Sun, 30 Sep 2018 09:47:12 +0800 Subject: [PATCH 01/17] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20'pigx-config/src/mai?= =?UTF-8?q?n/resources/config/pigx-upms-dev.yml'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pigx-config/src/main/resources/config/pigx-upms-dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pigx-config/src/main/resources/config/pigx-upms-dev.yml b/pigx-config/src/main/resources/config/pigx-upms-dev.yml index bfa68b9c9..5d4f217b9 100644 --- a/pigx-config/src/main/resources/config/pigx-upms-dev.yml +++ b/pigx-config/src/main/resources/config/pigx-upms-dev.yml @@ -13,7 +13,7 @@ spring: driver-class-name: com.mysql.jdbc.Driver username: root password: root - url: jdbc:mysql://127.0.0.1:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false + url: jdbc:mysql://127.0.0.1:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true # mybaits 模块配置 mybatis-plus: From 710456f8bb87dd0b406cd67cd5daa5550338929b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Fri, 5 Oct 2018 17:38:36 +0800 Subject: [PATCH 02/17] =?UTF-8?q?:pushpin:=20=E6=8C=87=E5=AE=9A=E7=89=B9?= =?UTF-8?q?=E5=AE=9A=E7=89=88=E6=9C=AC=E4=BE=9D=E8=B5=96=E3=80=82=20?= =?UTF-8?q?=E6=8C=87=E5=AE=9Amaven=20=E6=8F=92=E4=BB=B6=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pom.xml b/pom.xml index 58e6c8e59..5068d998f 100644 --- a/pom.xml +++ b/pom.xml @@ -180,6 +180,7 @@ maven-compiler-plugin + 3.8.0 ${maven.compiler.target} ${maven.compiler.source} @@ -189,6 +190,7 @@ pl.project13.maven git-commit-id-plugin + 2.2.5 From faa93056425a1b424874d05b656d07fe5da11b57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Fri, 5 Oct 2018 17:45:25 +0800 Subject: [PATCH 03/17] =?UTF-8?q?:rewind:=20Reverting=20changes.=E5=9B=9E?= =?UTF-8?q?=E6=BB=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pigx-config/src/main/resources/config/pigx-upms-dev.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pigx-config/src/main/resources/config/pigx-upms-dev.yml b/pigx-config/src/main/resources/config/pigx-upms-dev.yml index 5d4f217b9..7f7c71a9d 100644 --- a/pigx-config/src/main/resources/config/pigx-upms-dev.yml +++ b/pigx-config/src/main/resources/config/pigx-upms-dev.yml @@ -13,11 +13,7 @@ spring: driver-class-name: com.mysql.jdbc.Driver username: root password: root - url: jdbc:mysql://127.0.0.1:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true - -# mybaits 模块配置 -mybatis-plus: - typeAliasesPackage: com.pig4cloud.pigx.admin.api.entity + url: jdbc:mysql://127.0.0.1:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false # swagger相关配置,覆盖全局配置 swagger: From 2d9d2c20cd96ce2b05000f0330f7fdf85b75231a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Fri, 5 Oct 2018 23:13:48 +0800 Subject: [PATCH 04/17] =?UTF-8?q?:wrench:=20=E4=BF=AE=E6=94=B9readme?= =?UTF-8?q?=E3=80=82=E5=A2=9E=E5=8A=A0=E8=A7=86=E9=A2=91=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 32e984fba..b7df59aa4 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,12 @@ -

- Build Status - Coverage Status - Downloads -

- -

Supporting Pig Developer Team

- -## 项目官网 -https://pig4cloud.com - -### 配套代码 -pigx-ui - -### pigx 和 pig 区别 - -- 基于最新的Spring Cloud Finchley.RELEASE 版本 -- 完整的oAuth 流程,资源服务器控制权限 -- 去除了部分对于开发不友好的中间件 - ### 使用说明 -请参考VIP群共享 《从零开始部署pigx》 -[>> 目录](doc/md/catalog.md) +请参考VIP群共享 《从零开始部署pigx》 +[>> 文档](doc/md/catalog.md) + +视频 | ppt +---|--- +[>> 环境准备、运行pigx](https://www.bilibili.com/video/av33200189)| [PPT](https://slides.com/lengleng/pigx-springcloud-6) + ## 协议和授权 From 2530b5538eea608429054d43716c3782d4470a06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Mon, 8 Oct 2018 11:26:43 +0800 Subject: [PATCH 05/17] :bug: Fixing a bug. userdetailsservice require --- .../pig4cloud/pigx/auth/config/AuthorizationServerConfig.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/AuthorizationServerConfig.java b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/AuthorizationServerConfig.java index 6cad348ff..e08d45e56 100644 --- a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/AuthorizationServerConfig.java +++ b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/AuthorizationServerConfig.java @@ -21,6 +21,7 @@ package com.pig4cloud.pigx.auth.config; import com.pig4cloud.pigx.common.core.constant.SecurityConstants; import com.pig4cloud.pigx.common.security.component.PigxWebResponseExceptionTranslator; +import com.pig4cloud.pigx.common.security.service.PigxUserDetailsService; import lombok.AllArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -52,6 +53,7 @@ import java.util.Map; @EnableAuthorizationServer public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter { private final DataSource dataSource; + private final PigxUserDetailsService pigxUserDetailsService; private final AuthenticationManager authenticationManager; private final RedisConnectionFactory redisConnectionFactory; @@ -76,6 +78,7 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap .allowedTokenEndpointRequestMethods(HttpMethod.GET, HttpMethod.POST) .tokenStore(tokenStore()) .tokenEnhancer(tokenEnhancer()) + .userDetailsService(pigxUserDetailsService) .authenticationManager(authenticationManager) .reuseRefreshTokens(false) .exceptionTranslator(new PigxWebResponseExceptionTranslator()); From 971c27ad5b771e7725f3f38f4c031572936b6b05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Mon, 8 Oct 2018 11:27:22 +0800 Subject: [PATCH 06/17] =?UTF-8?q?:white=5Fcheck=5Fmark:=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81=E3=80=82=20?= =?UTF-8?q?=E5=8A=A0=E8=A7=A3=E5=AF=86=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pigx/admin/PigxAdminApplicationTest.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 pigx-upms/pigx-upms-biz/src/test/java/com/pig4cloud/pigx/admin/PigxAdminApplicationTest.java diff --git a/pigx-upms/pigx-upms-biz/src/test/java/com/pig4cloud/pigx/admin/PigxAdminApplicationTest.java b/pigx-upms/pigx-upms-biz/src/test/java/com/pig4cloud/pigx/admin/PigxAdminApplicationTest.java new file mode 100644 index 000000000..022b64f2a --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/test/java/com/pig4cloud/pigx/admin/PigxAdminApplicationTest.java @@ -0,0 +1,44 @@ +/* + * 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.pigx.admin; + +import com.ulisesbocchio.jasyptspringboot.encryptor.DefaultLazyEncryptor; +import org.jasypt.encryption.StringEncryptor; +import org.junit.Test; +import org.springframework.core.env.StandardEnvironment; + +/** + * @author lengleng + * @date 2018/10/7 + *

+ * 加解密单元测试 + */ +public class PigxAdminApplicationTest { + @Test + public void testJasypt() { + // 对应application-dev.yml 中配置的根密码 + System.setProperty("jasypt.encryptor.password", "pigx"); + StringEncryptor stringEncryptor = new DefaultLazyEncryptor(new StandardEnvironment()); + + //加密方法 + System.out.println(stringEncryptor.encrypt("pig")); + + //解密方法 + System.out.println(stringEncryptor.decrypt("ltJPpR50wT0oIY9kfOe1Iw===")); + } +} From ab476e181078fb669075532f04045296fb362179 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Mon, 8 Oct 2018 11:27:43 +0800 Subject: [PATCH 07/17] =?UTF-8?q?:bookmark:=20=E5=8F=91=E5=B8=83=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E7=89=88=E6=9C=AC=E3=80=821.6.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 5068d998f..cfec5bc70 100644 --- a/pom.xml +++ b/pom.xml @@ -30,14 +30,14 @@ https://www.pig4cloud.com - 1.6.2 + 1.6.3 2.0.4.RELEASE Finchley.SR1 Cairo-SR3 UTF-8 1.8 1.8 - 2.0.2 + 2.0.3 4.1.13 2.3 0.0.9 From 3d7e13cca8b255b7ca839dc8c344fb27d63d67fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Mon, 8 Oct 2018 11:38:10 +0800 Subject: [PATCH 08/17] =?UTF-8?q?:memo:=20=E7=BC=96=E5=86=99=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E3=80=82=20readme=20=E6=96=B0=E5=A2=9E=E8=A7=86?= =?UTF-8?q?=E9=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b7df59aa4..bdcd3be60 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,9 @@ 视频 | ppt ---|--- -[>> 环境准备、运行pigx](https://www.bilibili.com/video/av33200189)| [PPT](https://slides.com/lengleng/pigx-springcloud-6) - +[>> 环境准备、运行pigx](https://www.bilibili.com/video/av33200189)| [PPT](https://slides.com/lengleng/pigx-springcloud-6/fullscreen#/) +[>> pigx定时任务、运维平台使用](https://www.bilibili.com/video/av33268288)| [PPT](https://slides.com/lengleng/pigx-springcloud-7/fullscreen#/) +[>> pigx 配置文件加解密原理和选择](https://www.bilibili.com/video/av33315412)| [PPT](https://slides.com/lengleng/pigx-springcloud-6-8/fullscreen#/) ## 协议和授权 From c5bf52b8ab070cbcdab2b1da3bf40edb11f41988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Mon, 8 Oct 2018 15:18:04 +0800 Subject: [PATCH 09/17] =?UTF-8?q?:sparkles:=20=E6=B7=BB=E5=8A=A0=E6=96=B0?= =?UTF-8?q?=E7=89=B9=E6=80=A7=E3=80=82=E7=99=BB=E5=BD=95=E6=88=90=E5=8A=9F?= =?UTF-8?q?=E3=80=81=E5=A4=B1=E8=B4=A5=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PigxAuthenticationFailureEvenHandler.java | 45 ++++++++++++++++ ...PigxAuthenticationSuccessEventHandler.java | 44 +++++++++++++++ .../AuthenticationFailureEvenHandler.java | 53 +++++++++++++++++++ .../AuthenticationSuccessEventHandler.java | 49 +++++++++++++++++ 4 files changed, 191 insertions(+) create mode 100644 pigx-auth/src/main/java/com/pig4cloud/pigx/auth/handle/PigxAuthenticationFailureEvenHandler.java create mode 100644 pigx-auth/src/main/java/com/pig4cloud/pigx/auth/handle/PigxAuthenticationSuccessEventHandler.java create mode 100644 pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handle/AuthenticationFailureEvenHandler.java create mode 100644 pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handle/AuthenticationSuccessEventHandler.java diff --git a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/handle/PigxAuthenticationFailureEvenHandler.java b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/handle/PigxAuthenticationFailureEvenHandler.java new file mode 100644 index 000000000..f1c2c694e --- /dev/null +++ b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/handle/PigxAuthenticationFailureEvenHandler.java @@ -0,0 +1,45 @@ +/* + * 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.pigx.auth.handle; + +import com.pig4cloud.pigx.common.security.handle.AuthenticationFailureEvenHandler; +import lombok.extern.slf4j.Slf4j; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.AuthenticationException; +import org.springframework.stereotype.Component; + +/** + * @author lengleng + * @date 2018/10/8 + */ +@Slf4j +@Component +public class PigxAuthenticationFailureEvenHandler extends AuthenticationFailureEvenHandler { + + /** + * 处理登录成功方法 + *

+ * + * @param authenticationException 登录的authentication 对象 + * @param authentication 登录的authenticationException 对象 + */ + @Override + public void handle(AuthenticationException authenticationException, Authentication authentication) { + log.info("用户:{} 登录失败,异常:{}", authentication.getPrincipal(), authenticationException.getLocalizedMessage()); + } +} diff --git a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/handle/PigxAuthenticationSuccessEventHandler.java b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/handle/PigxAuthenticationSuccessEventHandler.java new file mode 100644 index 000000000..78ffbcb82 --- /dev/null +++ b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/handle/PigxAuthenticationSuccessEventHandler.java @@ -0,0 +1,44 @@ +/* + * 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.pigx.auth.handle; + +import com.pig4cloud.pigx.common.security.handle.AuthenticationSuccessEventHandler; +import lombok.extern.slf4j.Slf4j; +import org.springframework.security.core.Authentication; +import org.springframework.stereotype.Component; + +/** + * @author lengleng + * @date 2018/10/8 + */ +@Slf4j +@Component +public class PigxAuthenticationSuccessEventHandler extends AuthenticationSuccessEventHandler { + + /** + * 处理登录成功方法 + *

+ * 获取到登录的authentication 对象 + * + * @param authentication 登录对象 + */ + @Override + public void handle(Authentication authentication) { + log.info("用户:{} 登录成功", authentication.getPrincipal()); + } +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handle/AuthenticationFailureEvenHandler.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handle/AuthenticationFailureEvenHandler.java new file mode 100644 index 000000000..b051c64f0 --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handle/AuthenticationFailureEvenHandler.java @@ -0,0 +1,53 @@ +/* + * 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.pigx.common.security.handle; + +import org.springframework.context.ApplicationListener; +import org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.AuthenticationException; + +/** + * @author lengleng + * @date 2018/10/8 + * 认证失败事件处理器 + */ +public abstract class AuthenticationFailureEvenHandler implements ApplicationListener { + + /** + * Handle an application event. + * + * @param event the event to respond to + */ + @Override + public void onApplicationEvent(AbstractAuthenticationFailureEvent event) { + AuthenticationException authenticationException = event.getException(); + Authentication authentication = (Authentication) event.getSource(); + + handle(authenticationException, authentication); + } + + /** + * 处理登录成功方法 + *

+ * + * @param authenticationException 登录的authentication 对象 + * @param authentication 登录的authenticationException 对象 + */ + public abstract void handle(AuthenticationException authenticationException, Authentication authentication); +} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handle/AuthenticationSuccessEventHandler.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handle/AuthenticationSuccessEventHandler.java new file mode 100644 index 000000000..b66659c30 --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handle/AuthenticationSuccessEventHandler.java @@ -0,0 +1,49 @@ +/* + * 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.pigx.common.security.handle; + +import org.springframework.context.ApplicationListener; +import org.springframework.security.authentication.event.AuthenticationSuccessEvent; +import org.springframework.security.core.Authentication; + +/** + * @author lengleng + * @date 2018/10/8 + * 认证成功事件处理器 + */ +public abstract class AuthenticationSuccessEventHandler implements ApplicationListener { + /** + * Handle an application event. + * + * @param event the event to respond to + */ + @Override + public void onApplicationEvent(AuthenticationSuccessEvent event) { + Authentication authentication = (Authentication) event.getSource(); + handle(authentication); + } + + /** + * 处理登录成功方法 + *

+ * 获取到登录的authentication 对象 + * + * @param authentication 登录对象 + */ + public abstract void handle(Authentication authentication); +} From 622cc31b339db159af288e0ed98552906f12fa1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Mon, 8 Oct 2018 15:18:33 +0800 Subject: [PATCH 10/17] =?UTF-8?q?:recycle:=20=E9=87=8D=E6=9E=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E3=80=82=E9=87=8D=E6=9E=84=E7=BD=91=E5=85=B3=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=EF=BC=8C=E7=BC=A9=E5=87=8F=E9=85=8D=E7=BD=AEfilter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/config/WebSecurityConfigurer.java | 2 +- .../MobileLoginSuccessHandler.java | 2 +- .../resources/config/pigx-gateway-dev.yml | 15 +-- .../filter/PigxRequestGlobalFilter.java | 92 +++++++++++++++++++ .../gateway/filter/SwaggerHeaderFilter.java | 53 ----------- 5 files changed, 95 insertions(+), 69 deletions(-) rename pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/{mobile => handle}/MobileLoginSuccessHandler.java (98%) create mode 100644 pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/PigxRequestGlobalFilter.java delete mode 100644 pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/SwaggerHeaderFilter.java diff --git a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/WebSecurityConfigurer.java b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/WebSecurityConfigurer.java index 24674832d..7d6dfc4b3 100644 --- a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/WebSecurityConfigurer.java +++ b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/WebSecurityConfigurer.java @@ -20,7 +20,7 @@ package com.pig4cloud.pigx.auth.config; import com.fasterxml.jackson.databind.ObjectMapper; -import com.pig4cloud.pigx.common.security.mobile.MobileLoginSuccessHandler; +import com.pig4cloud.pigx.common.security.handle.MobileLoginSuccessHandler; import com.pig4cloud.pigx.common.security.mobile.MobileSecurityConfigurer; import com.pig4cloud.pigx.common.security.service.PigxUserDetailsService; import org.springframework.beans.factory.annotation.Autowired; diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileLoginSuccessHandler.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handle/MobileLoginSuccessHandler.java similarity index 98% rename from pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileLoginSuccessHandler.java rename to pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handle/MobileLoginSuccessHandler.java index 69de555b3..bed4c7069 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileLoginSuccessHandler.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handle/MobileLoginSuccessHandler.java @@ -14,7 +14,7 @@ * this software without specific prior written permission. * Author: lengleng (wangiegie@gmail.com) */ -package com.pig4cloud.pigx.common.security.mobile; +package com.pig4cloud.pigx.common.security.handle; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.CharsetUtil; diff --git a/pigx-config/src/main/resources/config/pigx-gateway-dev.yml b/pigx-config/src/main/resources/config/pigx-gateway-dev.yml index 54ea8d7ac..f8723322b 100644 --- a/pigx-config/src/main/resources/config/pigx-gateway-dev.yml +++ b/pigx-config/src/main/resources/config/pigx-gateway-dev.yml @@ -14,26 +14,18 @@ spring: - ImageCodeGatewayFilter # 前端密码解密 - PasswordDecoderFilter - - StripPrefix=1 #UPMS 模块 - id: pigx-upms uri: lb://pigx-upms predicates: - Path=/admin/** filters: - # Swagger请求头处理 - - SwaggerHeaderFilter - # 请求头清理避免不合法请求头 - - name: RemoveRequestHeader - args: - name: from # 限流配置 - name: RequestRateLimiter args: key-resolver: '#{@remoteAddrKeyResolver}' redis-rate-limiter.replenishRate: 10 redis-rate-limiter.burstCapacity: 20 - - StripPrefix=1 # 降级配置 - name: Hystrix args: @@ -44,22 +36,17 @@ spring: uri: lb://pigx-codegen predicates: - Path=/gen/** - filters: - - StripPrefix=1 # 定时任务模块 - id: pigx-daemon uri: lb://pigx-daemon predicates: - Path=/daemon/** - filters: - - StripPrefix=1 # 分布式事务管理模块 - id: pigx-tx-manager uri: lb://pigx-tx-manager predicates: - Path=/tx/** - filters: - - StripPrefix=1 + security: encode: # 前端密码密钥,必须16位 diff --git a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/PigxRequestGlobalFilter.java b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/PigxRequestGlobalFilter.java new file mode 100644 index 000000000..13d3df60e --- /dev/null +++ b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/PigxRequestGlobalFilter.java @@ -0,0 +1,92 @@ +/* + * 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.pigx.gateway.filter; + +import com.pig4cloud.pigx.common.core.constant.SecurityConstants; +import com.pig4cloud.pigx.gateway.config.SwaggerProvider; +import org.springframework.cloud.gateway.filter.GatewayFilterChain; +import org.springframework.cloud.gateway.filter.GlobalFilter; +import org.springframework.core.Ordered; +import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Mono; + +import java.util.Arrays; +import java.util.stream.Collectors; + +import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR; +import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.addOriginalRequestUrl; + +/** + * @author lengleng + * @date 2018/10/8 + *

+ * 全局拦截器,作用所有的微服务 + *

+ * 1. 对请求头中参数进行处理 from 参数进行清洗 + * 2. 重写StripPrefix = 1,支持全局 + * 3. 支持swagger添加X-Forwarded-Prefix header + */ +@Component +public class PigxRequestGlobalFilter implements GlobalFilter, Ordered { + private static final String HEADER_NAME = "X-Forwarded-Prefix"; + + /** + * Process the Web request and (optionally) delegate to the next + * {@code WebFilter} through the given {@link GatewayFilterChain}. + * + * @param exchange the current server exchange + * @param chain provides a way to delegate to the next filter + * @return {@code Mono} to indicate when request processing is complete + */ + @Override + public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { + // 1. 清洗请求头中from 参数 + ServerHttpRequest request = exchange.getRequest().mutate() + .headers(httpHeaders -> httpHeaders.remove(SecurityConstants.FROM_IN)) + .build(); + + // 2. 重写StripPrefix + addOriginalRequestUrl(exchange, request.getURI()); + String rawPath = request.getURI().getRawPath(); + String newPath = "/" + Arrays.stream(StringUtils.tokenizeToStringArray(rawPath, "/")) + .skip(1L).collect(Collectors.joining("/")); + ServerHttpRequest newRequest = request.mutate() + .path(newPath) + .build(); + exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, newRequest.getURI()); + + // 3. 支持swagger添加X-Forwarded-Prefix header + String path = newRequest.getURI().getPath(); + if (!StringUtils.endsWithIgnoreCase(path, SwaggerProvider.API_URI)) { + return chain.filter(exchange.mutate().request(newRequest).build()); + } + String basePath = path.substring(0, path.lastIndexOf(SwaggerProvider.API_URI)); + return chain.filter(exchange.mutate() + .request(newRequest.mutate() + .header(HEADER_NAME, basePath) + .build()).build()); + } + + @Override + public int getOrder() { + return -1000; + } +} diff --git a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/SwaggerHeaderFilter.java b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/SwaggerHeaderFilter.java deleted file mode 100644 index 964ac0d65..000000000 --- a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/SwaggerHeaderFilter.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.pigx.gateway.filter; - -import com.pig4cloud.pigx.gateway.config.SwaggerProvider; -import org.springframework.cloud.gateway.filter.GatewayFilter; -import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; -import org.springframework.http.server.reactive.ServerHttpRequest; -import org.springframework.stereotype.Component; -import org.springframework.util.StringUtils; -import org.springframework.web.server.ServerWebExchange; - -/** - * @author Sywd - * 添加X-Forwarded-Prefix header - */ -@Component -public class SwaggerHeaderFilter extends AbstractGatewayFilterFactory { - private static final String HEADER_NAME = "X-Forwarded-Prefix"; - - @Override - public GatewayFilter apply(Object config) { - return (exchange, chain) -> { - ServerHttpRequest request = exchange.getRequest(); - String path = request.getURI().getPath(); - if (!StringUtils.endsWithIgnoreCase(path, SwaggerProvider.API_URI)) { - return chain.filter(exchange); - } - - String basePath = path.substring(0, path.lastIndexOf(SwaggerProvider.API_URI)); - - - ServerHttpRequest newRequest = request.mutate().header(HEADER_NAME, basePath).build(); - ServerWebExchange newExchange = exchange.mutate().request(newRequest).build(); - return chain.filter(newExchange); - }; - } -} From fd34dba3451f0be829d3e9fec9e54da9946bba54 Mon Sep 17 00:00:00 2001 From: lishangbu Date: Mon, 8 Oct 2018 17:49:12 +0800 Subject: [PATCH 11/17] =?UTF-8?q?:art:=20=E6=94=B9=E8=BF=9B=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E5=92=8C=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F:?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=8C=85=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/pig4cloud/pigx/auth/config/WebSecurityConfigurer.java | 2 +- .../PigxAuthenticationFailureEvenHandler.java | 4 ++-- .../PigxAuthenticationSuccessEventHandler.java | 4 ++-- .../{handle => handler}/AuthenticationFailureEvenHandler.java | 2 +- .../AuthenticationSuccessEventHandler.java | 2 +- .../{handle => handler}/MobileLoginSuccessHandler.java | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) rename pigx-auth/src/main/java/com/pig4cloud/pigx/auth/{handle => handler}/PigxAuthenticationFailureEvenHandler.java (92%) rename pigx-auth/src/main/java/com/pig4cloud/pigx/auth/{handle => handler}/PigxAuthenticationSuccessEventHandler.java (91%) rename pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/{handle => handler}/AuthenticationFailureEvenHandler.java (97%) rename pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/{handle => handler}/AuthenticationSuccessEventHandler.java (96%) rename pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/{handle => handler}/MobileLoginSuccessHandler.java (98%) diff --git a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/WebSecurityConfigurer.java b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/WebSecurityConfigurer.java index 7d6dfc4b3..2935ee747 100644 --- a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/WebSecurityConfigurer.java +++ b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/WebSecurityConfigurer.java @@ -20,7 +20,7 @@ package com.pig4cloud.pigx.auth.config; import com.fasterxml.jackson.databind.ObjectMapper; -import com.pig4cloud.pigx.common.security.handle.MobileLoginSuccessHandler; +import com.pig4cloud.pigx.common.security.handler.MobileLoginSuccessHandler; import com.pig4cloud.pigx.common.security.mobile.MobileSecurityConfigurer; import com.pig4cloud.pigx.common.security.service.PigxUserDetailsService; import org.springframework.beans.factory.annotation.Autowired; diff --git a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/handle/PigxAuthenticationFailureEvenHandler.java b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/handler/PigxAuthenticationFailureEvenHandler.java similarity index 92% rename from pigx-auth/src/main/java/com/pig4cloud/pigx/auth/handle/PigxAuthenticationFailureEvenHandler.java rename to pigx-auth/src/main/java/com/pig4cloud/pigx/auth/handler/PigxAuthenticationFailureEvenHandler.java index f1c2c694e..92e3cdfa3 100644 --- a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/handle/PigxAuthenticationFailureEvenHandler.java +++ b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/handler/PigxAuthenticationFailureEvenHandler.java @@ -15,9 +15,9 @@ * Author: lengleng (wangiegie@gmail.com) */ -package com.pig4cloud.pigx.auth.handle; +package com.pig4cloud.pigx.auth.handler; -import com.pig4cloud.pigx.common.security.handle.AuthenticationFailureEvenHandler; +import com.pig4cloud.pigx.common.security.handler.AuthenticationFailureEvenHandler; import lombok.extern.slf4j.Slf4j; import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; diff --git a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/handle/PigxAuthenticationSuccessEventHandler.java b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/handler/PigxAuthenticationSuccessEventHandler.java similarity index 91% rename from pigx-auth/src/main/java/com/pig4cloud/pigx/auth/handle/PigxAuthenticationSuccessEventHandler.java rename to pigx-auth/src/main/java/com/pig4cloud/pigx/auth/handler/PigxAuthenticationSuccessEventHandler.java index 78ffbcb82..4b8cf3ad7 100644 --- a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/handle/PigxAuthenticationSuccessEventHandler.java +++ b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/handler/PigxAuthenticationSuccessEventHandler.java @@ -15,9 +15,9 @@ * Author: lengleng (wangiegie@gmail.com) */ -package com.pig4cloud.pigx.auth.handle; +package com.pig4cloud.pigx.auth.handler; -import com.pig4cloud.pigx.common.security.handle.AuthenticationSuccessEventHandler; +import com.pig4cloud.pigx.common.security.handler.AuthenticationSuccessEventHandler; import lombok.extern.slf4j.Slf4j; import org.springframework.security.core.Authentication; import org.springframework.stereotype.Component; diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handle/AuthenticationFailureEvenHandler.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handler/AuthenticationFailureEvenHandler.java similarity index 97% rename from pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handle/AuthenticationFailureEvenHandler.java rename to pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handler/AuthenticationFailureEvenHandler.java index b051c64f0..5527264c7 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handle/AuthenticationFailureEvenHandler.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handler/AuthenticationFailureEvenHandler.java @@ -15,7 +15,7 @@ * Author: lengleng (wangiegie@gmail.com) */ -package com.pig4cloud.pigx.common.security.handle; +package com.pig4cloud.pigx.common.security.handler; import org.springframework.context.ApplicationListener; import org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent; diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handle/AuthenticationSuccessEventHandler.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handler/AuthenticationSuccessEventHandler.java similarity index 96% rename from pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handle/AuthenticationSuccessEventHandler.java rename to pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handler/AuthenticationSuccessEventHandler.java index b66659c30..388836fca 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handle/AuthenticationSuccessEventHandler.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handler/AuthenticationSuccessEventHandler.java @@ -15,7 +15,7 @@ * Author: lengleng (wangiegie@gmail.com) */ -package com.pig4cloud.pigx.common.security.handle; +package com.pig4cloud.pigx.common.security.handler; import org.springframework.context.ApplicationListener; import org.springframework.security.authentication.event.AuthenticationSuccessEvent; diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handle/MobileLoginSuccessHandler.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handler/MobileLoginSuccessHandler.java similarity index 98% rename from pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handle/MobileLoginSuccessHandler.java rename to pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handler/MobileLoginSuccessHandler.java index bed4c7069..53cec6c86 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handle/MobileLoginSuccessHandler.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/handler/MobileLoginSuccessHandler.java @@ -14,7 +14,7 @@ * this software without specific prior written permission. * Author: lengleng (wangiegie@gmail.com) */ -package com.pig4cloud.pigx.common.security.handle; +package com.pig4cloud.pigx.common.security.handler; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.CharsetUtil; From 5f85aa99d82f3006d361e8880d8c84aa8e295145 Mon Sep 17 00:00:00 2001 From: lishangbu Date: Mon, 8 Oct 2018 20:04:57 +0800 Subject: [PATCH 12/17] =?UTF-8?q?:sparkles:=20=E6=B7=BB=E5=8A=A0=E6=96=B0?= =?UTF-8?q?=E7=89=B9=E6=80=A7=EF=BC=9ASpring=20Boot=20Admin=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/config/pigx-monitor-dev.yml | 6 ++ .../pigx/admin/PigxAdminApplicationTest.java | 2 +- pigx-visual/pigx-monitor/pom.xml | 5 ++ .../monitor/config/WebSecurityConfigurer.java | 66 +++++++++++++++++++ 4 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 pigx-config/src/main/resources/config/pigx-monitor-dev.yml create mode 100644 pigx-visual/pigx-monitor/src/main/java/com/pig4cloud/pigx/monitor/config/WebSecurityConfigurer.java diff --git a/pigx-config/src/main/resources/config/pigx-monitor-dev.yml b/pigx-config/src/main/resources/config/pigx-monitor-dev.yml new file mode 100644 index 000000000..39e609042 --- /dev/null +++ b/pigx-config/src/main/resources/config/pigx-monitor-dev.yml @@ -0,0 +1,6 @@ +spring: + # 安全配置 + security: + user: + name: ENC(rZHA4LW5hHmhLAAzJoFNag==) + password: ENC(bjeyh+Aeii3kHXkoo00ZUw==) diff --git a/pigx-upms/pigx-upms-biz/src/test/java/com/pig4cloud/pigx/admin/PigxAdminApplicationTest.java b/pigx-upms/pigx-upms-biz/src/test/java/com/pig4cloud/pigx/admin/PigxAdminApplicationTest.java index 022b64f2a..554ab1f1c 100644 --- a/pigx-upms/pigx-upms-biz/src/test/java/com/pig4cloud/pigx/admin/PigxAdminApplicationTest.java +++ b/pigx-upms/pigx-upms-biz/src/test/java/com/pig4cloud/pigx/admin/PigxAdminApplicationTest.java @@ -36,7 +36,7 @@ public class PigxAdminApplicationTest { StringEncryptor stringEncryptor = new DefaultLazyEncryptor(new StandardEnvironment()); //加密方法 - System.out.println(stringEncryptor.encrypt("pig")); + System.out.println(stringEncryptor.encrypt("pigx")); //解密方法 System.out.println(stringEncryptor.decrypt("ltJPpR50wT0oIY9kfOe1Iw===")); diff --git a/pigx-visual/pigx-monitor/pom.xml b/pigx-visual/pigx-monitor/pom.xml index b1359ca98..2eb40ceb9 100644 --- a/pigx-visual/pigx-monitor/pom.xml +++ b/pigx-visual/pigx-monitor/pom.xml @@ -61,6 +61,11 @@ org.springframework.boot spring-boot-starter-undertow + + + org.springframework.cloud + spring-cloud-starter-security + diff --git a/pigx-visual/pigx-monitor/src/main/java/com/pig4cloud/pigx/monitor/config/WebSecurityConfigurer.java b/pigx-visual/pigx-monitor/src/main/java/com/pig4cloud/pigx/monitor/config/WebSecurityConfigurer.java new file mode 100644 index 000000000..0360680ce --- /dev/null +++ b/pigx-visual/pigx-monitor/src/main/java/com/pig4cloud/pigx/monitor/config/WebSecurityConfigurer.java @@ -0,0 +1,66 @@ +/* + * + * 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.pigx.monitor.config; + +import de.codecentric.boot.admin.server.config.AdminServerProperties; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; +import org.springframework.security.web.csrf.CookieCsrfTokenRepository; + +/** + * WebSecurityConfigurer + * + * @author: lishangbu + * @date: 2018/10/8 + */ +@Configuration +public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter { + private final String adminContextPath; + + public WebSecurityConfigurer(AdminServerProperties adminServerProperties) { + this.adminContextPath = adminServerProperties.getContextPath(); + } + + @Override + protected void configure(HttpSecurity http) throws Exception { + // @formatter:off + SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler(); + successHandler.setTargetUrlParameter("redirectTo"); + successHandler.setDefaultTargetUrl(adminContextPath + "/"); + + http.authorizeRequests() + .antMatchers(adminContextPath + "/assets/**").permitAll() + .antMatchers(adminContextPath + "/login").permitAll() + .anyRequest().authenticated() + .and() + .formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and() + .logout().logoutUrl(adminContextPath + "/logout").and() + .httpBasic().and() + .csrf() + .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) + .ignoringAntMatchers( + adminContextPath + "/instances", + adminContextPath + "/actuator/**" + ); + // @formatter:on + } +} From caee2530785460ccd08de1444e6db76f9015c92f Mon Sep 17 00:00:00 2001 From: lisb Date: Wed, 10 Oct 2018 18:37:21 +0800 Subject: [PATCH 13/17] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=20BUG:?= =?UTF-8?q?=E9=83=A8=E9=97=A8id=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/pig4cloud/pigx/common/security/service/PigxUser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUser.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUser.java index e69b617fc..5961d0f0a 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUser.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUser.java @@ -64,6 +64,6 @@ public class PigxUser extends User { public PigxUser(Integer id, Integer deptId, String username, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection authorities) { super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities); this.id = id; - this.deptId = id; + this.deptId = deptId; } } From 676cba867ab15353d5f9526e011e89ba81ab2d50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Thu, 11 Oct 2018 18:28:30 +0800 Subject: [PATCH 14/17] =?UTF-8?q?:wrench:=20=E4=BF=AE=E6=94=B9=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E3=80=82=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6IP=20host?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pigx-config/src/main/resources/config/application-dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pigx-config/src/main/resources/config/application-dev.yml b/pigx-config/src/main/resources/config/application-dev.yml index f0d60ca6d..9f1e379b9 100644 --- a/pigx-config/src/main/resources/config/application-dev.yml +++ b/pigx-config/src/main/resources/config/application-dev.yml @@ -6,7 +6,7 @@ jasypt: spring: redis: password: - host: localhost + host: redis # 暴露监控端点 management: endpoints: From 46bba25270d138c87ad4b232df96705c522f9810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Thu, 11 Oct 2018 18:28:51 +0800 Subject: [PATCH 15/17] =?UTF-8?q?:wrench:=20=E4=BF=AE=E6=94=B9=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E3=80=82=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6IP=20host?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/md/deploy.md | 2 +- doc/md/elastic-job-monitor-platform.md | 6 +++--- pigx-config/src/main/resources/config/pigx-auth-dev.yml | 4 ++-- pigx-config/src/main/resources/config/pigx-codegen-dev.yml | 4 ++-- pigx-config/src/main/resources/config/pigx-daemon-dev.yml | 6 +++--- pigx-config/src/main/resources/config/pigx-upms-dev.yml | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/doc/md/deploy.md b/doc/md/deploy.md index bdf9330a1..7f27cafe8 100644 --- a/doc/md/deploy.md +++ b/doc/md/deploy.md @@ -40,7 +40,7 @@ spring: driver-class-name: com.mysql.jdbc.Driver username: root password: lengleng - url: jdbc:mysql://127.0.0.1:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false + url: jdbc:mysql://mysql:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false ``` diff --git a/doc/md/elastic-job-monitor-platform.md b/doc/md/elastic-job-monitor-platform.md index 05e028c55..10fb7a895 100644 --- a/doc/md/elastic-job-monitor-platform.md +++ b/doc/md/elastic-job-monitor-platform.md @@ -48,8 +48,8 @@ spring: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.jdbc.Driver username: root - password: root - url: jdbc:mysql://127.0.0.1:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false + password: 123456 + url: jdbc:mysql://mysql:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false elasticjob: # 分布式任务协调依赖zookeeper zookeeper: @@ -71,4 +71,4 @@ spring: 最终效果如下: -![20189418110](http://p7sojn4oj.bkt.clouddn.com/20189418110.png) \ No newline at end of file +![20189418110](http://p7sojn4oj.bkt.clouddn.com/20189418110.png) diff --git a/pigx-config/src/main/resources/config/pigx-auth-dev.yml b/pigx-config/src/main/resources/config/pigx-auth-dev.yml index 8abdbf645..e4187342e 100644 --- a/pigx-config/src/main/resources/config/pigx-auth-dev.yml +++ b/pigx-config/src/main/resources/config/pigx-auth-dev.yml @@ -4,5 +4,5 @@ spring: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.jdbc.Driver username: root - password: root - url: jdbc:mysql://127.0.0.1:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false + password: 123456 + url: jdbc:mysql://mysql:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false diff --git a/pigx-config/src/main/resources/config/pigx-codegen-dev.yml b/pigx-config/src/main/resources/config/pigx-codegen-dev.yml index 1247ffb3a..133c73ab7 100644 --- a/pigx-config/src/main/resources/config/pigx-codegen-dev.yml +++ b/pigx-config/src/main/resources/config/pigx-codegen-dev.yml @@ -12,8 +12,8 @@ spring: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.jdbc.Driver username: root - password: root - url: jdbc:mysql://127.0.0.1:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false + password: 123456 + url: jdbc:mysql://mysql:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false jackson: time-zone: GMT+8 date-format: yyyy-MM-dd HH:mm:ss diff --git a/pigx-config/src/main/resources/config/pigx-daemon-dev.yml b/pigx-config/src/main/resources/config/pigx-daemon-dev.yml index 892f6174e..5bb30138b 100644 --- a/pigx-config/src/main/resources/config/pigx-daemon-dev.yml +++ b/pigx-config/src/main/resources/config/pigx-daemon-dev.yml @@ -13,12 +13,12 @@ spring: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.jdbc.Driver username: root - password: root - url: jdbc:mysql://127.0.0.1:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false + password: 123456 + url: jdbc:mysql://mysql:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false elasticjob: # 分布式任务协调依赖zookeeper zookeeper: - server-lists: 127.0.0.1:2181 + server-lists: zookeeper:2181 namespace: pigx-daemon # 普通任务 simples: diff --git a/pigx-config/src/main/resources/config/pigx-upms-dev.yml b/pigx-config/src/main/resources/config/pigx-upms-dev.yml index 7f7c71a9d..146ad8087 100644 --- a/pigx-config/src/main/resources/config/pigx-upms-dev.yml +++ b/pigx-config/src/main/resources/config/pigx-upms-dev.yml @@ -12,8 +12,8 @@ spring: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.jdbc.Driver username: root - password: root - url: jdbc:mysql://127.0.0.1:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false + password: 123456 + url: jdbc:mysql://mysql:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false # swagger相关配置,覆盖全局配置 swagger: From 9ae4bdf590861d9a8c19e585a9075d64ed43f559 Mon Sep 17 00:00:00 2001 From: lisb Date: Thu, 11 Oct 2018 23:45:16 +0800 Subject: [PATCH 16/17] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=20=E7=BC=A9?= =?UTF-8?q?=E5=87=8F=E7=BD=91=E5=85=B3=E5=BC=95=E5=8F=91=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pig4cloud/pigx/gateway/filter/PigxRequestGlobalFilter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/PigxRequestGlobalFilter.java b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/PigxRequestGlobalFilter.java index 13d3df60e..bb608d7f5 100644 --- a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/PigxRequestGlobalFilter.java +++ b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/PigxRequestGlobalFilter.java @@ -74,7 +74,7 @@ public class PigxRequestGlobalFilter implements GlobalFilter, Ordered { exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, newRequest.getURI()); // 3. 支持swagger添加X-Forwarded-Prefix header - String path = newRequest.getURI().getPath(); + String path = request.getURI().getPath(); if (!StringUtils.endsWithIgnoreCase(path, SwaggerProvider.API_URI)) { return chain.filter(exchange.mutate().request(newRequest).build()); } From 89c14ede227e9ce5034dea65596fde190651e579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Fri, 12 Oct 2018 13:04:08 +0800 Subject: [PATCH 17/17] =?UTF-8?q?:recycle:=20Refactoring=20code.=20=20OAut?= =?UTF-8?q?h=E6=8B=A6=E6=88=AA=E5=99=A8=E8=BF=98=E5=8E=9Ftoken=20=E9=87=8D?= =?UTF-8?q?=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/constant/SecurityConstants.java | 5 ++++ ...urceServerTokenRelayAutoConfiguration.java | 28 ++----------------- .../feign/PigxFeignClientConfiguration.java | 8 ++++-- .../feign/PigxFeignClientInterceptor.java | 20 ++++++++++--- 4 files changed, 28 insertions(+), 33 deletions(-) diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/SecurityConstants.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/SecurityConstants.java index a923ac523..8a9158b21 100644 --- a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/SecurityConstants.java +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/SecurityConstants.java @@ -47,6 +47,11 @@ public interface SecurityConstants { */ String FROM_IN = "Y"; + /** + * 标志 + */ + String FROM = "from"; + /** * {bcrypt} 加密的特征码 */ diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerTokenRelayAutoConfiguration.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerTokenRelayAutoConfiguration.java index 54c406dea..78577d921 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerTokenRelayAutoConfiguration.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerTokenRelayAutoConfiguration.java @@ -2,15 +2,13 @@ package com.pig4cloud.pigx.common.security.component; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.AllNestedConditions; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.boot.autoconfigure.condition.*; import org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration; import org.springframework.cloud.security.oauth2.client.AccessTokenContextRelay; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.Order; import org.springframework.security.oauth2.client.OAuth2ClientContext; import org.springframework.security.oauth2.config.annotation.web.configuration.OAuth2ClientConfiguration; import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfiguration; @@ -38,28 +36,6 @@ public class PigxResourceServerTokenRelayAutoConfiguration { return new AccessTokenContextRelay(context); } - @Configuration - public static class ResourceServerTokenRelayRegistrationAutoConfiguration implements WebMvcConfigurer { - @Autowired - AccessTokenContextRelay accessTokenContextRelay; - - @Override - public void addInterceptors(InterceptorRegistry registry) { - registry.addInterceptor( - new HandlerInterceptorAdapter() { - @Override - public boolean preHandle(HttpServletRequest request, - HttpServletResponse response, Object handler) throws Exception { - accessTokenContextRelay.copyToken(); - return true; - } - } - - ); - } - - } - @Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @Documented diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/feign/PigxFeignClientConfiguration.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/feign/PigxFeignClientConfiguration.java index 84ffd021a..211b0bea9 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/feign/PigxFeignClientConfiguration.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/feign/PigxFeignClientConfiguration.java @@ -21,7 +21,9 @@ package com.pig4cloud.pigx.common.security.feign; import feign.RequestInterceptor; import lombok.AllArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.cloud.security.oauth2.client.AccessTokenContextRelay; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.oauth2.client.OAuth2ClientContext; @@ -37,10 +39,10 @@ import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResour @AllArgsConstructor @ConditionalOnProperty("security.oauth2.client.client-id") public class PigxFeignClientConfiguration { - @Bean public RequestInterceptor oauth2FeignRequestInterceptor(OAuth2ClientContext oAuth2ClientContext, - OAuth2ProtectedResourceDetails resource) { - return new PigxFeignClientInterceptor(oAuth2ClientContext, resource); + OAuth2ProtectedResourceDetails resource, + AccessTokenContextRelay accessTokenContextRelay) { + return new PigxFeignClientInterceptor(oAuth2ClientContext, resource,accessTokenContextRelay); } } diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/feign/PigxFeignClientInterceptor.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/feign/PigxFeignClientInterceptor.java index 1c011f0ab..1aad67fc6 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/feign/PigxFeignClientInterceptor.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/feign/PigxFeignClientInterceptor.java @@ -17,12 +17,17 @@ package com.pig4cloud.pigx.common.security.feign; +import cn.hutool.core.collection.CollUtil; +import com.pig4cloud.pigx.common.core.constant.SecurityConstants; import feign.RequestTemplate; import lombok.extern.slf4j.Slf4j; +import org.springframework.cloud.security.oauth2.client.AccessTokenContextRelay; import org.springframework.cloud.security.oauth2.client.feign.OAuth2FeignRequestInterceptor; import org.springframework.security.oauth2.client.OAuth2ClientContext; import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails; +import java.util.Collection; + /** * @author lengleng * @date 2018/8/13 @@ -31,32 +36,39 @@ import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResour @Slf4j public class PigxFeignClientInterceptor extends OAuth2FeignRequestInterceptor { private final OAuth2ClientContext oAuth2ClientContext; + private final AccessTokenContextRelay accessTokenContextRelay; /** * Default constructor which uses the provided OAuth2ClientContext and Bearer tokens * within Authorization header * - * @param oAuth2ClientContext provided context - * @param resource type of resource to be accessed + * @param oAuth2ClientContext provided context + * @param resource type of resource to be accessed + * @param accessTokenContextRelay */ public PigxFeignClientInterceptor(OAuth2ClientContext oAuth2ClientContext - , OAuth2ProtectedResourceDetails resource) { + , OAuth2ProtectedResourceDetails resource, AccessTokenContextRelay accessTokenContextRelay) { super(oAuth2ClientContext, resource); this.oAuth2ClientContext = oAuth2ClientContext; + this.accessTokenContextRelay = accessTokenContextRelay; } /** * Create a template with the header of provided name and extracted extract + * 1. 如果使用 非web 请求,header 区别 + * 2. 根据authentication 还原请求token * * @param template */ @Override public void apply(RequestTemplate template) { - if (template.headers().isEmpty()) { + Collection fromHeader = template.headers().get(SecurityConstants.FROM); + if (CollUtil.isNotEmpty(fromHeader) && fromHeader.contains(SecurityConstants.FROM_IN)) { return; } + accessTokenContextRelay.copyToken(); if (oAuth2ClientContext != null && oAuth2ClientContext.getAccessToken() != null) { super.apply(template);