Search in sources :

Example 6 with CertPolicyGroupDomainReltn

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

the class PolicyCommands method deletePolicyGroupFromDomain.

@Command(name = "DeletePolicyGroupFromDomain", usage = DELETE_GROUP_FROM_DOMAIN_USAGE)
public void deletePolicyGroupFromDomain(String[] args) {
    // make sure the group exists
    final String groupName = StringArrayUtil.getRequiredValue(args, 0);
    final String domainName = StringArrayUtil.getRequiredValue(args, 1);
    long policyGroupId = -1;
    // make sure the domain exists
    Domain[] domains;
    try {
        domains = proxy.getDomains(new String[] { domainName }, null);
        if (domains == null || domains.length == 0) {
            System.out.println("No domain with name " + domainName + " found");
            return;
        }
        // make sure it's really associated
        final CertPolicyGroupDomainReltn[] reltns = proxy.getPolicyGroupsByDomain(domains[0].getId());
        if (reltns == null || reltns.length == 0) {
            System.out.println("Policy group is not associated with domain.");
            return;
        } else {
            for (org.nhind.config.CertPolicyGroupDomainReltn reltn : reltns) {
                if (reltn.getCertPolicyGroup().getPolicyGroupName().compareToIgnoreCase(groupName) == 0) {
                    policyGroupId = reltn.getCertPolicyGroup().getId();
                    break;
                }
            }
            if (policyGroupId == -1) {
                System.out.println("Policy group is not associated with domain.");
                return;
            }
        }
    } catch (Exception e) {
        System.out.println("Failed to lookup domain: " + e.getMessage());
        return;
    }
    try {
        proxy.disassociatePolicyGroupFromDomain(domains[0].getId(), policyGroupId);
        System.out.println("Successfully delete policy group from domain.");
    } catch (Exception e) {
        System.out.println("Failed to delete policy group from domain: " + e.getMessage());
        return;
    }
}
Also used : CertPolicyGroupDomainReltn(org.nhind.config.CertPolicyGroupDomainReltn) CertPolicyGroupDomainReltn(org.nhind.config.CertPolicyGroupDomainReltn) Domain(org.nhind.config.Domain) IOException(java.io.IOException) PolicyParseException(org.nhindirect.policy.PolicyParseException) Command(org.nhindirect.dns.tools.utils.Command)

Example 7 with CertPolicyGroupDomainReltn

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

the class ClientProxyCertificatePolicyTest method testAddGetRemovePolicyGroupAndDomain_dissasociateGroupBeforeDeleteDomain.

@Test
public void testAddGetRemovePolicyGroupAndDomain_dissasociateGroupBeforeDeleteDomain() 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);
    // remove policy from single domain
    proxy.disassociatePolicyGroupFromDomain(retrievedDomains[0].getId(), retrievedGroups[0].getId());
    domainGroups = proxy.getPolicyGroupsByDomain(retrievedDomains[0].getId());
    assertNull(domainGroups);
    // 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)

Aggregations

CertPolicyGroupDomainReltn (org.nhind.config.CertPolicyGroupDomainReltn)7 Domain (org.nhind.config.Domain)6 IOException (java.io.IOException)4 PolicyParseException (org.nhindirect.policy.PolicyParseException)4 Test (org.junit.Test)3 CertPolicy (org.nhind.config.CertPolicy)3 CertPolicyGroup (org.nhind.config.CertPolicyGroup)3 Command (org.nhindirect.dns.tools.utils.Command)3 CertificateException (java.security.cert.CertificateException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 AddressException (javax.mail.internet.AddressException)1 CertPolicyGroupReltn (org.nhind.config.CertPolicyGroupReltn)1 SmtpAgentException (org.nhindirect.gateway.smtp.SmtpAgentException)1 PolicyExpression (org.nhindirect.policy.PolicyExpression)1 DomainPolicyResolverProvider (org.nhindirect.stagent.policy.impl.provider.DomainPolicyResolverProvider)1