Search in sources :

Example 21 with ConfigurationStoreException

use of org.nhindirect.config.store.ConfigurationStoreException in project nhin-d by DirectProject.

the class TrustBundleDaoImpl method updateTrustBundleAttributes.

/**
	 * {@inheritDoc}
	 */
@Override
@Transactional(readOnly = false)
public void updateTrustBundleAttributes(long trustBundleId, String bundleName, String bundleUrl, X509Certificate signingCert, int refreshInterval) throws ConfigurationStoreException {
    validateState();
    try {
        final TrustBundle existingBundle = this.getTrustBundleById(trustBundleId);
        if (existingBundle == null)
            throw new ConfigurationStoreException("Trust bundle does not exist");
        if (signingCert == null)
            existingBundle.setSigningCertificateData(null);
        else
            existingBundle.setSigningCertificateData(signingCert.getEncoded());
        existingBundle.setRefreshInterval(refreshInterval);
        if (bundleName != null && !bundleName.isEmpty())
            existingBundle.setBundleName(bundleName);
        if (bundleUrl != null && !bundleUrl.isEmpty())
            existingBundle.setBundleURL(bundleUrl);
        entityManager.persist(existingBundle);
        entityManager.flush();
    } catch (ConfigurationStoreException cse) {
        throw cse;
    }///CLOVER:OFF
     catch (Exception e) {
        throw new ConfigurationStoreException("Failed to update bundle last refresh error.", e);
    }
///CLOVER:ON
}
Also used : TrustBundle(org.nhindirect.config.store.TrustBundle) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with ConfigurationStoreException

use of org.nhindirect.config.store.ConfigurationStoreException in project nhin-d by DirectProject.

the class TrustBundleDaoImpl method getTrustBundles.

/**
	 * {@inheritDoc}
	 */
@SuppressWarnings("unchecked")
@Override
@Transactional(readOnly = true)
public Collection<TrustBundle> getTrustBundles() throws ConfigurationStoreException {
    validateState();
    Collection<TrustBundle> rs;
    try {
        Query select = entityManager.createQuery("SELECT tb from TrustBundle tb");
        rs = select.getResultList();
        if (rs.size() == 0)
            return Collections.emptyList();
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to execute trust bundle DAO query.", e);
    }
    // make sure the anchors are loaded
    for (TrustBundle bundle : rs) {
        if (!bundle.getTrustBundleAnchors().isEmpty())
            for (TrustBundleAnchor anchor : bundle.getTrustBundleAnchors()) anchor.getData();
    }
    return rs;
}
Also used : Query(javax.persistence.Query) TrustBundle(org.nhindirect.config.store.TrustBundle) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) TrustBundleAnchor(org.nhindirect.config.store.TrustBundleAnchor) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with ConfigurationStoreException

use of org.nhindirect.config.store.ConfigurationStoreException in project nhin-d by DirectProject.

the class DefaultBundleRefreshProcessorImpl method refreshBundle.

/**
	 * {@inheritDoc}
	 */
@Handler
public void refreshBundle(TrustBundle bundle) {
    // track when the process started
    final Calendar processAttempStart = Calendar.getInstance(Locale.getDefault());
    // get the bundle from the URL
    final byte[] rawBundle = downloadBundleToByteArray(bundle, processAttempStart);
    if (rawBundle == null)
        return;
    // check to see if there is a difference in the anchor sets
    // use a checksum 
    boolean update = false;
    String checkSum = "";
    if (bundle.getCheckSum() == null)
        // never got a check sum... 
        update = true;
    else {
        try {
            checkSum = BundleThumbprint.toThumbprint(rawBundle).toString();
            update = !bundle.getCheckSum().equals(BundleThumbprint.toThumbprint(rawBundle).toString());
        }///CLOVER:OFF
         catch (NoSuchAlgorithmException ex) {
            dao.updateLastUpdateError(bundle.getId(), processAttempStart, BundleRefreshError.INVALID_BUNDLE_FORMAT);
            log.error("Failed to generate downloaded bundle thumbprint ", ex);
        }
    ///CLOVER:ON
    }
    if (!update) {
        dao.updateLastUpdateError(bundle.getId(), processAttempStart, BundleRefreshError.SUCCESS);
        return;
    }
    final Collection<X509Certificate> bundleCerts = convertRawBundleToAnchorCollection(rawBundle, bundle, processAttempStart);
    if (bundleCerts == null)
        return;
    final HashSet<X509Certificate> downloadedSet = new HashSet<X509Certificate>((Collection<X509Certificate>) bundleCerts);
    try {
        final Collection<TrustBundleAnchor> newAnchors = new ArrayList<TrustBundleAnchor>();
        for (X509Certificate downloadedAnchor : downloadedSet) {
            try {
                final TrustBundleAnchor anchorToAdd = new TrustBundleAnchor();
                anchorToAdd.setData(downloadedAnchor.getEncoded());
                anchorToAdd.setTrustBundle(bundle);
                newAnchors.add(anchorToAdd);
            }///CLOVER:OFF
             catch (Exception e) {
                log.warn("Failed to convert downloaded anchor to byte array. ", e);
            }
        ///CLOVER:ON
        }
        bundle.setTrustBundleAnchors(newAnchors);
        dao.updateTrustBundleAnchors(bundle.getId(), processAttempStart, newAnchors, checkSum);
        dao.updateLastUpdateError(bundle.getId(), processAttempStart, BundleRefreshError.SUCCESS);
    } catch (ConfigurationStoreException e) {
        dao.updateLastUpdateError(bundle.getId(), processAttempStart, BundleRefreshError.INVALID_BUNDLE_FORMAT);
        log.error("Failed to write updated bundle anchors to data store ", e);
    }
}
Also used : Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) X509Certificate(java.security.cert.X509Certificate) SocketTimeoutException(java.net.SocketTimeoutException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) TrustBundleAnchor(org.nhindirect.config.store.TrustBundleAnchor) HashSet(java.util.HashSet) Handler(org.apache.camel.Handler)

Example 24 with ConfigurationStoreException

use of org.nhindirect.config.store.ConfigurationStoreException in project nhin-d by DirectProject.

the class DefaultBundleCacheUpdateProcessorImpl_updateBundleCacheTest method testUpdateBundleCache_updateCache_errorInRetreavingBundles_assertBundleRefreshNotCalled.

public void testUpdateBundleCache_updateCache_errorInRetreavingBundles_assertBundleRefreshNotCalled() throws Exception {
    final DefaultBundleCacheUpdateProcessorImpl cacheUpdate = new DefaultBundleCacheUpdateProcessorImpl();
    cacheUpdate.setDao(dao);
    cacheUpdate.setRefreshProcessor(processor);
    doThrow(new ConfigurationStoreException("Just Passing Through")).when(dao).getTrustBundles();
    cacheUpdate.updateBundleCache();
    verify(dao, times(1)).getTrustBundles();
    verify(processor, never()).refreshBundle((TrustBundle) any());
}
Also used : ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException)

Example 25 with ConfigurationStoreException

use of org.nhindirect.config.store.ConfigurationStoreException in project nhin-d by DirectProject.

the class DomainService_realDataTest method testDeleteDomainByName_associatedTrustBundle_assertDomainDeleted.

@SuppressWarnings("deprecation")
public void testDeleteDomainByName_associatedTrustBundle_assertDomainDeleted() throws Exception {
    File bundleLocation = new File("./src/test/resources/bundles/signedbundle.p7b");
    final ApplicationContext ctx = ConfigServiceRunner.getSpringApplicationContext();
    // add a bundle
    TrustBundleService trustService = (TrustBundleService) ctx.getBean("trustBundleSvc");
    final TrustBundle bundle = new TrustBundle();
    bundle.setBundleName("Test Bundle");
    bundle.setBundleURL(filePrefix + bundleLocation.getAbsolutePath());
    trustService.addTrustBundle(bundle);
    // add a domain
    DomainService domainService = (DomainService) ctx.getBean("domainSvc");
    Domain domain = new Domain();
    domain.setDomainName("Test Domain");
    domain.setStatus(EntityStatus.ENABLED);
    domainService.addDomain(domain);
    //associate domain to bundle
    trustService.associateTrustBundleToDomain(domain.getId(), bundle.getId(), true, true);
    // assert the association
    Collection<TrustBundleDomainReltn> associatedBundel = trustService.getTrustBundlesByDomain(domain.getId(), true);
    assertEquals(1, associatedBundel.size());
    // now delete the domain
    domainService.removeDomain(domain.getDomainName());
    assertEquals(0, domainService.getDomainCount());
    boolean exceptionOccured = false;
    try {
        associatedBundel = trustService.getTrustBundlesByDomain(domain.getId(), true);
    } catch (ConfigurationStoreException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) TrustBundle(org.nhindirect.config.store.TrustBundle) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Domain(org.nhindirect.config.store.Domain) File(java.io.File) TrustBundleDomainReltn(org.nhindirect.config.store.TrustBundleDomainReltn)

Aggregations

ConfigurationStoreException (org.nhindirect.config.store.ConfigurationStoreException)45 Transactional (org.springframework.transaction.annotation.Transactional)39 NoResultException (javax.persistence.NoResultException)32 Query (javax.persistence.Query)21 TrustBundle (org.nhindirect.config.store.TrustBundle)15 CertPolicyGroup (org.nhindirect.config.store.CertPolicyGroup)10 Domain (org.nhindirect.config.store.Domain)10 CertPolicy (org.nhindirect.config.store.CertPolicy)8 TrustBundleAnchor (org.nhindirect.config.store.TrustBundleAnchor)6 TrustBundleDomainReltn (org.nhindirect.config.store.TrustBundleDomainReltn)5 CertPolicyGroupDomainReltn (org.nhindirect.config.store.CertPolicyGroupDomainReltn)4 File (java.io.File)3 CertPolicyGroupReltn (org.nhindirect.config.store.CertPolicyGroupReltn)3 DNSRecord (org.nhindirect.config.store.DNSRecord)2 ApplicationContext (org.springframework.context.ApplicationContext)2 IOException (java.io.IOException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 X509Certificate (java.security.cert.X509Certificate)1 RSAKey (java.security.interfaces.RSAKey)1