use of org.nhind.config.Domain in project nhin-d by DirectProject.
the class DomainCommands method deleteDomain.
@Command(name = "DeleteDomain", usage = DELETE_DOMAIN_USAGE)
public void deleteDomain(String[] args) {
final String strId = StringArrayUtil.getRequiredValue(args, 0);
long id = Long.parseLong(strId);
try {
// make sure this domain actually exists
final Domain exDomain = proxy.getDomain(id);
if (exDomain == null) {
System.out.println("The domain with the id " + id + " does not exists in the system");
return;
}
proxy.removeDomainById(id);
System.out.println("Domain " + exDomain.getDomainName() + " successfully removed.");
} catch (Exception e) {
e.printStackTrace();
System.err.println("Failed to add new domain: " + e.getMessage());
}
}
use of org.nhind.config.Domain 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.Domain in project nhin-d by DirectProject.
the class TrustBundleCommands method addTrustBundleToDomain.
@Command(name = "AddTrustBundleToDomain", usage = ADD_BUNDLE_TO_DOMAIN)
public void addTrustBundleToDomain(String[] args) {
final long bundleId = Long.parseLong(StringArrayUtil.getRequiredValue(args, 0));
final long domainId = Long.parseLong(StringArrayUtil.getRequiredValue(args, 1));
final boolean trustIncoming = Boolean.parseBoolean(StringArrayUtil.getRequiredValue(args, 2));
final boolean trustOutgoing = Boolean.parseBoolean(StringArrayUtil.getRequiredValue(args, 3));
try {
final TrustBundle bundle = proxy.getTrustBundleById(bundleId);
if (bundle == null) {
System.out.println("Bundle with id " + bundleId + " does not exist.");
return;
}
final Domain domain = proxy.getDomain(domainId);
if (domain == null) {
System.out.println("Domain with id " + domainId + " does not exist.");
return;
}
// make sure there isn't already an association
final TrustBundleDomainReltn[] reltns = proxy.getTrustBundlesByDomain(domainId, false);
if (reltns != null && reltns.length > 0) {
for (TrustBundleDomainReltn reltn : reltns) {
if (reltn.getTrustBundle().getId() == bundleId) {
System.out.println("Bundle " + bundle.getBundleName() + " is already associated with domain " + domain.getDomainName());
return;
}
}
}
proxy.associateTrustBundleToDomain(domainId, bundleId, trustIncoming, trustOutgoing);
System.out.println("Trust bundle " + bundle.getBundleName() + " added to domain " + domain.getDomainName());
} catch (Exception e) {
System.out.println("Error associating bundle to domain : " + e.getMessage());
}
}
use of org.nhind.config.Domain 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.Domain 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());
}
Aggregations