我正在使用Spring Security 4.1版。如果我在安全配置中指定了access="hasRole('ROLE_ADMIN')"
或access="ROLE_ADMIN"
,我可以登錄,但我無法訪問我的管理頁面。Spring Security不支持「hasRole('ROLE_ADMIN')」或ROLE_ADMIN
<security:http use-expressions="true">
<security:intercept-url pattern="/admin/**" access="hasRole('ROLE_ADMIN')" />
<!-- security:intercept-url pattern="/admin" access="hasRole('ROLE_ADMIN')"/-->
<security:intercept-url pattern="/createmanufsensors" access="isAuthenticated()" />
</security:http>
<security:global-method-security secured-annotations="enabled"></security:global-method-security>
下面是調試錯誤:
DEBUG [http-bio-8080-exec-10] [org.springframework.security.web.access.intercept.FilterSecurityInterceptor] Secure object: FilterInvocation: URL: /admin; Attributes: [hasRole('ROLE_ADMIN')]
2016-06-25 10:07:53,667 [] DEBUG [http-bio-8080-exec-10] [org.springframework.security.web.access.intercept.FilterSecurityInterceptor] Previously Authenticated: org.springframew[email protected]cc305a73: Principal: [email protected]: Username: francatore ; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_ADMIN ; Credentials: [PROTECTED]; Authenticated: true; Details: org.sprin[email protected]166c8: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: 7F702A6911A71EA5556C750B6D424FF5; Granted Authorities: ROLE_ADMIN
2016-06-25 10:07:53,667 [] DEBUG [http-bio-8080-exec-10] [org.springframework.security.access.vote.AffirmativeBased] Voter: org.sp[email protected]170ea084, returned: -1
2016-06-25 10:07:53,668 [] DEBUG [http-bio-8080-exec-10] [org.springframework.security.web.access.ExceptionTranslationFilter] Access is denied (user is not anonymous); delegating to AccessDeniedHandler
我該怎麼辦可能會丟失?
當用戶創建並記帳時,捲筒會分配給用戶。上面的用戶被分配了'ROLE_ADMIN',而其餘的用戶被分配了'ROLE_USER'。角色保存在數據庫的權限表中。 –