mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-19 01:48:47 +08:00
sso-server 改成 前后端分离登录
This commit is contained in:
parent
af1c70ed6b
commit
61d647c069
25
pom.xml
25
pom.xml
@ -567,31 +567,6 @@
|
|||||||
</resources>
|
</resources>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>public</id>
|
|
||||||
<name>huawei nexus</name>
|
|
||||||
<url>https://mirrors.huaweicloud.com/repository/maven/</url>
|
|
||||||
<releases>
|
|
||||||
<enabled>true</enabled>
|
|
||||||
</releases>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
|
|
||||||
<pluginRepositories>
|
|
||||||
<pluginRepository>
|
|
||||||
<id>public</id>
|
|
||||||
<name>huawei nexus</name>
|
|
||||||
<url>https://mirrors.huaweicloud.com/repository/maven/</url>
|
|
||||||
<releases>
|
|
||||||
<enabled>true</enabled>
|
|
||||||
</releases>
|
|
||||||
<snapshots>
|
|
||||||
<enabled>false</enabled>
|
|
||||||
</snapshots>
|
|
||||||
</pluginRepository>
|
|
||||||
</pluginRepositories>
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,6 @@ spring:
|
|||||||
|
|
||||||
# dubbo
|
# dubbo
|
||||||
dubbo:
|
dubbo:
|
||||||
config:
|
|
||||||
protocol:
|
protocol:
|
||||||
name: tri
|
name: tri
|
||||||
port: 20881
|
port: 20881
|
||||||
|
|||||||
@ -25,11 +25,6 @@
|
|||||||
<artifactId>ruoyi-common-core</artifactId>
|
<artifactId>ruoyi-common-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.dromara</groupId>
|
|
||||||
<artifactId>ruoyi-common-excel</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -21,32 +21,12 @@
|
|||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.cloud</groupId>
|
|
||||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<!-- 没有loadbalancer调用会报错 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.cloud</groupId>
|
|
||||||
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.github.openfeign</groupId>
|
|
||||||
<artifactId>feign-okhttp</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- SpringBoot Web依赖 -->
|
<!-- SpringBoot Web依赖 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- 视图引擎(在前后端不分离模式下提供视图支持) -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.dromara</groupId>
|
<groupId>org.dromara</groupId>
|
||||||
|
|||||||
@ -3,8 +3,13 @@ package org.ruoyi.sso.server.controller;
|
|||||||
import cn.dev33.satoken.context.SaHolder;
|
import cn.dev33.satoken.context.SaHolder;
|
||||||
import cn.dev33.satoken.context.model.SaRequest;
|
import cn.dev33.satoken.context.model.SaRequest;
|
||||||
import cn.dev33.satoken.sso.config.SaSsoServerConfig;
|
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.processor.SaSsoServerProcessor;
|
||||||
|
import cn.dev33.satoken.sso.template.SaSsoUtil;
|
||||||
|
import cn.dev33.satoken.sso.util.SaSsoConsts;
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
|
import cn.dev33.satoken.util.SaFoxUtil;
|
||||||
|
import cn.dev33.satoken.util.SaResult;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import org.ruoyi.sso.server.domain.vo.LoginVo;
|
import org.ruoyi.sso.server.domain.vo.LoginVo;
|
||||||
import org.ruoyi.sso.server.service.IAuthStrategy;
|
import org.ruoyi.sso.server.service.IAuthStrategy;
|
||||||
@ -87,6 +92,41 @@ public class SsoServerController {
|
|||||||
return R.ok(loginVo);
|
return R.ok(loginVo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 当前是否登录
|
||||||
|
@RequestMapping("/sso/isLogin")
|
||||||
|
public Object isLogin() {
|
||||||
|
return SaResult.data(StpUtil.isLogin());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 redirectUrl
|
||||||
|
*/
|
||||||
|
@RequestMapping("/sso/getRedirectUrl")
|
||||||
|
public SaResult getRedirectUrl(String redirect, String mode, String client) {
|
||||||
|
// 未登录情况下,返回 code=401
|
||||||
|
if (!StpUtil.isLogin()) {
|
||||||
|
return SaResult.code(401);
|
||||||
|
}
|
||||||
|
// 已登录情况下,构建 redirectUrl
|
||||||
|
redirect = SaFoxUtil.decoderUrl(redirect);
|
||||||
|
if (SaSsoConsts.MODE_SIMPLE.equals(mode)) {
|
||||||
|
// 模式一
|
||||||
|
SaSsoUtil.checkRedirectUrl(redirect);
|
||||||
|
return SaResult.data(redirect);
|
||||||
|
} else {
|
||||||
|
// 模式二或模式三
|
||||||
|
String redirectUrl = SaSsoUtil.buildRedirectUrl(StpUtil.getLoginId(), client, redirect);
|
||||||
|
return SaResult.data(redirectUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SSO-Server:单点注销
|
||||||
|
@RequestMapping("/sso/logout")
|
||||||
|
public Object ssoSignout() {
|
||||||
|
return SaSsoClientProcessor.instance.ssoLogoutByMode2();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 配置SSO相关参数
|
// 配置SSO相关参数
|
||||||
@Autowired
|
@Autowired
|
||||||
private void configSso(SaSsoServerConfig ssoServer) {
|
private void configSso(SaSsoServerConfig ssoServer) {
|
||||||
|
|||||||
@ -37,8 +37,8 @@ sa-token:
|
|||||||
# 读写同源,开启后每次访问都会自动续期
|
# 读写同源,开启后每次访问都会自动续期
|
||||||
# token名称 (同时也是cookie名称)
|
# token名称 (同时也是cookie名称)
|
||||||
token-name: Authorization
|
token-name: Authorization
|
||||||
# cookie写入 TODO 后续必须关掉,cookie 有安全隐患
|
# cookie写入 必须关掉,cookie 有安全隐患
|
||||||
is-read-cookie: true
|
is-read-cookie: false
|
||||||
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
|
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
|
||||||
is-concurrent: true
|
is-concurrent: true
|
||||||
# 在多人登录同一账号时,是否共用一个token (为true(默认)时所有登录共用一个token, 为false时每次登录新建一个token),这个为false会导致登陆多次后redis内存的token不能很好释放
|
# 在多人登录同一账号时,是否共用一个token (为true(默认)时所有登录共用一个token, 为false时每次登录新建一个token),这个为false会导致登陆多次后redis内存的token不能很好释放
|
||||||
@ -52,6 +52,8 @@ sa-token:
|
|||||||
ticket-timeout: 300
|
ticket-timeout: 300
|
||||||
# 所有允许的授权回调地址 TODO 生产和测试一定要改
|
# 所有允许的授权回调地址 TODO 生产和测试一定要改
|
||||||
allow-url: "*"
|
allow-url: "*"
|
||||||
|
|
||||||
|
auth-url: http://localhost:5173/#/sso-login
|
||||||
active-timeout: 30
|
active-timeout: 30
|
||||||
|
|
||||||
# ruoyi-security配置
|
# ruoyi-security配置
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user