首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring安全授权无法正常工作,尽管正确提供了角色

Spring安全授权无法正常工作,尽管正确提供了角色
EN

Stack Overflow用户
提问于 2016-11-10 19:24:52
回答 1查看 964关注 0票数 0
代码语言:javascript
复制
http.authorizeRequests().antMatchers("/dms**").access("hasAnyRole('admin','dms')");

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

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

代码语言:javascript
复制
Granted Authorities: admin

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

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2016-11-10 20:17:09

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40526445

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档