-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
资源服务器对 scope 作用域没有控制 #4
Comments
你好, |
是针对客户端的访问作用域。看到最后一次提交使用了 |
spring security方法级别的权限控制都差不多是这样的,如果是想控制某个服务可以配置资源id, @Override
public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
resources.resourceId(RESOURCE_ID).stateless(true);
} // 资源id列表,需要注意的是这里配置的需要与ResourceServerConfig中配置的相匹配,不匹
// 配将权限不足
List<String> resourceIds = new ArrayList<>();
resourceIds.add("auth-server");
resourceIds.add("resource-server");
clientDetails.setResourceIds(resourceIds); |
可使用Spring Security 表达式中的 OAuth2WebSecurityExpressionHandler 重写 @Component
public class AppSecurityExpressionHandler extends OAuth2WebSecurityExpressionHandler {
private final PermissionService permissionService;
@Autowired
public AppSecurityExpressionHandler(PermissionService permissionService) {
this.permissionService = permissionService;
}
@Override
protected StandardEvaluationContext createEvaluationContextInternal(Authentication authentication, FilterInvocation invocation) {
StandardEvaluationContext evaluationContext = super.createEvaluationContextInternal(authentication, invocation);
evaluationContext.setVariable("permissionService", permissionService);
return evaluationContext;
}
} 再重写 @Configuration
@EnableResourceServer
public class OAuth2ResourceServerConfig extends ResourceServerConfigurerAdapter {
private final AppSecurityExpressionHandler expressionHandler;
@Autowired
public OAuth2ResourceServerConfig(AppSecurityExpressionHandler expressionHandler) {
this.expressionHandler = expressionHandler;
}
@Override
public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
resources.expressionHandler(expressionHandler);
}
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/logout").permitAll()
.anyRequest().access("#permissionService.hasPermission(request, authentication)");
}
} |
看到在认证服务器模块, 添加 sever scope 作用域, 但在资源服务器没有区别 sever 和其他作用域怎么控制
The text was updated successfully, but these errors were encountered: