mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-07-05 02:02:15 +00:00
Fixed issue with hot redeploy as cache not being closed.
This commit is contained in:
parent
a51506d0d5
commit
b6e0c3076f
@ -23,6 +23,10 @@ import net.sf.ehcache.CacheException;
|
|||||||
import net.sf.ehcache.CacheManager;
|
import net.sf.ehcache.CacheManager;
|
||||||
import net.sf.ehcache.Element;
|
import net.sf.ehcache.Element;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.DisposableBean;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
|
||||||
import org.springframework.dao.DataRetrievalFailureException;
|
import org.springframework.dao.DataRetrievalFailureException;
|
||||||
@ -35,7 +39,12 @@ import org.springframework.dao.DataRetrievalFailureException;
|
|||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class EhCacheBasedTicketCache implements StatelessTicketCache,
|
public class EhCacheBasedTicketCache implements StatelessTicketCache,
|
||||||
InitializingBean {
|
InitializingBean, DisposableBean {
|
||||||
|
//~ Static fields/initializers =============================================
|
||||||
|
|
||||||
|
private static final Log logger = LogFactory.getLog(EhCacheBasedTicketCache.class);
|
||||||
|
private static final String CACHE_NAME = "ehCacheBasedTicketCache";
|
||||||
|
|
||||||
//~ Instance fields ========================================================
|
//~ Instance fields ========================================================
|
||||||
|
|
||||||
private Cache cache;
|
private Cache cache;
|
||||||
@ -54,13 +63,14 @@ public class EhCacheBasedTicketCache implements StatelessTicketCache,
|
|||||||
+ cacheException.getMessage());
|
+ cacheException.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element == null) {
|
if (logger.isDebugEnabled()) {
|
||||||
System.out.println("not found");
|
logger.debug("Cache hit: " + (element != null)
|
||||||
|
+ "; service ticket: " + serviceTicket);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (element == null) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
System.out.println("found");
|
|
||||||
|
|
||||||
return (CasAuthenticationToken) element.getValue();
|
return (CasAuthenticationToken) element.getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,18 +97,30 @@ public class EhCacheBasedTicketCache implements StatelessTicketCache,
|
|||||||
manager = CacheManager.create();
|
manager = CacheManager.create();
|
||||||
|
|
||||||
// Cache name, max memory, overflowToDisk, eternal, timeToLive, timeToIdle
|
// Cache name, max memory, overflowToDisk, eternal, timeToLive, timeToIdle
|
||||||
cache = new Cache("ehCacheBasedTicketCache", Integer.MAX_VALUE, false,
|
cache = new Cache(CACHE_NAME, Integer.MAX_VALUE, false, false,
|
||||||
false, minutesToIdle * 60, minutesToIdle * 60);
|
minutesToIdle * 60, minutesToIdle * 60);
|
||||||
manager.addCache(cache);
|
manager.addCache(cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void destroy() throws Exception {
|
||||||
|
manager.removeCache(CACHE_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
public void putTicketInCache(CasAuthenticationToken token) {
|
public void putTicketInCache(CasAuthenticationToken token) {
|
||||||
Element element = new Element(token.getCredentials().toString(), token);
|
Element element = new Element(token.getCredentials().toString(), token);
|
||||||
System.out.println("Adding " + element.getKey());
|
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("Cache put: " + element.getKey());
|
||||||
|
}
|
||||||
|
|
||||||
cache.put(element);
|
cache.put(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeTicketFromCache(CasAuthenticationToken token) {
|
public void removeTicketFromCache(CasAuthenticationToken token) {
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("Cache remove: " + token.getCredentials().toString());
|
||||||
|
}
|
||||||
|
|
||||||
this.removeTicketFromCache(token.getCredentials().toString());
|
this.removeTicketFromCache(token.getCredentials().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user