Hi Andy,

Just specifying the CacheManager on the SecurityManager instance is
good enough.  Do that first:

securityManager.cacheManager = $cacheManager

then, when the realms are set and the sessionDAO is set, the
CacheManager will automatically be applied to both.

That is, I'd probably set it up like this:

cacheManager = com.vonage.auth.VonageDistributedSessionCacheManager
securityManager.cacheManager = $cacheManager
securityManager.sessionMode = native

sessionDAO = org.apache.shiro.session.mgt.eis.MemorySessionDAO
securityManager.sessionDAO = $sessionDAO

realmA = com.vonage.auth.VonageAuthenticationRealm
securityManager.realm = $realmA

That should do it.

Cheers,

Les

On Mon, Aug 31, 2009 at 10:24 AM, Andy Tripp<[email protected]> wrote:
> I need to get this working, and I’m happy to track it down myself, but I
> need some starting direction.
>
>
>
> If I want to use my own cache for storing session data, I know I should
> write my own CacheManager and a class that implements Cache. But which class
> do I tell to use my own cache? Is it SessionDAO, securityManager, or my own
> Realm (in my case a subclass of JDBCRealm)? All three have a cacheManager
> property.
>
>
>
> Thanks,
>
> Andy
>
>
>
> ________________________________
>
> From: Andy Tripp [mailto:[email protected]]
> Sent: Friday, August 28, 2009 2:56 PM
> To: [email protected]
> Subject: need help plugging in my own session cache
>
>
>
> Hi again,
>
>
>
> I’m having trouble with specifying my own Cache.
>
> I’ve specified my own CacheManager and Cache classes in my ShiroFilter:
>
>
>
>                 realmA = com.vonage.auth.VonageAuthenticationRealm
>
>                 securityManager =
> org.apache.shiro.web.DefaultWebSecurityManager
>
>                 sessionManager =
> org.apache.shiro.web.session.DefaultWebSessionManager
>
>                 securityManager.sessionManager = $sessionManager
>
>                 securityManager.sessionMode = native
>
>                 #cacheManager = org.apache.shiro.cache.DefaultCacheManager
>
>                 cacheManager =
> com.vonage.auth.VonageDistributedSessionCacheManager
>
>                 sessionDAO =
> org.apache.shiro.session.mgt.eis.MemorySessionDAO
>
>                 sessionDAO.cacheManager = $cacheManager
>
>                 securityManager.sessionDAO = $sessionDAO
>
>                 securityManager.cacheManager = $cacheManager
>
>                 securityManager.realm = $realmA
>
>                 realmA.cacheManager = $cacheManager
>
>
>
> My VonageDistributedSessionCacheManager class simply returns an instance of
> my VonageDistributedSessionCache class, which implements the Cache
> interface.
>
>
>
> The problem is that the various methods in my VonageDistributedSessionCache
> class (get(), put(), etc) are never being called. By adding tracing, I can
> confirm that my VonageDistributedSessionCache constructor is being called
> from AuthorizationRealm.initAuthorizationCache(). But when I login to my
> servlet, my get() and put() methods are never called. On my first login
> attempt to get to my servlet, I have no session and so I’m challenged for
> username/password. Then on a second attempt, it lets me through. So
> somewhere Shiro is caching my sessionid, but I don’t know where. All I know
> is that it’s not using the Cache that I told it to :) In fact, I told it 3
> times ($cacheManager is mentioned 3 times above)!
>
>
>
> So where is it in Shiro that checks the session cache? I see that
> AuthorizingRealm.initAuthorizationCache() does create an instance of my
> VonageDistributedSessionCache class, and calls setAuthorizationCache() to
> store it. But I don’t see any calls to the corresponding
> getAuthorizationCache() to actually use it.
>
>
>
> I’m not sure if this helps or not, but below is a stack trace from my
> servlet. Somewhere along this chain of calls, somebody should have called
> AuthorizingRealm.getAuthorizationCache() but didn’t.
>
>
>
> Thanks,
>
> Andy
>
> ----------------------------------------------------------------------------------------------
>
>       at java.lang.Thread.dumpStack(Thread.java:1206)
>
>       at
> com.vonage.authenticatorTest.TestServlet1.doGet(TestServlet1.java:15)
>
>       at javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
>
>       at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
>
>       at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
>
>       at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
>
>       at
> org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:58)
>
>       at
> org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:107)
>
>       at
> org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
>
>       at
> org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:190)
>
>       at
> org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:63)
>
>       at
> org.apache.shiro.web.servlet.ShiroFilter.executeChain(ShiroFilter.java:648)
>
>       at
> org.apache.shiro.web.servlet.ShiroFilter.doFilterInternal(ShiroFilter.java:588)
>
>       at
> org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:190)
>
>       at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
>
>       at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
>
>       at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
>
>       at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
>
>       at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
>
>       at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
>
>       at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
>
>       at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
>
>       at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
>
>       at
> org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
>
>       at
> org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
>
>       at
> org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
>
>       at
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
>
>       at java.lang.Thread.run(Thread.java:619)
>
>

Reply via email to