use of org.nhindirect.config.store.TrustBundle in project nhin-d by DirectProject.
the class SpringBaseTest method cleanDataStore.
protected void cleanDataStore() throws Exception {
final ApplicationContext ctx = ConfigServiceRunner.getSpringApplicationContext();
final AddressDao addressDao = (AddressDao) ctx.getBean("addressDaoImpl");
final TrustBundleDao trustDao = (TrustBundleDao) ctx.getBean("trustBundleDao");
final DomainDao domainDao = (DomainDao) ctx.getBean("domainDao");
final AnchorDao anchorDao = (AnchorDao) ctx.getBean("anchorDao");
final CertificateDao certDao = (CertificateDao) ctx.getBean("certificateDao");
final DNSDao dnsDao = (DNSDao) ctx.getBean("DNSDaoImpl");
final SettingDao settingDao = (SettingDao) ctx.getBean("settingDao");
final CertPolicyDao policyDao = (CertPolicyDao) ctx.getBean("certPolicyDao");
// clean anchors
final List<Anchor> anchors = anchorDao.listAll();
if (!anchors.isEmpty()) {
final List<Long> anchorIds = new ArrayList<Long>();
for (Anchor anchor : anchors) anchorIds.add(anchor.getId());
anchorDao.delete(anchorIds);
}
// clean domains and the trust bundle domain relationships
final List<Domain> domains = domainDao.listDomains(null, domainDao.count());
if (domains != null) {
for (Domain domain : domains) {
Collection<Address> addresses = addressDao.getByDomain(domain, null);
if (addresses != null) {
for (Address address : addresses) {
addressDao.delete(address.getEmailAddress());
}
}
trustDao.disassociateTrustBundlesFromDomain(domain.getId());
domainDao.delete(domain.getId());
}
}
assertEquals(0, domainDao.count());
//clean trust bundles
Collection<TrustBundle> bundles = trustDao.getTrustBundles();
for (TrustBundle bundle : bundles) trustDao.deleteTrustBundles(new long[] { bundle.getId() });
bundles = trustDao.getTrustBundles();
assertEquals(0, bundles.size());
// clean certificates
final List<Certificate> certs = certDao.list((String) null);
if (!certs.isEmpty()) {
for (Certificate cert : certs) {
certDao.delete(cert.getOwner());
}
}
// clean DNS records
final Collection<DNSRecord> records = dnsDao.get(Type.ANY);
if (!records.isEmpty()) {
for (DNSRecord record : records) dnsDao.remove(record.getId());
}
// clean settings
final Collection<Setting> settings = settingDao.getAll();
if (!settings.isEmpty()) {
for (Setting setting : settings) settingDao.delete(Arrays.asList(setting.getName()));
}
// clean policies
final Collection<CertPolicy> policies = policyDao.getPolicies();
if (!policies.isEmpty()) {
for (CertPolicy policy : policies) policyDao.deletePolicies(new long[] { policy.getId() });
}
// clean policy groups
final Collection<CertPolicyGroup> groups = policyDao.getPolicyGroups();
if (!groups.isEmpty()) {
for (CertPolicyGroup group : groups) policyDao.deletePolicyGroups(new long[] { group.getId() });
}
}
use of org.nhindirect.config.store.TrustBundle in project nhin-d by DirectProject.
the class TrustBundleServiceImpl method updateTrustBundleAttributes.
/**
* {@inheritDoc}
*/
@Override
public void updateTrustBundleAttributes(long trustBundleId, String bundleName, String bundleUrl, Certificate signingCert, int refreshInterval) throws ConfigurationServiceException {
final TrustBundle oldBundle = dao.getTrustBundleById(trustBundleId);
String oldBundleURL = "";
X509Certificate newSigningCert = null;
// need to know if the URL changed... store off the old URL
if (oldBundle != null)
oldBundleURL = oldBundle.getBundleURL();
try {
// make sure the cert isn't null before converting to an X509Certificate
if (signingCert != null && signingCert.toCredential() != null)
newSigningCert = signingCert.toCredential().getCert();
dao.updateTrustBundleAttributes(trustBundleId, bundleName, bundleUrl, newSigningCert, refreshInterval);
// if the URL changed, the bundle needs to be refreshed
if (!oldBundleURL.equals(bundleUrl)) {
final TrustBundle bundle = dao.getTrustBundleById(trustBundleId);
if (bundle != null)
template.sendBody(bundle);
}
} catch (CertificateException e) {
throw new ConfigurationServiceException(e);
}
}
use of org.nhindirect.config.store.TrustBundle in project nhin-d by DirectProject.
the class SpringBaseTest method cleanDataStore.
protected void cleanDataStore() throws Exception {
final ApplicationContext ctx = ConfigServiceRunner.getSpringApplicationContext();
final AddressDao addressDao = (AddressDao) ctx.getBean("addressDao");
final TrustBundleDao trustDao = (TrustBundleDao) ctx.getBean("trustBundleDao");
final DomainDao domainDao = (DomainDao) ctx.getBean("domainDao");
final AnchorDao anchorDao = (AnchorDao) ctx.getBean("anchorDao");
final CertificateDao certDao = (CertificateDao) ctx.getBean("certificateDao");
final DNSDao dnsDao = (DNSDao) ctx.getBean("dnsDao");
final SettingDao settingDao = (SettingDao) ctx.getBean("settingDao");
final CertPolicyDao policyDao = (CertPolicyDao) ctx.getBean("certPolicyDao");
// clean anchors
final List<Anchor> anchors = anchorDao.listAll();
if (!anchors.isEmpty()) {
final List<Long> anchorIds = new ArrayList<Long>();
for (Anchor anchor : anchors) anchorIds.add(anchor.getId());
anchorDao.delete(anchorIds);
}
// clean domains and the trust bundle domain relationships
final List<Domain> domains = domainDao.listDomains(null, domainDao.count());
if (domains != null) {
for (Domain domain : domains) {
Collection<Address> addresses = addressDao.getByDomain(domain, null);
if (addresses != null) {
for (Address address : addresses) {
addressDao.delete(address.getEmailAddress());
}
}
trustDao.disassociateTrustBundlesFromDomain(domain.getId());
domainDao.delete(domain.getId());
}
}
assertEquals(0, domainDao.count());
//clean trust bundles
Collection<TrustBundle> bundles = trustDao.getTrustBundles();
for (TrustBundle bundle : bundles) trustDao.deleteTrustBundles(new long[] { bundle.getId() });
bundles = trustDao.getTrustBundles();
assertEquals(0, bundles.size());
// clean certificates
final List<Certificate> certs = certDao.list((String) null);
if (!certs.isEmpty()) {
for (Certificate cert : certs) {
certDao.delete(cert.getOwner());
}
}
// clean DNS records
final Collection<DNSRecord> records = dnsDao.get(Type.ANY);
if (!records.isEmpty()) {
for (DNSRecord record : records) dnsDao.remove(record.getId());
}
// clean settings
final Collection<Setting> settings = settingDao.getAll();
if (!settings.isEmpty()) {
for (Setting setting : settings) settingDao.delete(Arrays.asList(setting.getName()));
}
// clean policies
final Collection<CertPolicy> policies = policyDao.getPolicies();
if (!policies.isEmpty()) {
for (CertPolicy policy : policies) policyDao.deletePolicies(new long[] { policy.getId() });
}
// clean policy groups
final Collection<CertPolicyGroup> groups = policyDao.getPolicyGroups();
if (!groups.isEmpty()) {
for (CertPolicyGroup group : groups) policyDao.deletePolicyGroups(new long[] { group.getId() });
}
}
use of org.nhindirect.config.store.TrustBundle in project nhin-d by DirectProject.
the class TrustBundleService_realDataTest method testUpdateAttributes_noBundleRefresh.
public void testUpdateAttributes_noBundleRefresh() 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);
// make sure the bundle is there
final TrustBundle addedBundle = trustService.getTrustBundleByName("Test Bundle");
assertNotNull(addedBundle);
// update the bundle
trustService.updateTrustBundleAttributes(addedBundle.getId(), "Test Bundle 2", addedBundle.getBundleURL(), null, addedBundle.getRefreshInterval());
// now get the updated bundle
final TrustBundle updatedBundle = trustService.getTrustBundleById(addedBundle.getId());
assertEquals("Test Bundle 2", updatedBundle.getBundleName());
assertEquals(addedBundle.getBundleURL(), updatedBundle.getBundleURL());
assertEquals(addedBundle.getRefreshInterval(), updatedBundle.getRefreshInterval());
assertNull(updatedBundle.getSigningCertificateData());
assertEquals(addedBundle.getTrustBundleAnchors().size(), updatedBundle.getTrustBundleAnchors().size());
}
use of org.nhindirect.config.store.TrustBundle in project nhin-d by DirectProject.
the class TrustBundleService_realDataTest method testUpdateAttributes_bundleRefresh.
public void testUpdateAttributes_bundleRefresh() throws Exception {
final 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);
// make sure the bundle is there
final TrustBundle addedBundle = trustService.getTrustBundleByName("Test Bundle");
assertNotNull(addedBundle);
// update the bundle
final File newBundleLocation = new File("./src/test/resources/bundles/providerTestBundle.p7b");
trustService.updateTrustBundleAttributes(addedBundle.getId(), "Test Bundle 2", filePrefix + newBundleLocation.getAbsolutePath(), null, addedBundle.getRefreshInterval());
// now get the updated bundle
final TrustBundle updatedBundle = trustService.getTrustBundleById(addedBundle.getId());
assertEquals("Test Bundle 2", updatedBundle.getBundleName());
assertFalse(newBundleLocation.getAbsolutePath().equals(updatedBundle.getBundleURL()));
assertEquals(addedBundle.getRefreshInterval(), updatedBundle.getRefreshInterval());
assertNull(updatedBundle.getSigningCertificateData());
assertFalse(addedBundle.getTrustBundleAnchors().size() == updatedBundle.getTrustBundleAnchors().size());
}
Aggregations