我们有使用Struts1.3,Google-Guice和ApacheTomcat7运行的Web应用程序。 现在我想整合安全框架Apache shiro。
以下是我在pom.xml中的配置,用于下载依赖项:
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-web</artifactId>
<version>1.2.3</version>
</dependency>
以下是Web.xml配置(Filters&amp; Listener):
<listener>
<listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
</listener>
<filter>
<filter-name>ShiroFilter</filter-name>
<filter-class>org.apache.shiro.web.servlet.IniShiroFilter</filter-class>
</filter>
<!-- Make sure any request you want accessible to Shiro is filtered. /* catches all -->
<!-- requests. Usually this filter mapping is defined first (before all others) to -->
<!-- ensure that Shiro works in subsequent filters in the filter chain: -->
<filter-mapping>
<filter-name>ShiroFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
以下是我的shiro.ini文件配置: [主要]
# specify login page
authc.loginUrl = /welcome.do
# name of request parameter with username; if not present filter assumes 'username'
authc.usernameParam = user
# name of request parameter with password; if not present filter assumes 'password'
authc.passwordParam = password
# redirect after successful login
authc.successUrl = /Views/welcome.jsp
# Let's use some in-memory caching to reduce the number of runtime lookups against Stormpath.
# A real application might want to use a more robust caching solution (e.g. ehcache or a
# distributed cache). When using such caches, be aware of your cache TTL settings: too high
# a TTL and the cache won't reflect any potential changes in Stormpath fast enough. Too low
# and the cache could evict too often, reducing performance.
cacheManager = org.apache.shiro.cache.MemoryConstrainedCacheManager
securityManager.cacheManager = $cacheManager
ds = com.jolbox.bonecp.BoneCPDataSource
ds.driverClass = oracle.jdbc.driver.OracleDriver
ds.jdbcUrl = jdbc:oracle:thin:@10.87.54.2:1521:WAPD
ds.username = USRIG395
ds.password = changeme123
# other BoneCP connection pool settings as desired
jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
jdbcRealm.dataSource = $ds
jdbcRealm.authenticationQuery = "SELECT password FROM users WHERE username = ?"
jdbcRealm.userRolesQuery = "SELECT authority FROM user_roles WHERE username = ?"
[urls]
# enable authc filter for all application pages/**=authc
[users]
[roles]
[urls]
/** = authcBasic
之后,当我启动我的tomcat时,它会给我以下错误,它不允许我启动我的应用程序:
Apr 29, 2014 5:32:00 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.apache.shiro.web.env.EnvironmentLoaderListener
java.lang.IllegalAccessError: tried to access method org.apache.shiro.web.util.WebUtils.normalize(Ljava/lang/String;)Ljava/lang/String; from class org.apache.shiro.web.env.IniWebEnvironment
at org.apache.shiro.web.env.IniWebEnvironment.getServletContextResourceStream(IniWebEnvironment.java:280)
at org.apache.shiro.web.env.IniWebEnvironment.convertPathToIni(IniWebEnvironment.java:249)
at org.apache.shiro.web.env.IniWebEnvironment.createIni(IniWebEnvironment.java:163)
at org.apache.shiro.web.env.IniWebEnvironment.getDefaultIni(IniWebEnvironment.java:134)
at org.apache.shiro.web.env.IniWebEnvironment.init(IniWebEnvironment.java:82)
at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:45)
at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:40)
at org.apache.shiro.web.env.EnvironmentLoader.createEnvironment(EnvironmentLoader.java:221)
at org.apache.shiro.web.env.EnvironmentLoader.initEnvironment(EnvironmentLoader.java:133)
at org.apache.shiro.web.env.EnvironmentLoaderListener.contextInitialized(EnvironmentLoaderListener.java:58)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Apr 29, 2014 5:32:00 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
ERROR - Shiro environment initialization failed
java.lang.IllegalAccessError: tried to access method org.apache.shiro.web.util.WebUtils.normalize(Ljava/lang/String;)Ljava/lang/String; from class org.apache.shiro.web.env.IniWebEnvironment
at org.apache.shiro.web.env.IniWebEnvironment.getServletContextResourceStream(IniWebEnvironment.java:280)
at org.apache.shiro.web.env.IniWebEnvironment.convertPathToIni(IniWebEnvironment.java:249)
at org.apache.shiro.web.env.IniWebEnvironment.createIni(IniWebEnvironment.java:163)
at org.apache.shiro.web.env.IniWebEnvironment.getDefaultIni(IniWebEnvironment.java:134)
at org.apache.shiro.web.env.IniWebEnvironment.init(IniWebEnvironment.java:82)
at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:45)
at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:40)
at org.apache.shiro.web.env.EnvironmentLoader.createEnvironment(EnvironmentLoader.java:221)
at org.apache.shiro.web.env.EnvironmentLoader.initEnvironment(EnvironmentLoader.java:133)
at org.apache.shiro.web.env.EnvironmentLoaderListener.contextInitialized(EnvironmentLoaderListener.java:58)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
我的配置中是否有任何错误或我的配置错误?如果我在我的问题中缺少某些内容,请告诉我吗?
提前致谢。
答案 0 :(得分:0)
此错误几乎总是来自类路径上的不兼容的jar。
您的WEB-INF / lib文件夹或tomcat中的其他位置(例如TOMCAT_HOME / lib文件夹)中可能有旧版本的shiro-web.jar。