You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by jeffp <je...@gmail.com> on 2011/09/24 06:25:55 UTC

New session created after 2 minutes of inactivity

Hi,

I have a Spring3 MVC application with Shiro handling the user auth and
native session management.  Session timeout is set to 1hr, but after 2
minutes of inactivity the user is forced back to the Shiro/login page.  I
dropped in a SessionListener and I'm seeing a new session being created, but
no sessions being expired. 

I'm using:
Spring-3.01
Shiro-core/web/ehcache 1.1.0

Any ideas what I'm missing or doing wrong?  Below is log output and my
Spring configuration.

2011-09-23 23:07:46 MySessionListener [INFO] Session has STARTED
6064467f-64b7-4bfd-b11c-6283dd36305e
...
2011-09-23 23:07:49 AbstractBaseController [INFO] Session id
6064467f-64b7-4bfd-b11c-6283dd36305e
2011-09-23 23:07:49 AbstractBaseController [INFO]
currentPrincipal:bb@test.net
...
2011-09-23 23:09:53 MySessionListener [INFO] Session has STARTED
da5250cd-d3b1-4472-94d1-ae557eddd9e2
REDIRECT TO LOGIN PAGE AGAIN
2011-09-23 23:09:58 AbstractBaseController [INFO]
currentPrincipal:bb@test.net


	 <bean id="shiroFilter"
class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
	    <property name="securityManager" ref="securityManager"/>
	    <property name="loginUrl" value="/login.jsp"/>
		<property name="filterChainDefinitions">
		    <value>
        		/login.jsp = authc
        		/admin/** = authc
    		</value>
  		</property>		
	 </bean>
					
	<bean id="securityManager"
class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
	    <property name="realm" ref="siteRealm"/>
	    <property name="sessionMode" value="native"/>
	    <property name="sessionManager" ref="sessionManager"/>
	    <property name="cacheManager" ref="cacheManager"/>
	    <property name="sessionManager.sessionListeners">
	    	<list>
	    		 <bean id="mylistener"
class="com.parker.smsite.security.MySessionListener"/>
	    	</list>
	    </property>
	</bean>
	
	<bean id="cacheManager"
class="org.apache.shiro.cache.ehcache.EhCacheManager">
	    <property name="cacheManager" ref="ehCacheManager"/>
	</bean>

	<bean id="ehCacheManager" 
	    class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"/>

	<bean id="sessionDAO" 
	    class="org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO"/>
	
	<bean id="sessionManager"
	    class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">
	    <property name="globalSessionTimeout" value="3600000"/> 
	    <property name="sessionDAO" ref="sessionDAO"/>
	</bean>

	<bean id="credentialsMatcher"
class="org.apache.shiro.authc.credential.Sha256CredentialsMatcher">
		<property name="storedCredentialsHexEncoded" value="false"/>
		<property name="hashIterations" value="1024"/>
	</bean>
	
	<bean id="siteRealm" class="com.parker.smsite.security.SiteRealm">
		<property name="credentialsMatcher" ref="credentialsMatcher"/>
	</bean>

--
View this message in context: http://shiro-user.582556.n2.nabble.com/New-session-created-after-2-minutes-of-inactivity-tp6826476p6826476.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: New session created after 2 minutes of inactivity

Posted by Les Hazlewood <lh...@apache.org>.
Hi Jeff,

I'm glad you figured this out - yes, default ehcache settings for a
cache region is a TTL of 2 minutes: Ehcache was evicting the Session
entries without Shiro knowing about it.

For those that might come across this issue in the future, you can set
ehcache config settings for Shiro's session cache as described here:

http://shiro.apache.org/session-management.html#SessionManagement-EHCacheSessionCacheConfiguration

Terracotta config is mentioned below if you want to use Terracotta to
cluster those sessions.  Maybe one day someone will contribute
documentation about using other clustering options (e.g. Zookeeper).

HTH,

Les

On Sun, Sep 25, 2011 at 1:06 PM, jeffp <je...@gmail.com> wrote:
> This is resolved.  Looking back through the logs I noticed that ehcache was
> not able to find any ehcache.xml definition and so the default provided by
> ehcache was being used.
>
> The solution was to simply provide my own ehcache.xml and drop it into the
> classpath.
>
> --
> View this message in context: http://shiro-user.582556.n2.nabble.com/New-session-created-after-2-minutes-of-inactivity-tp6826476p6829888.html
> Sent from the Shiro User mailing list archive at Nabble.com.

Re: New session created after 2 minutes of inactivity

Posted by jeffp <je...@gmail.com>.
This is resolved.  Looking back through the logs I noticed that ehcache was
not able to find any ehcache.xml definition and so the default provided by
ehcache was being used.

The solution was to simply provide my own ehcache.xml and drop it into the
classpath.

--
View this message in context: http://shiro-user.582556.n2.nabble.com/New-session-created-after-2-minutes-of-inactivity-tp6826476p6829888.html
Sent from the Shiro User mailing list archive at Nabble.com.