【问题标题】:Spring Security - No Access After Successful AuthenticationSpring Security - 成功认证后无法访问
【发布时间】: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


    【解决方案1】:

    我找到了解决办法。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-30
      • 2022-09-23
      • 2021-01-27
      • 2021-02-17
      • 2021-05-30
      • 2018-08-07
      • 2019-06-03
      • 1970-01-01
      相关资源
      最近更新 更多