use of net.sf.ehcache.Element in project sling by apache.
the class CacheImpl method values.
/**
* {@inheritDoc}
*
* @see org.apache.sling.commons.cache.api.Cache#list()
*/
@SuppressWarnings("unchecked")
public Collection<V> values() {
List<String> keys = cache.getKeys();
List<V> values = new ArrayList<V>();
for (String k : keys) {
Element e = cache.get(k);
if (e != null) {
values.add((V) e.getObjectValue());
}
}
return values;
}
use of net.sf.ehcache.Element in project sling by apache.
the class CacheImpl method put.
/**
* {@inherit-doc}
*
* @see org.apache.sling.commons.cache.api.Cache#put(java.lang.String,
* java.lang.Object)
*/
@SuppressWarnings("unchecked")
public V put(String key, V payload) {
V previous = null;
if (cache.isKeyInCache(key)) {
Element e = cache.get(key);
if (e != null) {
previous = (V) e.getObjectValue();
}
}
cache.put(new Element(key, payload));
return previous;
}
use of net.sf.ehcache.Element in project cas by apereo.
the class CRLDistributionPointRevocationChecker method getCRLs.
@Override
protected List<X509CRL> getCRLs(final X509Certificate cert) {
if (this.crlCache == null) {
throw new IllegalArgumentException("CRL cache is not defined");
}
if (this.fetcher == null) {
throw new IllegalArgumentException("CRL fetcher is not defined");
}
if (getExpiredCRLPolicy() == null) {
throw new IllegalArgumentException("Expiration CRL policy is not defined");
}
if (getUnavailableCRLPolicy() == null) {
throw new IllegalArgumentException("Unavailable CRL policy is not defined");
}
final URI[] urls = getDistributionPoints(cert);
LOGGER.debug("Distribution points for [{}]: [{}].", CertUtils.toString(cert), Arrays.asList(urls));
final List<X509CRL> listOfLocations = new ArrayList<>(urls.length);
boolean stopFetching = false;
try {
for (int index = 0; !stopFetching && index < urls.length; index++) {
final URI url = urls[index];
final Element item = this.crlCache.get(url);
if (item != null) {
LOGGER.debug("Found CRL in cache for [{}]", CertUtils.toString(cert));
final byte[] encodedCrl = (byte[]) item.getObjectValue();
final X509CRL crlFetched = this.fetcher.fetch(new ByteArrayResource(encodedCrl));
if (crlFetched != null) {
listOfLocations.add(crlFetched);
} else {
LOGGER.warn("Could fetch X509 CRL for [{}]. Returned value is null", url);
}
} else {
LOGGER.debug("CRL for [{}] is not cached. Fetching and caching...", CertUtils.toString(cert));
try {
final X509CRL crl = this.fetcher.fetch(url);
if (crl != null) {
LOGGER.info("Success. Caching fetched CRL at [{}].", url);
addCRL(url, crl);
listOfLocations.add(crl);
}
} catch (final Exception e) {
LOGGER.error("Error fetching CRL at [{}]", url, e);
if (this.throwOnFetchFailure) {
throw Throwables.propagate(e);
}
}
}
if (!this.checkAll && !listOfLocations.isEmpty()) {
LOGGER.debug("CRL fetching is configured to not check all locations.");
stopFetching = true;
}
}
} catch (final Exception e) {
throw Throwables.propagate(e);
}
LOGGER.debug("Found [{}] CRLs", listOfLocations.size());
return listOfLocations;
}
use of net.sf.ehcache.Element in project cas by apereo.
the class EhCacheTicketRegistry method getTicket.
@Override
public Ticket getTicket(final String ticketIdToGet) {
final String ticketId = encodeTicketId(ticketIdToGet);
if (ticketId == null) {
return null;
}
final Element element = this.ehcacheTicketsCache.get(ticketId);
if (element == null) {
LOGGER.debug("No ticket by id [{}] is found in the registry", ticketId);
return null;
}
final Ticket ticket = decodeTicket((Ticket) element.getObjectValue());
final CacheConfiguration config = new CacheConfiguration();
config.setTimeToIdleSeconds(ticket.getExpirationPolicy().getTimeToIdle());
config.setTimeToLiveSeconds(ticket.getExpirationPolicy().getTimeToLive());
if (element.isExpired(config) || ticket.isExpired()) {
LOGGER.debug("Ticket [{}] has expired", ticket.getId());
this.ehcacheTicketsCache.evictExpiredElements();
this.ehcacheTicketsCache.flush();
return null;
}
return ticket;
}
use of net.sf.ehcache.Element in project cas by apereo.
the class EhCacheTicketRegistry method addTicket.
@Override
public void addTicket(final Ticket ticketToAdd) {
final Ticket ticket = encodeTicket(ticketToAdd);
final Element element = new Element(ticket.getId(), ticket);
int idleValue = ticketToAdd.getExpirationPolicy().getTimeToIdle().intValue();
if (idleValue <= 0) {
idleValue = ticketToAdd.getExpirationPolicy().getTimeToLive().intValue();
}
if (idleValue <= 0) {
idleValue = Integer.MAX_VALUE;
}
element.setTimeToIdle(idleValue);
int aliveValue = ticketToAdd.getExpirationPolicy().getTimeToLive().intValue();
if (aliveValue <= 0) {
aliveValue = Integer.MAX_VALUE;
}
element.setTimeToLive(aliveValue);
LOGGER.debug("Adding ticket [{}] to the cache [{}] to live [{}] seconds and stay idle for [{}] seconds", ticket.getId(), this.ehcacheTicketsCache.getName(), aliveValue, idleValue);
this.ehcacheTicketsCache.put(element);
}
Aggregations