【发布时间】:2014-11-17 09:27:33
【问题描述】:
我正在编写一个使用 Shiro 来确保安全的服务。我也将 Guice 与它结合在一起。我在 GuiceServletContextListener 中创建了 GUICE 注入器:
//Custom Shiro Web module with defined REALM
new MyShiroWebModule(this.servletContext, "/v1/*"),
//Shiro annotations
new MyAOPModule(),
我还在JerseyServletModule中绑定了Guice Container和GuiceShiroFilter:
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");
在 JerseyServletModule 中
serve("/v1/*").with(GuiceContainer.class, params);
所以来自 Shiro 的 AOP 仍然没有被过滤。
【问题讨论】:
标签: aop guice shiro guice-servlet