I'm developing application using Spring Boot, and I'm using Swagger to auto-generate API docs and also I use swagger-ui.html to interact with those APIs.
I have Spring Security enabled too, and I have Users with different roles. Different REST APIs are available to different roles.
Question: how do I configure Swagger to respect Spring's @Secured annotation and trim operations displayed by swagger-ui.html so that only operations available to current user are available?
I.e. imagine following controller
@RestController
@Secured(ROLE_USER)
public void SomeRestController {
@GetMapping
@Secured(ROLE_USER_TOP_MANAGER)
public String getInfoForTopManager() { /*...*/ }
@GetMapping
@Secured(ROLE_USER_MIDDLE_MANAGER)
public String getInfoForMiddleManager() { /*...*/ }
@GetMapping
public String getInfoForAnyUser() { /*...*/ }
}
Swagger will show both operations getInfoForTopManager and getInfoForMiddleManager regardless of current user role. In case currently authenticated user role is ROLE_USER_MIDDLE_MANAGER, I want only getInfoForMiddleManager and getInfoForAnyUser operations to be available in the Swagger.