mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-05-08 14:47:56 +08:00
!221 sa-token-solon-plugin::添加sso和oauth2框架的自动化适配
Merge pull request !221 from 西东/dev
This commit is contained in:
commit
f73336beb9
@ -10,7 +10,7 @@
|
|||||||
<!-- 定义 Sa-Token 版本号 -->
|
<!-- 定义 Sa-Token 版本号 -->
|
||||||
<properties>
|
<properties>
|
||||||
<sa-token.version>1.34.0</sa-token.version>
|
<sa-token.version>1.34.0</sa-token.version>
|
||||||
<solon.version>1.10.13</solon.version>
|
<solon.version>1.12.4</solon.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
@ -40,29 +40,16 @@
|
|||||||
<!-- sa-token整合redis (使用jdk默认序列化方式) -->
|
<!-- sa-token整合redis (使用jdk默认序列化方式) -->
|
||||||
<!-- <dependency>
|
<!-- <dependency>
|
||||||
<groupId>cn.dev33</groupId>
|
<groupId>cn.dev33</groupId>
|
||||||
<artifactId>sa-token-dao-redis</artifactId>
|
<artifactId>sa-token-dao-redisx</artifactId>
|
||||||
<version>${sa-token.version}</version>
|
|
||||||
</dependency> -->
|
|
||||||
|
|
||||||
<!-- sa-token整合redis (使用jackson序列化方式) -->
|
|
||||||
<!-- <dependency>
|
|
||||||
<groupId>cn.dev33</groupId>
|
|
||||||
<artifactId>sa-token-dao-redis-jackson</artifactId>
|
|
||||||
<version>${sa-token.version}</version>
|
<version>${sa-token.version}</version>
|
||||||
</dependency> -->
|
</dependency> -->
|
||||||
|
|
||||||
|
|
||||||
<!-- 提供redis连接池 -->
|
<!-- 提供redis连接池 -->
|
||||||
<!-- <dependency>
|
<!-- <dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-pool2</artifactId>
|
<artifactId>commons-pool2</artifactId>
|
||||||
</dependency> -->
|
</dependency> -->
|
||||||
|
|
||||||
<!-- sa-token整合SpringAOP实现注解鉴权 -->
|
|
||||||
<!-- <dependency>
|
|
||||||
<groupId>cn.dev33</groupId>
|
|
||||||
<artifactId>sa-token-spring-aop</artifactId>
|
|
||||||
<version>${sa-token.version}</version>
|
|
||||||
</dependency> -->
|
|
||||||
|
|
||||||
<!-- hutool工具类,用来生成雪花算法唯一id -->
|
<!-- hutool工具类,用来生成雪花算法唯一id -->
|
||||||
<!-- <dependency>
|
<!-- <dependency>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.pj.satoken;
|
package com.pj.satoken;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.dev33.satoken.solon.integration.SaTokenInterceptor;
|
||||||
import org.noear.solon.Solon;
|
import org.noear.solon.Solon;
|
||||||
import org.noear.solon.annotation.Bean;
|
import org.noear.solon.annotation.Bean;
|
||||||
import org.noear.solon.annotation.Configuration;
|
import org.noear.solon.annotation.Configuration;
|
||||||
@ -8,7 +9,6 @@ import org.noear.solon.annotation.Configuration;
|
|||||||
import com.pj.util.AjaxJson;
|
import com.pj.util.AjaxJson;
|
||||||
|
|
||||||
import cn.dev33.satoken.context.SaHolder;
|
import cn.dev33.satoken.context.SaHolder;
|
||||||
import cn.dev33.satoken.solon.integration.SaTokenPathInterceptor;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,17 +6,10 @@
|
|||||||
<artifactId>sa-token-demo-sso-server-solon</artifactId>
|
<artifactId>sa-token-demo-sso-server-solon</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
|
||||||
<!-- SpringBoot -->
|
|
||||||
<parent>
|
|
||||||
<groupId>org.noear</groupId>
|
|
||||||
<artifactId>solon-parent</artifactId>
|
|
||||||
<version>1.12.0</version>
|
|
||||||
<relativePath/>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<!-- 定义 Sa-Token 版本号 -->
|
<!-- 定义 Sa-Token 版本号 -->
|
||||||
<properties>
|
<properties>
|
||||||
<sa-token.version>1.34.0</sa-token.version>
|
<sa-token.version>1.34.0</sa-token.version>
|
||||||
|
<solon.version>1.12.4</solon.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -25,6 +18,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.noear</groupId>
|
<groupId>org.noear</groupId>
|
||||||
<artifactId>solon-web</artifactId>
|
<artifactId>solon-web</artifactId>
|
||||||
|
<version>${solon.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Sa-Token 权限认证, 在线文档:https://sa-token.cc/ -->
|
<!-- Sa-Token 权限认证, 在线文档:https://sa-token.cc/ -->
|
||||||
@ -52,12 +46,14 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.noear</groupId>
|
<groupId>org.noear</groupId>
|
||||||
<artifactId>solon.view.thymeleaf</artifactId>
|
<artifactId>solon.view.thymeleaf</artifactId>
|
||||||
|
<version>${solon.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Http请求工具(在模式三的单点注销功能下用到,如不需要可以注释掉) -->
|
<!-- Http请求工具(在模式三的单点注销功能下用到,如不需要可以注释掉) -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.noear</groupId>
|
<groupId>org.noear</groupId>
|
||||||
<artifactId>forest-solon-plugin</artifactId>
|
<artifactId>forest-solon-plugin</artifactId>
|
||||||
|
<version>${solon.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,13 +16,6 @@ import org.noear.solon.core.handle.ModelAndView;
|
|||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
public class SsoConfig {
|
public class SsoConfig {
|
||||||
/**
|
|
||||||
* 构建 SaSsoConfig bean
|
|
||||||
* */
|
|
||||||
@Bean
|
|
||||||
public SaSsoConfig getSaSsoConfig(@Inject("${sa-token.sso}") SaSsoConfig ssoConfig) {
|
|
||||||
return ssoConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建建 SaToken redis dao(如果不需要 redis;可以注释掉)
|
* 构建建 SaToken redis dao(如果不需要 redis;可以注释掉)
|
||||||
@ -34,7 +27,7 @@ public class SsoConfig {
|
|||||||
|
|
||||||
// 配置SSO相关参数
|
// 配置SSO相关参数
|
||||||
@Bean
|
@Bean
|
||||||
public void configSso(SaSsoConfig sso) {
|
public void configSso(SaSsoConfig sso) { //SaSsoConfig 已自动构建
|
||||||
|
|
||||||
// 配置:未登录时返回的View
|
// 配置:未登录时返回的View
|
||||||
sso.setNotLoginView(() -> {
|
sso.setNotLoginView(() -> {
|
||||||
|
@ -16,7 +16,7 @@ sa-token:
|
|||||||
# 所有允许的授权回调地址
|
# 所有允许的授权回调地址
|
||||||
allow-url: "*"
|
allow-url: "*"
|
||||||
# 是否打开单点注销功能
|
# 是否打开单点注销功能
|
||||||
is-slo: true
|
isSlo: true
|
||||||
|
|
||||||
# ------- SSO-模式三相关配置 (下面的配置在SSO模式三并且 is-slo=true 时打开)
|
# ------- SSO-模式三相关配置 (下面的配置在SSO模式三并且 is-slo=true 时打开)
|
||||||
# 是否打开模式三
|
# 是否打开模式三
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
<servlet-api.version>3.1.0</servlet-api.version>
|
<servlet-api.version>3.1.0</servlet-api.version>
|
||||||
<jakarta-servlet-api.version>6.0.0</jakarta-servlet-api.version>
|
<jakarta-servlet-api.version>6.0.0</jakarta-servlet-api.version>
|
||||||
<thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
|
<thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
|
||||||
<solon.version>1.12.2</solon.version>
|
<solon.version>1.12.4</solon.version>
|
||||||
<noear-redisx.version>1.4.5</noear-redisx.version>
|
<noear-redisx.version>1.4.5</noear-redisx.version>
|
||||||
<noear-snack3.version>3.2.50</noear-snack3.version>
|
<noear-snack3.version>3.2.50</noear-snack3.version>
|
||||||
<jfinal.version>4.9.17</jfinal.version>
|
<jfinal.version>4.9.17</jfinal.version>
|
||||||
|
@ -17,15 +17,29 @@
|
|||||||
<description>solon integrate sa-token</description>
|
<description>solon integrate sa-token</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>cn.dev33</groupId>
|
|
||||||
<artifactId>sa-token-core</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.noear</groupId>
|
<groupId>org.noear</groupId>
|
||||||
<artifactId>solon</artifactId>
|
<artifactId>solon</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.dev33</groupId>
|
||||||
|
<artifactId>sa-token-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- OAuth2.0 (optional) -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.dev33</groupId>
|
||||||
|
<artifactId>sa-token-oauth2</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- SSO (optional) -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.dev33</groupId>
|
||||||
|
<artifactId>sa-token-sso</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
@ -1,6 +1,9 @@
|
|||||||
package cn.dev33.satoken.solon;
|
package cn.dev33.satoken.solon;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.solon.oauth2.SaOAuth2AutoConfigure;
|
||||||
|
import cn.dev33.satoken.solon.sso.SaSsoAutoConfigure;
|
||||||
import org.noear.solon.Solon;
|
import org.noear.solon.Solon;
|
||||||
|
import org.noear.solon.Utils;
|
||||||
import org.noear.solon.core.AopContext;
|
import org.noear.solon.core.AopContext;
|
||||||
import org.noear.solon.core.Plugin;
|
import org.noear.solon.core.Plugin;
|
||||||
|
|
||||||
@ -39,9 +42,23 @@ public class XPluginImp implements Plugin {
|
|||||||
//注入其它 Bean
|
//注入其它 Bean
|
||||||
context.beanOnloaded(c -> {
|
context.beanOnloaded(c -> {
|
||||||
beanInitDo(c);
|
beanInitDo(c);
|
||||||
|
ssoBeanInitDo(c);
|
||||||
|
oauth2BeanInitDo(c);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ssoBeanInitDo(AopContext context){
|
||||||
|
if (Utils.loadClass("cn.dev33.satoken.sso.SaSsoManager") != null) {
|
||||||
|
context.beanMake(SaSsoAutoConfigure.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void oauth2BeanInitDo(AopContext context){
|
||||||
|
if(Utils.loadClass("cn.dev33.satoken.oauth2.SaOAuth2Manager") != null){
|
||||||
|
context.beanMake(SaOAuth2AutoConfigure.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void beanInitDo(AopContext context) {
|
private void beanInitDo(AopContext context) {
|
||||||
// 注入上下文Bean
|
// 注入上下文Bean
|
||||||
SaManager.setSaTokenContext(new SaContextForSolon());
|
SaManager.setSaTokenContext(new SaContextForSolon());
|
||||||
@ -112,5 +129,4 @@ public class XPluginImp implements Plugin {
|
|||||||
StpUtil.setStpLogic(bean);
|
StpUtil.setStpLogic(bean);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
package cn.dev33.satoken.solon.oauth2;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.oauth2.SaOAuth2Manager;
|
||||||
|
import cn.dev33.satoken.oauth2.config.SaOAuth2Config;
|
||||||
|
import cn.dev33.satoken.oauth2.logic.SaOAuth2Template;
|
||||||
|
import cn.dev33.satoken.oauth2.logic.SaOAuth2Util;
|
||||||
|
import org.noear.solon.annotation.Bean;
|
||||||
|
import org.noear.solon.annotation.Configuration;
|
||||||
|
import org.noear.solon.annotation.Inject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author noear
|
||||||
|
* @since 2.0
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class SaOAuth2AutoConfigure {
|
||||||
|
/**
|
||||||
|
* 获取 OAuth2配置Bean
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public SaOAuth2Config getConfig(@Inject(value = "${sa-token.oauth2}",required = false) SaOAuth2Config oAuth2Config) {
|
||||||
|
return oAuth2Config;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注入OAuth2配置Bean
|
||||||
|
*
|
||||||
|
* @param saOAuth2Config 配置对象
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public void setSaOAuth2Config(@Inject(required = false) SaOAuth2Config saOAuth2Config) {
|
||||||
|
SaOAuth2Manager.setConfig(saOAuth2Config);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注入代码模板Bean
|
||||||
|
*
|
||||||
|
* @param saOAuth2Template 代码模板Bean
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public void setSaOAuth2Interface(@Inject(required = false) SaOAuth2Template saOAuth2Template) {
|
||||||
|
SaOAuth2Util.saOAuth2Template = saOAuth2Template;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package cn.dev33.satoken.solon.sso;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.config.SaSsoConfig;
|
||||||
|
import cn.dev33.satoken.sso.SaSsoManager;
|
||||||
|
import cn.dev33.satoken.sso.SaSsoProcessor;
|
||||||
|
import cn.dev33.satoken.sso.SaSsoTemplate;
|
||||||
|
import cn.dev33.satoken.sso.SaSsoUtil;
|
||||||
|
import org.noear.solon.annotation.Bean;
|
||||||
|
import org.noear.solon.annotation.Configuration;
|
||||||
|
import org.noear.solon.annotation.Init;
|
||||||
|
import org.noear.solon.annotation.Inject;
|
||||||
|
import org.noear.solon.core.AopContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author noear
|
||||||
|
* @since 2.0
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class SaSsoAutoConfigure {
|
||||||
|
/**
|
||||||
|
* 获取 SSO 配置Bean
|
||||||
|
* */
|
||||||
|
@Bean
|
||||||
|
public SaSsoConfig getConfig(@Inject(value = "${sa-token.sso}",required = false) SaSsoConfig ssoConfig) {
|
||||||
|
return ssoConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注入 Sa-Token-SSO 配置Bean
|
||||||
|
*
|
||||||
|
* @param saSsoConfig 配置对象
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public void setSaSsoConfig(@Inject(required = false) SaSsoConfig saSsoConfig) {
|
||||||
|
SaSsoManager.setConfig(saSsoConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注入 Sa-Token-SSO 单点登录模块 Bean
|
||||||
|
*
|
||||||
|
* @param ssoTemplate saSsoTemplate对象
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public void setSaSsoTemplate(@Inject(required = false) SaSsoTemplate ssoTemplate) {
|
||||||
|
SaSsoUtil.ssoTemplate = ssoTemplate;
|
||||||
|
SaSsoProcessor.instance.ssoTemplate = ssoTemplate;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user