Search in sources :

Example 1 with TrustBundleAnchor

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

the class DefaultBundleCacheUpdateProcessorImpl_springInitTest method testLoadConfigService_addTrustBundle_bundleAnchorsAdded.

public void testLoadConfigService_addTrustBundle_bundleAnchorsAdded() throws Exception {
    File bundleLocation = new File("./src/test/resources/bundles/signedbundle.p7b");
    final ApplicationContext ctx = ConfigServiceRunner.getSpringApplicationContext();
    assertNotNull(ctx);
    TrustBundleService trustService = (TrustBundleService) ctx.getBean("trustBundleSvc");
    final TrustBundle bundle = new TrustBundle();
    bundle.setBundleName("Test Bundle");
    bundle.setBundleURL(filePrefix + bundleLocation.getAbsolutePath());
    trustService.addTrustBundle(bundle);
    final TrustBundle addedBundle = trustService.getTrustBundleByName("Test Bundle");
    assertTrue(addedBundle.getTrustBundleAnchors().size() > 0);
    for (TrustBundleAnchor anchor : addedBundle.getTrustBundleAnchors()) assertNotNull(anchor.getData());
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) TrustBundleService(org.nhindirect.config.service.TrustBundleService) TrustBundle(org.nhindirect.config.store.TrustBundle) File(java.io.File) TrustBundleAnchor(org.nhindirect.config.store.TrustBundleAnchor)

Example 2 with TrustBundleAnchor

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

the class DefaultBundleRefreshProcessorImpl_refreshBundleTest method testRefreshBundle_validBundle_unmatchedChecksum_needsRefreshed_assertUpdateCalled.

@SuppressWarnings("unchecked")
public void testRefreshBundle_validBundle_unmatchedChecksum_needsRefreshed_assertUpdateCalled() throws Exception {
    DefaultBundleRefreshProcessorImpl processor = new DefaultBundleRefreshProcessorImpl();
    processor.setDao(dao);
    final TrustBundle bundle = new TrustBundle();
    bundle.setBundleName("Junit Bundle");
    File fl = new File("src/test/resources/bundles/signedbundle.p7b");
    bundle.setBundleURL(filePrefix + fl.getAbsolutePath());
    bundle.setCheckSum("12345");
    processor.refreshBundle(bundle);
    verify(dao, times(1)).updateTrustBundleAnchors(eq(bundle.getId()), (Calendar) any(), (Collection<TrustBundleAnchor>) any(), (String) any());
}
Also used : TrustBundle(org.nhindirect.config.store.TrustBundle) File(java.io.File) TrustBundleAnchor(org.nhindirect.config.store.TrustBundleAnchor)

Example 3 with TrustBundleAnchor

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

the class DefaultBundleRefreshProcessorImpl_refreshBundleTest method testRefreshBundle_checkSumsMatch_assertUpdateNotCalled.

@SuppressWarnings("unchecked")
public void testRefreshBundle_checkSumsMatch_assertUpdateNotCalled() throws Exception {
    DefaultBundleRefreshProcessorImpl processor = new DefaultBundleRefreshProcessorImpl();
    processor.setDao(dao);
    final TrustBundle bundle = new TrustBundle();
    File fl = new File("src/test/resources/bundles/signedbundle.p7b");
    byte[] rawBundleByte = FileUtils.readFileToByteArray(fl);
    bundle.setBundleName("Junit Bundle");
    bundle.setBundleURL(filePrefix + fl.getAbsolutePath());
    bundle.setCheckSum(BundleThumbprint.toThumbprint(rawBundleByte).toString());
    processor.refreshBundle(bundle);
    verify(dao, times(0)).updateTrustBundleAnchors(eq(bundle.getId()), (Calendar) any(), (Collection<TrustBundleAnchor>) any(), (String) any());
}
Also used : TrustBundle(org.nhindirect.config.store.TrustBundle) File(java.io.File) TrustBundleAnchor(org.nhindirect.config.store.TrustBundleAnchor)

Example 4 with TrustBundleAnchor

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

the class DefaultBundleRefreshProcessorImpl_refreshBundleTest method testRefreshBundle_errorOnUpdate.

@SuppressWarnings("unchecked")
public void testRefreshBundle_errorOnUpdate() throws Exception {
    DefaultBundleRefreshProcessorImpl processor = new DefaultBundleRefreshProcessorImpl();
    processor.setDao(dao);
    final TrustBundle bundle = new TrustBundle();
    bundle.setBundleName("Junit Bundle");
    File fl = new File("src/test/resources/bundles/signedbundle.p7b");
    bundle.setBundleURL(filePrefix + fl.getAbsolutePath());
    doThrow(new ConfigurationStoreException("Just Passing Through")).when(dao).updateTrustBundleAnchors(eq(bundle.getId()), (Calendar) any(), (Collection<TrustBundleAnchor>) any(), (String) any());
    processor.refreshBundle(bundle);
    verify(dao, times(1)).updateTrustBundleAnchors(eq(bundle.getId()), (Calendar) any(), (Collection<TrustBundleAnchor>) any(), (String) any());
}
Also used : TrustBundle(org.nhindirect.config.store.TrustBundle) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) File(java.io.File) TrustBundleAnchor(org.nhindirect.config.store.TrustBundleAnchor)

Example 5 with TrustBundleAnchor

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

the class TrustBundleDaoImpl method getTrustBundlesByDomain.

/**
	 * {@inheritDoc}
	 */
@SuppressWarnings("unchecked")
@Override
@Transactional(readOnly = true)
public Collection<TrustBundleDomainReltn> getTrustBundlesByDomain(long domainId) throws ConfigurationStoreException {
    validateState();
    // make sure the domain exists
    final Domain domain = domainDao.getDomain(domainId);
    if (domain == null)
        throw new ConfigurationStoreException("Domain with id " + domainId + " does not exist");
    Collection<TrustBundleDomainReltn> retVal = null;
    try {
        final Query select = entityManager.createQuery("SELECT tbd from TrustBundleDomainReltn tbd where tbd.domain = ?1");
        select.setParameter(1, domain);
        retVal = (Collection<TrustBundleDomainReltn>) select.getResultList();
        if (retVal.size() == 0)
            return Collections.emptyList();
        for (TrustBundleDomainReltn reltn : retVal) {
            if (!reltn.getTrustBundle().getTrustBundleAnchors().isEmpty())
                for (TrustBundleAnchor anchor : reltn.getTrustBundle().getTrustBundleAnchors()) anchor.getData();
        }
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to execute trust bundle relation DAO query.", e);
    }
    return retVal;
}
Also used : Query(javax.persistence.Query) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Domain(org.nhindirect.config.store.Domain) TrustBundleAnchor(org.nhindirect.config.store.TrustBundleAnchor) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) TrustBundleDomainReltn(org.nhindirect.config.store.TrustBundleDomainReltn) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

TrustBundleAnchor (org.nhindirect.config.store.TrustBundleAnchor)12 TrustBundle (org.nhindirect.config.store.TrustBundle)10 File (java.io.File)7 ConfigurationStoreException (org.nhindirect.config.store.ConfigurationStoreException)6 NoResultException (javax.persistence.NoResultException)4 Query (javax.persistence.Query)4 Transactional (org.springframework.transaction.annotation.Transactional)4 SocketTimeoutException (java.net.SocketTimeoutException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 X509Certificate (java.security.cert.X509Certificate)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 HashSet (java.util.HashSet)1 Handler (org.apache.camel.Handler)1 TrustBundleService (org.nhindirect.config.service.TrustBundleService)1 Domain (org.nhindirect.config.store.Domain)1 TrustBundleDomainReltn (org.nhindirect.config.store.TrustBundleDomainReltn)1 ApplicationContext (org.springframework.context.ApplicationContext)1