use of org.nhindirect.config.store.TrustBundle in project nhin-d by DirectProject.
the class DefaultBundleRefreshProcessorImpl_convertRawBundleToAnchorCollectionTest method testConvertRawBundleToAnchorCollection_getFromSignedBundle_verifySigner_assertAnchors.
public void testConvertRawBundleToAnchorCollection_getFromSignedBundle_verifySigner_assertAnchors() throws Exception {
final X509Certificate signer = TestUtils.loadSigner("bundleSigner.der");
final byte[] rawBundle = TestUtils.loadBundle("signedbundle.p7m");
final DefaultBundleRefreshProcessorImpl processor = new DefaultBundleRefreshProcessorImpl();
final TrustBundle existingBundle = new TrustBundle();
existingBundle.setSigningCertificateData(signer.getEncoded());
final Calendar processAttempStart = Calendar.getInstance(Locale.getDefault());
Collection<X509Certificate> anchors = processor.convertRawBundleToAnchorCollection(rawBundle, existingBundle, processAttempStart);
assertNotNull(anchors);
assertEquals(1, anchors.size());
}
use of org.nhindirect.config.store.TrustBundle in project nhin-d by DirectProject.
the class DefaultBundleCacheUpdateProcessorImpl method updateBundleCache.
/**
* {@inheritDoc}
*/
@Handler
public void updateBundleCache() {
Collection<TrustBundle> bundles;
try {
bundles = dao.getTrustBundles();
for (TrustBundle bundle : bundles) {
boolean refresh = false;
// if the refresh interval is 0 or less, then we won't ever auto refresh the bundle
if (bundle.getRefreshInterval() <= 0)
continue;
// see if this bundle needs to be checked for updating
final Calendar lastAttempt = bundle.getLastSuccessfulRefresh();
if (lastAttempt == null)
// never been attempted successfully... better go get it
refresh = true;
else {
// check the the last attempt date against now and see if we need to refresh
long now = System.currentTimeMillis();
Calendar lastAttemptCheck = (Calendar) lastAttempt.clone();
lastAttemptCheck.add(Calendar.SECOND, bundle.getRefreshInterval());
if (lastAttemptCheck.getTimeInMillis() <= now)
refresh = true;
}
if (refresh) {
// refresh the bundle
try {
refreshProcessor.refreshBundle(bundle);
} catch (Exception e) {
log.warn("Failed to check the status of bundle " + bundle.getBundleName(), e);
}
}
}
} catch (Exception e) {
log.warn("Failed to check the status of trust bundles ", e);
}
}
use of org.nhindirect.config.store.TrustBundle in project nhin-d by DirectProject.
the class DefaultBundleCacheUpdateProcessorImpl_springInitTest method testLoadConfigService_refreshBundle_assertBundleRefreshed.
public void testLoadConfigService_refreshBundle_assertBundleRefreshed() 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);
final Calendar lastRefreshAttemp = addedBundle.getLastRefreshAttempt();
final Calendar lastSuccessfulRefresh = addedBundle.getLastSuccessfulRefresh();
// now refresh
trustService.refreshTrustBundle(addedBundle.getId());
final TrustBundle refreshedBundle = trustService.getTrustBundleByName("Test Bundle");
assertEquals(lastSuccessfulRefresh.getTimeInMillis(), refreshedBundle.getLastSuccessfulRefresh().getTimeInMillis());
assertTrue(refreshedBundle.getLastRefreshAttempt().getTimeInMillis() > lastRefreshAttemp.getTimeInMillis());
}
use of org.nhindirect.config.store.TrustBundle in project nhin-d by DirectProject.
the class DefaultBundleCacheUpdateProcessorImpl_updateBundleCacheTest method testUpdateBundleCache_updateCache_zeroRefreshInterval_assertBundleRefreshNotCalled.
public void testUpdateBundleCache_updateCache_zeroRefreshInterval_assertBundleRefreshNotCalled() throws Exception {
final DefaultBundleCacheUpdateProcessorImpl cacheUpdate = new DefaultBundleCacheUpdateProcessorImpl();
cacheUpdate.setDao(dao);
cacheUpdate.setRefreshProcessor(processor);
final TrustBundle bundle = new TrustBundle();
final Collection<TrustBundle> bundles = Arrays.asList(bundle);
when(dao.getTrustBundles()).thenReturn(bundles);
cacheUpdate.updateBundleCache();
verify(dao, times(1)).getTrustBundles();
verify(processor, never()).refreshBundle(bundle);
}
use of org.nhindirect.config.store.TrustBundle in project nhin-d by DirectProject.
the class DefaultBundleCacheUpdateProcessorImpl_updateBundleCacheTest method testUpdateBundleCache_updateCache_refreshIntervalExpired_assertBundleRefreshCalled.
public void testUpdateBundleCache_updateCache_refreshIntervalExpired_assertBundleRefreshCalled() throws Exception {
final DefaultBundleCacheUpdateProcessorImpl cacheUpdate = new DefaultBundleCacheUpdateProcessorImpl();
cacheUpdate.setDao(dao);
cacheUpdate.setRefreshProcessor(processor);
final TrustBundle bundle = new TrustBundle();
bundle.setRefreshInterval(1000);
final Calendar lastSuccessRefresh = Calendar.getInstance(Locale.getDefault());
lastSuccessRefresh.add(Calendar.SECOND, -1200);
bundle.setLastSuccessfulRefresh(lastSuccessRefresh);
final Collection<TrustBundle> bundles = Arrays.asList(bundle);
when(dao.getTrustBundles()).thenReturn(bundles);
cacheUpdate.updateBundleCache();
verify(dao, times(1)).getTrustBundles();
verify(processor, times(1)).refreshBundle(bundle);
}
Aggregations