How do I use custom roles/authorities in Spring Security?

前端 未结 5 1130
遥遥无期
遥遥无期 2020-12-02 08:37

While migrating a legacy application to spring security I got the following exception:

org.springframework.beans.factory.BeanCreationException: Error creatin         


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 09:28

    You can also always using expression (by config use-expressions="true") to ignore ROLE_ prefix.

    After reading Spring Security 3.1 source code, I found when use-expressions="true" :

    For :
    HttpConfigurationBuilder#createFilterSecurityInterceptor() will regist WebExpressionVoter but not RoleVoterAuthenticatedVoter;

    For : GlobalMethodSecurityBeanDefinitionParser#registerAccessManager() will regist PreInvocationAuthorizationAdviceVoter (conditionally), then always regist RoleVoterAuthenticatedVoter, regist Jsr250Voter conditionally;

    PreInvocationAuthorizationAdviceVoter will process PreInvocationAttribute (PreInvocationExpressionAttribute will be used as implementation) which is generated according @PreAuthorize. PreInvocationExpressionAttribute#getAttribute() always return null, so RoleVoterAuthenticatedVoter do not vote it.

提交回复
热议问题