Spring security与access一起工作=";角色“用户”;但艾尔没有
我正在学习使用Spring安全性,并将其集成到web应用程序中。我使用的是Spring和Spring安全版本3.1.2 如果我在安全配置中指定了Spring security与access一起工作=";角色“用户”;但艾尔没有,spring,spring-security,Spring,Spring Security,我正在学习使用Spring安全性,并将其集成到web应用程序中。我使用的是Spring和Spring安全版本3.1.2 如果我在安全配置中指定了access=“ROLE\u USER”,则身份验证工作正常,即我首先收到401,登录后,我能够访问资源 <http> <http-basic /> <logout /> <intercept-url pattern="/exports/**" access
access=“ROLE\u USER”
,则身份验证工作正常,即我首先收到401,登录后,我能够访问资源
<http>
<http-basic />
<logout />
<intercept-url
pattern="/exports/**"
access="ROLE_USER" />
</http>
如果我理解正确的话,WebExpressionVoter投票反对我,尽管身份验证有效
我遗漏了什么?解决方案很简单:只需在
hasRole()
中添加ROLE\uu
,例如:
access="hasRole('ROLE_USER')"
我被第16.2节的一个例子误导了。嘿,我知道这是一个老问题,但在你的研究中,你发现为什么需要这样做了吗?为什么必须在前面加上“角色”?是否所有角色名称都需要此语法?“前缀role_uu的使用是一个标记,用于指示这些属性是角色,应该由Spring Security的RoleVoter使用。这仅在使用基于投票者的AccessDecisionManager时才相关。”
DEBUG org.springframework.security.web.access.intercept.FilterSecurityInterceptor - Previously Authenticated: org.springframework.security.authentication.UsernamePasswordAuthenticationToken@844f42c6: Principal: org.springframework.security.core.userdetails.User@c052d588: Username: test; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_USER; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null; Granted Authorities: ROLE_USER
DEBUG org.springframework.security.access.vote.AffirmativeBased - Voter: org.springframework.security.web.access.expression.WebExpressionVoter@1a15597, returned: -1
DEBUG org.springframework.security.web.access.ExceptionTranslationFilter - Access is denied (user is not anonymous); delegating to AccessDeniedHandler
access="hasRole('ROLE_USER')"