【发布时间】:2018-05-31 07:35:46
【问题描述】:
有谁知道如何使用复杂对象作为spring安全权限,而不是实现自定义accessDecisionManager。我不想实现自定义 accessDecisionManager,因为我还需要重新实现角色投票者,这适用于 SPeL,并且认为这不是一个好主意。
【问题讨论】:
标签: spring-security
有谁知道如何使用复杂对象作为spring安全权限,而不是实现自定义accessDecisionManager。我不想实现自定义 accessDecisionManager,因为我还需要重新实现角色投票者,这适用于 SPeL,并且认为这不是一个好主意。
【问题讨论】:
标签: spring-security
是的,可能最简单的方法是连接 bean:
@Component
public class MyAuthorizer {
boolean authorize(Authentication authentication) {
// do your custom checking here
}
}
然后
@Controller
public class MyController {
@PreAuthorize("@myAuthorizer.authorize(authentication)")
// ... request mapping, etc
}
或者,如果可以将您的复杂对象简化为字符串,hasAuthority 将像使用简单权限一样工作:
public class MyCustomAuthority implements GrantedAuthority {
Object all;
Object my;
Object complexity;
public String getAuthority() {
return String.valueOf(this.complexity);
}
}
【讨论】: