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;
}
}
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());
}
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());
}
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));
}
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;
}
}
Aggregations