Search in sources :

Example 1 with ConfigurationStoreException

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

the class DomainService_realDataTest method testDeleteDomainById_associatedTrustBundle_assertDomainDeleted.

public void testDeleteDomainById_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.removeDomainById(domain.getId());
    assertEquals(0, domainService.getDomainCount());
    boolean exceptionOccured = false;
    try {
        associatedBundel = trustService.getTrustBundlesByDomain(domain.getId(), true);
    } catch (ConfigurationStoreException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) TrustBundle(org.nhindirect.config.store.TrustBundle) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Domain(org.nhindirect.config.store.Domain) File(java.io.File) TrustBundleDomainReltn(org.nhindirect.config.store.TrustBundleDomainReltn)

Example 2 with ConfigurationStoreException

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

the class DefaultBundleRefreshProcessorImpl_refreshBundleTest method testRefreshBundle_errorOnUpdate.

@SuppressWarnings("unchecked")
public void testRefreshBundle_errorOnUpdate() 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());
    doThrow(new ConfigurationStoreException("Just Passing Through")).when(dao).updateTrustBundleAnchors(eq(bundle.getId()), (Calendar) any(), (Collection<TrustBundleAnchor>) any(), (String) any());
    processor.refreshBundle(bundle);
    verify(dao, times(1)).updateTrustBundleAnchors(eq(bundle.getId()), (Calendar) any(), (Collection<TrustBundleAnchor>) any(), (String) any());
}
Also used : TrustBundle(org.nhindirect.config.store.TrustBundle) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) File(java.io.File) TrustBundleAnchor(org.nhindirect.config.store.TrustBundleAnchor)

Example 3 with ConfigurationStoreException

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

the class CertPolicyDaoImpl method getPolicyGroupDomainReltns.

@SuppressWarnings("unchecked")
@Override
@Transactional(readOnly = true)
public Collection<CertPolicyGroupDomainReltn> getPolicyGroupDomainReltns() throws ConfigurationStoreException {
    validateState();
    try {
        final Query select = entityManager.createQuery("SELECT cpdr from CertPolicyGroupDomainReltn cpdr");
        final Collection<CertPolicyGroupDomainReltn> rs = select.getResultList();
        if (rs.size() == 0)
            return Collections.emptyList();
        for (CertPolicyGroupDomainReltn reltn : rs) {
            if (!reltn.getCertPolicyGroup().getCertPolicyGroupReltn().isEmpty())
                for (CertPolicyGroupReltn groupReltn : reltn.getCertPolicyGroup().getCertPolicyGroupReltn()) groupReltn.getCertPolicy().getPolicyData();
        }
        return rs;
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to execute certificate policy DAO query.", e);
    }
}
Also used : CertPolicyGroupReltn(org.nhindirect.config.store.CertPolicyGroupReltn) CertPolicyGroupDomainReltn(org.nhindirect.config.store.CertPolicyGroupDomainReltn) Query(javax.persistence.Query) 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 ConfigurationStoreException

use of org.nhindirect.config.store.ConfigurationStoreException 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 5 with ConfigurationStoreException

use of org.nhindirect.config.store.ConfigurationStoreException 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)

Aggregations

ConfigurationStoreException (org.nhindirect.config.store.ConfigurationStoreException)45 Transactional (org.springframework.transaction.annotation.Transactional)39 NoResultException (javax.persistence.NoResultException)32 Query (javax.persistence.Query)21 TrustBundle (org.nhindirect.config.store.TrustBundle)15 CertPolicyGroup (org.nhindirect.config.store.CertPolicyGroup)10 Domain (org.nhindirect.config.store.Domain)10 CertPolicy (org.nhindirect.config.store.CertPolicy)8 TrustBundleAnchor (org.nhindirect.config.store.TrustBundleAnchor)6 TrustBundleDomainReltn (org.nhindirect.config.store.TrustBundleDomainReltn)5 CertPolicyGroupDomainReltn (org.nhindirect.config.store.CertPolicyGroupDomainReltn)4 File (java.io.File)3 CertPolicyGroupReltn (org.nhindirect.config.store.CertPolicyGroupReltn)3 DNSRecord (org.nhindirect.config.store.DNSRecord)2 ApplicationContext (org.springframework.context.ApplicationContext)2 IOException (java.io.IOException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 X509Certificate (java.security.cert.X509Certificate)1 RSAKey (java.security.interfaces.RSAKey)1