shiro web整合报错,请帮忙看看。

mars.will 发布于 2012/03/05 22:29
阅读 9K+
收藏 0

环境:apache-shiro;

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>

applicationContext-shiro.xml:

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"
	default-lazy-init="false">

	<description>shiro配置 </description>

	<bean id="shiroFilter" class="com.atlastiger.emr.system.filter.CustomShiroFilterFactoryBean" init-method="setSecurityManagerToUtils">
		<property name="securityManager" ref="securityManager" />
		<property name="loginUrl" value="/login.jsp" />
		<property name="successUrl" value="/system/user!list.action" />
		<property name="unauthorizedUrl" value="/login.jsp" />
		<property name="filterChainDefinitions">
			<value>
				/common/** = anon
				/css/** = anon
				/js/** anon
				/template/** = anon
				/logout = logout
				/** = anon
        </value>
		</property>
	</bean>


	<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
		<property name="realm" ref="emrJdbcRealm" />
	</bean>

	<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />

	<!--
		Define the Shiro Realm implementation you want to use to connect to
		your back-end
	-->
	<!-- security datasource: -->
	<bean id="emrJdbcRealm" class="com.atlastiger.emr.system.service.EmrJdbcRealm">

	</bean>

	<!--
		Enable Shiro Annotations for Spring-configured beans. Only run after
		the lifecycleBeanProcessor has run:
	-->
	<bean
		class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
		depends-on="lifecycleBeanPostProcessor" />
	<bean
		class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
		<property name="securityManager" ref="securityManager" />
	</bean>
</beans>

com.atlastiger.emr.system.filter.CustomShiroFilterFactoryBean源码:

 

public class CustomShiroFilterFactoryBean extends ShiroFilterFactoryBean
{

	public void setSecurityManagerToUtils()
	{
		SecurityUtils.setSecurityManager(getSecurityManager());
	}
}

jsp:

 

<div id="bd">
				<div id="yui-main">
					<div class="yui-b">
						<div id="message">
							<s:actionmessage theme="custom" cssClass="error" />
						</div>
						<form id="loginForm" action="${ctx}/system/user!login.action"
							method="post" style="margin-top: 1em">
							<table class="noborder">
								<tr>
									<td>
										<label>
											用户名:
										</label>
									</td>
									<td>
										<input type='text' id='username' name='user.loginName'
											class="required"
									</td>
								</tr>
								<tr>
									<td>
										<label>
											密码:
										</label>
									</td>
									<td>
										<input type='password' id='password' name='user.password'
											class="required" />
									</td>
								</tr>
								<tr>
									<td colspan='2' align="right">
										<input value="登录" type="submit" class="button" />
									</td>
								</tr>
							</table>
						</form>
						<div>
							(管理员
							<b>admin/1</b>, 普通用户
							<b>user/1</b>)
						</div>
					</div>
				</div>
			</div>

异常:

 

2012-03-05 22:19:45,167 [http-9900-5] ERROR [500.jsp] - SessionContext must be an HTTP compatible implementation.
java.lang.IllegalArgumentException: SessionContext must be an HTTP compatible implementation.
	at org.apache.shiro.web.session.mgt.ServletContainerSessionManager.createSession(ServletContainerSessionManager.java:103)
	at org.apache.shiro.web.session.mgt.ServletContainerSessionManager.start(ServletContainerSessionManager.java:64)
	at org.apache.shiro.mgt.SessionsSecurityManager.start(SessionsSecurityManager.java:121)
	at org.apache.shiro.subject.support.DelegatingSubject.getSession(DelegatingSubject.java:336)
	at org.apache.shiro.subject.support.DelegatingSubject.getSession(DelegatingSubject.java:314)
	at org.apache.shiro.mgt.DefaultSubjectDAO.mergePrincipals(DefaultSubjectDAO.java:182)
	at org.apache.shiro.mgt.DefaultSubjectDAO.saveToSession(DefaultSubjectDAO.java:163)
	at org.apache.shiro.mgt.DefaultSubjectDAO.save(DefaultSubjectDAO.java:144)
	at org.apache.shiro.mgt.DefaultSecurityManager.save(DefaultSecurityManager.java:383)
	at org.apache.shiro.mgt.DefaultSecurityManager.createSubject(DefaultSecurityManager.java:350)
	at org.apache.shiro.mgt.DefaultSecurityManager.createSubject(DefaultSecurityManager.java:183)
	at org.apache.shiro.mgt.DefaultSecurityManager.login(DefaultSecurityManager.java:283)
	at org.apache.shiro.subject.support.DelegatingSubject.login(DelegatingSubject.java:257)
	at com.atlastiger.emr.system.web.UserAction.setLogin(UserAction.java:129)
	at com.atlastiger.emr.system.web.UserAction.login(UserAction.java:111)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453)
	at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:292)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:255)
	at com.opensymphony.xwork2.interceptor.annotations.AnnotationWorkflowInterceptor.intercept(AnnotationWorkflowInterceptor.java:135)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
	at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
	at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
	at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
	at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
	at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
	at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
	at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
	at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
	at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
	at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
	at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
	at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
	at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
	at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
	at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
	at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
	at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
	at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
	at org.apache.struts2.interceptor.MessageStoreInterceptor.intercept(MessageStoreInterceptor.java:194)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
	at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
	at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:510)
	at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
	at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:102)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:119)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Thread.java:662)

请问哪位知道是什么原因引起的?谢谢?
加载中
0
mars.will
mars.will

问题已经解决,将<filter><filter-name>shiroFilter</filter-name><filter>在web.xml的位置

移动到所有涉及的URL过滤的filter前面即可

 
Firebug
Firebug
就是这样的。
0
oid
oid

还是不行呀


<?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>ACS</display-name>
  <!-- Shiro filter-->  
<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>/jsp/*</url-pattern>
</filter-mapping>
<!-- shiro end-->
  <servlet>
<servlet-name>initServlet</servlet-name>
<servlet-class>com.gforce.util.InitPathServlet</servlet-class>
<init-param>
<param-name>path</param-name>
<param-value>http://localhost:8080/ACS</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/config/spring/spring.xml</param-value>
  </context-param>
  <context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/config/log4j/log4j.properties</param-value>
</context-param>
  <!-- log4j Listener -->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
  <listener>
    <!-- spring Listener -->
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <!-- shiro Listener -->
 <!--  <listener>     
  <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>  
 </listener>  -->


<!-- struts2 filter-->
<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  <init-param>
  <param-name>config</param-name>
  <param-value>
  struts-default.xml,struts-plugin.xml,../config/struts/struts.xml
  </param-value>
  </init-param>
  </filter>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>




  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>jsp/index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>


0
oid
oid
求助哟,楼主帮帮忙,看看还有其它可能不
0
mars.will
mars.will

今天是节日呢,兄弟,也不休息一下呀?哈哈

<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/jsp/*</url-pattern>
</filter-mapping>

有可能是过滤地址没有过滤到请求的地址,

把您的错误信息发上来,后台调用方法发上来,还有shiro的配置,我也好久没有弄了,嘿嘿

oid
oid
会是这个嘛,额可以过滤啊,就是报跟你一样的错误,java.lang.IllegalArgumentException: SessionContext must be an HTTP compatible implementation. 哥们还得上课呢,刚学用这个shiro
0
8446666
8446666

给大家一个Shrio项目的完整Demo:http://www.sojson.com/shiro 一个基于Spring4.25 + Mybatis + Redis 的Demo

本教程包含的内容。

  1. SSM(SpringMVC + Spring +Mybatis)框架的增删改查(含分页),所以如果框架小白也是可以看看的。
  2. View层主要是Freemarker,但是为了考虑到好多人还使用的是JSP,也有一个页面是用JSP实现的,并且框架支持Freemarker 和JSP双View展示(优先找Freemarker)。
  3. Shiro + Redis 的集成,也提供Ehcache的依赖Jar。
  4. Shiro初始权限动态加载。
  5. Shiro自定义权限校验Filter定义,及功能实现。
  6. ShiroAjax请求权限不满足,拦截后解决方案。
  7. ShiroFreemarker标签使用。
  8. ShiroJSP标签使用。
  9. Shiro登录后跳转到最后一个访问的页面。
  10. 用户禁止登录Demo。
  11. 在线显示,在线用户管理(踢出登录)。
  12. 登录注册密码加密传输Demo(详细请见下面讲解)。
  13. 密码修改。
  14. 用户个人中心。
  15. 权限的增删改查。
  16. 角色的增删改查。
  17. 权限->角色->用户之间的关系维护。
  18. 管理员权限的自动添加(当有一个权限创建,自动添加到管理员角色下,保证管理员是最大权限)。
  19. Spring定时任务数据化数据。
  20. 集成多种验证码(包括动态的gif验证码哦)。
  21. 后续会陆陆续续升级... ...
返回顶部
顶部