From 7c95ec51faed951ab41afad1760d77b36419125e Mon Sep 17 00:00:00 2001 From: click33 <2393584716@qq.com> Date: Fri, 27 Feb 2026 00:25:12 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=20springboot=20?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E9=9B=86=E6=88=90=E5=8C=85=EF=BC=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E4=BE=9D=E8=B5=96=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 9 +- sa-token-bom/pom.xml | 7 +- .../sa-token-demo-springboot3-redis/pom.xml | 2 +- .../sa-token-demo-springboot4-redis/pom.xml | 7 +- sa-token-dependencies/pom.xml | 69 +---- sa-token-plugin/pom.xml | 22 +- sa-token-plugin/sa-token-thymeleaf/pom.xml | 1 + sa-token-spring-boot2-dependencies/pom.xml | 95 ++++++ sa-token-spring-boot3-dependencies/pom.xml | 49 ++++ sa-token-spring-boot4-dependencies/pom.xml | 49 ++++ sa-token-starter/pom.xml | 3 +- .../pom.xml | 23 +- .../pom.xml | 17 +- .../sa-token-spring-boot-autoconfig/pom.xml | 16 +- .../sa-token-spring-boot-starter/pom.xml | 23 +- .../pom.xml | 86 ++++++ .../java/cn/dev33/satoken/package-info.java | 4 +- .../cn/dev33/satoken/spring/SaBeanInject.java | 273 ++++++++++++++++++ .../dev33/satoken/spring/SaBeanRegister.java | 51 ++++ .../spring/apikey/SaApiKeyBeanInject.java | 64 ++++ .../spring/apikey/SaApiKeyBeanRegister.java | 43 +++ .../satoken/spring/apikey/package-info.java | 19 ++ .../path/ApplicationContextPathLoading.java | 68 +++++ .../spring/oauth2/SaOAuth2BeanInject.java | 153 ++++++++++ .../spring/oauth2/SaOAuth2BeanRegister.java | 44 +++ .../satoken/spring/oauth2/package-info.java | 19 ++ .../spring/pathmatch/SaPathMatcherHolder.java | 56 ++++ .../pathmatch/SaPathPatternParserUtil.java | 53 ++++ .../SaPatternsRequestConditionHolder.java | 71 +++++ .../satoken/spring/sign/SaSignBeanInject.java | 64 ++++ .../spring/sign/SaSignBeanRegister.java | 54 ++++ .../satoken/spring/sign/package-info.java | 19 ++ .../satoken/spring/sso/SaSsoBeanInject.java | 77 +++++ .../satoken/spring/sso/SaSsoBeanRegister.java | 81 ++++++ .../satoken/spring/sso/package-info.java | 19 ++ .../main/resources/META-INF/spring.factories | 11 + ...ot.autoconfigure.AutoConfiguration.imports | 10 + .../pom.xml | 63 ++++ ...aFirewallCheckFilterForJakartaServlet.java | 0 .../dev33/satoken/filter/SaServletFilter.java | 0 ...SaTokenContextFilterForJakartaServlet.java | 0 .../SaTokenCorsFilterForJakartaServlet.java | 0 .../satoken/interceptor/SaInterceptor.java | 0 .../java/cn/dev33/satoken/package-info.java | 0 ...TokenContextForSpringInJakartaServlet.java | 0 .../spring/SaTokenContextRegister.java | 0 .../dev33/satoken/spring/SpringMVCUtil.java | 0 ...ot.autoconfigure.AutoConfiguration.imports | 0 .../sa-token-spring-boot3-starter/pom.xml | 62 ++-- ...ot.autoconfigure.AutoConfiguration.imports | 1 - .../sa-token-spring-boot4-starter/pom.xml | 73 +---- ...aFirewallCheckFilterForJakartaServlet.java | 73 ----- .../dev33/satoken/filter/SaServletFilter.java | 146 ---------- ...SaTokenContextFilterForJakartaServlet.java | 46 --- .../SaTokenCorsFilterForJakartaServlet.java | 55 ---- .../satoken/interceptor/SaInterceptor.java | 122 -------- ...TokenContextForSpringInJakartaServlet.java | 68 ----- .../spring/SaTokenContextRegister.java | 70 ----- .../dev33/satoken/spring/SpringMVCUtil.java | 67 ----- sa-token-test/pom.xml | 1 + 60 files changed, 1720 insertions(+), 858 deletions(-) create mode 100644 sa-token-spring-boot2-dependencies/pom.xml create mode 100644 sa-token-spring-boot3-dependencies/pom.xml create mode 100644 sa-token-spring-boot4-dependencies/pom.xml create mode 100644 sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/pom.xml rename sa-token-starter/{sa-token-spring-boot4-starter => sa-token-spring-boot-webmvc-reactor-v2v3v4-common}/src/main/java/cn/dev33/satoken/package-info.java (89%) create mode 100644 sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/SaBeanInject.java create mode 100644 sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/SaBeanRegister.java create mode 100644 sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/apikey/SaApiKeyBeanInject.java create mode 100644 sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/apikey/SaApiKeyBeanRegister.java create mode 100644 sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/apikey/package-info.java create mode 100644 sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/context/path/ApplicationContextPathLoading.java create mode 100644 sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/oauth2/SaOAuth2BeanInject.java create mode 100644 sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/oauth2/SaOAuth2BeanRegister.java create mode 100644 sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/oauth2/package-info.java create mode 100644 sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/pathmatch/SaPathMatcherHolder.java create mode 100644 sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/pathmatch/SaPathPatternParserUtil.java create mode 100644 sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/pathmatch/SaPatternsRequestConditionHolder.java create mode 100644 sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/sign/SaSignBeanInject.java create mode 100644 sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/sign/SaSignBeanRegister.java create mode 100644 sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/sign/package-info.java create mode 100644 sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/sso/SaSsoBeanInject.java create mode 100644 sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/sso/SaSsoBeanRegister.java create mode 100644 sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/sso/package-info.java create mode 100644 sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/resources/META-INF/spring.factories create mode 100644 sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports create mode 100644 sa-token-starter/sa-token-spring-boot-webmvc-v3v4-common/pom.xml rename sa-token-starter/{sa-token-spring-boot3-starter => sa-token-spring-boot-webmvc-v3v4-common}/src/main/java/cn/dev33/satoken/filter/SaFirewallCheckFilterForJakartaServlet.java (100%) rename sa-token-starter/{sa-token-spring-boot3-starter => sa-token-spring-boot-webmvc-v3v4-common}/src/main/java/cn/dev33/satoken/filter/SaServletFilter.java (100%) rename sa-token-starter/{sa-token-spring-boot3-starter => sa-token-spring-boot-webmvc-v3v4-common}/src/main/java/cn/dev33/satoken/filter/SaTokenContextFilterForJakartaServlet.java (100%) rename sa-token-starter/{sa-token-spring-boot3-starter => sa-token-spring-boot-webmvc-v3v4-common}/src/main/java/cn/dev33/satoken/filter/SaTokenCorsFilterForJakartaServlet.java (100%) rename sa-token-starter/{sa-token-spring-boot3-starter => sa-token-spring-boot-webmvc-v3v4-common}/src/main/java/cn/dev33/satoken/interceptor/SaInterceptor.java (100%) rename sa-token-starter/{sa-token-spring-boot3-starter => sa-token-spring-boot-webmvc-v3v4-common}/src/main/java/cn/dev33/satoken/package-info.java (100%) rename sa-token-starter/{sa-token-spring-boot3-starter => sa-token-spring-boot-webmvc-v3v4-common}/src/main/java/cn/dev33/satoken/spring/SaTokenContextForSpringInJakartaServlet.java (100%) rename sa-token-starter/{sa-token-spring-boot3-starter => sa-token-spring-boot-webmvc-v3v4-common}/src/main/java/cn/dev33/satoken/spring/SaTokenContextRegister.java (100%) rename sa-token-starter/{sa-token-spring-boot3-starter => sa-token-spring-boot-webmvc-v3v4-common}/src/main/java/cn/dev33/satoken/spring/SpringMVCUtil.java (100%) rename sa-token-starter/{sa-token-spring-boot4-starter => sa-token-spring-boot-webmvc-v3v4-common}/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports (100%) delete mode 100644 sa-token-starter/sa-token-spring-boot3-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports delete mode 100644 sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/filter/SaFirewallCheckFilterForJakartaServlet.java delete mode 100644 sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/filter/SaServletFilter.java delete mode 100644 sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/filter/SaTokenContextFilterForJakartaServlet.java delete mode 100644 sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/filter/SaTokenCorsFilterForJakartaServlet.java delete mode 100644 sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/interceptor/SaInterceptor.java delete mode 100644 sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/spring/SaTokenContextForSpringInJakartaServlet.java delete mode 100644 sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/spring/SaTokenContextRegister.java delete mode 100644 sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/spring/SpringMVCUtil.java diff --git a/pom.xml b/pom.xml index 596adba2..9754d14b 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,9 @@ sa-token-dependencies + sa-token-spring-boot2-dependencies + sa-token-spring-boot3-dependencies + sa-token-spring-boot4-dependencies sa-token-bom sa-token-core sa-token-starter @@ -75,7 +78,11 @@ - + + cn.dev33 sa-token-dependencies diff --git a/sa-token-bom/pom.xml b/sa-token-bom/pom.xml index 0a2b0df0..eba21d85 100644 --- a/sa-token-bom/pom.xml +++ b/sa-token-bom/pom.xml @@ -68,7 +68,12 @@ cn.dev33 - sa-token-spring-boot-autoconfig + sa-token-spring-boot-webmvc-reactor-v2v3v4-common + ${revision} + + + cn.dev33 + sa-token-spring-boot-webmvc-v3v4-common ${revision} diff --git a/sa-token-demo/sa-token-demo-springboot3-redis/pom.xml b/sa-token-demo/sa-token-demo-springboot3-redis/pom.xml index e4ddc6e1..14b4307c 100644 --- a/sa-token-demo/sa-token-demo-springboot3-redis/pom.xml +++ b/sa-token-demo/sa-token-demo-springboot3-redis/pom.xml @@ -48,7 +48,7 @@ cn.dev33 - sa-token-redis-jackson + sa-token-redis-template ${sa-token.version} diff --git a/sa-token-demo/sa-token-demo-springboot4-redis/pom.xml b/sa-token-demo/sa-token-demo-springboot4-redis/pom.xml index 8066e8fc..d345e7d8 100644 --- a/sa-token-demo/sa-token-demo-springboot4-redis/pom.xml +++ b/sa-token-demo/sa-token-demo-springboot4-redis/pom.xml @@ -30,7 +30,7 @@ org.springframework.boot spring-boot-starter-aspectj - + cn.dev33 @@ -38,10 +38,10 @@ ${sa-token.version} - + cn.dev33 - sa-token-redis-jackson + sa-token-redis-template ${sa-token.version} @@ -58,6 +58,7 @@ true + diff --git a/sa-token-dependencies/pom.xml b/sa-token-dependencies/pom.xml index b7f07f5f..9d0ace90 100644 --- a/sa-token-dependencies/pom.xml +++ b/sa-token-dependencies/pom.xml @@ -15,10 +15,10 @@ 1.44.0 - 2.7.18 + 3.4.3 4.0.3 - 5.3.39 + 3.7.4 2.13.4.1 2.11.2 @@ -65,34 +65,13 @@ ${jakarta-servlet-api.version} - - - org.springframework.boot - spring-boot-starter-web - ${springboot.version} - - org.springframework.boot spring-boot-starter-webmvc ${springboot4.version} - - - - org.springframework.boot - spring-boot-starter - ${springboot.version} - - - - - + io.projectreactor @@ -100,14 +79,14 @@ ${reactor-core.version} - + com.fasterxml.jackson.core jackson-databind ${jackson-databind.version} - + tools.jackson.core jackson-databind @@ -163,25 +142,7 @@ ${loveqq.version} - - - - org.springframework.boot - spring-boot-configuration-processor - ${springboot.version} - - - - - org.springframework.boot - spring-boot-starter-data-redis - ${springboot.version} - @@ -252,26 +213,6 @@ ${freemarker.version} - - - org.springframework.boot - spring-boot-starter-thymeleaf - ${springboot.version} - - - - - org.springframework.boot - spring-boot-starter-aop - ${springboot.version} - - - - - org.springframework.boot - spring-boot-starter-actuator - ${springboot.version} - diff --git a/sa-token-plugin/pom.xml b/sa-token-plugin/pom.xml index f96056de..77fa4694 100644 --- a/sa-token-plugin/pom.xml +++ b/sa-token-plugin/pom.xml @@ -56,10 +56,28 @@ - + + + + + + + + + cn.dev33 + sa-token-spring-boot2-dependencies + ${revision} + pom + import + + + + + \ No newline at end of file diff --git a/sa-token-plugin/sa-token-thymeleaf/pom.xml b/sa-token-plugin/sa-token-thymeleaf/pom.xml index 89e1c935..5f595c14 100644 --- a/sa-token-plugin/sa-token-thymeleaf/pom.xml +++ b/sa-token-plugin/sa-token-thymeleaf/pom.xml @@ -32,6 +32,7 @@ org.springframework.boot spring-boot-configuration-processor + 2.5.14 true diff --git a/sa-token-spring-boot2-dependencies/pom.xml b/sa-token-spring-boot2-dependencies/pom.xml new file mode 100644 index 00000000..1e961399 --- /dev/null +++ b/sa-token-spring-boot2-dependencies/pom.xml @@ -0,0 +1,95 @@ + + + 4.0.0 + + + + cn.dev33 + sa-token-parent + ${revision} + ../pom.xml + + pom + + sa-token-spring-boot2-dependencies + sa-token-spring-boot2-dependencies + Sa-Token SpringBoot2 Dependencies + + + 2.7.18 + 5.3.39 + + + + + + + + org.springframework.boot + spring-boot-starter + ${springboot.version} + + + + + org.springframework.boot + spring-boot-starter-web + ${springboot.version} + + + + + org.springframework.boot + spring-boot-configuration-processor + ${springboot.version} + + + + org.springframework + spring-web + ${spring-web.low.version} + + + + org.springframework + spring-webmvc + ${spring-web.low.version} + + + + + + + + org.springframework.boot + spring-boot-starter-data-redis + ${springboot.version} + + + + + org.springframework.boot + spring-boot-starter-thymeleaf + ${springboot.version} + + + + + org.springframework.boot + spring-boot-starter-aop + ${springboot.version} + + + + + org.springframework.boot + spring-boot-starter-actuator + ${springboot.version} + + + + + + \ No newline at end of file diff --git a/sa-token-spring-boot3-dependencies/pom.xml b/sa-token-spring-boot3-dependencies/pom.xml new file mode 100644 index 00000000..0a2acfcf --- /dev/null +++ b/sa-token-spring-boot3-dependencies/pom.xml @@ -0,0 +1,49 @@ + + + 4.0.0 + + + + cn.dev33 + sa-token-parent + ${revision} + ../pom.xml + + pom + + sa-token-spring-boot3-dependencies + sa-token-spring-boot3-dependencies + Sa-Token SpringBoot3 Dependencies + + + 3.0.1 + + + + + + + + org.springframework.boot + spring-boot-starter + ${springboot3.version} + + + + org.springframework.boot + spring-boot-starter-web + ${springboot3.version} + + + + org.springframework.boot + spring-boot-configuration-processor + ${springboot3.version} + + + + + + \ No newline at end of file diff --git a/sa-token-spring-boot4-dependencies/pom.xml b/sa-token-spring-boot4-dependencies/pom.xml new file mode 100644 index 00000000..973dabb7 --- /dev/null +++ b/sa-token-spring-boot4-dependencies/pom.xml @@ -0,0 +1,49 @@ + + + 4.0.0 + + + + cn.dev33 + sa-token-parent + ${revision} + ../pom.xml + + pom + + sa-token-spring-boot4-dependencies + sa-token-spring-boot4-dependencies + Sa-Token SpringBoot4 Dependencies + + + 4.0.3 + + + + + + + + org.springframework.boot + spring-boot-starter + ${springboot4.version} + + + + org.springframework.boot + spring-boot-starter-webmvc + ${springboot4.version} + + + + org.springframework.boot + spring-boot-configuration-processor + ${springboot4.version} + + + + + + \ No newline at end of file diff --git a/sa-token-starter/pom.xml b/sa-token-starter/pom.xml index ca4312d5..c2b93cb8 100644 --- a/sa-token-starter/pom.xml +++ b/sa-token-starter/pom.xml @@ -20,8 +20,9 @@ sa-token-servlet sa-token-jakarta-servlet - sa-token-spring-boot-autoconfig + sa-token-spring-boot-webmvc-reactor-v2v3v4-common sa-token-spring-boot-starter + sa-token-spring-boot-webmvc-v3v4-common sa-token-spring-boot3-starter sa-token-spring-boot4-starter sa-token-reactor-spring-boot-starter diff --git a/sa-token-starter/sa-token-reactor-spring-boot-starter/pom.xml b/sa-token-starter/sa-token-reactor-spring-boot-starter/pom.xml index d61cd5c9..b3eff5f1 100644 --- a/sa-token-starter/sa-token-reactor-spring-boot-starter/pom.xml +++ b/sa-token-starter/sa-token-reactor-spring-boot-starter/pom.xml @@ -51,23 +51,32 @@ true - + cn.dev33 - sa-token-spring-boot-autoconfig + sa-token-spring-boot-webmvc-reactor-v2v3v4-common + + + cn.dev33 + sa-token-jackson + + - - org.springframework - spring-web - 5.3.39 - + + + cn.dev33 + sa-token-spring-boot2-dependencies + ${revision} + pom + import + diff --git a/sa-token-starter/sa-token-reactor-spring-boot3-starter/pom.xml b/sa-token-starter/sa-token-reactor-spring-boot3-starter/pom.xml index 0c13412b..f517c9fc 100644 --- a/sa-token-starter/sa-token-reactor-spring-boot3-starter/pom.xml +++ b/sa-token-starter/sa-token-reactor-spring-boot3-starter/pom.xml @@ -55,12 +55,18 @@ true - + cn.dev33 - sa-token-spring-boot-autoconfig + sa-token-spring-boot-webmvc-reactor-v2v3v4-common + + + cn.dev33 + sa-token-jackson + + @@ -79,13 +85,6 @@ 6.2.5 - - - org.springframework.boot diff --git a/sa-token-starter/sa-token-spring-boot-autoconfig/pom.xml b/sa-token-starter/sa-token-spring-boot-autoconfig/pom.xml index 23e02945..aa0ece07 100644 --- a/sa-token-starter/sa-token-spring-boot-autoconfig/pom.xml +++ b/sa-token-starter/sa-token-spring-boot-autoconfig/pom.xml @@ -30,11 +30,11 @@ 5.3.7 true - - com.fasterxml.jackson.core - jackson-databind - true - + + + + + @@ -43,12 +43,6 @@ true - - - cn.dev33 - sa-token-jackson - - cn.dev33 diff --git a/sa-token-starter/sa-token-spring-boot-starter/pom.xml b/sa-token-starter/sa-token-spring-boot-starter/pom.xml index 14939051..ece994b9 100644 --- a/sa-token-starter/sa-token-spring-boot-starter/pom.xml +++ b/sa-token-starter/sa-token-spring-boot-starter/pom.xml @@ -36,14 +36,33 @@ sa-token-servlet - + cn.dev33 - sa-token-spring-boot-autoconfig + sa-token-spring-boot-webmvc-reactor-v2v3v4-common + + + + + cn.dev33 + sa-token-jackson + + + + + cn.dev33 + sa-token-spring-boot2-dependencies + ${revision} + pom + import + + + + diff --git a/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/pom.xml b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/pom.xml new file mode 100644 index 00000000..cc1b7a14 --- /dev/null +++ b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/pom.xml @@ -0,0 +1,86 @@ + + + 4.0.0 + + + cn.dev33 + sa-token-starter + ${revision} + ../pom.xml + + jar + + sa-token-spring-boot-webmvc-reactor-v2v3v4-common + sa-token-spring-boot-webmvc-reactor-v2v3v4-common + sa-token springboot webmvc/reactor v2/v3/v4 common + + + + + + org.springframework.boot + spring-boot-starter + true + + + org.springframework + spring-webmvc + true + + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + + cn.dev33 + sa-token-sso + true + + + + + cn.dev33 + sa-token-oauth2 + true + + + + + cn.dev33 + sa-token-apikey + true + + + + + cn.dev33 + sa-token-sign + true + + + + + + + + + + + cn.dev33 + sa-token-spring-boot2-dependencies + ${revision} + pom + import + + + + + + diff --git a/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/package-info.java b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/package-info.java similarity index 89% rename from sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/package-info.java rename to sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/package-info.java index 41194975..3b171337 100644 --- a/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/package-info.java +++ b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/package-info.java @@ -14,6 +14,6 @@ * limitations under the License. */ /** - * Sa-Token 集成 SpringBoot4 的各个组件 + * Sa-Token 集成 SpringBoot 的各个组件 */ -package cn.dev33.satoken; +package cn.dev33.satoken; \ No newline at end of file diff --git a/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/SaBeanInject.java b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/SaBeanInject.java new file mode 100644 index 00000000..326f8676 --- /dev/null +++ b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/SaBeanInject.java @@ -0,0 +1,273 @@ +/* + * Copyright 2020-2099 sa-token.cc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 cn.dev33.satoken.spring; + +import cn.dev33.satoken.SaManager; +import cn.dev33.satoken.annotation.handler.SaAnnotationHandlerInterface; +import cn.dev33.satoken.config.SaTokenConfig; +import cn.dev33.satoken.context.SaTokenContext; +import cn.dev33.satoken.dao.SaTokenDao; +import cn.dev33.satoken.fun.strategy.SaCorsHandleFunction; +import cn.dev33.satoken.http.SaHttpTemplate; +import cn.dev33.satoken.httpauth.basic.SaHttpBasicTemplate; +import cn.dev33.satoken.httpauth.basic.SaHttpBasicUtil; +import cn.dev33.satoken.httpauth.digest.SaHttpDigestTemplate; +import cn.dev33.satoken.httpauth.digest.SaHttpDigestUtil; +import cn.dev33.satoken.json.SaJsonTemplate; +import cn.dev33.satoken.listener.SaTokenEventCenter; +import cn.dev33.satoken.listener.SaTokenListener; +import cn.dev33.satoken.log.SaLog; +import cn.dev33.satoken.plugin.SaTokenPlugin; +import cn.dev33.satoken.plugin.SaTokenPluginHolder; +import cn.dev33.satoken.same.SaSameTemplate; +import cn.dev33.satoken.secure.totp.SaTotpTemplate; +import cn.dev33.satoken.serializer.SaSerializerTemplate; +import cn.dev33.satoken.spring.pathmatch.SaPathMatcherHolder; +import cn.dev33.satoken.stp.StpInterface; +import cn.dev33.satoken.stp.StpLogic; +import cn.dev33.satoken.stp.StpUtil; +import cn.dev33.satoken.strategy.SaAnnotationStrategy; +import cn.dev33.satoken.strategy.SaFirewallStrategy; +import cn.dev33.satoken.strategy.SaStrategy; +import cn.dev33.satoken.strategy.hooks.SaFirewallCheckHook; +import cn.dev33.satoken.temp.SaTempTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.util.PathMatcher; + +import java.util.List; + +/** + * 注入 Sa-Token 所需要的 Bean + * + * @author click33 + * @since 1.34.0 + */ +public class SaBeanInject { + + /** + * 组件注入 + *

为确保 Log 组件正常打印,必须将 SaLog 和 SaTokenConfig 率先初始化

+ * + * @param log log 对象 + * @param saTokenConfig 配置对象 + */ + public SaBeanInject( + @Autowired(required = false) SaLog log, + @Autowired(required = false) SaTokenConfig saTokenConfig, + @Autowired(required = false) SaTokenPluginHolder pluginHolder + ){ + if(log != null) { + SaManager.setLog(log); + } + if(saTokenConfig != null) { + SaManager.setConfig(saTokenConfig); + } + // 初始化 Sa-Token SPI 插件 + if (pluginHolder == null) { + pluginHolder = SaTokenPluginHolder.instance; + } + pluginHolder.init(); + SaTokenPluginHolder.instance = pluginHolder; + } + + /** + * 注入持久化Bean + * + * @param saTokenDao SaTokenDao对象 + */ + @Autowired(required = false) + public void setSaTokenDao(SaTokenDao saTokenDao) { + SaManager.setSaTokenDao(saTokenDao); + } + + /** + * 注入权限认证Bean + * + * @param stpInterface StpInterface对象 + */ + @Autowired(required = false) + public void setStpInterface(StpInterface stpInterface) { + SaManager.setStpInterface(stpInterface); + } + + /** + * 注入上下文Bean + * + * @param saTokenContext SaTokenContext对象 + */ + @Autowired(required = false) + public void setSaTokenContext(SaTokenContext saTokenContext) { + SaManager.setSaTokenContext(saTokenContext); + } + + /** + * 注入侦听器Bean + * + * @param listenerList 侦听器集合 + */ + @Autowired(required = false) + public void setSaTokenListener(List listenerList) { + SaTokenEventCenter.registerListenerList(listenerList); + } + + /** + * 注入自定义注解处理器 + * + * @param handlerList 自定义注解处理器集合 + */ + @Autowired(required = false) + public void setSaAnnotationHandler(List> handlerList) { + for (SaAnnotationHandlerInterface handler : handlerList) { + SaAnnotationStrategy.instance.registerAnnotationHandler(handler); + } + } + + /** + * 注入临时令牌验证模块 Bean + * + * @param saTempTemplate / + */ + @Autowired(required = false) + public void setSaTempTemplate(SaTempTemplate saTempTemplate) { + SaManager.setSaTempTemplate(saTempTemplate); + } + + /** + * 注入 Same-Token 模块 Bean + * + * @param saSameTemplate saSameTemplate对象 + */ + @Autowired(required = false) + public void setSaIdTemplate(SaSameTemplate saSameTemplate) { + SaManager.setSaSameTemplate(saSameTemplate); + } + + /** + * 注入 Sa-Token Http Basic 认证模块 + * + * @param saBasicTemplate saBasicTemplate对象 + */ + @Autowired(required = false) + public void setSaHttpBasicTemplate(SaHttpBasicTemplate saBasicTemplate) { + SaHttpBasicUtil.saHttpBasicTemplate = saBasicTemplate; + } + + /** + * 注入 Sa-Token Http Digest 认证模块 + * + * @param saHttpDigestTemplate saHttpDigestTemplate 对象 + */ + @Autowired(required = false) + public void setSaHttpDigestTemplate(SaHttpDigestTemplate saHttpDigestTemplate) { + SaHttpDigestUtil.saHttpDigestTemplate = saHttpDigestTemplate; + } + + /** + * 注入自定义的 JSON 转换器 Bean + * + * @param saJsonTemplate JSON 转换器 + */ + @Autowired(required = false) + public void setSaJsonTemplate(SaJsonTemplate saJsonTemplate) { + SaManager.setSaJsonTemplate(saJsonTemplate); + } + + /** + * 注入自定义的 Http 转换器 Bean + * + * @param saHttpTemplate / + */ + @Autowired(required = false) + public void setSaHttpTemplate(SaHttpTemplate saHttpTemplate) { + SaManager.setSaHttpTemplate(saHttpTemplate); + } + + /** + * 注入自定义的序列化器 Bean + * + * @param saSerializerTemplate 序列化器 + */ + @Autowired(required = false) + public void setSaSerializerTemplate(SaSerializerTemplate saSerializerTemplate) { + SaManager.setSaSerializerTemplate(saSerializerTemplate); + } + + /** + * 注入自定义的 TOTP 算法 Bean + * + * @param totpTemplate TOTP 算法类 + */ + @Autowired(required = false) + public void setSaTotpTemplate(SaTotpTemplate totpTemplate) { + SaManager.setSaTotpTemplate(totpTemplate); + } + + /** + * 注入自定义的 StpLogic + * @param stpLogic / + */ + @Autowired(required = false) + public void setStpLogic(StpLogic stpLogic) { + StpUtil.setStpLogic(stpLogic); + } + + /** + * 利用自动注入特性,获取Spring框架内部使用的路由匹配器 + * + * @param pathMatcher 要设置的 pathMatcher + */ + @Autowired(required = false) + @Qualifier("mvcPathMatcher") + public void setPathMatcher(PathMatcher pathMatcher) { + SaPathMatcherHolder.setPathMatcher(pathMatcher); + } + + /** + * 注入自定义防火墙校验 hook 集合 + * + * @param hooks / + */ + @Autowired(required = false) + public void setSaFirewallCheckHooks(List hooks) { + for (SaFirewallCheckHook hook : hooks) { + SaFirewallStrategy.instance.registerHook(hook); + } + } + + /** + * 注入CORS 策略处理函数 + * + * @param corsHandle / + */ + @Autowired(required = false) + public void setCorsHandle(SaCorsHandleFunction corsHandle) { + SaStrategy.instance.corsHandle = corsHandle; + } + + /** + * 注入自定义插件集合 + * + * @param plugins / + */ + @Autowired(required = false) + public void setSaTokenPluginList(List plugins) { + for (SaTokenPlugin plugin : plugins) { + SaTokenPluginHolder.instance.installPlugin(plugin); + } + } + +} diff --git a/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/SaBeanRegister.java b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/SaBeanRegister.java new file mode 100644 index 00000000..ab8e1e91 --- /dev/null +++ b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/SaBeanRegister.java @@ -0,0 +1,51 @@ +/* + * Copyright 2020-2099 sa-token.cc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 cn.dev33.satoken.spring; + +import cn.dev33.satoken.config.SaTokenConfig; +import cn.dev33.satoken.spring.context.path.ApplicationContextPathLoading; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; + +/** + * 注册Sa-Token所需要的Bean + *

Bean 的注册与注入应该分开在两个文件中,否则在某些场景下会造成循环依赖 + * @author click33 + * + */ +public class SaBeanRegister { + + /** + * 获取配置Bean + * + * @return 配置对象 + */ + @Bean + @ConfigurationProperties(prefix = "sa-token") + public SaTokenConfig getSaTokenConfig() { + return new SaTokenConfig(); + } + + /** + * 应用上下文路径加载器 + * @return / + */ + @Bean + public ApplicationContextPathLoading getApplicationContextPathLoading() { + return new ApplicationContextPathLoading(); + } + +} diff --git a/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/apikey/SaApiKeyBeanInject.java b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/apikey/SaApiKeyBeanInject.java new file mode 100644 index 00000000..fda6a507 --- /dev/null +++ b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/apikey/SaApiKeyBeanInject.java @@ -0,0 +1,64 @@ +/* + * Copyright 2020-2099 sa-token.cc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 cn.dev33.satoken.spring.apikey; + +import cn.dev33.satoken.apikey.SaApiKeyManager; +import cn.dev33.satoken.apikey.config.SaApiKeyConfig; +import cn.dev33.satoken.apikey.loader.SaApiKeyDataLoader; +import cn.dev33.satoken.apikey.template.SaApiKeyTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; + +/** + * 注入 Sa-Token API Key 所需要的 Bean + * + * @author click33 + * @since 1.43.0 + */ +@ConditionalOnClass(SaApiKeyManager.class) +public class SaApiKeyBeanInject { + + /** + * 注入 API Key 配置对象 + * + * @param saApiKeyConfig 配置对象 + */ + @Autowired(required = false) + public void setSaApiKeyConfig(SaApiKeyConfig saApiKeyConfig) { + SaApiKeyManager.setConfig(saApiKeyConfig); + } + + /** + * 注入自定义的 API Key 模版方法 Bean + * + * @param apiKeyTemplate / + */ + @Autowired(required = false) + public void setSaApiKeyTemplate(SaApiKeyTemplate apiKeyTemplate) { + SaApiKeyManager.setSaApiKeyTemplate(apiKeyTemplate); + } + + /** + * 注入自定义的 API Key 数据加载器 Bean + * + * @param apiKeyDataLoader / + */ + @Autowired(required = false) + public void setSaApiKeyDataLoader(SaApiKeyDataLoader apiKeyDataLoader) { + SaApiKeyManager.setSaApiKeyDataLoader(apiKeyDataLoader); + } + +} diff --git a/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/apikey/SaApiKeyBeanRegister.java b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/apikey/SaApiKeyBeanRegister.java new file mode 100644 index 00000000..d6414514 --- /dev/null +++ b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/apikey/SaApiKeyBeanRegister.java @@ -0,0 +1,43 @@ +/* + * Copyright 2020-2099 sa-token.cc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 cn.dev33.satoken.spring.apikey; + +import cn.dev33.satoken.apikey.SaApiKeyManager; +import cn.dev33.satoken.apikey.config.SaApiKeyConfig; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; + +/** + * 注册 Sa-Token API Key 所需要的 Bean + * + * @author click33 + * @since 1.43.0 + */ +@ConditionalOnClass(SaApiKeyManager.class) +public class SaApiKeyBeanRegister { + + /** + * 获取 API Key 配置对象 + * @return 配置对象 + */ + @Bean + @ConfigurationProperties(prefix = "sa-token.api-key") + public SaApiKeyConfig getSaApiKeyConfig() { + return new SaApiKeyConfig(); + } + +} diff --git a/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/apikey/package-info.java b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/apikey/package-info.java new file mode 100644 index 00000000..f5874af8 --- /dev/null +++ b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/apikey/package-info.java @@ -0,0 +1,19 @@ +/* + * Copyright 2020-2099 sa-token.cc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ +/** + * sa-token-apikey 模块自动化配置(只有引入了 sa-token-apikey 模块后,此包下的代码才会开始工作) + */ +package cn.dev33.satoken.spring.apikey; \ No newline at end of file diff --git a/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/context/path/ApplicationContextPathLoading.java b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/context/path/ApplicationContextPathLoading.java new file mode 100644 index 00000000..9ce85586 --- /dev/null +++ b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/context/path/ApplicationContextPathLoading.java @@ -0,0 +1,68 @@ +/* + * Copyright 2020-2099 sa-token.cc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 cn.dev33.satoken.spring.context.path; + +import cn.dev33.satoken.application.ApplicationInfo; +import cn.dev33.satoken.util.SaFoxUtil; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; + +/** + * 应用上下文路径加载器 + * + * @author click33 + * @since 1.37.0 + */ +public class ApplicationContextPathLoading implements ApplicationRunner { + + @Value("${server.servlet.context-path:}") + String contextPath; + + @Value("${spring.mvc.servlet.path:}") + String servletPath; + + @Override + public void run(ApplicationArguments args) throws Exception { + + String routePrefix = ""; + + if(SaFoxUtil.isNotEmpty(contextPath)) { + if(! contextPath.startsWith("/")){ + contextPath = "/" + contextPath; + } + if (contextPath.endsWith("/")) { + contextPath = contextPath.substring(0, contextPath.length() - 1); + } + routePrefix += contextPath; + } + + if(SaFoxUtil.isNotEmpty(servletPath)) { + if(! servletPath.startsWith("/")){ + servletPath = "/" + servletPath; + } + if (servletPath.endsWith("/")) { + servletPath = servletPath.substring(0, servletPath.length() - 1); + } + routePrefix += servletPath; + } + + if(SaFoxUtil.isNotEmpty(routePrefix) && ! routePrefix.equals("/") ){ + ApplicationInfo.routePrefix = routePrefix; + } + } + +} \ No newline at end of file diff --git a/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/oauth2/SaOAuth2BeanInject.java b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/oauth2/SaOAuth2BeanInject.java new file mode 100644 index 00000000..03748859 --- /dev/null +++ b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/oauth2/SaOAuth2BeanInject.java @@ -0,0 +1,153 @@ +/* + * Copyright 2020-2099 sa-token.cc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 cn.dev33.satoken.spring.oauth2; + +import cn.dev33.satoken.oauth2.SaOAuth2Manager; +import cn.dev33.satoken.oauth2.config.SaOAuth2ServerConfig; +import cn.dev33.satoken.oauth2.dao.SaOAuth2Dao; +import cn.dev33.satoken.oauth2.data.convert.SaOAuth2DataConverter; +import cn.dev33.satoken.oauth2.data.generate.SaOAuth2DataGenerate; +import cn.dev33.satoken.oauth2.data.loader.SaOAuth2DataLoader; +import cn.dev33.satoken.oauth2.data.resolver.SaOAuth2DataResolver; +import cn.dev33.satoken.oauth2.granttype.handler.SaOAuth2GrantTypeHandlerInterface; +import cn.dev33.satoken.oauth2.processor.SaOAuth2ServerProcessor; +import cn.dev33.satoken.oauth2.scope.handler.SaOAuth2ScopeHandlerInterface; +import cn.dev33.satoken.oauth2.strategy.SaOAuth2Strategy; +import cn.dev33.satoken.oauth2.template.SaOAuth2Template; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; + +import java.util.List; + + +// 小提示:如果你在 idea 中运行源码时出现异常:java: 程序包cn.dev33.satoken.oauth2不存在。 +// 在项目根目录进入 cmd,执行 mvn package 即可解决 + + +/** + * 注入 Sa-Token-OAuth2 所需要的组件 + * + * @author click33 + * @since 1.34.0 + */ +@ConditionalOnClass(SaOAuth2Manager.class) +public class SaOAuth2BeanInject { + + /** + * 注入 OAuth2 配置对象 + * + * @param saOAuth2Config 配置对象 + */ + @Autowired(required = false) + public void setSaOAuth2Config(SaOAuth2ServerConfig saOAuth2Config) { + SaOAuth2Manager.setServerConfig(saOAuth2Config); + } + + /** + * 注入 OAuth2 模板代码类 + * + * @param saOAuth2Template 模板代码类 + */ + @Autowired(required = false) + public void setSaOAuth2Template(SaOAuth2Template saOAuth2Template) { + SaOAuth2Manager.setTemplate(saOAuth2Template); + } + + /** + * 注入 OAuth2 请求处理器 + * + * @param serverProcessor 请求处理器 + */ + @Autowired(required = false) + public void setSaOAuth2Template(SaOAuth2ServerProcessor serverProcessor) { + SaOAuth2ServerProcessor.instance = serverProcessor; + } + + /** + * 注入 OAuth2 数据加载器 + * + * @param dataLoader / + */ + @Autowired(required = false) + public void setSaOAuth2DataLoader(SaOAuth2DataLoader dataLoader) { + SaOAuth2Manager.setDataLoader(dataLoader); + } + + /** + * 注入 OAuth2 数据解析器 Bean + * + * @param dataResolver / + */ + @Autowired(required = false) + public void setSaOAuth2DataResolver(SaOAuth2DataResolver dataResolver) { + SaOAuth2Manager.setDataResolver(dataResolver); + } + + /** + * 注入 OAuth2 数据格式转换器 Bean + * + * @param dataConverter / + */ + @Autowired(required = false) + public void setSaOAuth2DataConverter(SaOAuth2DataConverter dataConverter) { + SaOAuth2Manager.setDataConverter(dataConverter); + } + + /** + * 注入 OAuth2 数据构建器 Bean + * + * @param dataGenerate / + */ + @Autowired(required = false) + public void setSaOAuth2DataGenerate(SaOAuth2DataGenerate dataGenerate) { + SaOAuth2Manager.setDataGenerate(dataGenerate); + } + + /** + * 注入 OAuth2 数据持久 Bean + * + * @param dao / + */ + @Autowired(required = false) + public void setSaOAuth2Dao(SaOAuth2Dao dao) { + SaOAuth2Manager.setDao(dao); + } + + /** + * 注入自定义 scope 处理器 + * + * @param handlerList 自定义 scope 处理器集合 + */ + @Autowired(required = false) + public void setSaOAuth2ScopeHandler(List handlerList) { + for (SaOAuth2ScopeHandlerInterface handler : handlerList) { + SaOAuth2Strategy.instance.registerScopeHandler(handler); + } + } + + /** + * 注入自定义 grant_type 处理器 + * + * @param handlerList 自定义 grant_type 处理器集合 + */ + @Autowired(required = false) + public void setSaOAuth2GrantTypeHandlerInterface(List handlerList) { + for (SaOAuth2GrantTypeHandlerInterface handler : handlerList) { + SaOAuth2Strategy.instance.registerGrantTypeHandler(handler); + } + } + +} diff --git a/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/oauth2/SaOAuth2BeanRegister.java b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/oauth2/SaOAuth2BeanRegister.java new file mode 100644 index 00000000..788f97af --- /dev/null +++ b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/oauth2/SaOAuth2BeanRegister.java @@ -0,0 +1,44 @@ +/* + * Copyright 2020-2099 sa-token.cc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 cn.dev33.satoken.spring.oauth2; + +import cn.dev33.satoken.oauth2.SaOAuth2Manager; +import cn.dev33.satoken.oauth2.config.SaOAuth2ServerConfig; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; + +/** + * 注册 Sa-Token-OAuth2 所需要的Bean + * + * @author click33 + * @since 1.34.0 + */ +@ConditionalOnClass(SaOAuth2Manager.class) +public class SaOAuth2BeanRegister { + + /** + * 获取 OAuth2 配置 Bean + * + * @return 配置对象 + */ + @Bean + @ConfigurationProperties(prefix = "sa-token.oauth2-server") + public SaOAuth2ServerConfig getSaOAuth2Config() { + return new SaOAuth2ServerConfig(); + } + +} diff --git a/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/oauth2/package-info.java b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/oauth2/package-info.java new file mode 100644 index 00000000..d4f2d942 --- /dev/null +++ b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/oauth2/package-info.java @@ -0,0 +1,19 @@ +/* + * Copyright 2020-2099 sa-token.cc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ +/** + * Sa-Token-OAuth2 模块自动化配置(只有引入了Sa-Token-OAuth2模块后,此包下的代码才会开始工作) + */ +package cn.dev33.satoken.spring.oauth2; \ No newline at end of file diff --git a/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/pathmatch/SaPathMatcherHolder.java b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/pathmatch/SaPathMatcherHolder.java new file mode 100644 index 00000000..f5a92491 --- /dev/null +++ b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/pathmatch/SaPathMatcherHolder.java @@ -0,0 +1,56 @@ +/* + * Copyright 2020-2099 sa-token.cc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 cn.dev33.satoken.spring.pathmatch; + +import org.springframework.util.AntPathMatcher; +import org.springframework.util.PathMatcher; + +/** + * 路由匹配工具类:持有 PathMatcher 全局引用,方便快捷的调用 PathMatcher 相关方法 + * + * @author click33 + * @since 1.34.0 + */ +public class SaPathMatcherHolder { + + private SaPathMatcherHolder() { + } + + /** + * 路由匹配器 + */ + public static PathMatcher pathMatcher; + + /** + * 获取路由匹配器 + * @return 路由匹配器 + */ + public static PathMatcher getPathMatcher() { + if(pathMatcher == null) { + pathMatcher = new AntPathMatcher(); + } + return pathMatcher; + } + + /** + * 写入路由匹配器 + * @param pathMatcher 路由匹配器 + */ + public static void setPathMatcher(PathMatcher pathMatcher) { + SaPathMatcherHolder.pathMatcher = pathMatcher; + } + +} diff --git a/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/pathmatch/SaPathPatternParserUtil.java b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/pathmatch/SaPathPatternParserUtil.java new file mode 100644 index 00000000..176f9025 --- /dev/null +++ b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/pathmatch/SaPathPatternParserUtil.java @@ -0,0 +1,53 @@ +/* + * Copyright 2020-2099 sa-token.cc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 cn.dev33.satoken.spring.pathmatch; + +import org.springframework.http.server.PathContainer; +import org.springframework.web.util.pattern.PathPattern; +import org.springframework.web.util.pattern.PathPatternParser; + +/** + * 路由匹配工具类:使用 PathPatternParser 模式匹配 + * + * @author click33 + * @since 1.35.1 + */ +public class SaPathPatternParserUtil { + + private SaPathPatternParserUtil() { + } + + /** + * 判断:指定路由匹配符是否可以匹配成功指定路径 + * @param pattern 路由匹配符 + * @param path 要匹配的路径 + * @return 是否匹配成功 + */ + public static boolean match(String pattern, String path) { + PathPattern pathPattern = PathPatternParser.defaultInstance.parse(pattern); + PathContainer pathContainer = PathContainer.parsePath(path); + return pathPattern.matches(pathContainer); + } + + /* + 表现: + springboot 2.x SpringMVC match("/test/test", "/test/test/") // true + springboot 2.x WebFlux match("/test/test", "/test/test/") // true + springboot 3.x SpringMVC match("/test/test", "/test/test/") // false + springboot 3.x WebFlux match("/test/test", "/test/test/") // false + */ + +} diff --git a/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/pathmatch/SaPatternsRequestConditionHolder.java b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/pathmatch/SaPatternsRequestConditionHolder.java new file mode 100644 index 00000000..bb9e503e --- /dev/null +++ b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/pathmatch/SaPatternsRequestConditionHolder.java @@ -0,0 +1,71 @@ +/* + * Copyright 2020-2099 sa-token.cc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 cn.dev33.satoken.spring.pathmatch; + +import cn.dev33.satoken.exception.SaTokenException; +import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +/** + * 路由匹配工具类 + * + * @author click33 + * @since 1.35.1 + */ +public class SaPatternsRequestConditionHolder { + + private SaPatternsRequestConditionHolder() { + } + + public static PatternsRequestCondition patternsRequestCondition; + + public static Method matcherMethod; + + static { + try { + patternsRequestCondition = new PatternsRequestCondition(); + matcherMethod = PatternsRequestCondition.class.getDeclaredMethod("getMatchingPattern", String.class, String.class); + matcherMethod.setAccessible(true); + } catch (NoSuchMethodException e) { + throw new SaTokenException("路由匹配器初始化失败", e); + } + } + + /** + * 判断:指定路由匹配符是否可以匹配成功指定路径 + * @param pattern 路由匹配符 + * @param lookupPath 要匹配的路径 + * @return 是否匹配成功 + */ + public static boolean match(String pattern, String lookupPath) { + try { + return matcherMethod.invoke(patternsRequestCondition, pattern, lookupPath) != null; + } catch (IllegalAccessException | InvocationTargetException e) { + throw new SaTokenException("路由匹配器调用失败", e); + } + } + + /* + 性能测试: + 100万次 + new 对象方式,耗时:3.685s 最慢 + 反射调方法方式,耗时:1.311s 中等 + 原始方式,耗时:0.445s 最快,但有bug + */ + +} diff --git a/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/sign/SaSignBeanInject.java b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/sign/SaSignBeanInject.java new file mode 100644 index 00000000..8944e2a1 --- /dev/null +++ b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/sign/SaSignBeanInject.java @@ -0,0 +1,64 @@ +/* + * Copyright 2020-2099 sa-token.cc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 cn.dev33.satoken.spring.sign; + +import cn.dev33.satoken.sign.SaSignManager; +import cn.dev33.satoken.sign.config.SaSignConfig; +import cn.dev33.satoken.sign.config.SaSignManyConfigWrapper; +import cn.dev33.satoken.sign.template.SaSignTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; + +/** + * 注入 Sa-Token API 参数签名 所需要的 Bean + * + * @author click33 + * @since 1.43.0 + */ +@ConditionalOnClass(SaSignManager.class) +public class SaSignBeanInject { + + /** + * 注入 API 参数签名配置对象 + * + * @param saSignConfig 配置对象 + */ + @Autowired(required = false) + public void setSignConfig(SaSignConfig saSignConfig) { + SaSignManager.setConfig(saSignConfig); + } + + /** + * 注入 API 参数签名配置对象 + * + * @param signManyConfigWrapper 配置对象 + */ + @Autowired(required = false) + public void setSignManyConfig(SaSignManyConfigWrapper signManyConfigWrapper) { + SaSignManager.setSignMany(signManyConfigWrapper.getSignMany()); + } + + /** + * 注入自定义的 参数签名 模版方法 Bean + * + * @param saSignTemplate 参数签名 Bean + */ + @Autowired(required = false) + public void setSaSignTemplate(SaSignTemplate saSignTemplate) { + SaSignManager.setSaSignTemplate(saSignTemplate); + } + +} diff --git a/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/sign/SaSignBeanRegister.java b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/sign/SaSignBeanRegister.java new file mode 100644 index 00000000..a6e740d2 --- /dev/null +++ b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/sign/SaSignBeanRegister.java @@ -0,0 +1,54 @@ +/* + * Copyright 2020-2099 sa-token.cc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 cn.dev33.satoken.spring.sign; + +import cn.dev33.satoken.sign.SaSignManager; +import cn.dev33.satoken.sign.config.SaSignConfig; +import cn.dev33.satoken.sign.config.SaSignManyConfigWrapper; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; + +/** + * 注册 Sa-Token API 参数签名所需要的 Bean + * + * @author click33 + * @since 1.43.0 + */ +@ConditionalOnClass(SaSignManager.class) +public class SaSignBeanRegister { + + /** + * 获取 API 参数签名配置对象 + * @return 配置对象 + */ + @Bean + @ConfigurationProperties(prefix = "sa-token.sign") + public SaSignConfig getSaSignConfig() { + return new SaSignConfig(); + } + + /** + * 获取 API 参数签名 Many 配置对象 + * @return 配置对象 + */ + @Bean + @ConfigurationProperties(prefix = "sa-token") + public SaSignManyConfigWrapper getSaSignManyConfigWrapper() { + return new SaSignManyConfigWrapper(); + } + +} diff --git a/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/sign/package-info.java b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/sign/package-info.java new file mode 100644 index 00000000..be4e2f90 --- /dev/null +++ b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/sign/package-info.java @@ -0,0 +1,19 @@ +/* + * Copyright 2020-2099 sa-token.cc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ +/** + * sa-token-sign 模块自动化配置(只有引入了 sa-token-sign 模块后,此包下的代码才会开始工作) + */ +package cn.dev33.satoken.spring.sign; \ No newline at end of file diff --git a/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/sso/SaSsoBeanInject.java b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/sso/SaSsoBeanInject.java new file mode 100644 index 00000000..9e8f07b9 --- /dev/null +++ b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/sso/SaSsoBeanInject.java @@ -0,0 +1,77 @@ +/* + * Copyright 2020-2099 sa-token.cc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 cn.dev33.satoken.spring.sso; + +import cn.dev33.satoken.sso.SaSsoManager; +import cn.dev33.satoken.sso.config.SaSsoClientConfig; +import cn.dev33.satoken.sso.config.SaSsoServerConfig; +import cn.dev33.satoken.sso.processor.SaSsoClientProcessor; +import cn.dev33.satoken.sso.processor.SaSsoServerProcessor; +import cn.dev33.satoken.sso.template.SaSsoClientTemplate; +import cn.dev33.satoken.sso.template.SaSsoServerTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; + +/** + * 注入 Sa-Token SSO 所需要的 Bean + * + * @author click33 + * @since 1.34.0 + */ +@ConditionalOnClass(SaSsoManager.class) +public class SaSsoBeanInject { + + /** + * 注入 Sa-Token SSO Server 端 配置类 + * + * @param serverConfig 配置对象 + */ + @Autowired(required = false) + public void setSaSsoServerConfig(SaSsoServerConfig serverConfig) { + SaSsoManager.setServerConfig(serverConfig); + } + + /** + * 注入 Sa-Token SSO Client 端 配置类 + * + * @param clientConfig 配置对象 + */ + @Autowired(required = false) + public void setSaSsoClientConfig(SaSsoClientConfig clientConfig) { + SaSsoManager.setClientConfig(clientConfig); + } + + /** + * 注入 SSO 模板代码类 (Server 端) + * + * @param ssoServerTemplate / + */ + @Autowired(required = false) + public void setSaSsoServerTemplate(SaSsoServerTemplate ssoServerTemplate) { + SaSsoServerProcessor.instance.ssoServerTemplate = ssoServerTemplate; + } + + /** + * 注入 SSO 模板代码类 (Client 端) + * + * @param ssoClientTemplate / + */ + @Autowired(required = false) + public void setSaSsoClientTemplate(SaSsoClientTemplate ssoClientTemplate) { + SaSsoClientProcessor.instance.ssoClientTemplate = ssoClientTemplate; + } + +} diff --git a/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/sso/SaSsoBeanRegister.java b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/sso/SaSsoBeanRegister.java new file mode 100644 index 00000000..2c102df8 --- /dev/null +++ b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/sso/SaSsoBeanRegister.java @@ -0,0 +1,81 @@ +/* + * Copyright 2020-2099 sa-token.cc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 cn.dev33.satoken.spring.sso; + +import cn.dev33.satoken.sso.SaSsoManager; +import cn.dev33.satoken.sso.config.SaSsoClientConfig; +import cn.dev33.satoken.sso.config.SaSsoServerConfig; +import cn.dev33.satoken.sso.processor.SaSsoClientProcessor; +import cn.dev33.satoken.sso.processor.SaSsoServerProcessor; +import cn.dev33.satoken.sso.template.SaSsoClientTemplate; +import cn.dev33.satoken.sso.template.SaSsoServerTemplate; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; + +/** + * 注册 Sa-Token SSO 所需要的 Bean + * + * @author click33 + * @since 1.34.0 + */ +@ConditionalOnClass(SaSsoManager.class) +public class SaSsoBeanRegister { + + /** + * 获取 SSO Server 端 配置对象 + * @return 配置对象 + */ + @Bean + @ConfigurationProperties(prefix = "sa-token.sso-server") + public SaSsoServerConfig getSaSsoServerConfig() { + return new SaSsoServerConfig(); + } + + /** + * 获取 SSO Client 端 配置对象 + * @return 配置对象 + */ + @Bean + @ConfigurationProperties(prefix = "sa-token.sso-client") + public SaSsoClientConfig getSaSsoClientConfig() { + return new SaSsoClientConfig(); + } + + /** + * 获取 SSO Server 端 SaSsoServerTemplate + * + * @return / + */ + @Bean + @ConditionalOnMissingBean(SaSsoServerTemplate.class) + public SaSsoServerTemplate getSaSsoServerTemplate() { + return SaSsoServerProcessor.instance.ssoServerTemplate; + } + + /** + * 获取 SSO Client 端 SaSsoClientTemplate + * + * @return / + */ + @Bean + @ConditionalOnMissingBean(SaSsoClientTemplate.class) + public SaSsoClientTemplate getSaSsoClientTemplate() { + return SaSsoClientProcessor.instance.ssoClientTemplate; + } + +} diff --git a/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/sso/package-info.java b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/sso/package-info.java new file mode 100644 index 00000000..bc022e56 --- /dev/null +++ b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/java/cn/dev33/satoken/spring/sso/package-info.java @@ -0,0 +1,19 @@ +/* + * Copyright 2020-2099 sa-token.cc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ +/** + * Sa-Token-SSO 模块自动化配置(只有引入了 sa-token-sso 模块后,此包下的代码才会开始工作) + */ +package cn.dev33.satoken.spring.sso; \ No newline at end of file diff --git a/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/resources/META-INF/spring.factories b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/resources/META-INF/spring.factories new file mode 100644 index 00000000..d592afc2 --- /dev/null +++ b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/resources/META-INF/spring.factories @@ -0,0 +1,11 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +cn.dev33.satoken.spring.SaBeanRegister,\ +cn.dev33.satoken.spring.SaBeanInject,\ +cn.dev33.satoken.spring.sso.SaSsoBeanRegister,\ +cn.dev33.satoken.spring.sso.SaSsoBeanInject,\ +cn.dev33.satoken.spring.oauth2.SaOAuth2BeanRegister,\ +cn.dev33.satoken.spring.oauth2.SaOAuth2BeanInject,\ +cn.dev33.satoken.spring.apikey.SaApiKeyBeanRegister,\ +cn.dev33.satoken.spring.apikey.SaApiKeyBeanInject,\ +cn.dev33.satoken.spring.sign.SaSignBeanRegister,\ +cn.dev33.satoken.spring.sign.SaSignBeanInject \ No newline at end of file diff --git a/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 00000000..b227d742 --- /dev/null +++ b/sa-token-starter/sa-token-spring-boot-webmvc-reactor-v2v3v4-common/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1,10 @@ +cn.dev33.satoken.spring.SaBeanRegister +cn.dev33.satoken.spring.SaBeanInject +cn.dev33.satoken.spring.sso.SaSsoBeanRegister +cn.dev33.satoken.spring.sso.SaSsoBeanInject +cn.dev33.satoken.spring.oauth2.SaOAuth2BeanRegister +cn.dev33.satoken.spring.oauth2.SaOAuth2BeanInject +cn.dev33.satoken.spring.apikey.SaApiKeyBeanRegister +cn.dev33.satoken.spring.apikey.SaApiKeyBeanInject +cn.dev33.satoken.spring.sign.SaSignBeanRegister +cn.dev33.satoken.spring.sign.SaSignBeanInject \ No newline at end of file diff --git a/sa-token-starter/sa-token-spring-boot-webmvc-v3v4-common/pom.xml b/sa-token-starter/sa-token-spring-boot-webmvc-v3v4-common/pom.xml new file mode 100644 index 00000000..e5dcc637 --- /dev/null +++ b/sa-token-starter/sa-token-spring-boot-webmvc-v3v4-common/pom.xml @@ -0,0 +1,63 @@ + + + 4.0.0 + + + cn.dev33 + sa-token-starter + ${revision} + ../pom.xml + + jar + + sa-token-spring-boot-webmvc-v3v4-common + sa-token-spring-boot-webmvc-v3v4-common + sa-token springboot webmvc v3v4 common + + + + + org.springframework.boot + spring-boot-starter-web + true + + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + + cn.dev33 + sa-token-jakarta-servlet + + + + + cn.dev33 + sa-token-spring-boot-webmvc-reactor-v2v3v4-common + + + + + + + + + + cn.dev33 + sa-token-spring-boot3-dependencies + ${revision} + pom + import + + + + + + diff --git a/sa-token-starter/sa-token-spring-boot3-starter/src/main/java/cn/dev33/satoken/filter/SaFirewallCheckFilterForJakartaServlet.java b/sa-token-starter/sa-token-spring-boot-webmvc-v3v4-common/src/main/java/cn/dev33/satoken/filter/SaFirewallCheckFilterForJakartaServlet.java similarity index 100% rename from sa-token-starter/sa-token-spring-boot3-starter/src/main/java/cn/dev33/satoken/filter/SaFirewallCheckFilterForJakartaServlet.java rename to sa-token-starter/sa-token-spring-boot-webmvc-v3v4-common/src/main/java/cn/dev33/satoken/filter/SaFirewallCheckFilterForJakartaServlet.java diff --git a/sa-token-starter/sa-token-spring-boot3-starter/src/main/java/cn/dev33/satoken/filter/SaServletFilter.java b/sa-token-starter/sa-token-spring-boot-webmvc-v3v4-common/src/main/java/cn/dev33/satoken/filter/SaServletFilter.java similarity index 100% rename from sa-token-starter/sa-token-spring-boot3-starter/src/main/java/cn/dev33/satoken/filter/SaServletFilter.java rename to sa-token-starter/sa-token-spring-boot-webmvc-v3v4-common/src/main/java/cn/dev33/satoken/filter/SaServletFilter.java diff --git a/sa-token-starter/sa-token-spring-boot3-starter/src/main/java/cn/dev33/satoken/filter/SaTokenContextFilterForJakartaServlet.java b/sa-token-starter/sa-token-spring-boot-webmvc-v3v4-common/src/main/java/cn/dev33/satoken/filter/SaTokenContextFilterForJakartaServlet.java similarity index 100% rename from sa-token-starter/sa-token-spring-boot3-starter/src/main/java/cn/dev33/satoken/filter/SaTokenContextFilterForJakartaServlet.java rename to sa-token-starter/sa-token-spring-boot-webmvc-v3v4-common/src/main/java/cn/dev33/satoken/filter/SaTokenContextFilterForJakartaServlet.java diff --git a/sa-token-starter/sa-token-spring-boot3-starter/src/main/java/cn/dev33/satoken/filter/SaTokenCorsFilterForJakartaServlet.java b/sa-token-starter/sa-token-spring-boot-webmvc-v3v4-common/src/main/java/cn/dev33/satoken/filter/SaTokenCorsFilterForJakartaServlet.java similarity index 100% rename from sa-token-starter/sa-token-spring-boot3-starter/src/main/java/cn/dev33/satoken/filter/SaTokenCorsFilterForJakartaServlet.java rename to sa-token-starter/sa-token-spring-boot-webmvc-v3v4-common/src/main/java/cn/dev33/satoken/filter/SaTokenCorsFilterForJakartaServlet.java diff --git a/sa-token-starter/sa-token-spring-boot3-starter/src/main/java/cn/dev33/satoken/interceptor/SaInterceptor.java b/sa-token-starter/sa-token-spring-boot-webmvc-v3v4-common/src/main/java/cn/dev33/satoken/interceptor/SaInterceptor.java similarity index 100% rename from sa-token-starter/sa-token-spring-boot3-starter/src/main/java/cn/dev33/satoken/interceptor/SaInterceptor.java rename to sa-token-starter/sa-token-spring-boot-webmvc-v3v4-common/src/main/java/cn/dev33/satoken/interceptor/SaInterceptor.java diff --git a/sa-token-starter/sa-token-spring-boot3-starter/src/main/java/cn/dev33/satoken/package-info.java b/sa-token-starter/sa-token-spring-boot-webmvc-v3v4-common/src/main/java/cn/dev33/satoken/package-info.java similarity index 100% rename from sa-token-starter/sa-token-spring-boot3-starter/src/main/java/cn/dev33/satoken/package-info.java rename to sa-token-starter/sa-token-spring-boot-webmvc-v3v4-common/src/main/java/cn/dev33/satoken/package-info.java diff --git a/sa-token-starter/sa-token-spring-boot3-starter/src/main/java/cn/dev33/satoken/spring/SaTokenContextForSpringInJakartaServlet.java b/sa-token-starter/sa-token-spring-boot-webmvc-v3v4-common/src/main/java/cn/dev33/satoken/spring/SaTokenContextForSpringInJakartaServlet.java similarity index 100% rename from sa-token-starter/sa-token-spring-boot3-starter/src/main/java/cn/dev33/satoken/spring/SaTokenContextForSpringInJakartaServlet.java rename to sa-token-starter/sa-token-spring-boot-webmvc-v3v4-common/src/main/java/cn/dev33/satoken/spring/SaTokenContextForSpringInJakartaServlet.java diff --git a/sa-token-starter/sa-token-spring-boot3-starter/src/main/java/cn/dev33/satoken/spring/SaTokenContextRegister.java b/sa-token-starter/sa-token-spring-boot-webmvc-v3v4-common/src/main/java/cn/dev33/satoken/spring/SaTokenContextRegister.java similarity index 100% rename from sa-token-starter/sa-token-spring-boot3-starter/src/main/java/cn/dev33/satoken/spring/SaTokenContextRegister.java rename to sa-token-starter/sa-token-spring-boot-webmvc-v3v4-common/src/main/java/cn/dev33/satoken/spring/SaTokenContextRegister.java diff --git a/sa-token-starter/sa-token-spring-boot3-starter/src/main/java/cn/dev33/satoken/spring/SpringMVCUtil.java b/sa-token-starter/sa-token-spring-boot-webmvc-v3v4-common/src/main/java/cn/dev33/satoken/spring/SpringMVCUtil.java similarity index 100% rename from sa-token-starter/sa-token-spring-boot3-starter/src/main/java/cn/dev33/satoken/spring/SpringMVCUtil.java rename to sa-token-starter/sa-token-spring-boot-webmvc-v3v4-common/src/main/java/cn/dev33/satoken/spring/SpringMVCUtil.java diff --git a/sa-token-starter/sa-token-spring-boot4-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/sa-token-starter/sa-token-spring-boot-webmvc-v3v4-common/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports similarity index 100% rename from sa-token-starter/sa-token-spring-boot4-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports rename to sa-token-starter/sa-token-spring-boot-webmvc-v3v4-common/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports diff --git a/sa-token-starter/sa-token-spring-boot3-starter/pom.xml b/sa-token-starter/sa-token-spring-boot3-starter/pom.xml index 436e9ad1..cdd9f830 100644 --- a/sa-token-starter/sa-token-spring-boot3-starter/pom.xml +++ b/sa-token-starter/sa-token-spring-boot3-starter/pom.xml @@ -15,63 +15,37 @@ sa-token-spring-boot3-starter sa-token-spring-boot3-starter springboot3 integrate sa-token - - - 3.0.1 - - - - org.springframework.boot - spring-boot-starter-web - - - - - org.springframework.boot - spring-boot-configuration-processor - true - - - + + cn.dev33 - sa-token-jakarta-servlet + sa-token-spring-boot-webmvc-v3v4-common - + cn.dev33 - sa-token-spring-boot-autoconfig + sa-token-jackson - + - - - - - - org.springframework.boot - spring-boot-starter - ${springboot3.version} - - + + + + - org.springframework.boot - spring-boot-starter-web - ${springboot3.version} + cn.dev33 + sa-token-spring-boot3-dependencies + ${revision} + pom + import - - - org.springframework.boot - spring-boot-configuration-processor - ${springboot3.version} - - - - + + + diff --git a/sa-token-starter/sa-token-spring-boot3-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/sa-token-starter/sa-token-spring-boot3-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index 6a35303e..00000000 --- a/sa-token-starter/sa-token-spring-boot3-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1 +0,0 @@ -cn.dev33.satoken.spring.SaTokenContextRegister \ No newline at end of file diff --git a/sa-token-starter/sa-token-spring-boot4-starter/pom.xml b/sa-token-starter/sa-token-spring-boot4-starter/pom.xml index f6ce6e6f..906e73b8 100644 --- a/sa-token-starter/sa-token-spring-boot4-starter/pom.xml +++ b/sa-token-starter/sa-token-spring-boot4-starter/pom.xml @@ -15,41 +15,13 @@ sa-token-spring-boot4-starter sa-token-spring-boot4-starter springboot4 integrate sa-token - - - 4.0.3 - - - - org.springframework.boot - spring-boot-starter-webmvc - - - - - org.springframework.boot - spring-boot-configuration-processor - true - - - + + cn.dev33 - sa-token-jakarta-servlet - - - - - cn.dev33 - sa-token-spring-boot-autoconfig - - - cn.dev33 - sa-token-jackson - - + sa-token-spring-boot-webmvc-v3v4-common @@ -57,45 +29,22 @@ cn.dev33 sa-token-jackson3 - + - - - - org.springframework.boot - spring-boot-starter - ${springboot4.version} - - + + - org.springframework.boot - spring-boot-starter-webmvc - ${springboot4.version} - - - - org.springframework.boot - spring-boot-configuration-processor - ${springboot4.version} + cn.dev33 + sa-token-spring-boot4-dependencies + ${revision} + pom + import - - - - org.apache.maven.plugins - maven-compiler-plugin - - 17 - 17 - - - - - diff --git a/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/filter/SaFirewallCheckFilterForJakartaServlet.java b/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/filter/SaFirewallCheckFilterForJakartaServlet.java deleted file mode 100644 index b279eef1..00000000 --- a/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/filter/SaFirewallCheckFilterForJakartaServlet.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2020-2099 sa-token.cc - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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 cn.dev33.satoken.filter; - -import cn.dev33.satoken.exception.BackResultException; -import cn.dev33.satoken.exception.FirewallCheckException; -import cn.dev33.satoken.exception.StopMatchException; -import cn.dev33.satoken.servlet.model.SaRequestForServlet; -import cn.dev33.satoken.servlet.model.SaResponseForServlet; -import cn.dev33.satoken.servlet.util.SaJakartaServletOperateUtil; -import cn.dev33.satoken.strategy.SaFirewallStrategy; -import cn.dev33.satoken.util.SaTokenConsts; -import jakarta.servlet.*; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import org.springframework.core.annotation.Order; - -import java.io.IOException; - -/** - * 防火墙校验过滤器 (基于 Jakarta-Servlet) - * - * @author click33 - * @since 1.37.0 - */ -@Order(SaTokenConsts.FIREWALL_CHECK_FILTER_ORDER) -public class SaFirewallCheckFilterForJakartaServlet implements Filter { - - @Override - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { - - HttpServletRequest req = (HttpServletRequest) request; - HttpServletResponse res = (HttpServletResponse) response; - SaRequestForServlet saRequest = new SaRequestForServlet(req); - SaResponseForServlet saResponse = new SaResponseForServlet(res); - - try { - SaFirewallStrategy.instance.check.execute(saRequest, saResponse, null); - } - catch (StopMatchException ignored) {} - catch (BackResultException e) { - SaJakartaServletOperateUtil.writeResult(response, e.getMessage()); - return; - } - catch (FirewallCheckException e) { - if(SaFirewallStrategy.instance.checkFailHandle == null) { - SaJakartaServletOperateUtil.writeResult(response, e.getMessage()); - } else { - SaFirewallStrategy.instance.checkFailHandle.run(e, saRequest, saResponse, null); - } - return; - } - // 更多异常则不处理,交由 Web 框架处理 - - // 向内执行 - chain.doFilter(request, response); - } - - -} diff --git a/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/filter/SaServletFilter.java b/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/filter/SaServletFilter.java deleted file mode 100644 index 7d3e6ff9..00000000 --- a/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/filter/SaServletFilter.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright 2020-2099 sa-token.cc - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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 cn.dev33.satoken.filter; - -import cn.dev33.satoken.exception.BackResultException; -import cn.dev33.satoken.exception.SaTokenException; -import cn.dev33.satoken.exception.StopMatchException; -import cn.dev33.satoken.router.SaRouter; -import cn.dev33.satoken.servlet.util.SaJakartaServletOperateUtil; -import cn.dev33.satoken.util.SaTokenConsts; -import jakarta.servlet.*; -import org.springframework.core.annotation.Order; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * 全局鉴权过滤器 (基于 Jakarta-Servlet) - *

- * 默认优先级为 -100,尽量保证在其它过滤器之前执行 - *

- * - * @author click33 - * @since 1.34.0 - */ -@Order(SaTokenConsts.ASSEMBLY_ORDER) -public class SaServletFilter implements SaFilter, Filter { - - // ------------------------ 设置此过滤器 拦截 & 放行 的路由 - - /** - * 拦截路由 - */ - public List includeList = new ArrayList<>(); - - /** - * 放行路由 - */ - public List excludeList = new ArrayList<>(); - - @Override - public SaServletFilter addInclude(String... paths) { - includeList.addAll(Arrays.asList(paths)); - return this; - } - - @Override - public SaServletFilter addExclude(String... paths) { - excludeList.addAll(Arrays.asList(paths)); - return this; - } - - @Override - public SaServletFilter setIncludeList(List pathList) { - includeList = pathList; - return this; - } - - @Override - public SaServletFilter setExcludeList(List pathList) { - excludeList = pathList; - return this; - } - - - // ------------------------ 钩子函数 - - /** - * 认证函数:每次请求执行 - */ - public SaFilterAuthStrategy auth = r -> {}; - - /** - * 异常处理函数:每次[认证函数]发生异常时执行此函数 - */ - public SaFilterErrorStrategy error = e -> { - throw new SaTokenException(e); - }; - - /** - * 前置函数:在每次[认证函数]之前执行 - * 注意点:前置认证函数将不受 includeList 与 excludeList 的限制,所有路由的请求都会进入 beforeAuth - */ - public SaFilterAuthStrategy beforeAuth = r -> {}; - - @Override - public SaServletFilter setAuth(SaFilterAuthStrategy auth) { - this.auth = auth; - return this; - } - - @Override - public SaServletFilter setError(SaFilterErrorStrategy error) { - this.error = error; - return this; - } - - @Override - public SaServletFilter setBeforeAuth(SaFilterAuthStrategy beforeAuth) { - this.beforeAuth = beforeAuth; - return this; - } - - - // ------------------------ doFilter - - @Override - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { - - try { - // 执行全局过滤器 - beforeAuth.run(null); - SaRouter.match(includeList).notMatch(excludeList).check(r -> { - auth.run(null); - }); - } - catch (StopMatchException ignored) {} - catch (BackResultException e) { - SaJakartaServletOperateUtil.writeResult(response, e.getMessage()); - return; - } - catch (Throwable e) { - SaJakartaServletOperateUtil.writeResult(response, String.valueOf(error.run(e))); - return; - } - - // 执行 - chain.doFilter(request, response); - } - -} diff --git a/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/filter/SaTokenContextFilterForJakartaServlet.java b/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/filter/SaTokenContextFilterForJakartaServlet.java deleted file mode 100644 index 22dce8ce..00000000 --- a/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/filter/SaTokenContextFilterForJakartaServlet.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2020-2099 sa-token.cc - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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 cn.dev33.satoken.filter; - -import cn.dev33.satoken.servlet.util.SaTokenContextJakartaServletUtil; -import cn.dev33.satoken.util.SaTokenConsts; -import jakarta.servlet.*; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import org.springframework.core.annotation.Order; - -import java.io.IOException; - -/** - * SaTokenContext 上下文初始化过滤器 (基于 Jakarta-Servlet) - * - * @author click33 - * @since 1.42.0 - */ -@Order(SaTokenConsts.SA_TOKEN_CONTEXT_FILTER_ORDER) -public class SaTokenContextFilterForJakartaServlet implements Filter { - - @Override - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { - try { - SaTokenContextJakartaServletUtil.setContext((HttpServletRequest) request, (HttpServletResponse) response); - chain.doFilter(request, response); - } finally { - SaTokenContextJakartaServletUtil.clearContext(); - } - } - -} diff --git a/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/filter/SaTokenCorsFilterForJakartaServlet.java b/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/filter/SaTokenCorsFilterForJakartaServlet.java deleted file mode 100644 index f0c04a99..00000000 --- a/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/filter/SaTokenCorsFilterForJakartaServlet.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2020-2099 sa-token.cc - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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 cn.dev33.satoken.filter; - -import cn.dev33.satoken.context.SaHolder; -import cn.dev33.satoken.context.model.SaTokenContextModelBox; -import cn.dev33.satoken.exception.BackResultException; -import cn.dev33.satoken.exception.StopMatchException; -import cn.dev33.satoken.servlet.util.SaJakartaServletOperateUtil; -import cn.dev33.satoken.strategy.SaStrategy; -import cn.dev33.satoken.util.SaTokenConsts; -import jakarta.servlet.*; -import org.springframework.core.annotation.Order; - -import java.io.IOException; - -/** - * CORS 跨域策略过滤器 (基于 Jakarta-Servlet) - * - * @author click33 - * @since 1.42.0 - */ -@Order(SaTokenConsts.CORS_FILTER_ORDER) -public class SaTokenCorsFilterForJakartaServlet implements Filter { - - @Override - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { - - try { - SaTokenContextModelBox box = SaHolder.getContext().getModelBox(); - SaStrategy.instance.corsHandle.execute(box.getRequest(), box.getResponse(), box.getStorage()); - } - catch (StopMatchException ignored) {} - catch (BackResultException e) { - SaJakartaServletOperateUtil.writeResult(response, e.getMessage()); - return; - } - - chain.doFilter(request, response); - } - -} diff --git a/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/interceptor/SaInterceptor.java b/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/interceptor/SaInterceptor.java deleted file mode 100644 index f42e892a..00000000 --- a/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/interceptor/SaInterceptor.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright 2020-2099 sa-token.cc - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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 cn.dev33.satoken.interceptor; - -import cn.dev33.satoken.exception.BackResultException; -import cn.dev33.satoken.exception.StopMatchException; -import cn.dev33.satoken.fun.SaParamFunction; -import cn.dev33.satoken.strategy.SaAnnotationStrategy; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import org.springframework.web.method.HandlerMethod; -import org.springframework.web.servlet.HandlerInterceptor; - -import java.lang.reflect.Method; - -/** - * Sa-Token 综合拦截器,提供注解鉴权和路由拦截鉴权能力 - * - * @author click33 - * @since 1.34.0 - */ -public class SaInterceptor implements HandlerInterceptor { - - /** - * 是否打开注解鉴权 - */ - public boolean isAnnotation = true; - - /** - * 认证函数:每次请求执行 - *

参数:路由处理函数指针 - */ - public SaParamFunction auth = handler -> {}; - - /** - * 创建一个 Sa-Token 综合拦截器,默认带有注解鉴权能力 - */ - public SaInterceptor() { - } - - /** - * 创建一个 Sa-Token 综合拦截器,默认带有注解鉴权能力 - * @param auth 认证函数,每次请求执行 - */ - public SaInterceptor(SaParamFunction auth) { - this.auth = auth; - } - - /** - * 设置是否打开注解鉴权 - * @param isAnnotation / - * @return 对象自身 - */ - public SaInterceptor isAnnotation(boolean isAnnotation) { - this.isAnnotation = isAnnotation; - return this; - } - - /** - * 写入[认证函数]: 每次请求执行 - * @param auth / - * @return 对象自身 - */ - public SaInterceptor setAuth(SaParamFunction auth) { - this.auth = auth; - return this; - } - - - // ----------------- 验证方法 ----------------- - - /** - * 每次请求之前触发的方法 - */ - @Override - @SuppressWarnings("all") - public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) - throws Exception { - - try { - - // 这里必须确保 handler 是 HandlerMethod 类型时,才能进行注解鉴权 - if(isAnnotation && handler instanceof HandlerMethod) { - Method method = ((HandlerMethod) handler).getMethod(); - SaAnnotationStrategy.instance.checkMethodAnnotation.accept(method); - } - - // Auth 校验 - auth.run(handler); - - } catch (StopMatchException e) { - // StopMatchException 异常代表:停止匹配,进入Controller - - } catch (BackResultException e) { - // BackResultException 异常代表:停止匹配,向前端输出结果 - // 请注意此处默认 Content-Type 为 text/plain,如果需要返回 JSON 信息,需要在 back 前自行设置 Content-Type 为 application/json - // 例如:SaHolder.getResponse().setHeader("Content-Type", "application/json;charset=UTF-8"); - if(response.getContentType() == null) { - response.setContentType("text/plain; charset=utf-8"); - } - response.getWriter().print(e.getMessage()); - return false; - } - - // 通过验证 - return true; - } - -} diff --git a/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/spring/SaTokenContextForSpringInJakartaServlet.java b/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/spring/SaTokenContextForSpringInJakartaServlet.java deleted file mode 100644 index 7ace87bf..00000000 --- a/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/spring/SaTokenContextForSpringInJakartaServlet.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2020-2099 sa-token.cc - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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 cn.dev33.satoken.spring; - -import cn.dev33.satoken.context.SaTokenContextForReadOnly; -import cn.dev33.satoken.context.model.SaRequest; -import cn.dev33.satoken.context.model.SaResponse; -import cn.dev33.satoken.context.model.SaStorage; -import cn.dev33.satoken.servlet.model.SaRequestForServlet; -import cn.dev33.satoken.servlet.model.SaResponseForServlet; -import cn.dev33.satoken.servlet.model.SaStorageForServlet; - -/** - *

此为低版本(<1.42.0) 的上下文处理方案,基于 Spring 内部工具类 RequestContextHolder 读写上下文,仅做留档,如无必要请勿使用

- * - * Sa-Token 上下文处理器 [ SpringBoot4 Jakarta Servlet 版 ],在 SpringBoot4 中使用 Sa-Token 时,必须注入此实现类,否则会出现上下文无效异常 - * - * @author click33 - * @since 1.34.0 - */ -public class SaTokenContextForSpringInJakartaServlet implements SaTokenContextForReadOnly { - - /** - * 获取当前请求的 Request 包装对象 - */ - @Override - public SaRequest getRequest() { - return new SaRequestForServlet(SpringMVCUtil.getRequest()); - } - - /** - * 获取当前请求的 Response 包装对象 - */ - @Override - public SaResponse getResponse() { - return new SaResponseForServlet(SpringMVCUtil.getResponse()); - } - - /** - * 获取当前请求的 Storage 包装对象 - */ - @Override - public SaStorage getStorage() { - return new SaStorageForServlet(SpringMVCUtil.getRequest()); - } - - /** - * 判断:在本次请求中,此上下文是否可用。 - */ - @Override - public boolean isValid() { - return SpringMVCUtil.isWeb(); - } - -} diff --git a/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/spring/SaTokenContextRegister.java b/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/spring/SaTokenContextRegister.java deleted file mode 100644 index 4792da2d..00000000 --- a/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/spring/SaTokenContextRegister.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2020-2099 sa-token.cc - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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 cn.dev33.satoken.spring; - -import cn.dev33.satoken.filter.SaFirewallCheckFilterForJakartaServlet; -import cn.dev33.satoken.filter.SaTokenContextFilterForJakartaServlet; -import cn.dev33.satoken.filter.SaTokenCorsFilterForJakartaServlet; -import cn.dev33.satoken.spring.pathmatch.SaPathPatternParserUtil; -import cn.dev33.satoken.strategy.SaStrategy; -import org.springframework.context.annotation.Bean; - -/** - * 注册 Sa-Token 框架所需要的 Bean - * - * @author click33 - * @since 1.34.0 - */ -public class SaTokenContextRegister { - - public SaTokenContextRegister() { - // 重写路由匹配算法 - SaStrategy.instance.routeMatcher = (pattern, path) -> { - return SaPathPatternParserUtil.match(pattern, path); - }; - } - - /** - * 上下文过滤器 - * - * @return / - */ - @Bean - public SaTokenContextFilterForJakartaServlet saTokenContextFilterForServlet() { - return new SaTokenContextFilterForJakartaServlet(); - } - - /** - * CORS 跨域策略过滤器 - * - * @return / - */ - @Bean - public SaTokenCorsFilterForJakartaServlet saTokenCorsFilterForJakartaServlet() { - return new SaTokenCorsFilterForJakartaServlet(); - } - - /** - * 防火墙过滤器 - * - * @return / - */ - @Bean - public SaFirewallCheckFilterForJakartaServlet saFirewallCheckFilterForJakartaServlet() { - return new SaFirewallCheckFilterForJakartaServlet(); - } - -} diff --git a/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/spring/SpringMVCUtil.java b/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/spring/SpringMVCUtil.java deleted file mode 100644 index 4f52cdca..00000000 --- a/sa-token-starter/sa-token-spring-boot4-starter/src/main/java/cn/dev33/satoken/spring/SpringMVCUtil.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2020-2099 sa-token.cc - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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 cn.dev33.satoken.spring; - -import cn.dev33.satoken.exception.NotWebContextException; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; - -/** - * SpringMVC 相关操作工具类,快速获取当前会话的 HttpServletRequest、HttpServletResponse 对象 - * - * @author click33 - * @since 1.34.0 - */ -public class SpringMVCUtil { - - private SpringMVCUtil() { - } - - /** - * 获取当前会话的 request - * @return request - */ - public static HttpServletRequest getRequest() { - ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - if(servletRequestAttributes == null) { - throw new NotWebContextException("非 web 上下文无法获取 HttpServletRequest"); - } - return servletRequestAttributes.getRequest(); - } - - /** - * 获取当前会话的 response - * @return response - */ - public static HttpServletResponse getResponse() { - ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - if(servletRequestAttributes == null) { - throw new NotWebContextException("非 web 上下文无法获取 HttpServletRequest"); - } - return servletRequestAttributes.getResponse(); - } - - /** - * 判断当前是否处于 Web 上下文中 - * @return request - */ - public static boolean isWeb() { - return RequestContextHolder.getRequestAttributes() != null; - } - -} diff --git a/sa-token-test/pom.xml b/sa-token-test/pom.xml index 0704a08f..87af7e7b 100644 --- a/sa-token-test/pom.xml +++ b/sa-token-test/pom.xml @@ -43,6 +43,7 @@ org.springframework.boot spring-boot-configuration-processor + 2.5.12 true