Spring安全授权检查不起作用

时间:2017-07-23 08:45:04

标签: spring spring-mvc spring-security

我有以下内容。

@EnableWebSecurity
@Configuration
public class RetailerSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http
                .csrf().ignoringAntMatchers("/login/**")
                .and()
                .authorizeRequests()
                .antMatchers("/login", "/login/reset", "/resources/**", "/balance/getResult/**").permitAll()
                .anyRequest().fullyAuthenticated()
                .antMatchers("/retailers/**", "/balance/**").access("hasRole('ROLE_ADMIN')")
                .antMatchers("/tellers/**", "/tellers").hasAnyAuthority("PRIMARY")
                .antMatchers("/sell/**", "/sell").hasAnyAuthority("TELLER")
                .and()
                .formLogin()
                .loginPage("/login")
                .successForwardUrl("/login/success")
                .permitAll()
                .and()
                .logout()
                .permitAll();

    }
}

我也试过了一堆其他的排列,似乎都没有。我已经检查过这部分代码是否被执行,它确实执行并且没有错误。

修改

忘记提及,经过身份验证的用户无法访问所有网址。但任何经过身份验证的用户都可以访问所有网址。 E.g以PRIMARY身份登录,我可以点/sell/retailers/create这不应该发生。

我的事情已经不多了。嗯......我已经出去了。我该怎么检查?

1 个答案:

答案 0 :(得分:0)

很奇怪,但在权限设置修复之前移动AL。最后它看起来像这样

anyRequest().fullyAuthenticated()
相关问题