spring-security - Spring Security 进行身份验证并立即返回 Access Denied

标签 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 编译的。我知道 Spring 3 的底层 spring 依赖项和 thymeleaf 存在一些冲突,因为 spring boot 使用 spring 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();
  }

最佳答案

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

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

关于spring-security - Spring Security 进行身份验证并立即返回 Access Denied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21458768/

相关文章:

java - 从 Spring Rest api 中的 JPA 查询返回列表

java - Spring Boot Path变量带斜杠的问题

java - Spring Boot with JPA - 列中遇到错误的列类型

spring-mvc - Spring OAuth - 没有 PlatformTransactionManager 类型的合格 bean

Spring Session 不使用自定义 RedisTemplate bean

grails - Grails 2.4.4覆盖springSecurityService

java - Spring Security Active Directory 身份验证但在获取用户数据时抛出异常

java - 如何在 Spring MVC 中创建基于角色的标题菜单控件?

ldap - Spring LDAP ODM-入口类应声明为最终警告

java - 如何使用 Spring 从 ldap 检索只读属性