【问题标题】:Spring security authorization not working though the roles provided correctly尽管正确提供了角色,但 Spring 安全授权不起作用
【发布时间】:2017-03-24 09:54:37
【问题描述】:
http.authorizeRequests().antMatchers("/dms**").access("hasAnyRole('admin','dms')");

用户应具有 admin 或 dms 角色才能导航到该页面。 我以管理员身份登录。

从日志中我可以看到正确匹配的角色(数据库角色和登录用户角色)

Granted Authorities: admin

但我仍然可以看到访问被拒绝。任何线索? 完整的日志在这里

2016-11-10 16:41:46 DEBUG AntPathRequestMatcher:157 - Checking match of 
request : '/dms.jsp'; against '/dms**'
2016-11-10 16:41:46 DEBUG FilterSecurityInterceptor:219 - Secure object: FilterInvocation: URL: /dms.jsp; Attributes: [hasAnyRole('admin','dms')]
2016-11-10 16:41:46 DEBUG FilterSecurityInterceptor:348 - Previously Authenticated: org.springframework.security.authentication.UsernamePasswordAuthenticationToken@9546: Principal: org.springframework.security.core.userdetails.User@586034f: Username: admin; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: admin; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@ffff6a82: RemoteIpAddress: 127.0.0.1; SessionId: LVXYO0lvcLRvJFcH9pJO_kO2R5B7ha4LLm3DwZ7m; Granted Authorities: admin
2016-11-10 16:41:46 DEBUG AffirmativeBased:66 - Voter: org.springframework.security.web.access.expression.WebExpressionVoter@7ade02ad, returned: -1
2016-11-10 16:41:46 DEBUG ExceptionTranslationFilter:186 - Access is denied (user is not anonymous); delegating to AccessDeniedHandler
org.springframework.security.access.AccessDeniedException: Access is denied
    at org.springframework.security.access.vote.AffirmativeBased.decide(AffirmativeBased.java:84)

【问题讨论】:

    标签: java spring spring-mvc spring-security


    【解决方案1】:

    只需为可用角色添加前缀“ROLE_”即可解决问题。 不知道为什么 spring 不允许自己的角色

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-04
      • 2019-06-15
      • 2017-11-25
      • 1970-01-01
      • 2020-11-29
      相关资源
      最近更新 更多