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