mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-10-27 02:59:02 +08:00
升级优化一下 solon 相关集成 demo
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.38.0</sa-token.version>
|
||||
<solon.version>2.7.0</solon.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@@ -48,7 +49,7 @@
|
||||
<artifactId>sa-token-redisx</artifactId>
|
||||
<version>${sa-token.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- 视图引擎(在前后端不分离模式下提供视图支持) -->
|
||||
<dependency>
|
||||
<groupId>org.noear</groupId>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.pj;
|
||||
|
||||
|
||||
import cn.dev33.satoken.sso.SaSsoManager;
|
||||
import org.noear.solon.Solon;
|
||||
import org.noear.solon.annotation.SolonMain;
|
||||
|
||||
@@ -9,7 +10,13 @@ public class SaSsoServerApp {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Solon.start(SaSsoServerApp.class, args);
|
||||
System.out.println("\n------ Sa-Token-SSO 统一认证中心启动成功 ");
|
||||
|
||||
System.out.println();
|
||||
System.out.println("---------------------- Solon Sa-Token SSO 统一认证中心启动成功 ----------------------");
|
||||
System.out.println("配置信息:" + SaSsoManager.getServerConfig());
|
||||
System.out.println("统一认证登录地址:http://sa-sso-server.com:9000/sso/auth");
|
||||
System.out.println("测试前需要根据官网文档修改hosts文件,测试账号密码:sa / 123456");
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -44,12 +44,13 @@ public class SsoConfig {
|
||||
return SaResult.error("登录失败!");
|
||||
};
|
||||
|
||||
// 配置 Http 请求处理器 (在模式三的单点注销功能下用到,如不需要可以注释掉)
|
||||
// 配置 Http 请求处理器
|
||||
ssoServer.sendHttp = url -> {
|
||||
try {
|
||||
// 发起 http 请求
|
||||
System.out.println("------ 发起请求:" + url);
|
||||
return Forest.get(url).executeAsString();
|
||||
String resStr = Forest.get(url).executeAsString();
|
||||
System.out.println("------ 请求结果:" + resStr);
|
||||
return resStr;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
|
||||
@@ -29,7 +29,7 @@ sa-token:
|
||||
sa-token.dao: #名字可以随意取
|
||||
redis:
|
||||
server: "localhost:6379"
|
||||
password: 123456
|
||||
# password: 123456
|
||||
db: 1
|
||||
maxTotal: 200
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.pj;
|
||||
|
||||
|
||||
import cn.dev33.satoken.sso.SaSsoManager;
|
||||
import org.noear.solon.Solon;
|
||||
import org.noear.solon.annotation.SolonMain;
|
||||
|
||||
@@ -15,6 +16,15 @@ public class SaSso1ClientApp {
|
||||
public static void main(String[] args) {
|
||||
Solon.start(SaSso1ClientApp.class, args);
|
||||
System.out.println("\nSa-Token SSO模式一 Client端启动成功");
|
||||
|
||||
System.out.println();
|
||||
System.out.println("---------------------- Solon Sa-Token SSO 模式一 Client 端启动成功 ----------------------");
|
||||
System.out.println("配置信息:" + SaSsoManager.getClientConfig());
|
||||
System.out.println("测试访问应用端一: http://s1.stp.com:9001");
|
||||
System.out.println("测试访问应用端二: http://s2.stp.com:9001");
|
||||
System.out.println("测试访问应用端三: http://s3.stp.com:9001");
|
||||
System.out.println("测试前需要根据官网文档修改hosts文件,测试账号密码:sa / 123456");
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,16 +6,14 @@ server:
|
||||
sa-token:
|
||||
# SSO-相关配置
|
||||
sso-client:
|
||||
# SSO-Server端-单点登录授权地址
|
||||
auth-url: http://sso.stp.com:9000/sso/auth
|
||||
# SSO-Server端-单点注销地址
|
||||
slo-url: http://sso.stp.com:9000/sso/signout
|
||||
# SSO-Server端 - 主机地址
|
||||
server-url: http://sso.stp.com:9000
|
||||
|
||||
# 配置 Sa-Token 单独使用的Redis连接 (此处需要和SSO-Server端连接同一个Redis)
|
||||
sa-token.dao: #名字可以随意取
|
||||
redis:
|
||||
server: "localhost:6379"
|
||||
password: 123456
|
||||
# password: 123456
|
||||
db: 1
|
||||
maxTotal: 200
|
||||
|
||||
|
||||
@@ -47,6 +47,13 @@
|
||||
<artifactId>sa-token-redisx</artifactId>
|
||||
<version>${sa-token.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Http 请求工具 -->
|
||||
<dependency>
|
||||
<groupId>org.noear</groupId>
|
||||
<artifactId>forest-solon-plugin</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
@@ -2,8 +2,11 @@ package com.pj;
|
||||
|
||||
import cn.dev33.satoken.dao.SaTokenDao;
|
||||
import cn.dev33.satoken.dao.SaTokenDaoOfRedis;
|
||||
import cn.dev33.satoken.sso.config.SaSsoClientConfig;
|
||||
import com.dtflys.forest.Forest;
|
||||
import org.noear.solon.annotation.Bean;
|
||||
import org.noear.solon.annotation.Configuration;
|
||||
import org.noear.solon.annotation.Init;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
/**
|
||||
@@ -19,4 +22,16 @@ public class SaConfig {
|
||||
public SaTokenDao saTokenDaoInit(@Inject("${sa-token.dao.redis}") SaTokenDaoOfRedis saTokenDao) {
|
||||
return saTokenDao;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public void configSso(SaSsoClientConfig ssoClient) {
|
||||
// 配置Http请求处理器
|
||||
ssoClient.sendHttp = url -> {
|
||||
System.out.println("------ 发起请求:" + url);
|
||||
String resStr = Forest.get(url).executeAsString();
|
||||
System.out.println("------ 请求结果:" + resStr);
|
||||
return resStr;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.pj;
|
||||
|
||||
|
||||
import cn.dev33.satoken.sso.SaSsoManager;
|
||||
import org.noear.solon.Solon;
|
||||
import org.noear.solon.annotation.SolonMain;
|
||||
|
||||
@@ -9,7 +10,15 @@ public class SaSso2ClientApp {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Solon.start(SaSso2ClientApp.class, args);
|
||||
System.out.println("\nSa-Token SSO模式二 Client端启动成功");
|
||||
|
||||
System.out.println();
|
||||
System.out.println("---------------------- Solon Sa-Token SSO 模式二 Client 端启动成功 ----------------------");
|
||||
System.out.println("配置信息:" + SaSsoManager.getClientConfig());
|
||||
System.out.println("测试访问应用端一: http://sa-sso-client1.com:9002");
|
||||
System.out.println("测试访问应用端二: http://sa-sso-client2.com:9002");
|
||||
System.out.println("测试访问应用端三: http://sa-sso-client3.com:9002");
|
||||
System.out.println("测试前需要根据官网文档修改hosts文件,测试账号密码:sa / 123456");
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,17 +6,20 @@ server:
|
||||
sa-token:
|
||||
# SSO-相关配置
|
||||
sso-client:
|
||||
# SSO-Server端 统一认证地址
|
||||
auth-url: http://sa-sso-server.com:9000/sso/auth
|
||||
# SSO-Server端 主机地址
|
||||
server-url: http://sa-sso-server.com:9000
|
||||
# auth-url: http://127.0.0.1:8848/sa-token-demo-sso-server-h5/sso-auth.html
|
||||
# 是否打开单点注销接口
|
||||
is-slo: true
|
||||
sign:
|
||||
# API 接口调用秘钥
|
||||
secret-key: kQwIOrYvnXmSDkwEiFngrKidMcdrgKor
|
||||
|
||||
# 配置 Sa-Token 单独使用的Redis连接 (此处需要和SSO-Server端连接同一个Redis)
|
||||
sa-token.dao: #名字可以随意取
|
||||
redis:
|
||||
server: "localhost:6379"
|
||||
password: 123456
|
||||
# password: 123456
|
||||
db: 1
|
||||
maxTotal: 200
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.pj;
|
||||
|
||||
import cn.dev33.satoken.sso.SaSsoManager;
|
||||
import org.noear.solon.Solon;
|
||||
import org.noear.solon.annotation.SolonMain;
|
||||
|
||||
@@ -8,7 +9,15 @@ public class SaSso3ClientApp {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Solon.start(SaSso3ClientApp.class, args);
|
||||
System.out.println("\nSa-Token SSO模式三 Client端启动成功");
|
||||
|
||||
System.out.println();
|
||||
System.out.println("---------------------- Sa-Token SSO 模式三 Client 端启动成功 ----------------------");
|
||||
System.out.println("配置信息:" + SaSsoManager.getClientConfig());
|
||||
System.out.println("测试访问应用端一: http://sa-sso-client1.com:9003");
|
||||
System.out.println("测试访问应用端二: http://sa-sso-client2.com:9003");
|
||||
System.out.println("测试访问应用端三: http://sa-sso-client3.com:9003");
|
||||
System.out.println("测试前需要根据官网文档修改hosts文件,测试账号密码:sa / 123456");
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,50 +1,50 @@
|
||||
package com.pj.sso;
|
||||
|
||||
import cn.dev33.satoken.sso.SaSsoManager;
|
||||
import cn.dev33.satoken.sso.config.SaSsoClientConfig;
|
||||
import cn.dev33.satoken.sso.processor.SaSsoClientProcessor;
|
||||
import cn.dev33.satoken.sso.template.SaSsoClientTemplate;
|
||||
import org.noear.solon.annotation.Bean;
|
||||
import org.noear.solon.annotation.Condition;
|
||||
import org.noear.solon.annotation.Configuration;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
/**
|
||||
* solon 的 sso 适配,在 cn.dev33:sa-token-solon-plugin:1.34.0 里还没有。(临时加这个类)
|
||||
*
|
||||
* //todo: 如果使用 org.noear:sa-token-solon-plugin:xxx ,则需要删掉这个类
|
||||
*
|
||||
* @author noear
|
||||
* @since 2.0
|
||||
*/
|
||||
@Condition(onClass = SaSsoManager.class)
|
||||
@Configuration
|
||||
public class SaSsoAutoConfigure {
|
||||
/**
|
||||
* 获取 SSO 配置Bean
|
||||
* */
|
||||
@Bean
|
||||
public SaSsoClientConfig getConfig(@Inject(value = "${sa-token.sso-client}",required = false) SaSsoClientConfig ssoConfig) {
|
||||
return ssoConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入 Sa-Token-SSO 配置Bean
|
||||
*
|
||||
* @param saSsoConfig 配置对象
|
||||
*/
|
||||
@Bean
|
||||
public void setSaSsoConfig(@Inject(required = false) SaSsoClientConfig saSsoConfig) {
|
||||
SaSsoManager.setClientConfig(saSsoConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入 Sa-Token-SSO 单点登录模块 Bean
|
||||
*
|
||||
* @param ssoClientTemplate ssoClientTemplate对象
|
||||
*/
|
||||
@Bean
|
||||
public void setSaSsoClientTemplate(@Inject(required = false) SaSsoClientTemplate ssoClientTemplate) {
|
||||
SaSsoClientProcessor.instance.ssoClientTemplate = ssoClientTemplate;
|
||||
}
|
||||
}
|
||||
//package com.pj.sso;
|
||||
//
|
||||
//import cn.dev33.satoken.sso.SaSsoManager;
|
||||
//import cn.dev33.satoken.sso.config.SaSsoClientConfig;
|
||||
//import cn.dev33.satoken.sso.processor.SaSsoClientProcessor;
|
||||
//import cn.dev33.satoken.sso.template.SaSsoClientTemplate;
|
||||
//import org.noear.solon.annotation.Bean;
|
||||
//import org.noear.solon.annotation.Condition;
|
||||
//import org.noear.solon.annotation.Configuration;
|
||||
//import org.noear.solon.annotation.Inject;
|
||||
//
|
||||
///**
|
||||
// * solon 的 sso 适配,在 cn.dev33:sa-token-solon-plugin:1.34.0 里还没有。(临时加这个类)
|
||||
// *
|
||||
// * //todo: 如果使用 org.noear:sa-token-solon-plugin:xxx ,则需要删掉这个类
|
||||
// *
|
||||
// * @author noear
|
||||
// * @since 2.0
|
||||
// */
|
||||
//@Condition(onClass = SaSsoManager.class)
|
||||
//@Configuration
|
||||
//public class SaSsoAutoConfigure {
|
||||
// /**
|
||||
// * 获取 SSO 配置Bean
|
||||
// * */
|
||||
// @Bean
|
||||
// public SaSsoClientConfig getConfig(@Inject(value = "${sa-token.sso-client}",required = false) SaSsoClientConfig ssoConfig) {
|
||||
// return ssoConfig;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 注入 Sa-Token-SSO 配置Bean
|
||||
// *
|
||||
// * @param saSsoConfig 配置对象
|
||||
// */
|
||||
// @Bean
|
||||
// public void setSaSsoConfig(@Inject(required = false) SaSsoClientConfig saSsoConfig) {
|
||||
// SaSsoManager.setClientConfig(saSsoConfig);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 注入 Sa-Token-SSO 单点登录模块 Bean
|
||||
// *
|
||||
// * @param ssoClientTemplate ssoClientTemplate对象
|
||||
// */
|
||||
// @Bean
|
||||
// public void setSaSsoClientTemplate(@Inject(required = false) SaSsoClientTemplate ssoClientTemplate) {
|
||||
// SaSsoClientProcessor.instance.ssoClientTemplate = ssoClientTemplate;
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -16,7 +16,9 @@ public class SsoConfig {
|
||||
// 配置Http请求处理器
|
||||
ssoClient.sendHttp = url -> {
|
||||
System.out.println("------ 发起请求:" + url);
|
||||
return Forest.get(url).executeAsString();
|
||||
String resStr = Forest.get(url).executeAsString();
|
||||
System.out.println("------ 请求结果:" + resStr);
|
||||
return resStr;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,27 +6,22 @@ server:
|
||||
sa-token:
|
||||
# SSO-相关配置
|
||||
sso-client:
|
||||
# SSO-Server端 统一认证地址
|
||||
auth-url: http://sa-sso-server.com:9000/sso/auth
|
||||
# SSO-Server端 主机地址
|
||||
server-url: http://sa-sso-server.com:9000
|
||||
# 使用Http请求校验ticket
|
||||
is-http: true
|
||||
# SSO-Server端 ticket校验地址
|
||||
check-ticket-url: http://sa-sso-server.com:9000/sso/checkTicket
|
||||
# 打开单点注销功能
|
||||
is-slo: true
|
||||
# 单点注销地址
|
||||
slo-url: http://sa-sso-server.com:9000/sso/signout
|
||||
sign:
|
||||
# 接口调用秘钥
|
||||
secretkey: kQwIOrYvnXmSDkwEiFngrKidMcdrgKor
|
||||
# SSO-Server端 查询userinfo地址
|
||||
userinfo-url: http://sa-sso-server.com:9000/sso/userinfo
|
||||
secret-key: kQwIOrYvnXmSDkwEiFngrKidMcdrgKor
|
||||
|
||||
|
||||
# 配置 Sa-Token Dao(此处与SSO-Server端连接不同的Redis)
|
||||
sa-token.dao: #名字可以随意取
|
||||
redis:
|
||||
server: "localhost:6379"
|
||||
password: 123456
|
||||
# password: 123456
|
||||
db: 2
|
||||
maxTotal: 200
|
||||
|
||||
|
||||
Reference in New Issue
Block a user