use of org.nhindirect.policy.PolicyExpression in project nhin-d by DirectProject.
the class RESTSmtpAgentConfig method addPolicyToMap.
public void addPolicyToMap(Map<String, Collection<PolicyExpression>> policyMap, String domainName, CertPolicyGroupUse 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.getPolicy();
final PolicyLexicon lexicon = policy.getLexicon();
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.nhindirect.policy.PolicyExpression in project nhin-d by DirectProject.
the class RESTSmtpAgentConfig method buildPolicyResolvers.
@Override
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>>();
Collection<CertPolicyGroupDomainReltn> domainReltns = null;
try {
// get all of the policy group to domain relations...
// doing this all in one call for efficiency
domainReltns = policyService.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.getPolicyGroup().getPolicies() != null) {
for (CertPolicyGroupUse policyReltn : domainReltn.getPolicyGroup().getPolicies()) {
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.nhindirect.policy.PolicyExpression 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.nhindirect.policy.PolicyExpression in project nhin-d by DirectProject.
the class DefaultNHINDAgent_filterCertificateByPolicyTest method testFilterCertificateByPolicy_badPolicyExpression_assertNoCertsFiltered.
public void testFilterCertificateByPolicy_badPolicyExpression_assertNoCertsFiltered() throws Exception {
final PolicyFilter filter = mock(PolicyFilter.class);
doThrow(new PolicyProcessException("Just Passing Through")).when(filter).isCompliant((X509Certificate) any(), (PolicyExpression) any());
final PolicyExpression expression = mock(PolicyExpression.class);
final X509Certificate cert = mock(X509Certificate.class);
final Collection<X509Certificate> certs = Arrays.asList(cert);
final PolicyResolver resolver = mock(PolicyResolver.class);
when(resolver.getIncomingPolicy((InternetAddress) any())).thenReturn(Arrays.asList(expression));
final DefaultNHINDAgent agent = new DefaultNHINDAgent("", mock(CertificateResolver.class), mock(CertificateResolver.class), mock(TrustAnchorResolver.class));
agent.setPolicyFilter(filter);
boolean exceptionOccured = false;
try {
agent.filterCertificatesByPolicy(new InternetAddress("me@you.com"), resolver, certs, true);
} catch (AgentException e) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
}
use of org.nhindirect.policy.PolicyExpression in project nhin-d by DirectProject.
the class TrustModel_isCertPolicyCompliantTest method testIsCertPolicyCompliant_policyExpressionError_assertExecption.
public void testIsCertPolicyCompliant_policyExpressionError_assertExecption() throws Exception {
final TrustModel model = new TrustModel();
final PolicyFilter filter = mock(PolicyFilter.class);
doThrow(new PolicyProcessException("Just Passing Through")).when(filter).isCompliant((X509Certificate) any(), (PolicyExpression) any());
final PolicyResolver resolver = mock(PolicyResolver.class);
final PolicyExpression expression = mock(PolicyExpression.class);
when(resolver.getIncomingPolicy((InternetAddress) any())).thenReturn(Arrays.asList(expression));
model.setTrustPolicyResolver(resolver);
model.setPolicyFilter(filter);
final X509Certificate cert = mock(X509Certificate.class);
boolean exceptionOccured = false;
try {
model.isCertPolicyCompliant(new InternetAddress("me@test.com"), cert);
} catch (AgentException e) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
}
Aggregations