我正在研究一个项目,当我登录我的登录页面时。它显示了下一页,但浏览器保留在login.xhtml而不是test.xhtml中。
这里我认为问题出在applicationContext.xml中:
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager"/>
<property name="loginUrl" value="/login.xhtml"/>
<property name="successUrl" value="/test.xhtml"/>
<property name="unauthorizedUrl" value="/unauthorized.xhtml"/>
<property name="filterChainDefinitions">
<value>
/login.xhtml = anon
/test.xhtml = authc
/unauthorized.xhtml = anon
</value>
</property>
您实际上并没有登录到您的应用程序,并且没有注册会话cookie,因为您使用了两个完全不同的过滤器。您的登录路径设置为anon
,丢弃您发布的任何内容,但您的受保护资源路径正在使用authc
过滤器,该过滤器需要现在授权或授权调用者。
在一个类似的问题中阅读更多关于这个问题,我回答了here。
这是正确的方法并修复了您的问题:
<property name="filterChainDefinitions">
<value>
/login.xhtml = authc
/test.xhtml = authc
/unauthorized.xhtml = anon
</value>
</property>
请确保添加logout
过滤器以便能够注销您的应用程序。另请注意,您的配置缺少通用的/**
过滤器路径,以保护服务器的所有资源。