【发布时间】:2014-02-26 15:01:03
【问题描述】:
我为使用 Ajax 会话超时添加的代码的详细信息,如 BaluC 所述
Faces-Config.xml
<factory>
<exception-handler-factory>org.omnifaces.exceptionhandler.FullAjaxExceptionHandlerFactory</exception-handler-factory>
</factory>
Web.xml
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/expired.xhtml</location>
</error-page>
application-config.xml
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager" />
<!-- override these for application-specific URLs if you like: -->
<property name="loginUrl" value="/index.xhtml" />
<property name="successUrl" value="/dashboard" />
<property name="unauthorizedUrl" value="/login" />
<property name="filters">
<util:map>
<entry key="authc">
<bean
class="org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter" />
</entry>
</util:map>
</property>
<property name="filterChainDefinitions">
<value>
[main]
user.loginUrl = /login.xhtml
[users]
admin = password
[urls]
/login.xhtml = user
/css/**=anon
/images/**=anon
/emailimages/**=anon
/login=anon
/test=anon
/sso=anon
/ssologin=anon
/**=authc
</value>
</property>
</bean>
<bean id="facesFilter" class="com.xxx.temp.FacesAjaxAwareUserFilter"></bean>
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<!-- <property name="sessionMode" value="native"/> -->
<property name="realms">
<list>
<ref bean="jdbcRealm" />
<ref bean="googleRealm" />
</list>
</property>
<!-- <property name="realms" ref="jdbcRealm googleRealm" /> -->
<property name="cacheManager" ref="cacheManager" />
<!-- <property name="sessionManager" ref="sessionManager"/> -->
</bean>
<!-- <bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
<property name="cacheManagerConfigFile" value="/WEB-INF/ehcache.xml"/> </bean> -->
<bean id="passwordService"
class="org.apache.shiro.authc.credential.DefaultPasswordService">
</bean>
<bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
<property name="cacheManager" ref="ehCacheManager" />
</bean>
<!-- <bean id="sessionManager" class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">
<property name="sessionDAO" ref="sessionDAO"/> </bean> -->
<bean id="ehCacheManager"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" />
<!-- <bean id="sessionDAO" class="org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO"/> -->
<bean id="jdbcRealm" class="com.xxx.domain.web.permissions.MyWebRealm">
</bean>
<bean id="googleRealm" class="com.xxx.domain.web.permissions.GoogleRealm">
<!-- <property name="dataSource" ref="dataSource" /> -->
<property name="credentialsMatcher"> <bean class="com.fetchinglife.domain.web.permissions.GoogleCredentialsMatcher"/> </property>
</bean>
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />
<bean
class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor" />
添加类文件FacesAjaxAwareUserFilter
** 从 BaluC 博客复制的代码 **
已添加 Jar 文件
omniface-1.7.jar
在 .xhtml 文件中添加了这个
xmlns:o="http://omnifaces.org/ui"
xmlns:of="http://omnifaces.org/functions"
提出警告
NLS missing message: CANNOT_FIND_FACELET_TAGLIB in:
org.eclipse.jst.jsf.core.validation.internal.facelet.messages
当前状态:
未找到响应,页面不会在会话超时 ajax 调用时重定向。
【问题讨论】:
-
看起来您将
FacesAjaxAwareUserFilter配置为 Spring 托管 bean 而不是 Shiro 过滤器。为什么?在您找到的 JSF2-Shiro 教程中绝对没有这样描述。 -
@BalusC 我对 shiro 和 spring 不太擅长,我不知道它是如何工作的。我刚刚按照说明进行操作,在我的应用程序中没有 shiro.ini 文件,所以当我在网上搜索时,它向我展示了我已经实现的这个示例。你能帮我解决这个问题吗? :)
-
所以你甚至连 Shiro 都没有启动并运行?我会首先使用普通的 HTML 页面来解决这个问题,直到它可以工作,然后你就可以开始专注于解决 JSF ajax 的问题。一次吃一口大象。
-
@BalusC 是的 shiro 工作正常,我只是在修复 ajax 超时问题。我正在使用带有 shiro 的 spring-jsf,我将使用完整的详细信息更新应用程序 config.xml
-
我检查了更新后的
application-config.xml,filterChainDefinitions的值恰好代表了shiro.ini文件的内容。我不确定 Spring 为何以及如何这样做,但将其视为真正的shiro.ini在逻辑上是有意义的。我只需按照真实shiro.ini文件的说明配置Shiro 过滤器即可。
标签: java jsf-2 session-timeout shiro omnifaces