Search in sources :

Example 6 with CacheException

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
        }
    }
}
Also used : CacheException(org.apache.jcs.access.exception.CacheException) ICompositeCacheAttributes(org.apache.jcs.engine.behavior.ICompositeCacheAttributes) IElementAttributes(org.apache.jcs.engine.behavior.IElementAttributes)

Example 7 with CacheException

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;
}
Also used : CacheException(org.apache.jcs.access.exception.CacheException) JCS(org.apache.jcs.JCS) X509Certificate(java.security.cert.X509Certificate)

Example 8 with CacheException

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
        }
    }
}
Also used : CacheException(org.apache.jcs.access.exception.CacheException) ICompositeCacheAttributes(org.apache.jcs.engine.behavior.ICompositeCacheAttributes) IElementAttributes(org.apache.jcs.engine.behavior.IElementAttributes)

Example 9 with CacheException

use of org.apache.jcs.access.exception.CacheException in project nhin-d by DirectProject.

the class ConfigServiceCertificateStore method lookupFromConfigStore.

private Collection<X509Certificate> lookupFromConfigStore(String subjectName) {
    String domain;
    org.nhind.config.Certificate[] certificates;
    try {
        certificates = proxy.getCertificatesForOwner(subjectName, null);
    } catch (Exception e) {
        throw new NHINDException("WebService error getting certificates by subject: " + e.getMessage(), e);
    }
    if (certificates == null || certificates.length == 0) {
        // try again with the domain name
        int index;
        if ((index = subjectName.indexOf("@")) > -1)
            domain = subjectName.substring(index + 1);
        else
            domain = subjectName;
        try {
            certificates = proxy.getCertificatesForOwner(domain, null);
        } catch (Exception e) {
            throw new NHINDException("WebService error getting certificates by domain: " + e.getMessage(), e);
        }
    }
    if (certificates == null || certificates.length == 0)
        return Collections.emptyList();
    Collection<X509Certificate> retVal = new ArrayList<X509Certificate>();
    for (org.nhind.config.Certificate cert : certificates) {
        X509Certificate storeCert = CertStoreUtils.certFromData(mgr, cert.getData());
        retVal.add(storeCert);
        if (localStoreDelegate != null) {
            if (localStoreDelegate.contains(storeCert))
                localStoreDelegate.update(storeCert);
            else
                localStoreDelegate.add(storeCert);
        }
    }
    // add to JCS and cache
    try {
        if (cache != null)
            cache.put(subjectName, retVal);
    } catch (CacheException e) {
    /*
			 * TODO: handle exception
			 */
    }
    return retVal;
}
Also used : CacheException(org.apache.jcs.access.exception.CacheException) ArrayList(java.util.ArrayList) NHINDException(org.nhindirect.stagent.NHINDException) CacheException(org.apache.jcs.access.exception.CacheException) NHINDException(org.nhindirect.stagent.NHINDException) X509Certificate(java.security.cert.X509Certificate) X509Certificate(java.security.cert.X509Certificate)

Example 10 with CacheException

use of org.apache.jcs.access.exception.CacheException in project nhin-d by DirectProject.

the class ConfigServiceRESTCertificateStore 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
        }
    }
}
Also used : CacheException(org.apache.jcs.access.exception.CacheException) ICompositeCacheAttributes(org.apache.jcs.engine.behavior.ICompositeCacheAttributes) IElementAttributes(org.apache.jcs.engine.behavior.IElementAttributes)

Aggregations

CacheException (org.apache.jcs.access.exception.CacheException)13 X509Certificate (java.security.cert.X509Certificate)7 ArrayList (java.util.ArrayList)5 ICompositeCacheAttributes (org.apache.jcs.engine.behavior.ICompositeCacheAttributes)5 IElementAttributes (org.apache.jcs.engine.behavior.IElementAttributes)5 NHINDException (org.nhindirect.stagent.NHINDException)5 JCS (org.apache.jcs.JCS)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 UnknownHostException (java.net.UnknownHostException)1 Certificate (java.security.cert.Certificate)1 Thumbprint (org.nhindirect.stagent.cert.Thumbprint)1 CERTRecord (org.xbill.DNS.CERTRecord)1 CNAMERecord (org.xbill.DNS.CNAMERecord)1 ExtendedResolver (org.xbill.DNS.ExtendedResolver)1 Lookup (org.xbill.DNS.Lookup)1 NSRecord (org.xbill.DNS.NSRecord)1 Name (org.xbill.DNS.Name)1 Record (org.xbill.DNS.Record)1