Search in sources :

Example 1 with CertPolicyGroup

use of org.nhindirect.config.store.CertPolicyGroup 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() });
    }
}
Also used : CertificateDao(org.nhindirect.config.store.dao.CertificateDao) Address(org.nhindirect.config.store.Address) ArrayList(java.util.ArrayList) TrustBundleDao(org.nhindirect.config.store.dao.TrustBundleDao) AnchorDao(org.nhindirect.config.store.dao.AnchorDao) ApplicationContext(org.springframework.context.ApplicationContext) SettingDao(org.nhindirect.config.store.dao.SettingDao) DomainDao(org.nhindirect.config.store.dao.DomainDao) TrustBundle(org.nhindirect.config.store.TrustBundle) AddressDao(org.nhindirect.config.store.dao.AddressDao) CertPolicyDao(org.nhindirect.config.store.dao.CertPolicyDao) DNSRecord(org.nhindirect.config.store.DNSRecord) Setting(org.nhindirect.config.store.Setting) DNSDao(org.nhindirect.config.store.dao.DNSDao) Anchor(org.nhindirect.config.store.Anchor) CertPolicy(org.nhindirect.config.store.CertPolicy) CertPolicyGroup(org.nhindirect.config.store.CertPolicyGroup) Domain(org.nhindirect.config.store.Domain) Certificate(org.nhindirect.config.store.Certificate)

Example 2 with CertPolicyGroup

use of org.nhindirect.config.store.CertPolicyGroup in project nhin-d by DirectProject.

the class CertificatePolicyServiceTest method testAddPolicyGruop.

public void testAddPolicyGruop() throws Exception {
    final CertPolicyGroup group = new CertPolicyGroup();
    impl.addPolicyGroup(group);
    verify(dao, times(1)).addPolicyGroup(group);
}
Also used : CertPolicyGroup(org.nhindirect.config.store.CertPolicyGroup)

Example 3 with CertPolicyGroup

use of org.nhindirect.config.store.CertPolicyGroup 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);
    }
}
Also used : CertPolicyGroupReltn(org.nhindirect.config.store.CertPolicyGroupReltn) CertPolicy(org.nhindirect.config.store.CertPolicy) CertPolicyGroup(org.nhindirect.config.store.CertPolicyGroup) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with CertPolicyGroup

use of org.nhindirect.config.store.CertPolicyGroup in project nhin-d by DirectProject.

the class CertPolicyDaoImpl method disassociatePolicyGroupFromDomain.

@Override
@Transactional(readOnly = false)
public void disassociatePolicyGroupFromDomain(long domainId, long policyGroupId) throws ConfigurationStoreException {
    validateState();
    // make sure the domain exists
    final Domain domain = domainDao.getDomain(domainId);
    if (domain == null)
        throw new ConfigurationStoreException("Domain with id " + domainId + " does not exist");
    // make sure the policy group exists
    final CertPolicyGroup policyGroup = this.getPolicyGroupById(policyGroupId);
    if (policyGroup == null)
        throw new ConfigurationStoreException("Policy group with id " + policyGroup + " does not exist");
    try {
        final Query select = entityManager.createQuery("SELECT cpr from CertPolicyGroupDomainReltn cpr where cpr.domain  = ?1 " + " and cpr.certPolicyGroup = ?2 ");
        select.setParameter(1, domain);
        select.setParameter(2, policyGroup);
        final CertPolicyGroupDomainReltn reltn = (CertPolicyGroupDomainReltn) select.getSingleResult();
        entityManager.remove(reltn);
        entityManager.flush();
    } catch (NoResultException e) {
        throw new ConfigurationStoreException("Association between domain id " + domainId + " and policy group id " + policyGroupId + " does not exist", e);
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to delete policy group from domain relation.", e);
    }
}
Also used : CertPolicyGroupDomainReltn(org.nhindirect.config.store.CertPolicyGroupDomainReltn) Query(javax.persistence.Query) CertPolicyGroup(org.nhindirect.config.store.CertPolicyGroup) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) NoResultException(javax.persistence.NoResultException) Domain(org.nhindirect.config.store.Domain) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with CertPolicyGroup

use of org.nhindirect.config.store.CertPolicyGroup in project nhin-d by DirectProject.

the class CertPolicyDaoImpl method addPolicyGroup.

@Override
@Transactional(readOnly = false)
public void addPolicyGroup(CertPolicyGroup group) throws ConfigurationStoreException {
    validateState();
    try {
        final CertPolicyGroup existingPolicyGroup = this.getPolicyGroupByName(group.getPolicyGroupName());
        if (existingPolicyGroup != null)
            throw new ConfigurationStoreException("Certificate policy group " + group.getPolicyGroupName() + " already exists");
        group.setCreateTime(Calendar.getInstance(Locale.getDefault()));
        entityManager.persist(group);
        entityManager.flush();
    } catch (ConfigurationStoreException cse) {
        throw cse;
    }///CLOVER:OFF
     catch (Exception e) {
        throw new ConfigurationStoreException("Failed to add certificate policy group " + group.getPolicyGroupName(), e);
    }
///CLOVER:ON
}
Also used : CertPolicyGroup(org.nhindirect.config.store.CertPolicyGroup) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

CertPolicyGroup (org.nhindirect.config.store.CertPolicyGroup)13 ConfigurationStoreException (org.nhindirect.config.store.ConfigurationStoreException)10 Transactional (org.springframework.transaction.annotation.Transactional)10 NoResultException (javax.persistence.NoResultException)9 Query (javax.persistence.Query)5 Domain (org.nhindirect.config.store.Domain)4 CertPolicy (org.nhindirect.config.store.CertPolicy)3 ArrayList (java.util.ArrayList)2 Address (org.nhindirect.config.store.Address)2 Anchor (org.nhindirect.config.store.Anchor)2 CertPolicyGroupDomainReltn (org.nhindirect.config.store.CertPolicyGroupDomainReltn)2 Certificate (org.nhindirect.config.store.Certificate)2 DNSRecord (org.nhindirect.config.store.DNSRecord)2 Setting (org.nhindirect.config.store.Setting)2 TrustBundle (org.nhindirect.config.store.TrustBundle)2 AddressDao (org.nhindirect.config.store.dao.AddressDao)2 AnchorDao (org.nhindirect.config.store.dao.AnchorDao)2 CertPolicyDao (org.nhindirect.config.store.dao.CertPolicyDao)2 CertificateDao (org.nhindirect.config.store.dao.CertificateDao)2 DNSDao (org.nhindirect.config.store.dao.DNSDao)2