Search in sources :

Example 1 with CertPolicyGroupDomainReltn

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

the class PolicyCommands method addGroupToDomain.

@Command(name = "AddPolicyGroupToDomain", usage = ADD_GROUP_TO_DOMAIN_USAGE)
public void addGroupToDomain(String[] args) {
    // make sure the group exists
    final String groupName = StringArrayUtil.getRequiredValue(args, 0);
    final String domainName = StringArrayUtil.getRequiredValue(args, 1);
    // make sure the group exists
    org.nhind.config.CertPolicyGroup group = null;
    try {
        group = proxy.getPolicyGroupByName(groupName);
        if (group == null) {
            System.out.println("No policy group with name " + groupName + " found");
            return;
        }
    } catch (Exception e) {
        System.out.println("Failed to lookup policy group: " + e.getMessage());
        return;
    }
    // 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;
        }
    } catch (Exception e) {
        System.out.println("Failed to lookup domain: " + e.getMessage());
        return;
    }
    // make sure it's not already associated
    try {
        final CertPolicyGroupDomainReltn[] reltns = proxy.getPolicyGroupsByDomain(domains[0].getId());
        if (reltns != null && reltns.length > 0) {
            boolean reltnExists = false;
            for (CertPolicyGroupDomainReltn reltn : reltns) {
                if (reltn.getCertPolicyGroup().getPolicyGroupName().compareToIgnoreCase(groupName) == 0) {
                    reltnExists = true;
                    break;
                }
            }
            if (reltnExists) {
                System.out.println("Group " + groupName + " already associated with domain " + domainName);
                return;
            }
        }
    } catch (Exception e) {
        System.out.println("Failed to lookup existing group to domain associations: " + e.getMessage());
        return;
    }
    // now make the association
    try {
        proxy.associatePolicyGroupToDomain(domains[0].getId(), group.getId());
        System.out.println("Successfully added policy to group.");
    } catch (Exception e) {
        System.out.println("Failed to add group to domain: " + e.getMessage());
        return;
    }
}
Also used : 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 2 with CertPolicyGroupDomainReltn

use of org.nhind.config.CertPolicyGroupDomainReltn 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 3 with CertPolicyGroupDomainReltn

use of org.nhind.config.CertPolicyGroupDomainReltn 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)

Example 4 with CertPolicyGroupDomainReltn

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

the class WSSmtpAgentConfig method buildPolicyResolvers.

protected void buildPolicyResolvers() {
    final Map<String, Collection<PolicyExpression>> incomingPrivatePolicies = new HashMap<String, Collection<PolicyExpression>>();
    final Map<String, Collection<PolicyExpression>> outgoingPrivatePolicies = new HashMap<String, Collection<PolicyExpression>>();
    final Map<String, Collection<PolicyExpression>> incomingPublicPolicies = new HashMap<String, Collection<PolicyExpression>>();
    final Map<String, Collection<PolicyExpression>> outgoingPublicPolicies = new HashMap<String, Collection<PolicyExpression>>();
    final Map<String, Collection<PolicyExpression>> trustPolicies = new HashMap<String, Collection<PolicyExpression>>();
    CertPolicyGroupDomainReltn[] domainReltns = null;
    try {
        // get all of the policy group to domain relations... 
        // doing this all in one call for efficiency
        domainReltns = cfService.getPolicyGroupDomainReltns();
    } catch (Exception e) {
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "WebService error getting certificate policy configuration: " + e.getMessage(), e);
    }
    if (domainReltns != null) {
        for (CertPolicyGroupDomainReltn domainReltn : domainReltns) {
            if (domainReltn.getCertPolicyGroup().getCertPolicyGroupReltn() != null) {
                for (CertPolicyGroupReltn policyReltn : domainReltn.getCertPolicyGroup().getCertPolicyGroupReltn()) {
                    if (policyReltn.getPolicyUse().equals(CertPolicyUse.PRIVATE_RESOLVER)) {
                        if (policyReltn.isIncoming())
                            addPolicyToMap(incomingPrivatePolicies, domainReltn.getDomain().getDomainName(), policyReltn);
                        if (policyReltn.isOutgoing())
                            addPolicyToMap(outgoingPrivatePolicies, domainReltn.getDomain().getDomainName(), policyReltn);
                    } else if (policyReltn.getPolicyUse().equals(CertPolicyUse.PUBLIC_RESOLVER)) {
                        if (policyReltn.isIncoming())
                            addPolicyToMap(incomingPublicPolicies, domainReltn.getDomain().getDomainName(), policyReltn);
                        if (policyReltn.isOutgoing())
                            addPolicyToMap(outgoingPublicPolicies, domainReltn.getDomain().getDomainName(), policyReltn);
                    } else if (policyReltn.getPolicyUse().equals(CertPolicyUse.TRUST)) {
                        addPolicyToMap(trustPolicies, domainReltn.getDomain().getDomainName(), policyReltn);
                    }
                }
            }
        }
    }
    publicPolicyResolverModule = PublicPolicyResolverModule.create(new DomainPolicyResolverProvider(incomingPublicPolicies, outgoingPublicPolicies));
    privatePolicyResolverModule = PrivatePolicyResolverModule.create(new DomainPolicyResolverProvider(incomingPrivatePolicies, outgoingPrivatePolicies));
    trustPolicyResolverModule = TrustPolicyResolverModule.create(new DomainPolicyResolverProvider(trustPolicies));
}
Also used : CertPolicyGroupReltn(org.nhind.config.CertPolicyGroupReltn) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) CertPolicyGroupDomainReltn(org.nhind.config.CertPolicyGroupDomainReltn) HashMap(java.util.HashMap) Collection(java.util.Collection) PolicyExpression(org.nhindirect.policy.PolicyExpression) DomainPolicyResolverProvider(org.nhindirect.stagent.policy.impl.provider.DomainPolicyResolverProvider) AddressException(javax.mail.internet.AddressException) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) PolicyParseException(org.nhindirect.policy.PolicyParseException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException)

Example 5 with CertPolicyGroupDomainReltn

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

the class PolicyCommands method listDomainPolicyGroups.

@Command(name = "ListDomainPolicyGroups", usage = LIST_DOMAIN_POLICY_GROUPS)
public void listDomainPolicyGroups(String[] args) {
    final String domainName = StringArrayUtil.getRequiredValue(args, 0);
    // 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;
        }
    } catch (Exception e) {
        System.out.println("Failed to lookup domain: " + e.getMessage());
        return;
    }
    try {
        final CertPolicyGroupDomainReltn[] reltns = proxy.getPolicyGroupsByDomain(domains[0].getId());
        if (reltns == null || reltns.length == 0) {
            System.out.println("Domain does not have any policy groups associated with it.");
            return;
        }
        List<org.nhind.config.CertPolicyGroup> groups = new ArrayList<org.nhind.config.CertPolicyGroup>();
        for (CertPolicyGroupDomainReltn reltn : reltns) groups.add(reltn.getCertPolicyGroup());
        groupPrinter.printRecords(groups);
    } catch (Exception e) {
        System.out.println("Failed to lookup domain policy groups: " + e.getMessage());
        return;
    }
}
Also used : CertPolicyGroupDomainReltn(org.nhind.config.CertPolicyGroupDomainReltn) ArrayList(java.util.ArrayList) Domain(org.nhind.config.Domain) IOException(java.io.IOException) PolicyParseException(org.nhindirect.policy.PolicyParseException) Command(org.nhindirect.dns.tools.utils.Command)

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