Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
有来技术
youlai-mall
提交
c3f37a18
Y
youlai-mall
项目概览
有来技术
/
youlai-mall
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
youlai-mall
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c3f37a18
编写于
9月 23, 2020
作者:
H
haoxr
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
docs:README添加文章链接
上级
cf57c59e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
21 addition
and
17 deletion
+21
-17
README.md
README.md
+9
-8
youlai-gateway/src/main/java/com/youlai/gateway/component/AuthorizationManager.java
...va/com/youlai/gateway/component/AuthorizationManager.java
+12
-9
未找到文件。
README.md
浏览文件 @
c3f37a18
...
...
@@ -71,16 +71,17 @@ youlai-mall
## 项目文档
1.
[
SpringCloud实战 | 第一篇:Windows搭建Nacos服务
](
https://www.cnblogs.com/haoxianrui/p/13581881.html
)
2.
[
SpringCloud实战 | 第二篇:SpringCloud整合Nacos实现注册中心
](
https://www.cnblogs.com/haoxianrui/p/13584204.html
)
3.
[
SpringCloud实战 | 第三篇:SpringCloud整合Nacos实现配置中心
](
https://www.cnblogs.com/haoxianrui/p/13585125.html
)
4.
[
SpringCloud实战 | 第四篇:SpringCloud整合Gateway实现API网关
](
https://www.cnblogs.com/haoxianrui/p/13608650.html
)
5.
[
SpringCloud实战 | 第五篇:SpringCloud整合OpenFeign实现微服务之间的调用
](
https://www.cnblogs.com/haoxianrui/p/13615592.html
)
6.
[
vue-element-admin实战 | 第一篇: 移除mock接入后台,搭建有来商城youlai-mall前后端分离管理平台
](
https://www.cnblogs.com/haoxianrui/p/13624548.html
)
7.
[
vue-element-admin实战 | 第二篇: 最小改动接入后台实现根据权限动态加载菜单
](
https://www.cnblogs.com/haoxianrui/p/13676619.html
)
1.
[
Spring Cloud实战 | 第一篇:Windows搭建Nacos服务
](
https://www.cnblogs.com/haoxianrui/p/13581881.html
)
2.
[
Spring Cloud实战 | 第二篇:Spring Cloud整合Nacos实现注册中心
](
https://www.cnblogs.com/haoxianrui/p/13584204.html
)
3.
[
Spring Cloud实战 | 第三篇:Spring Cloud整合Nacos实现配置中心
](
https://www.cnblogs.com/haoxianrui/p/13585125.html
)
4.
[
Spring Cloud实战 | 第四篇:Spring Cloud整合Gateway实现API网关
](
https://www.cnblogs.com/haoxianrui/p/13608650.html
)
5.
[
Spring Cloud实战 | 第五篇:Spring Cloud整合OpenFeign实现微服务之间的调用
](
https://www.cnblogs.com/haoxianrui/p/13615592.html
)
6.
[
Spring Cloud实战 | 第六篇:Spring Cloud Gateway+Spring Security OAuth2+JWT实现微服务统一认证授权
](
https://www.cnblogs.com/haoxianrui/p/13719356.html
)
7.
[
vue-element-admin实战 | 第一篇: 移除mock接入后台,搭建有来商城youlai-mall前后端分离管理平台
](
https://www.cnblogs.com/haoxianrui/p/13624548.html
)
8.
[
vue-element-admin实战 | 第二篇: 最小改动接入后台实现根据权限动态加载菜单
](
https://www.cnblogs.com/haoxianrui/p/13676619.html
)
## 问题
项目在搭建的过程中如您遇到任何问题,都可以联系我
帮你解决
(微信号:haoxianrui)。
项目在搭建的过程中如您遇到任何问题,都可以联系我(微信号:haoxianrui)。
youlai-gateway/src/main/java/com/youlai/gateway/component/AuthorizationManager.java
浏览文件 @
c3f37a18
...
...
@@ -6,6 +6,7 @@ import com.youlai.common.core.constant.AuthConstants;
import
com.youlai.gateway.config.WhiteListConfig
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.logging.log4j.util.Strings
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.server.reactive.ServerHttpRequest
;
...
...
@@ -20,10 +21,7 @@ import org.springframework.util.PathMatcher;
import
reactor.core.publisher.Mono
;
import
java.net.URI
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.*
;
/**
* 鉴权管理器
...
...
@@ -39,15 +37,17 @@ public class AuthorizationManager implements ReactiveAuthorizationManager<Author
@Override
public
Mono
<
AuthorizationDecision
>
check
(
Mono
<
Authentication
>
mono
,
AuthorizationContext
authorizationContext
)
{
ServerHttpRequest
request
=
authorizationContext
.
getExchange
().
getRequest
();
URI
uri
=
request
.
getURI
();
// 白名单路径直接放行
String
path
=
request
.
getURI
().
getPath
();
PathMatcher
pathMatcher
=
new
AntPathMatcher
();
// 白名单路径直接放行
List
<
String
>
whiteList
=
whiteListConfig
.
getUrls
();
for
(
String
ignoreUrl
:
whiteList
)
{
if
(
pathMatcher
.
match
(
ignoreUrl
,
uri
.
getPath
()
))
{
if
(
pathMatcher
.
match
(
ignoreUrl
,
path
))
{
return
Mono
.
just
(
new
AuthorizationDecision
(
true
));
}
}
// 对应跨域的预检请求直接放行
if
(
request
.
getMethod
()
==
HttpMethod
.
OPTIONS
)
{
return
Mono
.
just
(
new
AuthorizationDecision
(
true
));
...
...
@@ -64,10 +64,10 @@ public class AuthorizationManager implements ReactiveAuthorizationManager<Author
Iterator
<
Object
>
iterator
=
resourceRolesMap
.
keySet
().
iterator
();
// 请求路径匹配到的资源需要的角色权限集合authorities统计
List
<
String
>
authorities
=
new
ArrayLis
t
<>();
Set
<
String
>
authorities
=
new
HashSe
t
<>();
while
(
iterator
.
hasNext
())
{
String
pattern
=
(
String
)
iterator
.
next
();
if
(
pathMatcher
.
match
(
pattern
,
uri
.
getPath
()
))
{
if
(
pathMatcher
.
match
(
pattern
,
path
))
{
authorities
.
addAll
(
Convert
.
toList
(
String
.
class
,
resourceRolesMap
.
get
(
pattern
)));
}
}
...
...
@@ -77,6 +77,9 @@ public class AuthorizationManager implements ReactiveAuthorizationManager<Author
.
map
(
GrantedAuthority:
:
getAuthority
)
.
any
(
roleId
->
{
// roleId是请求用户的角色(格式:ROLE_{roleId}),authorities是请求资源所需要角色的集合
log
.
info
(
"访问路径:{}"
,
path
);
log
.
info
(
"用户角色信息:{}"
,
roleId
);
log
.
info
(
"资源需要权限authorities:{}"
,
authorities
);
return
authorities
.
contains
(
roleId
);
})
.
map
(
AuthorizationDecision:
:
new
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录