use of org.nhindirect.config.store.TrustBundleAnchor 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;
}
use of org.nhindirect.config.store.TrustBundleAnchor 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);
}
}
use of org.nhindirect.config.store.TrustBundleAnchor in project nhin-d by DirectProject.
the class DefaultBundleRefreshProcessorImpl_refreshBundleTest method testRefreshBundle_invalidBundle_assertUpdateNotCalled.
@SuppressWarnings("unchecked")
public void testRefreshBundle_invalidBundle_assertUpdateNotCalled() 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/invalidBundle.der");
bundle.setBundleURL(filePrefix + fl.getAbsolutePath());
processor.refreshBundle(bundle);
verify(dao, times(0)).updateTrustBundleAnchors(eq(bundle.getId()), (Calendar) any(), (Collection<TrustBundleAnchor>) any(), (String) any());
}
use of org.nhindirect.config.store.TrustBundleAnchor in project nhin-d by DirectProject.
the class DefaultBundleRefreshProcessorImpl_refreshBundleTest method testRefreshBundle_bundleNotFound_assertUpdateNotCalled.
@SuppressWarnings("unchecked")
public void testRefreshBundle_bundleNotFound_assertUpdateNotCalled() 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.p7b2122");
bundle.setBundleURL(filePrefix + fl.getAbsolutePath());
processor.refreshBundle(bundle);
verify(dao, times(0)).updateTrustBundleAnchors(eq(bundle.getId()), (Calendar) any(), (Collection<TrustBundleAnchor>) any(), (String) any());
}
use of org.nhindirect.config.store.TrustBundleAnchor in project nhin-d by DirectProject.
the class DefaultBundleRefreshProcessorImpl_refreshBundleTest method testRefreshBundle_validBundle_noCheckSum_needsRefreshed_assertUpdateCalled.
@SuppressWarnings("unchecked")
public void testRefreshBundle_validBundle_noCheckSum_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());
processor.refreshBundle(bundle);
verify(dao, times(1)).updateTrustBundleAnchors(eq(bundle.getId()), (Calendar) any(), (Collection<TrustBundleAnchor>) any(), (String) any());
}
Aggregations