提交 c3f37a18 编写于 作者: H haoxr

docs:README添加文章链接

上级 cf57c59e
......@@ -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)。
......@@ -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 ArrayList<>();
Set<String> authorities = new HashSet<>();
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.
先完成此消息的编辑!
想要评论请 注册