diff options
author | (no author) <(no author)@d688527b-c9ab-4aba-bd8d-4036d912da1d> | 2004-06-28 20:46:16 +0000 |
---|---|---|
committer | (no author) <(no author)@d688527b-c9ab-4aba-bd8d-4036d912da1d> | 2004-06-28 20:46:16 +0000 |
commit | a5694b6491307efb55893ac7ea61920b48d8c9cc (patch) | |
tree | 8f601119d277a90bbddae005d8fc02272dde01e3 /spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/filters | |
parent | 4dd1877ef3771633e096509dae7b8c99fee9ce4b (diff) | |
download | moa-id-spss-tags/Root_proxy_parameter_ordering_projekt.tar.gz moa-id-spss-tags/Root_proxy_parameter_ordering_projekt.tar.bz2 moa-id-spss-tags/Root_proxy_parameter_ordering_projekt.zip |
This commit was manufactured by cvs2svn to create tagtags/Root_proxy_parameter_ordering_projekt
'Root_proxy_parameter_ordering_projekt'.
git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/tags/Root_proxy_parameter_ordering_projekt@146 d688527b-c9ab-4aba-bd8d-4036d912da1d
Diffstat (limited to 'spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/filters')
5 files changed, 0 insertions, 571 deletions
diff --git a/spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/filters/RequestWrapper.java b/spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/filters/RequestWrapper.java deleted file mode 100644 index a6652a56e..000000000 --- a/spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/filters/RequestWrapper.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Created on 19.11.2003 - * - * (c) Stabsstelle IKT-Strategie des Bundes - */ -package at.gv.egovernment.moa.spss.slinterface.filters; - -import java.io.ByteArrayInputStream; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletRequestWrapper; - -/** - * @author Gregor Karlinger (mailto:gregor.karlinger@cio.gv.at) - */ -public class RequestWrapper extends HttpServletRequestWrapper -{ - - private ServletInputStream inputStream_; - - /* ---------------------------------------------------------------------------------------------------- */ - - /** - * Generates a request wrapper around a particular request. - * - * @param request The request to be wrapped. - * - * @param inputStream The new inputstream, which will be returned by method {@link #getInputStream}, and - * whose length will be returned by method {@link #getContentLength}. - */ - public RequestWrapper(HttpServletRequest request, ByteArrayInputStream inputStream) - { - super(request); - inputStream_ = new ServletInputStream(inputStream); - } - - /* ---------------------------------------------------------------------------------------------------- */ - - /** - * @see #RequestWrapper(HttpServletRequest, ByteArrayInputStream) - */ - public javax.servlet.ServletInputStream getInputStream() - { - return inputStream_; - } - - /* ---------------------------------------------------------------------------------------------------- */ - - /** - * @see #RequestWrapper(HttpServletRequest, ByteArrayInputStream) - */ - public int getContentLength() - { - return inputStream_.getContentLength(); - } - -} diff --git a/spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/filters/ResponseWrapper.java b/spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/filters/ResponseWrapper.java deleted file mode 100644 index 420723abb..000000000 --- a/spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/filters/ResponseWrapper.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Created on 18.11.2003 - * - * (c) Stabsstelle IKT-Strategie des Bundes - */ -package at.gv.egovernment.moa.spss.slinterface.filters; - -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpServletResponseWrapper; - -/** - * @author Gregor Karlinger (mailto:gregor.karlinger@cio.gv.at) - */ -public class ResponseWrapper extends HttpServletResponseWrapper -{ - private ServletOutputStream outputStream_; - - /* ---------------------------------------------------------------------------------------------------- */ - - public ResponseWrapper(HttpServletResponse response) - { - super(response); - outputStream_ = new ServletOutputStream(); - } - - /* ---------------------------------------------------------------------------------------------------- */ - - public javax.servlet.ServletOutputStream getOutputStream() - { - return outputStream_; - } - - /* ---------------------------------------------------------------------------------------------------- */ - - /** - * Returns the wrapped response as a byte array. - * - * @return the response as a byte array. - */ - public byte[] toByteArray() - { - return outputStream_.toByteArray(); - } -} diff --git a/spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/filters/SL2MOAFilter.java b/spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/filters/SL2MOAFilter.java deleted file mode 100644 index b67d978ad..000000000 --- a/spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/filters/SL2MOAFilter.java +++ /dev/null @@ -1,365 +0,0 @@ -/* - * Created on 18.11.2003 - * - * (c) Stabsstelle IKT-Strategie des Bundes - */ -package at.gv.egovernment.moa.spss.slinterface.filters; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.CharArrayReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.stream.StreamSource; - -import org.apache.commons.fileupload.DiskFileUpload; -import org.apache.commons.fileupload.FileItem; -import org.apache.commons.fileupload.FileUpload; -import org.apache.commons.fileupload.FileUploadException; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; -import org.apache.xerces.parsers.DOMParser; -import org.w3c.dom.Document; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -import at.gv.egovernment.moa.spss.slinterface.Constants; -import at.gv.egovernment.moa.spss.slinterface.beans.ChecksInfoBean; -import at.gv.egovernment.moa.spss.slinterface.beans.DataInfoBean; -import at.gv.egovernment.moa.spss.slinterface.beans.SignerInfoBean; -import at.gv.egovernment.moa.spss.slinterface.moainvoker.MOAInvoker; -import at.gv.egovernment.moa.spss.slinterface.servlets.SLRequest; -import at.gv.egovernment.moa.spss.slinterface.transformers.MOA2SL; -import at.gv.egovernment.moa.spss.slinterface.transformers.SL2MOA; - -/** - * @author Gregor Karlinger (mailto:gregor.karlinger@cio.gv.at) - */ -public class SL2MOAFilter implements Filter -{ - private static Logger logger_ = Logger.getLogger(Constants.LH_FILTERS_); - - private FilterConfig config_; - - /* ---------------------------------------------------------------------------------------------------- */ - - /** - * @see javax.servlet.Filter#init(javax.servlet.FilterConfig) - */ - public void init(FilterConfig config) throws ServletException - { - // Store filter configuration - config_ = config; - } - - /* ---------------------------------------------------------------------------------------------------- */ - - /** - * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, - * javax.servlet.FilterChain) - */ - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) - throws IOException, ServletException - { - // Create session - HttpSession session = ((HttpServletRequest) request).getSession(true); - - // Check if request is HTTP-POST - checkHttpPost((HttpServletRequest) request); - - // Get SL request from content of request - SLRequest slRequest = parseRequest((HttpServletRequest) request); - session.setAttribute("slRequest", slRequest); - - // Schema validate SL request - CharArrayReader slXmlRequestCAR = new CharArrayReader(slRequest.xmlRequest_.toCharArray()); - Document slXMLRequestDoc = parseSlXmlRequest(slXmlRequestCAR); - - // Transform SL request into a MOA SPSS request - Properties initProps = (Properties)config_.getServletContext().getAttribute(Constants.WSCP_INIT_PROPS_); - String trustProfileId = initProps.getProperty(Constants.IP_SP_TRUSTPROFILEID_); - Document moaXMLRequestDoc = SL2MOA.toMoaVerifyXMLSignatureRequest(slXMLRequestDoc, trustProfileId); - ByteArrayOutputStream moaRequestBOS = new ByteArrayOutputStream(); - MOAInvoker.serializeDocument(moaXMLRequestDoc, moaRequestBOS); - logger_.debug("SL request transformed into MOA request:\n" + moaRequestBOS); - ByteArrayInputStream moaRequestIS = new ByteArrayInputStream(moaRequestBOS.toByteArray()); - - // Invoke MOA SPSS - RequestWrapper requestWrapper = new RequestWrapper((HttpServletRequest) request, moaRequestIS); - ResponseWrapper responseWrapper = new ResponseWrapper((HttpServletResponse) response); - chain.doFilter(requestWrapper, responseWrapper); - - // Parse MOA response - DOMParser xmlParser = (DOMParser) config_.getServletContext().getAttribute(Constants.WSCP_XMLPARSER_); - ServletOutputStream moaResponseSOS = (ServletOutputStream) responseWrapper.getOutputStream(); - ByteArrayInputStream moaResponseBIS = new ByteArrayInputStream(moaResponseSOS.toByteArray()); - InputSource responseSource = new InputSource(moaResponseBIS); - Document moaResponseDoc; - try - { - xmlParser.parse(responseSource); - moaResponseDoc = xmlParser.getDocument(); - } - catch (SAXException e) - { - String message = "Parsing MOA XML response failed."; - logger_.error(message, e); - throw new ServletException(message, e); - } - - // Create bean with info about signed data - try - { - DataInfoBean dataInfo = new DataInfoBean( - moaXMLRequestDoc, moaResponseDoc, config_.getServletContext(), session); - session.setAttribute("dataInfo", dataInfo); - } - catch (Exception e) - { - String message = "Creating DataInfobean failed."; - logger_.error(message, e); - throw new ServletException(message, e); - } - - // Transform MOA response into a SL response - Document slResponseDoc; - slResponseDoc = MOA2SL.toSlVerifyXMLSignatureResponse(moaResponseDoc); - session.setAttribute("slResponseDoc", slResponseDoc); - - // Create bean with info about signer - SignerInfoBean signerInfo = new SignerInfoBean(slResponseDoc); - request.setAttribute("signerInfo", signerInfo); - - // Create bean with info about checks - ChecksInfoBean checksInfo = new ChecksInfoBean(slResponseDoc); - request.setAttribute("checksInfo", checksInfo); - - // Include jsp page, which writes the overview information about the verified signature - response.setContentType("text/html"); - try - { - RequestDispatcher dispatcher = request.getRequestDispatcher("/pages/resultOverview.jsp"); - dispatcher.include(request, response); - } - catch (IOException e) - { - String message = "Failed to create result overview page."; - logger_.error(message, e); - throw new ServletException(message, e); - } - } - - /* ---------------------------------------------------------------------------------------------------- */ - - /** - * @see javax.servlet.Filter#destroy() - */ - public void destroy() - { - // Nothing to do here at the moment. - } - - /* ---------------------------------------------------------------------------------------------------- */ - - private void initTransformer(ServletContext context, String initPropStylesheetLoc) throws ServletException - { - String stylesheetName = - (Constants.IP_SL2MOA_STYLESHEET_.equals(initPropStylesheetLoc)) - ? "sl2Moa" - : "moa2Sl"; - - String contextAttrName = - (Constants.IP_SL2MOA_STYLESHEET_.equals(initPropStylesheetLoc)) - ? Constants.WSCP_SL2MOA_TRANSFORMER_ - : Constants.WSCP_MOA2SL_TRANSFORMER_; - - TransformerFactory transformerFactory = TransformerFactory.newInstance(); - Properties initProps = (Properties) context.getAttribute(Constants.WSCP_INIT_PROPS_); - String stylesheetLoc = initProps.getProperty(initPropStylesheetLoc); - InputStream stylesheetIS = context.getResourceAsStream(stylesheetLoc); - if (stylesheetIS == null) - { - String message = - "Cannot load " + stylesheetName + " stylesheet from location \"" + stylesheetLoc + "\"."; - logger_.error(message); - throw new ServletException(message); - } - Transformer transformer; - try - { - StreamSource stylesheetSS = new StreamSource(stylesheetIS); - transformer = transformerFactory.newTransformer(stylesheetSS); - } - catch (TransformerConfigurationException e) - { - String message = "Cannot create XSLT transformer with " + stylesheetName + " stylesheet."; - logger_.error(message, e); - throw new ServletException(message, e); - } - context.setAttribute(contextAttrName, transformer); - } - - /* ---------------------------------------------------------------------------------------------------- */ - - /** - * Parses the http request. - */ - private SLRequest parseRequest(HttpServletRequest request) throws IOException - { - SLRequest slRequest = new SLRequest(); - - // Check if request URL ends with "http-security-layer-request" - // @TODO Don't know if this check is sufficient - spec says request URL must have this value as path - String requestURI = request.getRequestURI(); - if (!requestURI.endsWith(Constants.SLC_NAME_HTTP_REQUEST_)) - { - String message = "Request does not end with \"" + Constants.SLC_NAME_HTTP_REQUEST_ + "\"."; - logger_.error(message); - throw new IOException(message); - } - - if (FileUpload.isMultipartContent(request)) - { - // Request is encoded as mulitpart/form-data - List items; - try - { - DiskFileUpload upload = new DiskFileUpload(); - items = upload.parseRequest(request); - } - catch (FileUploadException e) - { - String message = "Cannot parse multipart/form-data request."; - logger_.error(message); - throw new IOException(message); - } - - Iterator itemsIt = items.iterator(); - while (itemsIt.hasNext()) - { - FileItem currItem = (FileItem) itemsIt.next(); - String currItemName = currItem.getFieldName(); - if (Constants.SLC_NAME_XML_REQUEST_.equals(currItemName)) - slRequest.xmlRequest_ = currItem.getString(); - else if (Constants.SLC_NAME_DATA_URL_.equals(currItemName)) - slRequest.dataUrl_ = currItem.getString(); - else if (Constants.SLC_NAME_STYLESHEET_URL_.equals(currItemName)) - slRequest.stylesheetUrl_ = currItem.getString(); - else if (Constants.SLC_NAME_REDIRECT_URL_.equals(currItemName)) - slRequest.redirectUrl_ = currItem.getString(); - else - continue; // @TODO Do not evaluate other params at the moment - } - } - else - { - // Request is encoded as application/x-www-form-urlencoded - Map paramsMap = request.getParameterMap(); - Iterator paramNames = paramsMap.keySet().iterator(); - while (paramNames.hasNext()) - { - String currName = (String) paramNames.next(); - String[] currValues = (String[]) paramsMap.get(currName); - if (Constants.SLC_NAME_XML_REQUEST_.equals(currName)) - slRequest.xmlRequest_ = currValues[0]; - else if (Constants.SLC_NAME_DATA_URL_.equals(currName)) - slRequest.dataUrl_ = currValues[0]; - else if (Constants.SLC_NAME_STYLESHEET_URL_.equals(currName)) - slRequest.stylesheetUrl_ = currValues[0]; - else if (Constants.SLC_NAME_REDIRECT_URL_.equals(currName)) - slRequest.redirectUrl_ = currValues[0]; - else - continue; // @TODO Do not evaluate other params at the moment - } - } - - if (slRequest.xmlRequest_ == null || slRequest.dataUrl_ == null || - slRequest.stylesheetUrl_ != null || slRequest.redirectUrl_ != null) - { - // @TODO Only combination of XMLRequest and DataURL allowed at the moment - String message = "Currently only (XMLRequest + DataURL) is supported."; - logger_.error(message); - throw new IOException(message); - } - - return slRequest; - } - - /* ---------------------------------------------------------------------------------------------------- */ - - private Document parseSlXmlRequest(Reader slXmlRequest) throws ServletException - { - // Parse sl request - InputSource slXMLRequestIS = new InputSource(slXmlRequest); - Document slXmlRequestDoc = null; - try - { - DOMParser xmlParser = (DOMParser) config_.getServletContext().getAttribute(Constants.WSCP_XMLPARSER_); - xmlParser.parse(slXMLRequestIS); - slXmlRequestDoc = xmlParser.getDocument(); - } - catch (Exception e) - { - String message = "Parsing Security-Layer request failed."; - logger_.error(message, e); - throw new ServletException(message, e); - } - if (logger_.getEffectiveLevel().isGreaterOrEqual(Level.DEBUG)) - { - ByteArrayOutputStream debugOutputStream = new ByteArrayOutputStream(); - try - { - MOAInvoker.serializeDocument(slXmlRequestDoc, debugOutputStream); - logger_.debug("XML-Request received:\n" + debugOutputStream); - } - catch (IOException e) - { - // No debug output if this fails - } - } - - // Check if namespace is correct - String namespaceURI = slXmlRequestDoc.getDocumentElement().getNamespaceURI(); - if (!Constants.NSURI_SL_11_.equals(namespaceURI) && !Constants.NSURI_SL_12_.equals(namespaceURI)) - { - String message = "XML request has invalid namespace: \"" + namespaceURI + "\"."; - logger_.error(message); - throw new ServletException(message); - } - - return slXmlRequestDoc; - } - - /* ---------------------------------------------------------------------------------------------------- */ - - private void checkHttpPost(HttpServletRequest request) throws ServletException - { - String method = request.getMethod(); - if (!"POST".equals(method)) - { - String message = "HTTP method \"" + method + "\" not supported. Must be \"POST\"."; - logger_.error(message); - throw new ServletException(message); - } - } -} diff --git a/spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/filters/ServletInputStream.java b/spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/filters/ServletInputStream.java deleted file mode 100644 index b0609c2f8..000000000 --- a/spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/filters/ServletInputStream.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Created on 19.11.2003 - * - * (c) Stabsstelle IKT-Strategie des Bundes - */ -package at.gv.egovernment.moa.spss.slinterface.filters; - -import java.io.ByteArrayInputStream; -import java.io.IOException; - -/** - * @author Gregor Karlinger (mailto:gregor.karlinger@cio.gv.at) - */ -public class ServletInputStream extends javax.servlet.ServletInputStream -{ - private ByteArrayInputStream inputStream_; - private int length_; - - /* ---------------------------------------------------------------------------------------------------- */ - - /** - * Generates a new <code>ServletInputStram</code> from the specified stream. - * - * @param inputStream See above. - */ - public ServletInputStream(ByteArrayInputStream inputStream) - { - super(); - inputStream_ = inputStream; - length_ = inputStream_.available(); - } - - /* ---------------------------------------------------------------------------------------------------- */ - - /** - * Reads a single byte from the underlying <code>ByteArrayInputStream</code>. - * - * @see java.io.InputStream#read() - */ - public int read() throws IOException - { - return inputStream_.read(); - } - - /* ---------------------------------------------------------------------------------------------------- */ - - /** - * Gets the length of the content from this input stream. This equals to the number of bytes which where - * available at the time of creating this <code>ServletInputStream</code>. - */ - public int getContentLength() - { - return length_; - } -} diff --git a/spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/filters/ServletOutputStream.java b/spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/filters/ServletOutputStream.java deleted file mode 100644 index b790ee55c..000000000 --- a/spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/filters/ServletOutputStream.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Created on 18.11.2003 - * - * (c) Stabsstelle IKT-Strategie des Bundes - */ -package at.gv.egovernment.moa.spss.slinterface.filters; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -/** - * @author Gregor Karlinger (mailto:gregor.karlinger@cio.gv.at) - */ -public class ServletOutputStream extends javax.servlet.ServletOutputStream -{ - private ByteArrayOutputStream outputStream_; - - /* ---------------------------------------------------------------------------------------------------- */ - - /** - * Default constructor. - */ - public ServletOutputStream() - { - super(); - outputStream_ = new ByteArrayOutputStream(); - } - - /* ---------------------------------------------------------------------------------------------------- */ - - /** - * @see java.io.OutputStream#write(int) - */ - public void write(int b) throws IOException - { - outputStream_.write(b); - } - - /* ---------------------------------------------------------------------------------------------------- */ - - /** - * Returns the content of this stream as a byte array. - * - * @return the content of this stream as a byte array. - */ - public byte[] toByteArray() - { - return outputStream_.toByteArray(); - } -} |