【问题标题】:Spring Security Authenticates and immediately returns Access DeniedSpring Security 验证并立即返回拒绝访问
【发布时间】:2014-02-22 21:22:05
【问题描述】:

此文本在本地运行时直接来自我的控制台记录器。第二行紧跟第一行。我不确定提供访问被拒绝异常的幕后发生了什么。

2014-01-30 07:48:14.854  INFO 5452 --- [nio-8085-exec-3] o.s.b.a.audit.listener.AuditListener     : AuditEvent [timestamp=Thu Jan 30 07:48:14 CST 2014, principal=r2n, type=AUTHENTICATION_SUCCESS, data={details=org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: 2C7EC273522BB6880EE3410201F8A41F}]

2014-01-30 07:48:14.859  INFO 5452 --- [nio-8085-exec-4] o.s.b.a.audit.listener.AuditListener     : AuditEvent [timestamp=Thu Jan 30 07:48:14 CST 2014, principal=r2n, type=AUTHORIZATION_FAILURE, data={message=Access is denied, type=org.springframework.security.access.AccessDeniedException}]

我的代码是使用 Spring Boot 版本 1.0.0.RC1、Spring Security 3.1.0.Release 和用于 spring 2.1.1.Release 的 thymeleaf 编译的。我知道由于 Spring Boot 使用 Spring 4,因此 Spring 3 的基础 Spring 依赖项和 thymeleaf 存在一些冲突。

我不认为我的问题在于他们。

这是来自 WebSecurityConfiguration 扩展 WebSecurityConfigurerAdapter 的代码。我的身份验证是使用 ldap。

@Override
  protected void configure(HttpSecurity http) throws Exception {
    http
        .authorizeRequests()
            .antMatchers("/error").anonymous()
            .antMatchers("/navigation").anonymous()
            .antMatchers("/**").hasRole("ADMIN") // #4
            .and()
        .formLogin()
            .permitAll()
            .defaultSuccessUrl("/")
            .and()
        .csrf().disable();
  }

【问题讨论】:

    标签: spring-security spring-ldap spring-boot


    【解决方案1】:

    您的“r2n”用户似乎没有“ADMIN”权限。也许你给他设置了“ROLE_ADMIN”,访问规则是“ADMIN”之类的?

    附:我认为您的意思是 Spring Security 3.2.0.RELEASE(Javaconfig 不在 3.1 中)。

    【讨论】:

      猜你喜欢
      • 2012-02-15
      • 2015-11-13
      • 2018-04-23
      • 2022-01-16
      • 1970-01-01
      • 2015-08-07
      • 2020-12-19
      • 2014-09-25
      • 1970-01-01
      相关资源
      最近更新 更多