[jboss-user] [Security & JAAS/JBoss] - custom timedCacheFactory problem

lost_traveller do-not-reply at jboss.com
Thu Nov 2 05:52:51 EST 2006


We have a problem whereby a user is logged out after 30 minutes and JBoss attempts to re-login, since we use a custom Principal which contains a session id the session id is lost.

The reason a user logs out after 30 minutes is because in jboss-service.xml DefaultCacheTimeout is set to 1800 seconds. What we would like is not to specify a time but to allow a users timeout to be refreshed each time a secure method is called, which is possible because org.jboss.util.TimedCachePolicy contains a refersh() method, which is currently hard-coded to return false. So what we have done is extend TimedCachePolicy and override refresh() to refresh the timeout:

  | public class TimedRefreshCachePolicy extends TimedCachePolicy implements Serializable
  | {
  | 
  |    /**
  |     * @see org.jboss.util.TimedCachePolicy#insert(java.lang.Object, java.lang.Object)
  |     */
  |    @Override
  |    public void insert(Object key, Object value)
  |    {
  |       super.insert(key, new RefreshTimedEntry(getDefaultLifetime(), value));
  |    }
  | 
  |    /**
  |     * The default implementation of TimedEntry used to wrap non-TimedEntry objects inserted into the
  |     * cache.
  |     */
  |    static class RefreshTimedEntry implements TimedEntry, Serializable
  |    {
  | 
  |       private long expirationTime = -1;
  | 
  |       private Object value = null;
  | 
  |       private long lifetime = -1;
  | 
  |       RefreshTimedEntry(final long lifetime, final Object value)
  |       {
  |          this.expirationTime = 1000 * lifetime;
  |          this.value = value;
  |          this.lifetime = lifetime;
  |       }
  | 
  |       public void init(long now)
  |       {
  |          expirationTime += now;
  |       }
  | 
  |       public boolean isCurrent(long now)
  |       {
  |          return expirationTime > now;
  |       }
  | 
  |       public boolean refresh()
  |       {
  |          // this is called to refresh the time since the last call to this item in the
  |          // cache, return true to indicate that a refresh took place and that the item 
  |          // is still valid
  |          expirationTime = System.currentTimeMillis() + (1000 * lifetime);
  |          return true;
  |       }
  | 
  |       public void destroy()
  |       {
  |       }
  | 
  |       public Object getValue()
  |       {
  |          return value;
  |       }
  |    }
  | 
  | }

According to chapter 8 we can configure our own cache policy:

anonymous wrote : This is done by appending the name of the security domain to this name when looking up the CachePolicy for a domain

We have create an MBean to bind TimedRefreshCachePolicy to our security domain:


  | public class PetStoreService extends ServiceMBeanSupport implements PetStoreServiceMBean
  | {
  | ......
  |          new InitialContext().bind("java:/timedCacheFactory/petstore", Class.forName("com.foo.TimedRefreshCachePolicy").newInstance());
  | 
  |          Object obj0 = new InitialContext().lookup("java:/timedCacheFactory");
  |          Object obj1 = new InitialContext().lookup("java:/timedCacheFactory/petstore");
  |          Object obj3 = new InitialContext().lookup("java:/timedCacheFactory/sdmfhsjhdfcnb");
  | ....
  | }
  | 
The problem is TimedRefreshCachePolicy won't bind to java:/timedCacheFactory/petstore in fact we can insert any text after java:/timedCacheFactory and it will return a TimedCachePolicy, from the code above:
obj0 returns some proxy
obj1 returns a TimedCachePolicy
obj2 returns a TimedCachePolicy

So how do I bind my TimedRefreshCachePolicy to java:/timedCacheFactory/petstore? or have we got this wrong and implemented it in the wrong way? We would preferably like a CachePolicy on a per domain basis, without having to change any JBoss configuration.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3982617#3982617

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3982617



More information about the jboss-user mailing list