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(Applica
tionFilterChain.java:269)

      at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
erChain.java:188)

      at
org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterCh
ain.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(OncePerReques
tFilter.java:190)

      at
org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterCh
ain.java:63)

      at
org.apache.shiro.web.servlet.ShiroFilter.executeChain(ShiroFilter.java:6
48)

      at
org.apache.shiro.web.servlet.ShiroFilter.doFilterInternal(ShiroFilter.ja
va:588)

      at
org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerReques
tFilter.java:190)

      at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
tionFilterChain.java:215)

      at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
erChain.java:188)

      at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv
e.java:213)

      at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv
e.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:1
74)

      at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:87
5)

      at
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.proc
essConnection(Http11BaseProtocol.java:665)

      at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint
.java:528)

      at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollow
erWorkerThread.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