我使用的是具有java配置和两个HttpSecurity配置的spring-security 3.2.0.RC2。一个用于REST API,另一个用于UI。 当我发布到/注销它重定向到/ login?注销,但然后(不正确)重定向到/登录。 当我成功输入用户名和密码时,我将重定向到登录?注销,并且必须再次输入凭据以进入主页面。 所以看起来像permitAll登录是不是荣幸的登录?注销。弹簧安全登录?注销重定向登录
我的安全配置是这样的:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Resource
private MyUserDetailsService userDetailsService;
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth)
throws Exception {
StandardPasswordEncoder encoder = new StandardPasswordEncoder();
auth.userDetailsService(userDetailsService).passwordEncoder(encoder);
}
@Configuration
@Order(1)
public static class RestSecurityConfig
extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.antMatcher("/v1/**").authorizeRequests()
.antMatchers("/v1/admin/**").hasRole("admin")
.antMatchers("/v1/account/**").hasRole("admin")
.antMatchers("/v1/plant/**").access("hasRole('admin') or hasRole('dataProvider')")
.antMatchers("/v1/upload/**").access("hasRole('admin') or hasRole('dataProvider')")
.antMatchers("/v1/**").authenticated()
.and().httpBasic();
}
}
@Configuration
@Order(2)
public static class UiSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/resources/**");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/account/**").hasRole("admin")
.antMatchers("/admin/**").hasRole("admin")
.antMatchers("/plant/**").access("hasRole('admin') or hasRole('dataProvider')")
.antMatchers("/upload/**").access("hasRole('admin') or hasRole('dataProvider')")
.anyRequest().authenticated()
.and().formLogin().loginPage("/login").permitAll();
}
}
}
任何人都可以解释为什么发生这种情况或有什么不对我的配置?
我看到这个配置的第二个问题是,虽然sec:authorize access = ... does not work,但是jsp标签sec:authorize url = ...不起作用。 在url = ...大小写的情况下,即使用户未被授权,也会始终显示内容。 我知道用户没有被授权,因为它应该已经被sec隐藏的链接:授权标签导致403 Forbidden。
对此的任何帮助非常感谢!
这解决了我的问题 - 但我仍然不确定是什么让重定向登录?注销 - 我没有在我的代码在任何地方......是一个春季安全的事情? –
@wwarren很高兴帮助。当春季安全处理注销时,重定向到登录?注销以显示“您已被注销”的登录页面。信息。 – shawnim