use of org.apache.jcs.access.exception.CacheException in project nhin-d by DirectProject.
the class CertCacheFactory method getCertCache.
/**
* Retrieves a cert cache by name. Caches are created using a singleton pattern meaning one and only once instance of a cache for a given name
* is ever created.
* @param cacheName The name of the cache to retrieve.
* @param cachePolicy Policy to apply to the cache
* @return The certificate cache for the given cache name.
* @throws CacheException Thrown if the cache cannot be created.
*/
public synchronized JCS getCertCache(String cacheName, CertStoreCachePolicy cachePolicy) throws CacheException {
JCS retVal = certCacheMap.get(cacheName);
if (retVal == null) {
try {
// create instance
retVal = JCS.getInstance(cacheName);
if (cachePolicy != null)
applyCachePolicy(retVal, cachePolicy);
certCacheMap.put(cacheName, retVal);
} catch (CacheException e) {
LOGGER.warn("Failed to create JCS cache " + cacheName, e);
throw e;
}
}
return retVal;
}
use of org.apache.jcs.access.exception.CacheException in project nhin-d by DirectProject.
the class LDAPCertificateStore method getCertificates.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public Collection<X509Certificate> getCertificates(String subjectName) {
String realSubjectName;
int index;
if ((index = subjectName.indexOf("EMAILADDRESS=")) > -1)
realSubjectName = subjectName.substring(index + "EMAILADDRESS=".length());
else
realSubjectName = subjectName;
Collection<X509Certificate> retVal;
JCS cache = getCache();
if (cache != null) {
// try to get it from the cache first
retVal = (Collection<X509Certificate>) cache.get(realSubjectName);
// the certificate is not in the cache, so now hit the real server
if (retVal == null || retVal.size() == 0) {
retVal = ldapCertUtil.ldapSearch(realSubjectName);
// add or update the cache and the local cert store
if (retVal != null && retVal.size() > 0) {
// don't cache wildcard searches
if (!subjectName.contains("*")) {
try {
// first add the certificates to the cache
cache.putSafe(realSubjectName, retVal);
} catch (CacheException e) {
// TODO: handle exception
LOGGER.error("Error adding certificates to the cache: " + e.getMessage(), e);
}
// now add or update the local cert store
if (localStoreDelegate != null) {
addOrUpdateLocalStoreDelegate(retVal);
}
}
} else // couldn't retrieve the certificate from the real server, so have to go to the bootstrap
{
if (localStoreDelegate != null) {
// last ditch effort is to go to the bootstrap cache
retVal = localStoreDelegate.getCertificates(realSubjectName);
}
}
if (retVal == null || retVal.size() == 0) {
LOGGER.info("getCertificates(String subjectName) - Could not find an LDAP certificate for subject " + subjectName);
}
}
} else // cache miss
{
retVal = ldapCertUtil.ldapSearch(realSubjectName);
if (localStoreDelegate != null) {
if (retVal == null || retVal.size() == 0) {
// last ditch effort is to go to the bootstrap cache
retVal = localStoreDelegate.getCertificates(realSubjectName);
} else if (!subjectName.contains("*")) {
// now add or update the local cert store
addOrUpdateLocalStoreDelegate(retVal);
}
}
if (retVal == null || retVal.size() == 0) {
LOGGER.info("getCertificates(String subjectName) - Could not find an LDAP certificate for subject " + subjectName);
}
}
return retVal;
}
use of org.apache.jcs.access.exception.CacheException in project nhin-d by DirectProject.
the class CacheableKeyStoreManagerCertificateStore method applyCachePolicy.
private void applyCachePolicy(CertStoreCachePolicy policy) {
if (getCache() != null) {
try {
ICompositeCacheAttributes attributes = cache.getCacheAttributes();
attributes.setMaxObjects(policy.getMaxItems());
attributes.setUseLateral(false);
attributes.setUseRemote(false);
cache.setCacheAttributes(attributes);
IElementAttributes eattributes = cache.getDefaultElementAttributes();
eattributes.setMaxLifeSeconds(policy.getSubjectTTL());
eattributes.setIsEternal(false);
eattributes.setIsLateral(false);
eattributes.setIsRemote(false);
cache.setDefaultElementAttributes(eattributes);
} catch (CacheException e) {
// no-op
}
}
}
use of org.apache.jcs.access.exception.CacheException in project nhin-d by DirectProject.
the class CacheableKeyStoreManagerCertificateStore method getCertificates.
///CLOVER:ON
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public Collection<X509Certificate> getCertificates(String subjectName) {
String realSubjectName;
int index;
if ((index = subjectName.indexOf("EMAILADDRESS=")) > -1)
realSubjectName = subjectName.substring(index + "EMAILADDRESS=".length());
else
realSubjectName = subjectName;
Collection<X509Certificate> retVal;
final JCS cache = getCache();
if (cache != null) {
retVal = (Collection<X509Certificate>) cache.get(realSubjectName);
if (retVal == null || retVal.size() == 0)
retVal = super.getCertificates(subjectName);
} else
// cache miss
retVal = super.getCertificates(subjectName);
if (retVal == null || retVal.size() == 0) {
LOGGER.info("getCertificates(String subjectName) - Could not find a PKCS11 certificate for subject " + subjectName);
} else {
try {
if (cache != null)
cache.put(realSubjectName, retVal);
} catch (CacheException e) {
/*
* no-opss
*/
}
}
return retVal;
}
use of org.apache.jcs.access.exception.CacheException in project nhin-d by DirectProject.
the class DNSCertificateStore method applyCachePolicy.
private void applyCachePolicy(CertStoreCachePolicy policy) {
if (getCache() != null) {
try {
ICompositeCacheAttributes attributes = cache.getCacheAttributes();
attributes.setMaxObjects(policy.getMaxItems());
attributes.setUseLateral(false);
attributes.setUseRemote(false);
cache.setCacheAttributes(attributes);
IElementAttributes eattributes = cache.getDefaultElementAttributes();
eattributes.setMaxLifeSeconds(policy.getSubjectTTL());
eattributes.setIsEternal(false);
eattributes.setIsLateral(false);
eattributes.setIsRemote(false);
cache.setDefaultElementAttributes(eattributes);
} catch (CacheException e) {
// TODO: Handle exception
}
}
}
Aggregations