Java Shiro 1.2不与Guice(和Vaadin)合作
第一次使用,请善待 我在配置Shiro以使用Guice过滤Vaadin生成的页面时遇到了一些问题 我在网上浏览了各种网站,包括ApacheShiro的指南等。问题是大多数网站倾向于采用“旧”的方式,即使用Shiro 1.1,它不支持原生Guice 这就是问题所在。我的页面没有通过Shiro过滤。我尝试过无数不同的事情,包括使用AOP进行方法身份验证,在web.xml中手动设置过滤器。甚至设置一个shiro.ini文件,我在任何情况下都不想这样做 下面是我正在使用的东西的列表: -Shiro 1.2.0-SNAPSHOT -Guice 3.0 -瓦丁6.7.4 这是我的web.xml:Java Shiro 1.2不与Guice(和Vaadin)合作,java,dependency-injection,guice,vaadin,shiro,Java,Dependency Injection,Guice,Vaadin,Shiro,第一次使用,请善待 我在配置Shiro以使用Guice过滤Vaadin生成的页面时遇到了一些问题 我在网上浏览了各种网站,包括ApacheShiro的指南等。问题是大多数网站倾向于采用“旧”的方式,即使用Shiro 1.1,它不支持原生Guice 这就是问题所在。我的页面没有通过Shiro过滤。我尝试过无数不同的事情,包括使用AOP进行方法身份验证,在web.xml中手动设置过滤器。甚至设置一个shiro.ini文件,我在任何情况下都不想这样做 下面是我正在使用的东西的列表: -Shiro 1.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>App</display-name>
<context-param>
<description>Vaadin production mode</description>
<param-name>productionMode</param-name>
<param-value>false</param-value>
</context-param>
<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>com.app.GuiceServletInjector</listener-class>
</listener>
</web-app>
然后创建一个ServletModule,将请求传递给Vaadin应用程序:
protected void configureServlets() {
bind(Application.class).to(VaadinMainWindow.class).in(ServletScopes.SESSION);
bind(BasicHttpAuthenticationFilter.class).in(Singleton.class);
filter("/*").through(BasicHttpAuthenticationFilter.class);
serve("/*", "*").with(VaadinApp.class);
}
同样在injector阶段,请注意,我创建了一个ShiroConfigurationModule,它负责领域等:
public class ShiroConfigurationModule extends ShiroWebModule {
@Inject
public ShiroConfigurationModule(ServletContext servletContext) {
super(servletContext);
}
@Override
protected void configureShiroWeb() {
bindRealm().to(ShiroBaseRealm.class).in(Singleton.class);
bind(Realm.class).to(ShiroBaseRealm.class).in(Singleton.class);
processMethodInterceptors();
}
private void processMethodInterceptors() {
MethodInterceptor interceptor = new AopAllianceAnnotationsAuthorizingMethodInterceptor();
bindInterceptor(any(), annotatedWith(RequiresRoles.class), interceptor);
bindInterceptor(any(), annotatedWith(RequiresPermissions.class), interceptor);
bindInterceptor(any(), annotatedWith(RequiresAuthentication.class), interceptor);
bindInterceptor(any(), annotatedWith(RequiresUser.class), interceptor);
bindInterceptor(any(), annotatedWith(RequiresGuest.class), interceptor);
}
}
realm类为支持返回'true',但为所有内容返回'null',模拟用户不存在
做错事或错过一步的机会非常高。有人能解释一下我遗漏了什么,这样我至少可以得到一个基本的HTTP认证吗
非常感谢!
Mo.没错,在经过大量测试和与Shiro的混战,以及最终使用1.2版本后,我的工作开始了 我在我的网站上写了一个详细的答案,主要是因为它更容易写!。看看:
不管是谁,祝你好运 是的,经过大量测试和与Shiro的混战,以及最终使用1.2版本,我的工作开始了 我在我的网站上写了一个详细的答案,主要是因为它更容易写!。看看:
不管是谁,祝你好运 当然,博客链接已经过期,现在重定向到的站点不包含该博客文章的任何痕迹 这篇文章的副本可以在这里找到 答案的关键是:如果您使用的是guice,那么您必须包括
filter("/*").through(GuiceShiroFilter.class)
在您的ServletModule中,否则任何相关的shiro过滤器都不会被点击。当然,博客链接已过期,现在重定向到的站点不包含该博客文章的任何痕迹 这篇文章的副本可以在这里找到 答案的关键是:如果您使用的是guice,那么您必须包括
filter("/*").through(GuiceShiroFilter.class)
在您的ServletModule中,否则任何相关的shiro筛选器都不会被命中。为什么您要使用筛选器模式/index.html而不是/*作为BasicHttpAuthenticationFilter?这是我正在做的一个测试。我试过做/**和/*但都没有结果。我将编辑我的帖子以反映这一点。谢谢:为什么你要用过滤器模式/index.html而不是/*作为BasicHttpAuthenticationFilter?这是我正在做的一个测试。我试过做/**和/*但都没有结果。我将编辑我的帖子以反映这一点。谢谢:欢迎来到Stack Overflow!虽然这可以从理论上回答这个问题,但在这里包括答案的基本部分,并提供链接供参考。欢迎使用堆栈溢出!虽然这在理论上可以回答这个问题,但在这里包括答案的基本部分,并提供链接供参考。