Spring 安全性 - 身份验证成功后无法访问



我正在尝试包含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 

但是,我被重定向回登录页面,而不是请求的资源。手动导航到资源仍然会让我重定向回登录页面。

我的错误是显而易见的,还是我错过了什么?

我找到了解决方案。

显然,应用程序配置中的一些配置选项以某种方式干扰了安全上下文会话。

删除它们允许身份验证按预期进行。

最新更新