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
}
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;
}
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);
}
}
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());
}
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);
}
Aggregations