mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-10-21 19:17:25 +08:00
重构
This commit is contained in:
@@ -3,7 +3,7 @@ package com.pj;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
import cn.dev33.satoken.SaTokenManager;
|
||||
import cn.dev33.satoken.SaManager;
|
||||
|
||||
/**
|
||||
* sa-token整合SpringBoot 示例
|
||||
@@ -15,7 +15,7 @@ public class SaTokenDemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SaTokenDemoApplication.class, args);
|
||||
System.out.println("\n启动成功:sa-token配置如下:" + SaTokenManager.getConfig());
|
||||
System.out.println("\n启动成功:sa-token配置如下:" + SaManager.getConfig());
|
||||
}
|
||||
|
||||
}
|
@@ -1,10 +1,16 @@
|
||||
package com.pj.satoken;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import com.pj.util.AjaxJson;
|
||||
|
||||
import cn.dev33.satoken.context.SaHolder;
|
||||
import cn.dev33.satoken.filter.SaServletFilter;
|
||||
import cn.dev33.satoken.interceptor.SaAnnotationInterceptor;
|
||||
import cn.dev33.satoken.router.SaRouterUtil;
|
||||
|
||||
|
||||
/**
|
||||
@@ -24,27 +30,44 @@ public class SaTokenConfigure implements WebMvcConfigurer {
|
||||
registry.addInterceptor(new SaAnnotationInterceptor()).addPathPatterns("/**").excludePathPatterns("");
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 注册 [sa-token全局过滤器]
|
||||
// */
|
||||
// @Bean
|
||||
// public SaServletFilter getSaReactorFilter() {
|
||||
// return new SaServletFilter()
|
||||
// // 指定 [拦截路由]
|
||||
// .addInclude("/**")
|
||||
// // 指定 [放行路由]
|
||||
// .addExclude("/favicon.ico")
|
||||
// // 指定[认证函数]: 每次请求执行
|
||||
// .setAuth(r -> {
|
||||
// System.out.println("---------- sa全局认证");
|
||||
// SaRouterUtil.match("/test/test", () -> StpUtil.checkLogin());
|
||||
// })
|
||||
// // 指定[异常处理函数]:每次[认证函数]发生异常时执行此函数
|
||||
// .setError(e -> {
|
||||
// System.out.println("---------- sa全局异常 ");
|
||||
// return AjaxJson.getError(e.getMessage());
|
||||
// })
|
||||
// ;
|
||||
// }
|
||||
/**
|
||||
* 注册 [sa-token全局过滤器]
|
||||
*/
|
||||
@Bean
|
||||
public SaServletFilter getSaReactorFilter() {
|
||||
return new SaServletFilter()
|
||||
|
||||
// 指定 [拦截路由] 与 [放行路由]
|
||||
.addInclude("/**").addExclude("/favicon.ico")
|
||||
|
||||
// 认证函数: 每次请求执行
|
||||
.setAuth(r -> {
|
||||
System.out.println("---------- sa全局认证");
|
||||
|
||||
SaRouterUtil.match("/test/test", () -> new Object());
|
||||
})
|
||||
|
||||
// 异常处理函数:每次认证函数发生异常时执行此函数
|
||||
.setError(e -> {
|
||||
System.out.println("---------- sa全局异常 ");
|
||||
return AjaxJson.getError(e.getMessage());
|
||||
})
|
||||
|
||||
// 前置函数:在每次认证函数之前执行
|
||||
.setBeforeAuth(r -> {
|
||||
// ---------- 设置一些安全响应头 ----------
|
||||
SaHolder.getResponse()
|
||||
// 服务器名称
|
||||
.setServer("sa-server")
|
||||
// 是否可以在iframe显示视图: DENY=不可以 | SAMEORIGIN=同域下可以 | ALLOW-FROM uri=指定域名下可以
|
||||
.setHeader("X-Frame-Options", "SAMEORIGIN")
|
||||
// 是否启用浏览器默认XSS防护: 0=禁用 | 1=启用 | 1; mode=block 启用, 并在检查到XSS攻击时,停止渲染页面
|
||||
.setHeader("X-Frame-Options", "1; mode=block")
|
||||
// 禁用浏览器内容嗅探
|
||||
.setHeader("X-Content-Type-Options", "nosniff")
|
||||
;
|
||||
})
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -20,7 +20,6 @@ spring:
|
||||
# 是否输出操作日志
|
||||
is-log: false
|
||||
|
||||
|
||||
# redis配置
|
||||
redis:
|
||||
# Redis数据库索引(默认为0)
|
||||
@@ -44,4 +43,12 @@ spring:
|
||||
# 连接池中的最小空闲连接
|
||||
min-idle: 0
|
||||
|
||||
|
||||
|
||||
# 静态文件路径映射
|
||||
resources:
|
||||
static-locations: file:E:\work\project-yun\sa-admin
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user