SSO 认证中心增加平台中心跳转模式 demo

This commit is contained in:
click33 2024-07-31 23:54:46 +08:00
parent bb8a206dea
commit 968c5ea1b6
2 changed files with 36 additions and 2 deletions

View File

@ -0,0 +1,36 @@
package com.pj.home;
import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* SSO 平台中心模式示例跳连接进入子系统
*/
@RestController
public class HomeController {
// 平台化首页
@RequestMapping("/home")
public Object index() {
// 如果未登录则先去登录
if(!StpUtil.isLogin()) {
return SaHolder.getResponse().redirect("/sso/auth");
}
// 拼接各个子系统的地址格式形如/sso/auth?redirect=${子系统首页}/sso/login?back=${子系统首页}
String link1 = "/sso/auth?redirect=http://sa-sso-client1.com:9003/sso/login?back=http://sa-sso-client1.com:9003/";
String link2 = "/sso/auth?redirect=http://sa-sso-client2.com:9003/sso/login?back=http://sa-sso-client2.com:9003/";
String link3 = "/sso/auth?redirect=http://sa-sso-client3.com:9003/sso/login?back=http://sa-sso-client3.com:9003/";
// 组织网页结构返回到前端
String title = "<h2>SSO 平台首页</h2>";
String client1 = "<p><a href='" + link1 + "' target='_blank'> 进入Client1系统 </a></p>";
String client2 = "<p><a href='" + link2 + "' target='_blank'> 进入Client2系统 </a></p>";
String client3 = "<p><a href='" + link3 + "' target='_blank'> 进入Client3系统 </a></p>";
return title + client1 + client2 + client3;
}
}

View File

@ -6,8 +6,6 @@ server:
sa-token:
# sso-client 相关配置
sso-client:
# client 标识
client: sso-client3
# sso-server 端主机地址
server-url: http://sa-sso-server.com:9000
# 使用 Http 请求校验ticket (模式三)