我正在编写一项服务,其中我使用 Shiro 来确保安全。我也将 Guice 与它结合在一起。我在以下位置创建了 GUICE 注入器GuiceServletContextListener
:
//Custom Shiro Web module with defined REALM
new MyShiroWebModule(this.servletContext, "/v1/*"),
//Shiro annotations
new MyAOPModule(),
我还将 Guice Container 和 GuiceShiroFilter 绑定在JerseyServletModule
:
serve("/v1/*").with(GuiceContainer.class, params);
//Adds Shiro filtering
MyShiroWebModule.bindGuiceFilter(binder());
但是 Shiro 的注释似乎不起作用!
我在以下位置配置链MyShiroWebModule
:
addFilterChain("/v1/res/test", ANON);
addFilterChain("/v1/**", ROLES, AUTHC_BASIC);
因此,如果我使用“ROLES”过滤器,那么它会以 AOP 方式扫描角色:
@RolesAllowed("SomeFancyRole")
(见编辑)
但我想利用 GUICE Shiro AOP 功能。我已经尝试了基本的 ShiroAOPModule 而不是我自己的 -> my is 用于调试以查看是否调用了配置。
@User, @Authenticated etc.
我如何合并此功能,因为文档指出只有“添加” ShiroAOPModule 才能开箱即用?先感谢您
编辑:
事实证明,@RolesAllowed
由于添加:
params.put(PackagesResourceConfig.PROPERTY_RESOURCE_FILTER_FACTORIES, "com.sun.jersey.api.container.filter.RolesAllowedResourceFilterFactory");
在 JerseyServlet 模块中
serve("/v1/*").with(GuiceContainer.class, params);
所以 Shiro 的 AOP 仍然没有被过滤。