mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-18 01:25:28 +08:00
sso server支持vue页面
This commit is contained in:
parent
74651a414f
commit
627740d92c
20
pom.xml
20
pom.xml
@ -220,6 +220,26 @@
|
||||
<version>${satoken.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Sa-Token 整合 Redis (使用 jackson 序列化方式) -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-redis-jackson</artifactId>
|
||||
<version>${satoken.version}</version>
|
||||
</dependency>
|
||||
<!-- Sa-Token插件:权限缓存与业务缓存分离 -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-alone-redis</artifactId>
|
||||
<version>${satoken.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Sa-Token 插件:整合SSO -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-sso</artifactId>
|
||||
<version>${satoken.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- dynamic-datasource 多数据源-->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
|
||||
@ -32,10 +32,10 @@
|
||||
<artifactId>caffeine</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-nacos</artifactId>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.dromara</groupId>-->
|
||||
<!-- <artifactId>ruoyi-common-nacos</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!-- SpringBoot Actuator -->
|
||||
<dependency>
|
||||
@ -84,13 +84,17 @@
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-redis-jackson</artifactId>
|
||||
<version>${satoken.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-pool2</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Sa-Token插件:权限缓存与业务缓存分离 -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-alone-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- RuoYi Common Redis-->
|
||||
<dependency>
|
||||
|
||||
@ -10,7 +10,7 @@ import org.springframework.boot.context.metrics.buffering.BufferingApplicationSt
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class},scanBasePackages = {"org.dromara"})
|
||||
public class RuoYiGatewayApplication {
|
||||
public static void main(String[] args) {
|
||||
// 标记 sentinel 类型为 网关
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
package org.dromara.gateway.config;
|
||||
|
||||
import cn.dev33.satoken.jwt.StpLogicJwtForSimple;
|
||||
import cn.dev33.satoken.stp.StpLogic;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class SaTokenConfigure {
|
||||
// Sa-Token 整合 jwt (Simple 简单模式)
|
||||
@Bean
|
||||
public StpLogic getStpLogicJwt() {
|
||||
return new StpLogicJwtForSimple();
|
||||
}
|
||||
}
|
||||
@ -7,10 +7,10 @@ import cn.dev33.satoken.reactor.filter.SaReactorFilter;
|
||||
import cn.dev33.satoken.router.SaRouter;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.dev33.satoken.util.SaResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.constant.HttpStatus;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.dromara.gateway.config.properties.IgnoreWhiteProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@ -22,7 +22,9 @@ import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class AuthFilter {
|
||||
public static final String CLIENT_KEY = "clientid";
|
||||
|
||||
/**
|
||||
* 注册 Sa-Token 全局过滤器
|
||||
@ -54,9 +56,9 @@ public class AuthFilter {
|
||||
}
|
||||
|
||||
// 检查 header 与 param 里的 clientid 与 token 里的是否一致
|
||||
String headerCid = request.getHeaders().getFirst(LoginHelper.CLIENT_KEY);
|
||||
String paramCid = request.getQueryParams().getFirst(LoginHelper.CLIENT_KEY);
|
||||
String clientId = StpUtil.getExtra(LoginHelper.CLIENT_KEY).toString();
|
||||
String headerCid = request.getHeaders().getFirst(CLIENT_KEY);
|
||||
String paramCid = request.getQueryParams().getFirst(CLIENT_KEY);
|
||||
String clientId = StpUtil.getExtra(CLIENT_KEY).toString();
|
||||
if (!StringUtils.equalsAny(clientId, headerCid, paramCid)) {
|
||||
// token 无效
|
||||
throw NotLoginException.newInstance(StpUtil.getLoginType(),
|
||||
@ -71,7 +73,8 @@ public class AuthFilter {
|
||||
// }
|
||||
});
|
||||
}).setError(e -> {
|
||||
if (e instanceof NotLoginException) {
|
||||
log.error("认证错误", e);
|
||||
if (e instanceof NotLoginException) {
|
||||
return SaResult.error(e.getMessage()).setCode(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
return SaResult.error("认证失败,无法访问系统资源").setCode(HttpStatus.UNAUTHORIZED);
|
||||
|
||||
@ -19,30 +19,17 @@ security:
|
||||
- /sso/isLogin
|
||||
- /sso/doLoginByTicket
|
||||
|
||||
# sa-token配置
|
||||
sa-token:
|
||||
sign:
|
||||
# API client和server之间调用 接口签名秘钥 (随便乱摁几个字母即可)
|
||||
secret-key: kQwIOrYbtXmSDkwEiFngrKidMcdrgKor
|
||||
# token名称 (同时也是cookie名称)
|
||||
token-name: Authorization
|
||||
# 允许动态设置 token 有效期
|
||||
dynamic-active-timeout: true
|
||||
# 允许从 header 读取 token
|
||||
is-read-header: true
|
||||
# 关闭 cookie 鉴权 从根源杜绝 csrf 漏洞风险
|
||||
is-read-cookie: false
|
||||
# SSO-相关配置
|
||||
sso-client:
|
||||
# SSO-Server 端主机地址
|
||||
server-url: http://sa-sso-server.com:19000
|
||||
auth-url: http://sa-sso-server.com:8701/?mode=ticket#/sso-login
|
||||
client: "e5cd7e4891bf95d1d19206ce24a7b32e"
|
||||
#jwt密钥
|
||||
jwt-secret-key: abcdcosctlklmnopqrstuvwxyz
|
||||
token-prefix: Bearer
|
||||
|
||||
spring:
|
||||
data:
|
||||
redis:
|
||||
host: localhost # Redis服务器地址
|
||||
database: 0 # Redis数据库索引(默认为0)
|
||||
port: 6379 # Redis服务器连接端口
|
||||
password: Lzw8800580/
|
||||
# 连接超时时间
|
||||
timeout: 10s
|
||||
# 是否开启ssl
|
||||
ssl.enabled: false
|
||||
cloud:
|
||||
# 网关配置
|
||||
gateway:
|
||||
@ -100,3 +87,58 @@ spring:
|
||||
- Path=/ruoyi-h5/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
|
||||
|
||||
# sa-token配置
|
||||
sa-token:
|
||||
sign:
|
||||
# API client和server之间调用 接口签名秘钥 (随便乱摁几个字母即可)
|
||||
secret-key: kQwIOrYbtXmSDkwEiFngrKidMcdrgKor
|
||||
# token名称 (同时也是cookie名称)
|
||||
token-name: Authorization
|
||||
# 允许从 header 读取 token
|
||||
is-read-header: true
|
||||
# 关闭 cookie 鉴权 从根源杜绝 csrf 漏洞风险
|
||||
is-read-cookie: false
|
||||
# 允许从 请求参数 读取 token
|
||||
is-read-body: true
|
||||
# 在多人登录同一账号时,是否共用一个token (为true(默认)时所有登录共用一个token, 为false时每次登录新建一个token),这个为false会导致登陆多次后redis内存的token不能很好释放
|
||||
is-share: false
|
||||
# SSO-相关配置
|
||||
sso-client:
|
||||
# SSO-Server 端主机地址
|
||||
server-url: http://sa-sso-server.com:19000
|
||||
auth-url: http://sa-sso-server.com:8701/?mode=ticket#/sso-login
|
||||
# pc 客户端id
|
||||
client: e5cd7e4891bf95d1d19206ce24a7b32e
|
||||
#jwt密钥
|
||||
jwt-secret-key: abcdcosctlklmnopqrstuvwxyz
|
||||
token-prefix: Bearer
|
||||
|
||||
# 配置Sa-Token单独使用的Redis连接 (此处需要和SSO-Server端连接同一个Redis)
|
||||
alone-redis:
|
||||
# Redis数据库索引 (默认为0)
|
||||
database: ${spring.data.redis.database}
|
||||
# Redis服务器地址
|
||||
host: ${spring.data.redis.host}
|
||||
# Redis服务器连接端口
|
||||
port: ${spring.data.redis.port}
|
||||
# Redis服务器连接密码(默认为空)
|
||||
password: ${spring.data.redis.password}
|
||||
# 连接超时时间
|
||||
timeout: ${spring.data.redis.timeout}
|
||||
lettuce:
|
||||
pool:
|
||||
# 连接池最大连接数
|
||||
max-active: 200
|
||||
# 连接池最大阻塞等待时间(使用负值表示没有限制)
|
||||
max-wait: -1ms
|
||||
# 连接池中的最大空闲连接
|
||||
max-idle: 10
|
||||
# 连接池中的最小空闲连接
|
||||
min-idle: 1
|
||||
|
||||
# 多租户配置
|
||||
tenant:
|
||||
# 是否开启
|
||||
enable: false
|
||||
|
||||
@ -4,8 +4,8 @@
|
||||
<property name="log.path" value="logs/${project.artifactId}"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="console.log.pattern"
|
||||
value="%red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}%n) - %msg%n"/>
|
||||
<property name="log.pattern" value="%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"/>
|
||||
value="%red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}:%line) - %msg%n"/>
|
||||
<property name="log.pattern" value="%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}:%line - %msg%n"/>
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
|
||||
@ -95,7 +95,6 @@
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-redis-jackson</artifactId>
|
||||
<version>1.38.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
@ -106,14 +105,12 @@
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-sso</artifactId>
|
||||
<version>1.38.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Sa-Token 插件:整合SSO -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-sso</artifactId>
|
||||
<version>1.38.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Apache Dubbo 配置 -->
|
||||
|
||||
@ -44,7 +44,7 @@ sa-token:
|
||||
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
|
||||
is-concurrent: true
|
||||
# 在多人登录同一账号时,是否共用一个token (为true(默认)时所有登录共用一个token, 为false时每次登录新建一个token),这个为false会导致登陆多次后redis内存的token不能很好释放
|
||||
is-share: true
|
||||
is-share: false
|
||||
# jwt秘钥
|
||||
jwt-secret-key: abcdcosctlklmnopqrstuvwxyz
|
||||
|
||||
@ -56,7 +56,6 @@ sa-token:
|
||||
allow-url: "*"
|
||||
|
||||
auth-url: http://sa-sso-server.com:5173/#/sso-login
|
||||
active-timeout: 30
|
||||
|
||||
|
||||
# api接口加密
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
version: '3'
|
||||
version: '3.5'
|
||||
services:
|
||||
ruoyi-admin:
|
||||
image: ruoyi-admin:latest
|
||||
@ -9,6 +9,11 @@ services:
|
||||
- 'TZ="Asia/Shanghai"'
|
||||
networks:
|
||||
- docker_default
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 1024m # 限制内存为 512m
|
||||
|
||||
ruoyi-sso-server:
|
||||
image: ruoyi-sso-server:latest
|
||||
container_name: ruoyi-sso-server
|
||||
@ -18,6 +23,11 @@ services:
|
||||
- 'TZ="Asia/Shanghai"'
|
||||
networks:
|
||||
- docker_default
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 248m # 限制内存为 248mB
|
||||
|
||||
ruoyi-h5:
|
||||
image: ruoyi-h5:latest
|
||||
container_name: ruoyi-h5
|
||||
@ -27,6 +37,11 @@ services:
|
||||
- 'TZ="Asia/Shanghai"'
|
||||
networks:
|
||||
- docker_default
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 248m # 限制内存为 248mB
|
||||
|
||||
ruoyi-gateway:
|
||||
image: ruoyi-gateway:latest
|
||||
container_name: ruoyi-gateway
|
||||
@ -36,7 +51,11 @@ services:
|
||||
- 'TZ="Asia/Shanghai"'
|
||||
networks:
|
||||
- docker_default
|
||||
# # 前端
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 248m # 限制内存为 248mB
|
||||
|
||||
sso-server-vue3:
|
||||
image: sso-server-vue3:latest
|
||||
container_name: sso-server-vue3
|
||||
@ -46,6 +65,11 @@ services:
|
||||
- 'TZ="Asia/Shanghai"'
|
||||
networks:
|
||||
- docker_default
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 60m # 限制内存为 60MB
|
||||
|
||||
networks:
|
||||
docker_default:
|
||||
external: true
|
||||
|
||||
Loading…
Reference in New Issue
Block a user