Reputation: 5367
I'm building a permission based access control with hierarchically permissions for a spring project. For this, I'm extending the GrantedAuthority
object to a Permission
. A custom PermissionVoter
will finally draw benefits out of this, as the single permission parts can be retrieved.
This works as expected. The only problem are my integration tests.
With the annotation @WithMockUser
I can mock a security context. By default this mocking method will create SimpleGrantedAuthority
s. Expecting Permission
s in my voter, this obviously is not going to work. Can I configure @WithMockUser
to use my custom GrantedAuthority
class?
PS. I'm intentionally not using Shiro.
Upvotes: 3
Views: 836
Reputation: 4451
You could instead use @WithUserDetails
which takes a userDetailsService as parameter e.g. userDetailsServiceBeanName = "mockedUserDetailsService"
and a User ("value")
You can then mock your Users and their GrantedAuthorities with the mocked UserDetailsService.
Upvotes: 6