|
|
@@ -1,6 +1,5 @@
|
|
|
package com.inspur.smsb.gateway.config;
|
|
|
|
|
|
-import cn.hutool.core.convert.Convert;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
|
|
@@ -29,17 +28,15 @@ public class AuthorizationManager implements ReactiveAuthorizationManager<Author
|
|
|
String path = request.getURI().getPath();
|
|
|
PathMatcher pathMatcher = new AntPathMatcher();
|
|
|
// todo 资源权限角色关系列表,需要初始化到容器中
|
|
|
- Map<Object, Object> resourceRolesMap = new HashMap<>();
|
|
|
- resourceRolesMap.put("/token/**","force");
|
|
|
- Iterator<Object> iterator = resourceRolesMap.keySet().iterator();
|
|
|
+ Map<String, List<String>> resourceRolesMap = new HashMap<>();
|
|
|
List<String> authorities = new ArrayList<>();
|
|
|
- while (iterator.hasNext()) {
|
|
|
- String pattern = (String) iterator.next();
|
|
|
- if (pathMatcher.match(pattern, path)) {
|
|
|
- authorities.addAll(Convert.toList(String.class, resourceRolesMap.get(pattern)));
|
|
|
+ resourceRolesMap.put("/token/**",Collections.singletonList("force"));
|
|
|
+ resourceRolesMap.forEach((resource, roles) -> {
|
|
|
+ if (pathMatcher.match(resource, path)) {
|
|
|
+ authorities.addAll(roles);
|
|
|
}
|
|
|
- }
|
|
|
- Mono<AuthorizationDecision> authorizationDecisionMono = mono
|
|
|
+ });
|
|
|
+ return mono
|
|
|
.filter(Authentication::isAuthenticated)
|
|
|
.flatMapIterable(Authentication::getAuthorities)
|
|
|
.map(GrantedAuthority::getAuthority)
|
|
|
@@ -51,6 +48,5 @@ public class AuthorizationManager implements ReactiveAuthorizationManager<Author
|
|
|
})
|
|
|
.map(AuthorizationDecision::new)
|
|
|
.defaultIfEmpty(new AuthorizationDecision(false));
|
|
|
- return authorizationDecisionMono;
|
|
|
}
|
|
|
}
|