Search in sources :

Example 16 with PolicyExpression

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());
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) PolicyExpression(org.nhindirect.policy.PolicyExpression)

Example 17 with PolicyExpression

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);
    }
}
Also used : PolicyLexicon(org.nhindirect.policy.PolicyLexicon) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) CertPolicy(org.nhindirect.config.model.CertPolicy) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PolicyLexiconParser(org.nhindirect.policy.PolicyLexiconParser) PolicyExpression(org.nhindirect.policy.PolicyExpression) PolicyParseException(org.nhindirect.policy.PolicyParseException)

Example 18 with PolicyExpression

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));
}
Also used : SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) CertPolicyGroupDomainReltn(org.nhindirect.config.model.CertPolicyGroupDomainReltn) HashMap(java.util.HashMap) CertPolicyGroupUse(org.nhindirect.config.model.CertPolicyGroupUse) Collection(java.util.Collection) PolicyExpression(org.nhindirect.policy.PolicyExpression) DomainPolicyResolverProvider(org.nhindirect.stagent.policy.impl.provider.DomainPolicyResolverProvider) AddressException(javax.mail.internet.AddressException) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) PolicyParseException(org.nhindirect.policy.PolicyParseException)

Example 19 with PolicyExpression

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));
}
Also used : CertPolicyGroupReltn(org.nhind.config.CertPolicyGroupReltn) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) CertPolicyGroupDomainReltn(org.nhind.config.CertPolicyGroupDomainReltn) HashMap(java.util.HashMap) Collection(java.util.Collection) PolicyExpression(org.nhindirect.policy.PolicyExpression) DomainPolicyResolverProvider(org.nhindirect.stagent.policy.impl.provider.DomainPolicyResolverProvider) AddressException(javax.mail.internet.AddressException) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) PolicyParseException(org.nhindirect.policy.PolicyParseException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException)

Example 20 with PolicyExpression

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);
    }
}
Also used : PolicyExpression(org.nhindirect.policy.PolicyExpression) IOException(java.io.IOException) PolicyParseException(org.nhindirect.policy.PolicyParseException) PolicyParseException(org.nhindirect.policy.PolicyParseException) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

PolicyExpression (org.nhindirect.policy.PolicyExpression)54 X509Certificate (java.security.cert.X509Certificate)21 InternetAddress (javax.mail.internet.InternetAddress)18 LiteralPolicyExpression (org.nhindirect.policy.LiteralPolicyExpression)16 OperationPolicyExpression (org.nhindirect.policy.OperationPolicyExpression)16 PolicyResolver (org.nhindirect.stagent.policy.PolicyResolver)12 InputStream (java.io.InputStream)11 PolicyFilter (org.nhindirect.policy.PolicyFilter)10 Vector (java.util.Vector)9 Collection (java.util.Collection)8 HashMap (java.util.HashMap)8 Opcode (org.nhindirect.policy.Opcode)7 KeyUsageExtensionField (org.nhindirect.policy.x509.KeyUsageExtensionField)7 CertificateResolver (org.nhindirect.stagent.cert.CertificateResolver)7 TrustAnchorResolver (org.nhindirect.stagent.trust.TrustAnchorResolver)7 File (java.io.File)6 StackMachineCompiler (org.nhindirect.policy.impl.machine.StackMachineCompiler)6 ExtendedKeyUsageExtensionField (org.nhindirect.policy.x509.ExtendedKeyUsageExtensionField)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5