Are multiple roles allowed in the @Secured annotation with 'or' condition in Spring Security

前端 未结 3 945
忘掉有多难
忘掉有多难 2020-12-31 02:09

I am using spring and spring security 4 in my project. I have to call my dao method with ROLE_USER or ROLE_TIMER_TASK.

Currently I am using this annotation -

<
3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-31 02:55

    To call the method by any of the role mentioned use:

    @PreAuthorize("hasAnyRole('ROLE_USER','ROLE_TIMER_TASK')")
    

    and enable pre- and post- annotations in security Class :

    @EnableGlobalMethodSecurity(prePostEnabled = true)
    

提交回复
热议问题