Question

We have Web Application which is running with Struts1.3 , Google-Guice and ApacheTomcat7. Now I want to integrate security framework Apache shiro.

Following is my configuration in pom.xml for downloading dependencies:

 <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>

Following is the Web.xml configuration(Filters & 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>

Following is my shiro.ini file configuration: [main]

            # 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

After that when I start my tomcat it will give me following errors, it does not allow me to start my application:

            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)

Is there any error in my configuration or any configuration misssing on my part? Please let me if I Missing something to describe in my problem?

Thanks in advance.

Was it helpful?

Solution

This error almost always come from incompatible jars on the classpath.

You might have an old version of shiro-web.jar in your WEB-INF/lib folder or somewhere else in tomcat (the TOMCAT_HOME/lib folder for example).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top