【发布时间】:2017-06-13 15:44:38
【问题描述】:
我正在尝试为 Web 应用程序添加身份验证。 用户已成功通过登录页面,但他们仍然无法访问任何其他页面。
最初我认为问题与 Active Directory 有关,但在切换到内存身份验证进行调试后,我发现两者都无法正常工作。
这是我的安全配置:
@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf()
.disable()
.authorizeRequests()
.antMatchers("/css/**").permitAll()
.antMatchers("/js/**").permitAll()
.antMatchers("/img/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.and()
.logout()
.permitAll();
}
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user").password("test").roles("USER");
}
}
登录后,我在日志中验证成功:
Authentication event AuthenticationSuccessEvent: user; details: org.springframework.security.web.authentication.WebAuthenticationDetails@b364: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: null
Authentication event InteractiveAuthenticationSuccessEvent: user; details: org.springframework.security.web.authentication.WebAuthenticationDetails@b364: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: null
但是,我被重定向回登录页面,而不是请求的资源。手动导航到资源仍然让我重定向回登录页面。
我的错误很明显,还是我遗漏了什么?
【问题讨论】:
标签: spring-security