【发布时间】:2017-10-15 06:43:48
【问题描述】:
这实际上是两个问题,因为 Spring Security 参考中没有很好地解释它。第一个问题是,在我的配置中,我有这样的代码:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/admin").hasRole("ADMIN")
.antMatchers("/admin").access("hasRole('ADMIN')");
那么在这两种情况下,Spring 在哪里寻找当前用户的角色呢?是否可能在 UserDetailsService 上调用 loadUserByUsername() 方法,然后在获取的 UserDetails 上调用 getAuthorities()?
我的第二个问题是关于 hasPermission() 表达式。假设我有一个自定义的 PermissionEvaluator,有没有办法让它在配置类中工作,例如:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/admin").access("hasPermission(...)")
或者这是一个只在方法级别起作用的表达式?
【问题讨论】:
标签: java spring spring-security