Search in sources :

Example 1 with CertPolicy

use of org.nhind.config.CertPolicy in project nhin-d by DirectProject.

the class ConfigServiceDNSStore_configCertPolicyTest method testConfigCertPolicy_validPolicy_assertPolicyConfiged.

public void testConfigCertPolicy_validPolicy_assertPolicyConfiged() throws Exception {
    System.setProperty(ConfigServiceDNSStore.DNS_CERT_POLICY_NAME_VAR, "ValidPolicy");
    try {
        final CertPolicy policy = new CertPolicy();
        policy.setLexicon(PolicyLexicon.SIMPLE_TEXT_V1);
        policy.setPolicyName("ValidPolicy");
        policy.setPolicyData(VALID_POLICY.getBytes());
        proxy.addPolicy(policy);
        final ConfigServiceDNSStore store = new ConfigServiceDNSStore(new URL(ConfigServiceRunner.getConfigServiceURL()));
        assertNotNull(store.polExpression);
        assertNotNull(store.polFilter);
    } finally {
        System.setProperty(ConfigServiceDNSStore.DNS_CERT_POLICY_NAME_VAR, "");
    }
}
Also used : CertPolicy(org.nhind.config.CertPolicy) URL(java.net.URL)

Example 2 with CertPolicy

use of org.nhind.config.CertPolicy in project nhin-d by DirectProject.

the class ConfigServiceDNSStore_configCertPolicyTest method testConfigCertPolicy_invalidPolicy_assertNoPolicyConfiged.

public void testConfigCertPolicy_invalidPolicy_assertNoPolicyConfiged() throws Exception {
    System.setProperty(ConfigServiceDNSStore.DNS_CERT_POLICY_NAME_VAR, "InvalidPolicy");
    try {
        final CertPolicy policy = new CertPolicy();
        policy.setLexicon(PolicyLexicon.SIMPLE_TEXT_V1);
        policy.setPolicyName("InvalidPolicy");
        policy.setPolicyData(INVALID_VALID_POLICY.getBytes());
        proxy.addPolicy(policy);
        final ConfigServiceDNSStore store = new ConfigServiceDNSStore(new URL(ConfigServiceRunner.getConfigServiceURL()));
        assertNull(store.polExpression);
        assertNull(store.polFilter);
    } finally {
        System.setProperty(ConfigServiceDNSStore.DNS_CERT_POLICY_NAME_VAR, "");
    }
}
Also used : CertPolicy(org.nhind.config.CertPolicy) URL(java.net.URL)

Example 3 with CertPolicy

use of org.nhind.config.CertPolicy in project nhin-d by DirectProject.

the class ConfigServiceDNSStore_isCertCompliantWithPolicyTest method testisCertCompliantWithPolicy_policyConfigured_nonCompliantCert_assertNonCompliant.

public void testisCertCompliantWithPolicy_policyConfigured_nonCompliantCert_assertNonCompliant() throws Exception {
    System.setProperty(ConfigServiceDNSStore.DNS_CERT_POLICY_NAME_VAR, "ValidPolicy");
    try {
        final CertPolicy policy = new CertPolicy();
        policy.setLexicon(PolicyLexicon.SIMPLE_TEXT_V1);
        policy.setPolicyName("ValidPolicy");
        policy.setPolicyData(KEY_ENC_POLICY.getBytes());
        proxy.addPolicy(policy);
        final ConfigServiceDNSStore store = new ConfigServiceDNSStore(new URL(ConfigServiceRunner.getConfigServiceURL()));
        assertNotNull(store.polExpression);
        assertNotNull(store.polFilter);
        X509Certificate cert = DNSRecordUtil.loadCertificate("umesh.der");
        assertFalse(store.isCertCompliantWithPolicy(cert));
    } finally {
        System.setProperty(ConfigServiceDNSStore.DNS_CERT_POLICY_NAME_VAR, "");
    }
}
Also used : CertPolicy(org.nhind.config.CertPolicy) URL(java.net.URL) X509Certificate(java.security.cert.X509Certificate)

Example 4 with CertPolicy

use of org.nhind.config.CertPolicy in project nhin-d by DirectProject.

the class ClientProxyCertificatePolicyTest method testAddGetRemovePolicyGroupAndDomain_deleteDomainBeforeDissasociate.

@Test
public void testAddGetRemovePolicyGroupAndDomain_deleteDomainBeforeDissasociate() throws Exception {
    CertPolicy addPolicy = new CertPolicy();
    addPolicy.setLexicon(PolicyLexicon.XML);
    addPolicy.setPolicyName("Test Policy");
    addPolicy.setPolicyData(new byte[] { 1, 2, 3 });
    proxy.addPolicy(addPolicy);
    CertPolicy[] retrievedPolicies = proxy.getPolicies();
    assertEquals(1, retrievedPolicies.length);
    CertPolicyGroup addGroup = new CertPolicyGroup();
    addGroup.setPolicyGroupName("Test Group");
    proxy.addPolicyGroup(addGroup);
    CertPolicyGroup[] retrievedGroups = proxy.getPolicyGroups();
    assertEquals(1, retrievedGroups.length);
    proxy.addPolicyUseToGroup(retrievedGroups[0].getId(), retrievedPolicies[0].getId(), CertPolicyUse.TRUST, true, true);
    CertPolicyGroup retrievedGroup = proxy.getPolicyGroupById(retrievedGroups[0].getId());
    assertNotNull(retrievedGroup);
    assertEquals(1, retrievedGroup.getCertPolicyGroupReltn().length);
    assertEquals(addPolicy.getPolicyName(), retrievedGroup.getCertPolicyGroupReltn()[0].getCertPolicy().getPolicyName());
    Domain domain = new Domain();
    domain.setDomainName("Test Domain");
    proxy.addDomain(domain);
    Domain[] retrievedDomains = proxy.getDomains(new String[] { domain.getDomainName() }, null);
    assertEquals(1, retrievedDomains.length);
    proxy.associatePolicyGroupToDomain(retrievedDomains[0].getId(), retrievedGroups[0].getId());
    CertPolicyGroupDomainReltn[] domainGroups = proxy.getPolicyGroupsByDomain(retrievedDomains[0].getId());
    assertEquals(1, domainGroups.length);
    // also get all domain/group relts without domain id qualifier
    domainGroups = proxy.getPolicyGroupDomainReltns();
    assertEquals(1, domainGroups.length);
    // should delete domain without error
    proxy.removeDomainById(retrievedDomains[0].getId());
}
Also used : CertPolicyGroupDomainReltn(org.nhind.config.CertPolicyGroupDomainReltn) CertPolicy(org.nhind.config.CertPolicy) CertPolicyGroup(org.nhind.config.CertPolicyGroup) Domain(org.nhind.config.Domain) Test(org.junit.Test)

Example 5 with CertPolicy

use of org.nhind.config.CertPolicy in project nhin-d by DirectProject.

the class ClientProxyCertificatePolicyTest method testAddGetRemovePolicyGroupAndDomain_dissasociateGroupFromAllDomains.

@Test
public void testAddGetRemovePolicyGroupAndDomain_dissasociateGroupFromAllDomains() throws Exception {
    CertPolicy addPolicy = new CertPolicy();
    addPolicy.setLexicon(PolicyLexicon.XML);
    addPolicy.setPolicyName("Test Policy");
    addPolicy.setPolicyData(new byte[] { 1, 2, 3 });
    proxy.addPolicy(addPolicy);
    CertPolicy[] retrievedPolicies = proxy.getPolicies();
    assertEquals(1, retrievedPolicies.length);
    CertPolicyGroup addGroup = new CertPolicyGroup();
    addGroup.setPolicyGroupName("Test Group");
    proxy.addPolicyGroup(addGroup);
    CertPolicyGroup[] retrievedGroups = proxy.getPolicyGroups();
    assertEquals(1, retrievedGroups.length);
    proxy.addPolicyUseToGroup(retrievedGroups[0].getId(), retrievedPolicies[0].getId(), CertPolicyUse.TRUST, true, true);
    CertPolicyGroup retrievedGroup = proxy.getPolicyGroupById(retrievedGroups[0].getId());
    assertNotNull(retrievedGroup);
    assertEquals(1, retrievedGroup.getCertPolicyGroupReltn().length);
    assertEquals(addPolicy.getPolicyName(), retrievedGroup.getCertPolicyGroupReltn()[0].getCertPolicy().getPolicyName());
    Domain domain = new Domain();
    domain.setDomainName("Test Domain1");
    proxy.addDomain(domain);
    Domain[] retrievedDomains = proxy.listDomains(null, 100);
    assertEquals(1, retrievedDomains.length);
    domain = new Domain();
    domain.setDomainName("Test Domain2");
    proxy.addDomain(domain);
    retrievedDomains = proxy.listDomains(null, 100);
    assertEquals(2, retrievedDomains.length);
    proxy.associatePolicyGroupToDomain(retrievedDomains[0].getId(), retrievedGroups[0].getId());
    CertPolicyGroupDomainReltn[] domainGroups = proxy.getPolicyGroupsByDomain(retrievedDomains[0].getId());
    assertEquals(1, domainGroups.length);
    proxy.associatePolicyGroupToDomain(retrievedDomains[1].getId(), retrievedGroups[0].getId());
    domainGroups = proxy.getPolicyGroupsByDomain(retrievedDomains[1].getId());
    assertEquals(1, domainGroups.length);
    // also get all domain/group relts without domain id qualifier
    domainGroups = proxy.getPolicyGroupDomainReltns();
    assertEquals(2, domainGroups.length);
    // remove policy from all domains domains
    proxy.disassociatePolicyGroupFromDomains(retrievedGroups[0].getId());
    domainGroups = proxy.getPolicyGroupsByDomain(retrievedDomains[0].getId());
    assertNull(domainGroups);
    domainGroups = proxy.getPolicyGroupsByDomain(retrievedDomains[0].getId());
    assertNull(domainGroups);
    // should delete domain without error
    proxy.removeDomainById(retrievedDomains[0].getId());
    // should delete domain without error
    proxy.removeDomainById(retrievedDomains[1].getId());
}
Also used : CertPolicyGroupDomainReltn(org.nhind.config.CertPolicyGroupDomainReltn) CertPolicy(org.nhind.config.CertPolicy) CertPolicyGroup(org.nhind.config.CertPolicyGroup) Domain(org.nhind.config.Domain) Test(org.junit.Test)

Aggregations

CertPolicy (org.nhind.config.CertPolicy)11 CertPolicyGroup (org.nhind.config.CertPolicyGroup)6 Test (org.junit.Test)5 URL (java.net.URL)4 Domain (org.nhind.config.Domain)4 CertPolicyGroupDomainReltn (org.nhind.config.CertPolicyGroupDomainReltn)3 X509Certificate (java.security.cert.X509Certificate)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Before (org.junit.Before)1 SmtpAgentException (org.nhindirect.gateway.smtp.SmtpAgentException)1 PolicyExpression (org.nhindirect.policy.PolicyExpression)1 PolicyLexicon (org.nhindirect.policy.PolicyLexicon)1 PolicyLexiconParser (org.nhindirect.policy.PolicyLexiconParser)1 PolicyParseException (org.nhindirect.policy.PolicyParseException)1