Search in sources :

Example 56 with PipeRunException

use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.

the class LdapChallengePipe method doPipe.

/**
 * Checks to see if the supplied parameteres of the pipe can login to LDAP
 * @see nl.nn.adapterframework.core.IPipe#doPipe(java.lang.Object, nl.nn.adapterframework.core.PipeLineSession)
 */
public PipeRunResult doPipe(Object msg, IPipeLineSession pls) throws PipeRunException {
    LdapSender ldapSender = new LdapSender();
    String ldapProviderURL;
    String credentials;
    String principal;
    ParameterResolutionContext prc;
    try {
        prc = new ParameterResolutionContext((String) msg, pls);
        Map paramMap = prc.getValueMap(getParameterList());
        if (StringUtils.isNotEmpty(getLdapProviderURL())) {
            ldapProviderURL = getLdapProviderURL();
        } else {
            ldapProviderURL = (String) paramMap.get("ldapProviderURL");
        }
        credentials = (String) paramMap.get("credentials");
        principal = (String) paramMap.get("principal");
    } catch (ParameterException e) {
        throw new PipeRunException(this, "Invalid parameter", e);
    }
    ldapSender.setErrorSessionKey(getErrorSessionKey());
    if (StringUtils.isEmpty(ldapProviderURL)) {
        throw new PipeRunException(this, "ldapProviderURL is empty");
    }
    if (StringUtils.isEmpty(principal)) {
        // throw new PipeRunException(this, "principal is empty");
        handleError(ldapSender, prc, 34, "Principal is Empty");
        return new PipeRunResult(findForward("invalid"), msg);
    }
    if (StringUtils.isEmpty(credentials)) {
        // throw new PipeRunException(this, "credentials are empty");
        handleError(ldapSender, prc, 49, "Credentials are Empty");
        return new PipeRunResult(findForward("invalid"), msg);
    }
    Parameter dummyEntryName = new Parameter();
    dummyEntryName.setName("entryName");
    dummyEntryName.setValue(principal);
    ldapSender.addParameter(dummyEntryName);
    ldapSender.setUsePooling(false);
    ldapSender.setLdapProviderURL(ldapProviderURL);
    if (StringUtils.isNotEmpty(getInitialContextFactoryName())) {
        ldapSender.setInitialContextFactoryName(getInitialContextFactoryName());
    }
    ldapSender.setPrincipal(principal);
    ldapSender.setCredentials(credentials);
    ldapSender.setOperation(LdapSender.OPERATION_READ);
    try {
        log.debug("Looking up context for principal [" + principal + "]");
        ldapSender.configure();
        log.debug("Succesfully looked up context for principal [" + principal + "]");
    } catch (Exception e) {
        if (StringUtils.isNotEmpty(getErrorSessionKey())) {
            ldapSender.storeLdapException(e, prc);
        } else {
            log.warn("LDAP error looking up context for principal [" + principal + "]", e);
        }
        return new PipeRunResult(findForward("invalid"), msg);
    }
    return new PipeRunResult(findForward("success"), msg);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) Map(java.util.Map) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ParameterException(nl.nn.adapterframework.core.ParameterException)

Example 57 with PipeRunException

use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.

the class CounterSwitchPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    String forward = "";
    PipeForward pipeForward = null;
    StatisticsKeeper sk = getPipeLine().getPipeStatistics(this);
    if (sk != null) {
        long count = sk.getCount();
        forward = "" + (getDivisor() - (count % getDivisor()));
    }
    log.debug(getLogPrefix(session) + "determined forward [" + forward + "]");
    pipeForward = findForward(forward);
    if (pipeForward == null) {
        throw new PipeRunException(this, getLogPrefix(null) + "cannot find forward or pipe named [" + forward + "]");
    }
    log.debug(getLogPrefix(session) + "resolved forward [" + forward + "] to path [" + pipeForward.getPath() + "]");
    return new PipeRunResult(pipeForward, input);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper) PipeForward(nl.nn.adapterframework.core.PipeForward)

Example 58 with PipeRunException

use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.

the class CreateRestViewPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    HttpServletRequest httpServletRequest = (HttpServletRequest) session.get(IPipeLineSession.HTTP_REQUEST_KEY);
    String requestURL = httpServletRequest.getRequestURL().toString();
    String servletPath = httpServletRequest.getServletPath();
    String uri = StringUtils.substringAfter(requestURL, servletPath);
    int countSrcPrefix = StringUtils.countMatches(uri, "/");
    String srcPrefix = StringUtils.repeat("../", countSrcPrefix);
    session.put(SRCPREFIX, srcPrefix);
    log.debug(getLogPrefix(session) + "stored [" + srcPrefix + "] in pipeLineSession under key [" + SRCPREFIX + "]");
    PipeRunResult prr = super.doPipe(input, session);
    String result = (String) prr.getResult();
    log.debug("transforming page [" + result + "] to view");
    String newResult = null;
    ServletContext servletContext = (ServletContext) session.get(IPipeLineSession.SERVLET_CONTEXT_KEY);
    try {
        Map parameters = retrieveParameters(httpServletRequest, servletContext, srcPrefix);
        newResult = XmlUtils.getAdapterSite(result, parameters);
    } catch (Exception e) {
        throw new PipeRunException(this, getLogPrefix(session) + " Exception on transforming page to view", e);
    }
    session.put(CONTENTTYPE, getContentType());
    log.debug(getLogPrefix(session) + "stored [" + getContentType() + "] in pipeLineSession under key [" + CONTENTTYPE + "]");
    return new PipeRunResult(getForward(), newResult);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ServletContext(javax.servlet.ServletContext) Map(java.util.Map) PipeRunException(nl.nn.adapterframework.core.PipeRunException) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 59 with PipeRunException

use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.

the class CrlPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    X509CRL crl;
    InputStream inputStream = (InputStream) input;
    try {
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        crl = (X509CRL) cf.generateCRL(inputStream);
    } catch (CertificateException e) {
        throw new PipeRunException(this, "Could not read CRL", e);
    } catch (CRLException e) {
        throw new PipeRunException(this, "Could not read CRL", e);
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
                log.warn("Could not close CRL input stream", e);
            }
        }
    }
    String result = null;
    if (isCRLOK(crl, (InputStream) session.get(getIssuerSessionKey()))) {
        XmlBuilder root = new XmlBuilder("SerialNumbers");
        Iterator<? extends X509CRLEntry> it = crl.getRevokedCertificates().iterator();
        while (it.hasNext()) {
            X509CRLEntry e = (X509CRLEntry) it.next();
            XmlBuilder serialNumber = new XmlBuilder("SerialNumber");
            serialNumber.setValue(e.getSerialNumber().toString(16));
            root.addSubElement(serialNumber);
        }
        result = root.toXML();
    }
    return new PipeRunResult(getForward(), result);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) X509CRLEntry(java.security.cert.X509CRLEntry) X509CRL(java.security.cert.X509CRL) InputStream(java.io.InputStream) PipeRunException(nl.nn.adapterframework.core.PipeRunException) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) CertificateFactory(java.security.cert.CertificateFactory) CRLException(java.security.cert.CRLException)

Example 60 with PipeRunException

use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.

the class CrlPipe method isCRLOK.

private boolean isCRLOK(X509CRL x509crl, InputStream issuer) throws PipeRunException {
    try {
        CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
        X509Certificate issuerCertificate = (X509Certificate) certificateFactory.generateCertificate(issuer);
        if (x509crl.getIssuerX500Principal().equals(issuerCertificate.getSubjectX500Principal())) {
            return true;
        }
    } catch (CertificateException e) {
        throw new PipeRunException(this, "Could not read issuer certificate", e);
    } finally {
        if (issuer != null) {
            try {
                issuer.close();
            } catch (IOException e) {
                log.warn("Could not close issuer input stream", e);
            }
        }
    }
    return false;
}
Also used : PipeRunException(nl.nn.adapterframework.core.PipeRunException) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate)

Aggregations

PipeRunException (nl.nn.adapterframework.core.PipeRunException)101 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)65 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)40 IOException (java.io.IOException)34 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)32 PipeForward (nl.nn.adapterframework.core.PipeForward)20 ParameterException (nl.nn.adapterframework.core.ParameterException)16 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)13 Parameter (nl.nn.adapterframework.parameters.Parameter)12 InputStream (java.io.InputStream)10 File (java.io.File)9 Map (java.util.Map)9 ParameterList (nl.nn.adapterframework.parameters.ParameterList)8 FixedQuerySender (nl.nn.adapterframework.jdbc.FixedQuerySender)7 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)7 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)6 PipeStartException (nl.nn.adapterframework.core.PipeStartException)6 ArrayList (java.util.ArrayList)5 ZipInputStream (java.util.zip.ZipInputStream)5 IAdapter (nl.nn.adapterframework.core.IAdapter)5