- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
初次使用,请多关照!
我在配置 Shiro 以使用 Guice 过滤 Vaadin 生成的页面时遇到了一些问题。
我在各种网站上在线查看,包括 Apache Shiro 的指南等。问题是大多数网站倾向于使用“旧”时尚方式,即使用 Shiro 1.1(没有原生 Guice 支持)。
所以问题来了。我的页面不会被 Shiro 过滤。我尝试了无数种不同的方法,包括使用 AOP 进行方法身份验证,在 web.xml 中手动设置过滤器。甚至设置一个 shiro.ini 文件(我在任何情况下都不想这样做)。
所以这是我正在使用的东西的列表:- Shiro 1.2.0-快照- 指南 3.0-Vaadin 6.7.4
这是我的 web.xml:
<?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>
这是 Servlet 注入(inject)器:
public class GuiceServletInjector extends GuiceServletContextListener {
private ServletContext servletContext;
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
servletContext = servletContextEvent.getServletContext();
super.contextInitialized(servletContextEvent);
}
@Override
protected Injector getInjector() {
return Guice.createInjector(new GuiceServletModule(), new ShiroConfigurationModule(servletContext));
}
然后创建一个 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);
}
同样在注入(inject)器阶段,请注意我创建了一个 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 类为 supports() 返回“true”,但为所有内容返回“null”,模拟用户不存在。
做错事或漏掉一步的可能性非常高。有人可以解释一下我遗漏了什么,这样我至少可以获得基本的 HTTP 身份验证吗?
非常感谢!莫.
最佳答案
自然地,博客链接已经过期,现在重定向到的站点不包含该博客文章的任何痕迹。
可以在此处找到该文章的副本。
答案的症结所在:如果您使用的是 guice,那么您必须包含
filter("/*").through(GuiceShiroFilter.class)
在你的 ServletModule 中,否则相关的 shiro 过滤器都不会被命中。
关于java - Shiro 1.2 不能与 Guice(和 Vaadin)一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8952463/
我有很多 TabularResultSet 类的带注释的命名实例,我想将它们传递给多个类并传递给静态最终属性。我该如何注入(inject)?我认为它不喜欢该属性的最终和静态性质。必须在属性声明中直接调
我是 Guice 的新手,我想知道我能走多远。 我有一个接口(interface)UserInfo具有多个实现类 GoogleUserInfo , FacebookUserInfo , Twitter
我的应用程序中绑定(bind)了两个类型的命名实例: bind(Foo.class).toProvider(FooProvider.class); bind(Foo.class).annotatedW
我有一个 Guice 模块,它有一个 @Provides 方法,它接受 2 个参数并返回接口(interface)的实现: public class **ClientModule** extends
请解释在以下使用工厂的场景中使用 Google-Guice 自动连接的正确方法。我正在使用 XML 工厂进行 XSLT 处理。 StringWriter strWriter = new StringW
我有一个 Guice Module提供 List使用 @Provides - 带注释的方法。 class TestModule() : Module { override fun configur
为什么Guice 3.0针对错误的配置组件(例如,缺少@Inject)抛出此异常,而不是格式化消息? Exception in thread "main" com.google.inject.inte
我有以下供应商: public class GuiceResourceProvider implements Provider { @Inject private Configur
使用 Guice-servlet,我们可以轻松地进行 servlet 映射,如下所示: filter(*.jsp).through(MyFilter.class) 但是,谁能告诉我如何将过滤器映射到
我正在尝试向我的项目添加 Swagger 。我们的设置与示例项目略有不同。我们使用 guice 和 guice-servlet 来注入(inject)并启动我们的 JerseyServletModul
假设我有一个 Guice 模块 ProdModule,我想依赖其他 GuiceModule、ProdDbModule 和 ProdPubSubModule。我将如何实现 ProdModule 的 co
我正在考虑在我的应用程序中使用 Guice for DI,我应该能够在运行时交换实现。下面提供了一个示例来说明要求: class ValidationEngine { public void v
我想设置 Guice 绑定(bind),所以我用 Java 创建了一个完美运行的模块: public class CrashLoggerModule extends AbstractModule {
所以我有一个模块将接口(interface)与实现类绑定(bind)。 bind(ILocalStore.class).to(LocalStore.class); 此绑定(bind)是否还会注入(in
guice 4.0 是否向后兼容 3.x?无法从发行说明或常见问题解答中弄清楚... 如果没有,是否有兼容性问题列表? 最佳答案 我没有任何官方来源但根据我的经验,没有任何兼容性问题。 我使用了几个
我正在尝试使用 Guice,并且我来自 Spring。 我想知道 @Inject 是否相当于 Spring 中的 @Autowired 以及我是否可以在 Web 应用程序中使用它,就像在 Spring
我是 Guice DI 的新手。我想弄清楚我的情况。 简单来说,有没有通过Guice @annotations来替代MapBinder的? 我的场景: Interface A{} Class A1 i
我的项目正在使用 Guice作为负责为大型对象图(主要是单例)提供依赖项(服务类)的 IOC 容器。有时,如果在构造过程中依赖项失败,并且许多对象都需要此依赖项,则失败将一遍又一遍地发生,并将异常添加
我有一个类 (CustomConnectionProvider),它将由第三方库 (hibernate) 使用 class.forName().newInstance() 实例化。我需要注入(inje
删除 guice servlet 后,我需要进行一些清理。使用 guice servlet 时是否可以 Hook 到 servlet 破坏?我需要使用喷油器进行清理工作。 我可以覆盖 contex
我是一名优秀的程序员,十分优秀!