Spring Security验证并立即返回Access Denied

时间:2014-01-30 14:10:26

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

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

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和thymeleaf for spring 2.1.1.Release。我知道春季开始时使用弹簧4时,弹簧依赖关系和百里香叶存在一些冲突。

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

以下是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();
  }

1 个答案:

答案 0 :(得分:2)

您的“r2n”用户似乎没有“ADMIN”权限。也许你用“ROLE_ADMIN”设置他,访问规则是“ADMIN”或其他什么?

P.S。我认为你的意思是Spring Security 3.2.0.RELEASE(Javaconfig不在3.1中)。