@魏涛 你好,想跟你请教个问题:
现在遇见了一个现象,不增加shiro的配置,struts2是可以直接进行跳转的,一旦增加了shiro的配置,struts2则不能增加跳转,请问,这是什么原因?能加你的qq吗?43896453.谢谢。
shiro的配置:
<!-- 缓存管理器 --> <bean id="shiroCacheManager" class="com.stgroup.util.cache.SpringCacheManagerWrapper"> <property name="cacheManager" ref="springCacheManager"/> </bean>
<!-- 凭证匹配器 --> <bean id="credentialsMatcher" class="com.stgroup.shiro.credentials.RetryLimitHashedCredentialsMatcher"> <constructor-arg ref="shiroCacheManager"/> <property name="hashAlgorithmName" value="md5"/> <property name="hashIterations" value="2"/> <property name="storedCredentialsHexEncoded" value="true"/> </bean>
<!-- Realm实现 --> <bean id="userRealm" class="com.stgroup.shiro.realm.UserRealm"> <property name="credentialsMatcher" ref="credentialsMatcher"/> <property name="cachingEnabled" value="false"/> </bean>
<!-- 会话ID生成器 --> <bean id="sessionIdGenerator" class="org.apache.shiro.session.mgt.eis.JavaUuidSessionIdGenerator"/>
<!-- 会话Cookie模板 --> <bean id="sessionIdCookie" class="org.apache.shiro.web.servlet.SimpleCookie"> <constructor-arg value="sid"/> <property name="httpOnly" value="true"/> <property name="maxAge" value="-1"/> </bean>
<bean id="rememberMeCookie" class="org.apache.shiro.web.servlet.SimpleCookie"> <constructor-arg value="rememberMe"/> <property name="httpOnly" value="true"/> <property name="maxAge" value="2592000"/><!-- 30天 --> </bean>
<!-- rememberMe管理器 --> <bean id="rememberMeManager" class="org.apache.shiro.web.mgt.CookieRememberMeManager"> <property name="cipherKey" value="#{T(org.apache.shiro.codec.Base64).decode('4AvVhmFLUs0KTA3Kprsdag==')}"/> <property name="cookie" ref="rememberMeCookie"/> </bean>
<!-- 会话DAO --> <bean id="sessionDAO" class="org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO"> <property name="activeSessionsCacheName" value="shiro-activeSessionCache"/> <property name="sessionIdGenerator" ref="sessionIdGenerator"/> </bean>
<!-- 会话验证调度器 --> <bean id="sessionValidationScheduler" class="org.apache.shiro.session.mgt.quartz.QuartzSessionValidationScheduler"> <property name="sessionValidationInterval" value="1800000"/> <property name="sessionManager" ref="sessionManager"/> </bean>
<!-- 会话管理器 --> <bean id="sessionManager" class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager"> <property name="globalSessionTimeout" value="1800000"/> <property name="deleteInvalidSessions" value="true"/> <property name="sessionValidationSchedulerEnabled" value="true"/> <property name="sessionValidationScheduler" ref="sessionValidationScheduler"/> <property name="sessionDAO" ref="sessionDAO"/> <property name="sessionIdCookieEnabled" value="true"/> <property name="sessionIdCookie" ref="sessionIdCookie"/> </bean>
<!-- 安全管理器 --> <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager"> <property name="realm" ref="userRealm"/> <property name="sessionManager" ref="sessionManager"/> <property name="cacheManager" ref="shiroCacheManager"/> <property name="rememberMeManager" ref="rememberMeManager"/> </bean>
<!-- 相当于调用SecurityUtils.setSecurityManager(securityManager) --> <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> <property name="staticMethod" value="org.apache.shiro.SecurityUtils.setSecurityManager"/> <property name="arguments" ref="securityManager"/> </bean>
<!-- 基于Form表单的身份验证过滤器 --> <bean id="formAuthenticationFilter" class="org.apache.shiro.web.filter.authc.FormAuthenticationFilter"> <property name="usernameParam" value="account"/> <property name="passwordParam" value="password"/> <property name="rememberMeParam" value="rememberMe"/> <property name="loginUrl" value="/login"/> </bean>
<bean id="sysUserFilter" class="com.stgroup.shiro.filter.SysUserFilter"/>
<!-- Shiro的Web过滤器 --> <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean"> <property name="securityManager" ref="securityManager"/> <property name="loginUrl" value="/jsp/login.jsp"/> <property name="filters"> <util:map> <entry key="authc" value-ref="formAuthenticationFilter"/> <entry key="sysUser" value-ref="sysUserFilter"/> </util:map> </property> <property name="filterChainDefinitions"> <value> /jsp/login.jsp = anon /login = authc /logout = logout /authenticated = authc /** = user,sysUser </value> </property> </bean>
<!-- Shiro生命周期处理器--> <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>
struts配置(后面的部分就没有贴进来)
<struts> <include file="struts-default.xml" /> <constant name="struts.objectFactory" value="spring" />
<package name="login" extends="struts-default"> <action name="LoginAction" class="LoginAction-spring"> <result name="success" type="redirect">MainAction</result> <result name="input">jsp/login.jsp</result> <result name="error">jsp/login.jsp</result> </action>
login.jsp
(action的值我试着去掉或者不去掉,没有变化)
<form action="LoginAction" method="post"> 帐号: <input type="text" name="account" > <br /> 密码: <input type="password" name="password"> <br /> 自动登录: <input type="checkbox" name="rememberMe" value="true"> <br /> <div class="error"> ${errorMessage} </div> <br /> <input type="submit" value="登录"> </form>
web.xml
<filter> <filter-name>shiroFilter</filter-name> <filter-class> org.springframework.web.filter.DelegatingFilterProxy </filter-class> <init-param> <param-name>targetFilterLifecycle</param-name> <param-value>true</param-value> </init-param> </filter>
<filter-mapping> <filter-name>shiroFilter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> </filter-mapping>
<listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <listener> <listener-class> org.springframework.web.context.request.RequestContextListener </listener-class> </listener>
<filter> <filter-name>Set Character Encoding</filter-name> <filter-class> org.springframework.web.filter.CharacterEncodingFilter </filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter>
<filter-mapping> <filter-name>Set Character Encoding</filter-name> <url-pattern>/</url-pattern> </filter-mapping> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/</url-pattern> </filter-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/applicationContext-.xml,classpath:applicationContext-.xml,classpath:applicationContext*.xml </param-value> </context-param>
可以把发生问题的sample代码提交到http://git.oschina.net里吗?提交后告诉我地址,帮你检查一下。 ###### 十分的感谢。我是第一次用这个shiro,项目时间又非常的紧张,真的非常希望能获得你的帮助。
同时,也是第一次使用这个git,文件放置的位置如下所示,我测试了一下是能打开的,如果你不能获得的话(上传的是附件),再联系。再次感谢。
http://git.oschina.net/3000flowers/struts2-spring4-hibernate4-shiro1.2.3-ehcache/attach_files ######无法获取,请不要私有项目。或者私有项目加我为成员。###### https://git.oschina.net/3000flowers/shiro-demo
新增加的地址。不知道你的邮箱或者ID好像没办法加你成为项目成员。再次表示感谢。 ###### 提交jsp页面只能配置写成action="login.action"
struts.xml 的,只能配置写成 action="login"
applicationContext.xml 只能配置写成 /login.action = anon
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。