我是一个春季启动应用程序,我试图实现扩展标准@RolesAllowed
的自定义授权架构。
我创建了一个自定义AccessDecisionManage
r,它读取@RolesAllowed
,如果有一个用我的自定义注释注释的参数,我将检查用户是否在指定范围内具有指定的角色
@RequestMapping(value = "/{id}/user/list", method = RequestMethod.GET)
@RolesAllowed("manager")
public List<User> userList(@PathVariable("id") @AuthScope Project project) throws NotFoundException {
return projectService.findUsersByProject(project);
}
我已经使用我的自定义授权架构所需的逻辑实现了AccessDecisionManager
,但我现在无法配置应用安全性以使用此AccessDecisionManager
。
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.accessDecisionManager(accessDecisionManager())
.anyRequest().permitAll()
.and()
.csrf()
.disable()
.httpBasic();
}
以下是我遇到的错误:
AccessDecisionManager does not support secure object class: class org.springframework.security.web.FilterInvocation
关于我做错的任何想法? 干杯
答案 0 :(得分:0)
您要求将AccessDecisionManager
应用于HTTP过滤器链(通过在HttpSecurity
中进行处理),但是(不看代码)我猜它不是意味着支持这一点。它更有可能与GlobalMethodSecurityConfiguration
一起使用。我认为您需要扩展该类添加覆盖accessDecisionManager()
方法。例如:https://spring.io/blog/2013/07/04/spring-security-java-config-preview-method-security/。
答案 1 :(得分:0)
你是对的@Dave,这就是我设法让它发挥作用的方式。
public class MethodSecurityConfiguration extends GlobalMethodSecurityConfiguration {
@Override
protected AccessDecisionManager accessDecisionManager() {
return new AuthScopeDecisionManager();
}
}