use of org.nhindirect.config.store.CertPolicy in project nhin-d by DirectProject.
the class CertPolicyDaoImpl method addPolicyUseToGroup.
@Override
@Transactional(readOnly = false)
public void addPolicyUseToGroup(long groupId, long policyId, CertPolicyUse policyUse, boolean incoming, boolean outgoing) throws ConfigurationStoreException {
validateState();
// make sure the policy exists
final CertPolicyGroup policyGroup = this.getPolicyGroupById(groupId);
if (policyGroup == null)
throw new ConfigurationStoreException("Policy group with id " + groupId + " does not exist");
// make sure the policy exists
final CertPolicy policy = this.getPolicyById(policyId);
if (policy == null)
throw new ConfigurationStoreException("Policy with id " + policyId + " does not exist");
try {
final CertPolicyGroupReltn reltn = new CertPolicyGroupReltn();
reltn.setCertPolicy(policy);
reltn.setCertPolicyGroup(policyGroup);
reltn.setPolicyUse(policyUse);
reltn.setIncoming(incoming);
reltn.setOutgoing(outgoing);
policyGroup.getCertPolicyGroupReltn().add(reltn);
entityManager.persist(policyGroup);
entityManager.flush();
} catch (Exception e) {
throw new ConfigurationStoreException("Failed to add policy use to policy group.", e);
}
}
use of org.nhindirect.config.store.CertPolicy in project nhin-d by DirectProject.
the class CertPolicyDaoImpl method getPolicies.
@SuppressWarnings("unchecked")
@Override
@Transactional(readOnly = true)
public Collection<CertPolicy> getPolicies() throws ConfigurationStoreException {
validateState();
try {
final Query select = entityManager.createQuery("SELECT cp from CertPolicy cp");
final Collection<CertPolicy> rs = select.getResultList();
if (rs.size() == 0)
return Collections.emptyList();
return rs;
} catch (Exception e) {
throw new ConfigurationStoreException("Failed to execute certificate policy DAO query.", e);
}
}
use of org.nhindirect.config.store.CertPolicy in project nhin-d by DirectProject.
the class CertPolicyDaoImpl method deletePolicies.
@Override
@Transactional(readOnly = false)
public void deletePolicies(long[] policyIds) throws ConfigurationStoreException {
validateState();
if (policyIds == null || policyIds.length == 0)
return;
for (long id : policyIds) {
try {
final CertPolicy bundle = this.getPolicyById(id);
this.removePolicyUseFromGroups(id);
entityManager.remove(bundle);
entityManager.flush();
} catch (ConfigurationStoreException e) {
log.warn(e.getMessage(), e);
}
}
}
use of org.nhindirect.config.store.CertPolicy in project nhin-d by DirectProject.
the class CertPolicyDaoImpl method removePolicyUseFromGroups.
/**
* {@inheritDoc}
*/
@Transactional(readOnly = false)
public void removePolicyUseFromGroups(long policyId) throws ConfigurationStoreException {
validateState();
// make sure the trust bundle exists
final CertPolicy policy = this.getPolicyById(policyId);
if (policy == null)
throw new ConfigurationStoreException("Certificate policy with id " + policyId + " does not exist");
try {
final Query delete = entityManager.createQuery("DELETE from CertPolicyGroupReltn cpr where cpr.certPolicy = ?1");
delete.setParameter(1, policy);
delete.executeUpdate();
entityManager.flush();
} catch (Exception e) {
throw new ConfigurationStoreException("Failed to remove policy id " + policyId + " from all groups", e);
}
}
use of org.nhindirect.config.store.CertPolicy 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() });
}
}
Aggregations