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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations