use of org.nhind.config.CertPolicy in project nhin-d by DirectProject.
the class ConfigServiceDNSStore_configCertPolicyTest method testConfigCertPolicy_invalidPolicy_assertNoPolicyConfiged.
public void testConfigCertPolicy_invalidPolicy_assertNoPolicyConfiged() throws Exception {
System.setProperty(ConfigServiceDNSStore.DNS_CERT_POLICY_NAME_VAR, "InvalidPolicy");
try {
final CertPolicy policy = new CertPolicy();
policy.setLexicon(PolicyLexicon.SIMPLE_TEXT_V1);
policy.setPolicyName("InvalidPolicy");
policy.setPolicyData(INVALID_VALID_POLICY.getBytes());
proxy.addPolicy(policy);
final ConfigServiceDNSStore store = new ConfigServiceDNSStore(new URL(ConfigServiceRunner.getConfigServiceURL()));
assertNull(store.polExpression);
assertNull(store.polFilter);
} finally {
System.setProperty(ConfigServiceDNSStore.DNS_CERT_POLICY_NAME_VAR, "");
}
}
use of org.nhind.config.CertPolicy in project nhin-d by DirectProject.
the class ConfigServiceDNSStore_isCertCompliantWithPolicyTest method testisCertCompliantWithPolicy_policyConfigured_nonCompliantCert_assertNonCompliant.
public void testisCertCompliantWithPolicy_policyConfigured_nonCompliantCert_assertNonCompliant() throws Exception {
System.setProperty(ConfigServiceDNSStore.DNS_CERT_POLICY_NAME_VAR, "ValidPolicy");
try {
final CertPolicy policy = new CertPolicy();
policy.setLexicon(PolicyLexicon.SIMPLE_TEXT_V1);
policy.setPolicyName("ValidPolicy");
policy.setPolicyData(KEY_ENC_POLICY.getBytes());
proxy.addPolicy(policy);
final ConfigServiceDNSStore store = new ConfigServiceDNSStore(new URL(ConfigServiceRunner.getConfigServiceURL()));
assertNotNull(store.polExpression);
assertNotNull(store.polFilter);
X509Certificate cert = DNSRecordUtil.loadCertificate("umesh.der");
assertFalse(store.isCertCompliantWithPolicy(cert));
} finally {
System.setProperty(ConfigServiceDNSStore.DNS_CERT_POLICY_NAME_VAR, "");
}
}
use of org.nhind.config.CertPolicy in project nhin-d by DirectProject.
the class ConfigServiceDNSStore_isCertCompliantWithPolicyTest method testisCertCompliantWithPolicy_policyConfigured_compliantCert_assertCompliant.
public void testisCertCompliantWithPolicy_policyConfigured_compliantCert_assertCompliant() throws Exception {
System.setProperty(ConfigServiceDNSStore.DNS_CERT_POLICY_NAME_VAR, "ValidPolicy");
try {
final CertPolicy policy = new CertPolicy();
policy.setLexicon(PolicyLexicon.SIMPLE_TEXT_V1);
policy.setPolicyName("ValidPolicy");
policy.setPolicyData(KEY_ENC_POLICY.getBytes());
proxy.addPolicy(policy);
final ConfigServiceDNSStore store = new ConfigServiceDNSStore(new URL(ConfigServiceRunner.getConfigServiceURL()));
assertNotNull(store.polExpression);
assertNotNull(store.polFilter);
X509Certificate cert = DNSRecordUtil.loadCertificate("bob.der");
assertTrue(store.isCertCompliantWithPolicy(cert));
} finally {
System.setProperty(ConfigServiceDNSStore.DNS_CERT_POLICY_NAME_VAR, "");
}
}
use of org.nhind.config.CertPolicy in project nhin-d by DirectProject.
the class WSSmtpAgentConfig method addPolicyToMap.
public void addPolicyToMap(Map<String, Collection<PolicyExpression>> policyMap, String domainName, CertPolicyGroupReltn policyReltn) {
// check to see if the domain is in the map
Collection<PolicyExpression> policyExpressionCollection = policyMap.get(domainName);
if (policyExpressionCollection == null) {
policyExpressionCollection = new ArrayList<PolicyExpression>();
policyMap.put(domainName, policyExpressionCollection);
}
final CertPolicy policy = policyReltn.getCertPolicy();
final PolicyLexicon lexicon;
if (policy.getLexicon().equals(org.nhind.config.PolicyLexicon.JAVA_SER))
lexicon = PolicyLexicon.JAVA_SER;
else if (policy.getLexicon().equals(org.nhind.config.PolicyLexicon.SIMPLE_TEXT_V1))
lexicon = PolicyLexicon.SIMPLE_TEXT_V1;
else
lexicon = PolicyLexicon.XML;
final InputStream inStr = new ByteArrayInputStream(policy.getPolicyData());
try {
// grab a parser and compile this policy
final PolicyLexiconParser parser = PolicyLexiconParserFactory.getInstance(lexicon);
policyExpressionCollection.add(parser.parse(inStr));
} catch (PolicyParseException ex) {
throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "Failed parse policy into policy expression: " + ex.getMessage(), ex);
} finally {
IOUtils.closeQuietly(inStr);
}
}
use of org.nhind.config.CertPolicy 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