Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
shengzhang_
sa-token
提交
5e97c5d7
sa-token
项目概览
shengzhang_
/
sa-token
通知
68
Star
16
Fork
4
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
sa-token
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
5e97c5d7
编写于
4月 15, 2021
作者:
shengzhang_
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
重构:全局过滤器执行函数放到成员变量里
上级
b7859b67
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
55 addition
and
49 deletion
+55
-49
sa-token-core/src/main/java/cn/dev33/satoken/filter/SaFilterAuthStrategy.java
...in/java/cn/dev33/satoken/filter/SaFilterAuthStrategy.java
+1
-1
sa-token-doc/doc/README.md
sa-token-doc/doc/README.md
+1
-1
sa-token-doc/doc/fun/session-model.md
sa-token-doc/doc/fun/session-model.md
+1
-1
sa-token-doc/doc/lib/index.css
sa-token-doc/doc/lib/index.css
+5
-0
sa-token-doc/doc/use/global-filter.md
sa-token-doc/doc/use/global-filter.md
+29
-42
sa-token-doc/index.css
sa-token-doc/index.css
+9
-1
sa-token-doc/index.html
sa-token-doc/index.html
+9
-3
未找到文件。
sa-token-core/src/main/java/cn/dev33/satoken/filter/SaFilterStrategy.java
→
sa-token-core/src/main/java/cn/dev33/satoken/filter/SaFilter
Auth
Strategy.java
浏览文件 @
5e97c5d7
...
...
@@ -5,7 +5,7 @@ package cn.dev33.satoken.filter;
* @author kong
*
*/
public
interface
SaFilterStrategy
{
public
interface
SaFilter
Auth
Strategy
{
/**
* 执行方法
...
...
sa-token-doc/doc/README.md
浏览文件 @
5e97c5d7
...
...
@@ -122,7 +122,7 @@ sa-token API 众多,请恕此处无法为您逐一展示,更多示例请戳
## Star 趋势
[
![
Giteye
chart
](
https://chart.giteye.net/gitee/dromara/sa-token/77YQZ6UK.png
'Gitee'
)
](https://giteye.net/chart/77YQZ6UK)
[
![
giteye-
chart
](
https://chart.giteye.net/gitee/dromara/sa-token/77YQZ6UK.png
'Gitee'
)
](https://giteye.net/chart/77YQZ6UK)
[
![github-chart
](
https://starchart.cc/dromara/sa-token.svg
'GitHub'
)
](https://starchart.cc/dromara/sa-token)
...
...
sa-token-doc/doc/fun/session-model.md
浏览文件 @
5e97c5d7
...
...
@@ -10,7 +10,7 @@
User-Session和Token-Session到底有什么不同?下面这张图可以解释两者的区别
![
../static/session-model.png
](
../static/session-model.png
)
![
session-model
](
https://oss.dev33.cn/sa-token/doc/session-model2.png
's-w'
)
简而言之:
-
`Token-Session`
以token为主,只要token不同,那么对应的Session对象就不同
...
...
sa-token-doc/doc/lib/index.css
浏览文件 @
5e97c5d7
...
...
@@ -20,6 +20,11 @@ body{font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu
/* GitHub折线图最大宽度 */
[
alt
=
github-chart
]
{
max-width
:
897px
;}
/* 大屏幕时,某些图片限制一下宽度 */
@media
screen
and
(
min-width
:
800px
)
{
[
title
=
s-w
]
{
max-width
:
80%
;}
}
/* 公众号table */
.gzh-table
{
/* table-layout:fixed !important; */
}
...
...
sa-token-doc/doc/use/global-filter.md
浏览文件 @
5e97c5d7
...
...
@@ -33,50 +33,39 @@ public class SaTokenConfigure {
*/
@Bean
public
SaServletFilter
getSaReactorFilter
()
{
return
new
SaServletFilter
()
.
addInclude
(
"/**"
)
.
addExclude
(
"/favicon.ico"
);
}
/**
* 注册 [sa-token全局过滤器-认证策略]
*/
@Bean
public
SaFilterStrategy
getSaFilterStrategy
()
{
return
r
->
{
System
.
out
.
println
(
"---------- 进入sa-token全局过滤器 -----------"
);
// 登录验证 -- 拦截所有路由,并排除/user/doLogin 用于开放登录
SaRouterUtil
.
match
(
"/**"
,
"/user/doLogin"
,
()
->
StpUtil
.
checkLogin
());
// 权限认证 -- 不同模块, 校验不同权限
SaRouterUtil
.
match
(
"/user/**"
,
()
->
StpUtil
.
checkPermission
(
"user"
));
SaRouterUtil
.
match
(
"/admin/**"
,
()
->
StpUtil
.
checkPermission
(
"admin"
));
SaRouterUtil
.
match
(
"/goods/**"
,
()
->
StpUtil
.
checkPermission
(
"goods"
));
SaRouterUtil
.
match
(
"/orders/**"
,
()
->
StpUtil
.
checkPermission
(
"orders"
));
SaRouterUtil
.
match
(
"/notice/**"
,
()
->
StpUtil
.
checkPermission
(
"notice"
));
SaRouterUtil
.
match
(
"/comment/**"
,
()
->
StpUtil
.
checkPermission
(
"comment"
));
// 匹配 restful 风格路由
SaRouterUtil
.
match
(
"/article/get/{id}"
,
()
->
StpUtil
.
checkPermission
(
"article"
));
};
}
/**
* 注册 [sa-token全局过滤器-异常处理策略]
*/
@Bean
public
SaFilterErrorStrategy
getSaFilterErrorStrategy
()
{
return
e
->
AjaxJson
.
getError
(
e
.
getMessage
());
return
new
SaServletFilter
()
// 指定 [拦截路由]
.
addInclude
(
"/**"
)
// 指定 [放行路由]
.
addExclude
(
"/favicon.ico"
)
// 指定[认证函数]: 每次请求执行
.
setAuth
(
r
->
{
System
.
out
.
println
(
"---------- 进入sa-token全局认证 -----------"
);
// 登录验证 -- 拦截所有路由,并排除/user/doLogin 用于开放登录
SaRouterUtil
.
match
(
"/**"
,
"/user/doLogin"
,
()
->
StpUtil
.
checkLogin
());
// 更多拦截处理方式,请参考“路由拦截式鉴权”章节
})
// 指定[异常处理函数]:每次[认证函数]发生异常时执行此函数
.
setError
(
e
->
{
System
.
out
.
println
(
"---------- 进入sa-token异常处理 -----------"
);
return
AjaxJson
.
getError
(
e
.
getMessage
());
})
;
}
}
```
### 注意事项
-
在
`[认证
策略]`
里,你可以和拦截器里一致的代码,进行路由匹配鉴权
-
由于过滤器中抛出的异常不进入全局异常处理,所以你必须提供
`[异常处理
策略]`
来处理
`[认证策略
]`
里抛出的异常
-
在
`[异常处理
策略
]`
里的返回值,将作为字符串输出到前端,如果需要定制化返回数据,请注意其中的格式转换
-
在
`[认证
函数]`
里,你可以写和拦截器里一致的代码,进行路由匹配鉴权,参考:
[
路由拦截式鉴权
](
/use/route-check
)
-
由于过滤器中抛出的异常不进入全局异常处理,所以你必须提供
`[异常处理
函数]`
来处理
`[认证函数
]`
里抛出的异常
-
在
`[异常处理
函数
]`
里的返回值,将作为字符串输出到前端,如果需要定制化返回数据,请注意其中的格式转换
### 在WebFlux中使用过滤器
...
...
@@ -96,12 +85,10 @@ public class SaTokenConfigure {
@Bean
public
SaReactorFilter
getSaReactorFilter
()
{
return
new
SaReactorFilter
()
.
addInclude
(
"/**"
)
.
addExclude
(
"/favicon.ico"
)
;
// 其它代码...
;
}
// 其它代码 ...
}
```
\ No newline at end of file
sa-token-doc/index.css
浏览文件 @
5e97c5d7
...
...
@@ -35,7 +35,7 @@ body{font-size: 16px; color: #34495E; font-family: "Source Sans Pro","Helvetica
.title-logo:hover{transform: scale(1.2, 1.2);} */
.sub-title
{
font-size
:
26px
;
font-weight
:
400
;
margin-top
:
30px
;
margin-bottom
:
25px
;
color
:
#6a8bad
;
color
:
#444
;}
.content-box
p
{
line-height
:
30px
;
padding
:
0px
1em
;}
/* .content-box p{line-height: 30px; padding: 0px 1em;} */
.main-box
{
animation
:
changes
60s
0.2s
linear
infinite
normal
;
background-attachment
:
;}
/* normal | alternate */
@keyframes
changes
{
...
...
@@ -60,6 +60,9 @@ body{font-size: 16px; color: #34495E; font-family: "Source Sans Pro","Helvetica
}
/* 微信二维码 */
.wx-qr-box
{
margin-top
:
50px
;
margin-bottom
:
20px
;}
.qr-item
{
display
:
inline-block
;}
.qr-item
p
{
font-size
:
12px
;
padding
:
0
0.5em
;}
/* .qr-item a{color: #42B983;} */
.wx-qr
{
width
:
150px
;}
.wx-qr-box
p
{
margin-top
:
10px
;
color
:
#666
;}
.wx-qr
,
.dro-qr
{
cursor
:
pointer
;}
...
...
@@ -134,6 +137,11 @@ body{font-size: 16px; color: #34495E; font-family: "Source Sans Pro","Helvetica
footer
{
position
:
static
;
line-height
:
40px
;}
}
@media
screen
and
(
min-width
:
1700px
)
{
.content-box
h1
{
margin-top
:
120px
;}
}
/* 闪光背景 */
/* .main-box{
background-size: 500%;
...
...
sa-token-doc/index.html
浏览文件 @
5e97c5d7
...
...
@@ -51,7 +51,7 @@
<div
class=
"btn-box"
>
<a
href=
"https://github.com/dromara/sa-token"
target=
"_blank"
>
GitHub
</a>
<a
href=
"https://gitee.com/dromara/sa-token"
target=
"_blank"
>
码云
</a>
<
a
href=
"https://jq.qq.com/?_wv=1027&k=45H977HM"
target=
"_blank"
>
加QQ群
</a
>
<
!-- <a href="https://jq.qq.com/?_wv=1027&k=45H977HM" target="_blank">加QQ群</a> --
>
<!-- <a href="http://sa-app.dev33.cn/wall.html?name=sa-token" target="_blank">需求墙</a> -->
<a
href=
"doc/index.html"
target=
"_self"
class=
"doc-btn"
>
开发文档
</a>
</div>
...
...
@@ -65,8 +65,14 @@
<a
href=
"https://github.com/dromara/sa-token/blob/master/LICENSE"
><img
src=
"https://img.shields.io/github/license/dromara/sa-token.svg?style=flat-square"
></a>
</h4>
<div
class=
"wx-qr-box"
>
<img
class=
"wx-qr"
src=
"https://oss.dev33.cn/sa-token/wx-qr-300.png"
>
<p
style=
""
>
(扫码加入微信交流群,请备注: sa)
</p>
<div
class=
"qr-item"
>
<img
class=
"wx-qr"
src=
"https://oss.dev33.cn/sa-token/qq-group.png"
>
<p
style=
""
>
QQ交流群: 1002350610
<a
href=
"https://jq.qq.com/?_wv=1027&k=45H977HM"
target=
"_blank"
>
点击加入
</a></p>
</div>
<div
class=
"qr-item"
>
<img
class=
"wx-qr"
src=
"https://oss.dev33.cn/sa-token/wx-qr-300.png"
>
<p>
微信交流群:扫码加入 (请备注: sa)
</p>
</div>
</div>
</div>
</div>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录