【发布时间】:2019-08-07 16:36:56
【问题描述】:
我有一个由 Spring Security 保护的 Spring Boot 应用程序。为了保护对特定端点的访问,我们使用@PreAuthorize 注释,例如@PreAuthorize("hasAnyAuthority('first_role','second_role','third_role')")。
我想知道是否有可能生成(静态或动态)端点和权限之间的映射列表,以查看哪个端点由哪些权限保护。
所以作为一个输出,我想要这样的东西:
first_role -> endpoint_A, endpoint_B, endpoint_C
second_role -> endpoint_B
third_role -> endpoint_A, endpoint_C
或至少:
endpoint_A -> first_role, third_role
endpoint_B -> first_role, second_role
endpoint_C -> first_role, third_role
你知道有什么解决办法吗?
【问题讨论】:
-
AFAIK 没有内置方式,但您可以自己编写。您必须检查所有类/方法并查看注释。为方便起见,将
@PreAuthorize更改为@Secured,它只允许授权,不允许SPEL。 -
我的问题也需要同样的解决方案:我有一个网关,在我的 ResourceServerConfigurerAdapter 类中,我添加了所有端点的 antMatchers 以及所需的角色,我想知道哪个端点由哪个角色保护,我想要一个可以给我的服务,然后我会在我的招摇文档上显示这些有用的信息。
标签: spring spring-boot spring-security