use of org.nhindirect.policy.PolicyExpression in project nhin-d by DirectProject.
the class UniversalPolicyResolver_getPolicyTest method testGetIncomingPolicy_assertPolicyRetrieved.
public void testGetIncomingPolicy_assertPolicyRetrieved() throws Exception {
final PolicyExpression expression = mock(PolicyExpression.class);
final UniversalPolicyResolver resolver = new UniversalPolicyResolver(expression);
final Collection<PolicyExpression> policies = resolver.getIncomingPolicy(new InternetAddress("me@you.com"));
assertEquals(1, policies.size());
assertEquals(expression, policies.iterator().next());
}
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 JavaSerializedObjectLexiconPolicyParser method deserialize.
/**
* {@inheritDoc}
*/
@Override
public PolicyExpression deserialize(InputStream stream) throws PolicyParseException {
if (stream == null)
throw new IllegalArgumentException("POJO serialization input stream cannot be null.");
try {
final ObjectInputStream in = new ObjectInputStream(stream);
final PolicyExpression retVal = (PolicyExpression) in.readObject();
return retVal;
} catch (Exception e) {
throw new PolicyParseException("Could not deseriale policy expression from serialized POJO.", e);
}
}
Aggregations