Search in sources :

Example 1 with PolicyParseException

use of org.nhindirect.policy.PolicyParseException 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 2 with PolicyParseException

use of org.nhindirect.policy.PolicyParseException 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)

Example 3 with PolicyParseException

use of org.nhindirect.policy.PolicyParseException in project nhin-d by DirectProject.

the class JavaSerializedObjectLexiconPolicyParser method serialize.

/**
	 * {@inheritDoc}
	 */
@Override
public void serialize(PolicyExpression expression, OutputStream out) throws PolicyParseException {
    if (expression == null)
        throw new IllegalArgumentException("Policy expression cannot be null.");
    if (out == null)
        throw new IllegalArgumentException("POJO output stream cannot be null.");
    try {
        final ObjectOutputStream objectStream = new ObjectOutputStream(out);
        objectStream.writeObject(expression);
        objectStream.close();
    }///CLOVER:OFF
     catch (IOException e) {
        throw new PolicyParseException("Could not serialize policy expression to serialized POJO.", e);
    }
///CLOVER:ON
}
Also used : IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) PolicyParseException(org.nhindirect.policy.PolicyParseException)

Example 4 with PolicyParseException

use of org.nhindirect.policy.PolicyParseException in project nhin-d by DirectProject.

the class SimpleTextV1LexiconPolicyParser method buildTBSField.

/**
	 * Builds a certificate reference expression that is an {@link TBSField}.
	 * @param token The token used to build the field.
	 * @return An {@link TBSField} object that represents the token.  Returns null if the token does not represent an {@link TBSField}.
	 * @throws PolicyParseException
	 */
protected PolicyExpression buildTBSField(String token) throws PolicyParseException {
    TBSField<?> retVal = null;
    final TBSFieldName fieldName = TBSFieldName.fromToken(token);
    if (fieldName != null) {
        try {
            final Class<? extends TBSField<?>> fieldRefClass = fieldName.getReferenceClass(token);
            if (fieldRefClass == null)
                throw new PolicyParseException("TBSField with token name " + token + " has not been implemented yet.");
            if (fieldRefClass.equals(IssuerAttributeField.class) || fieldRefClass.equals(SubjectAttributeField.class)) {
                boolean required = token.endsWith("+");
                final String rdnLookupToken = (required) ? token.substring(0, token.length() - 1) : token;
                final RDNAttributeIdentifier identifier = RDNAttributeIdentifier.fromName(rdnLookupToken);
                retVal = fieldRefClass.equals(IssuerAttributeField.class) ? new IssuerAttributeField(required, identifier) : new SubjectAttributeField(required, identifier);
            } else {
                retVal = fieldRefClass.newInstance();
            }
        } catch (PolicyParseException ex) {
            throw ex;
        }///CLOVER:OFF
         catch (Exception e) {
            throw new PolicyParseException("Error building TBSField", e);
        }
    ///CLOVER:ON
    }
    return retVal;
}
Also used : IssuerAttributeField(org.nhindirect.policy.x509.IssuerAttributeField) RDNAttributeIdentifier(org.nhindirect.policy.x509.RDNAttributeIdentifier) TBSFieldName(org.nhindirect.policy.x509.TBSFieldName) SubjectAttributeField(org.nhindirect.policy.x509.SubjectAttributeField) PolicyParseException(org.nhindirect.policy.PolicyParseException) PolicyGrammarException(org.nhindirect.policy.PolicyGrammarException) IOException(java.io.IOException) PolicyParseException(org.nhindirect.policy.PolicyParseException)

Example 5 with PolicyParseException

use of org.nhindirect.policy.PolicyParseException in project nhin-d by DirectProject.

the class XMLLexiconPolicyParser_serializeTest method testDeserializeo_invalidXML_assertExecption.

public void testDeserializeo_invalidXML_assertExecption() throws Exception {
    boolean exceptionOccured = false;
    final XMLLexiconPolicyParser parser = new XMLLexiconPolicyParser();
    try {
        parser.deserialize(new ByteArrayInputStream(new byte[] { 0, 1, 2 }));
    } catch (PolicyParseException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) XMLLexiconPolicyParser(org.nhindirect.policy.impl.XMLLexiconPolicyParser) PolicyParseException(org.nhindirect.policy.PolicyParseException)

Aggregations

PolicyParseException (org.nhindirect.policy.PolicyParseException)13 IOException (java.io.IOException)9 ByteArrayInputStream (java.io.ByteArrayInputStream)7 InputStream (java.io.InputStream)5 PolicyLexiconParser (org.nhindirect.policy.PolicyLexiconParser)5 PolicyLexicon (org.nhindirect.policy.PolicyLexicon)4 PolicyExpression (org.nhindirect.policy.PolicyExpression)3 PolicyGrammarException (org.nhindirect.policy.PolicyGrammarException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 CertificateException (java.security.cert.CertificateException)2 FileUploadException (org.apache.commons.fileupload.FileUploadException)2 ServiceException (org.nhindirect.common.rest.exceptions.ServiceException)2 SmtpAgentException (org.nhindirect.gateway.smtp.SmtpAgentException)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 File (java.io.File)1 InputStreamReader (java.io.InputStreamReader)1