diff options
Diffstat (limited to 'erecht.client.ss/src/at/gv/egovernment/moa/ss/erechtclient/moainvoker')
3 files changed, 0 insertions, 402 deletions
diff --git a/erecht.client.ss/src/at/gv/egovernment/moa/ss/erechtclient/moainvoker/DOMErrorHandler.java b/erecht.client.ss/src/at/gv/egovernment/moa/ss/erechtclient/moainvoker/DOMErrorHandler.java deleted file mode 100644 index 47b389c31..000000000 --- a/erecht.client.ss/src/at/gv/egovernment/moa/ss/erechtclient/moainvoker/DOMErrorHandler.java +++ /dev/null @@ -1,55 +0,0 @@ -package at.gv.egovernment.moa.ss.erechtclient.moainvoker; - -import java.util.Iterator; -import java.util.LinkedList; - -import org.apache.log4j.Logger; -import org.w3c.dom.DOMError; - -import at.gv.egovernment.moa.ss.erechtclient.init.Constants; - -public class DOMErrorHandler implements org.w3c.dom.DOMErrorHandler -{ - private LinkedList errors_; - - private static Logger logger_ = Logger.getLogger(Constants.LH_MOAINVOKER_); - - public DOMErrorHandler() - { - errors_ = new LinkedList(); - } - public boolean handleError(DOMError error) - { - if (error.getSeverity() == DOMError.SEVERITY_WARNING) - { - logger_.warn("A warning occured while parsing: " + error.getMessage()); - return true; - } - else - { - logger_.error("A (fatal) error occured while parsing: " + error.getMessage()); - errors_.add(error.getMessage()); - return false; - } - } - - public int getErrorCount() - { - return errors_.size(); - } - - public String getErrorSummaryMsg() - { - if (errors_.size() <= 0) return null; - - StringBuffer errorSummaryMsg = new StringBuffer(); - errorSummaryMsg.append("The following errors have been reported during parsing:\n"); - for (int i = 0; i < errors_.size(); i++) - { - errorSummaryMsg.append("Error no. " + i + ":\n"); - errorSummaryMsg.append(errors_.get(i) + "\n"); - } - return errorSummaryMsg.toString(); - } - -} diff --git a/erecht.client.ss/src/at/gv/egovernment/moa/ss/erechtclient/moainvoker/MOAInvoker.java b/erecht.client.ss/src/at/gv/egovernment/moa/ss/erechtclient/moainvoker/MOAInvoker.java deleted file mode 100644 index 65cb55c04..000000000 --- a/erecht.client.ss/src/at/gv/egovernment/moa/ss/erechtclient/moainvoker/MOAInvoker.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Created on 19.11.2003 - * - * (c) Stabsstelle IKT-Strategie des Bundes - */ -package at.gv.egovernment.moa.ss.erechtclient.moainvoker; - -import java.io.IOException; -import java.io.OutputStream; -import java.rmi.RemoteException; -import java.util.Vector; - -import javax.xml.namespace.QName; -import javax.xml.rpc.Call; -import javax.xml.rpc.Service; -import javax.xml.rpc.ServiceException; -import javax.xml.rpc.ServiceFactory; - -import org.apache.axis.message.SOAPBodyElement; -import org.apache.log4j.Logger; -import org.apache.xerces.parsers.DOMParser; -import org.apache.xerces.xni.parser.XMLInputSource; -import org.apache.xml.serialize.OutputFormat; -import org.apache.xml.serialize.XMLSerializer; -import org.w3c.dom.DOMConfiguration; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import at.gv.egovernment.moa.ss.erechtclient.ERechtClientException; -import at.gv.egovernment.moa.ss.erechtclient.init.Constants; -import at.gv.egovernment.moa.ss.erechtclient.util.DOMUtils; - -/** - * @author Gregor Karlinger (mailto:gregor.karlinger@cio.gv.at) - */ -public class MOAInvoker -{ - private static Logger logger_ = Logger.getLogger(Constants.LH_MOAINVOKER_); - - private static final String NAME_ERROR_ = "ErrorResponse"; - private static final String NAME_ERROR_CODE_ = "ErrorCode"; - private static final String NAME_ERROR_INFO_ = "Info"; - - /** - * Invokes MOA SS. - * - * @param request The XML request to be sent to MOA SS. - * - * @param endpoint The endpoint of the SOAP service where to send the XML request to. - * - * @param mOASchemaLoc The schema location URI for the MOA schema (for validating the MOA SS service response). - * - * @return the XML response from the service. - * - * @throws Exception if getting the XML response from the SOAP response body fails. - * - * @throws RemoteException if MOA SS signals an error. - * - * @throws ServiceException if the SOAP client invoking MOA SS signals an error. - */ - public static Document invokeSS(Document request, String endpoint, String mOASchemaLoc) throws ERechtClientException - { - QName serviceQName = new QName(Constants.MI_SS_QNAME_); - return invoke(request, endpoint, serviceQName, mOASchemaLoc); - } - - /* ---------------------------------------------------------------------------------------------------- */ - - private static Document invoke(Document request, String endpoint, QName serviceQName, String mOASchemaLoc) throws ERechtClientException - { - Document response; - try { - // Instantiate AXIS service - Service service = ServiceFactory.newInstance().createService(serviceQName); - - // Create and configure service call - Call call = service.createCall(); - call.setTargetEndpointAddress(endpoint); - - // Create SOAP body - SOAPBodyElement body = new SOAPBodyElement(request.getDocumentElement()); - SOAPBodyElement[] params = new SOAPBodyElement[] {body}; - - // Make call - Vector responses = (Vector) call.invoke(params); - - // Get response - SOAPBodyElement responseBody = (SOAPBodyElement) responses.get(0); - response = responseBody.getAsDocument(); - } - catch (Exception e) - { - String message = "MOA SS Service invocation failed."; - logger_.error(message, e); - throw new ERechtClientException(message, e); - } - - // Validate response - DOMConfiguration docConfig = response.getDomConfig(); - DOMErrorHandler errorHandler = new DOMErrorHandler(); - docConfig.setParameter("namespaces", Boolean.FALSE); - docConfig.setParameter("schema-location", mOASchemaLoc); - docConfig.setParameter("schema-type", "http://www.w3.org/2001/XMLSchema"); - docConfig.setParameter("validate", Boolean.TRUE); - docConfig.setParameter("error-handler", errorHandler); - response.normalizeDocument(); - if (errorHandler.getErrorCount() > 0) - { - String message = "Parsing the MOA SS service response failed:\n" + errorHandler.getErrorSummaryMsg(); - logger_.error(message); - throw new ERechtClientException(message); - } - - // Check if first child of response root element is an error element - Element responseElem = response.getDocumentElement(); - Element errorElem = DOMUtils.getChildElem(responseElem, Constants.NSURI_MOA_13_, NAME_ERROR_); - if (errorElem != null) - { - String errorCode = DOMUtils.getChildText(errorElem, Constants.NSURI_MOA_13_, NAME_ERROR_CODE_); - String errorInfo = DOMUtils.getChildText(errorElem, Constants.NSURI_MOA_13_, NAME_ERROR_INFO_); - String message = "MOA SS Service indicated an error:\n" + - "Error code: " + errorCode + "\n" + - "Error info: " + errorInfo; - logger_.error(message); - throw new ERechtClientException(message); - } - - return response; - } - - /* ---------------------------------------------------------------------------------------------------- */ - - public static void serializeElement(Element rootElem, OutputStream out) throws ERechtClientException - { - - // TODO Replace with DOMImplementationLS - OutputFormat format = new OutputFormat(rootElem.getOwnerDocument()); - - format.setLineSeparator("\n"); - format.setIndenting(false); - format.setPreserveSpace(true); - format.setOmitXMLDeclaration(false); - format.setEncoding("UTF-8"); - - XMLSerializer serializer = new XMLSerializer(out, format); - try - { - serializer.serialize(rootElem); - } - catch (Exception e) - { - String message = "Serializing the XML document failed."; - logger_.error(message); - throw new ERechtClientException(message); - } - } -} diff --git a/erecht.client.ss/src/at/gv/egovernment/moa/ss/erechtclient/moainvoker/RequestBuilder.java b/erecht.client.ss/src/at/gv/egovernment/moa/ss/erechtclient/moainvoker/RequestBuilder.java deleted file mode 100644 index 2c6e0d0e8..000000000 --- a/erecht.client.ss/src/at/gv/egovernment/moa/ss/erechtclient/moainvoker/RequestBuilder.java +++ /dev/null @@ -1,190 +0,0 @@ -package at.gv.egovernment.moa.ss.erechtclient.moainvoker; - -import java.io.InputStream; -import java.util.Properties; - -import javax.servlet.ServletContext; - -import org.apache.log4j.Logger; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -import at.gv.egovernment.moa.ss.erechtclient.ERechtClientException; -import at.gv.egovernment.moa.ss.erechtclient.init.Constants; -import at.gv.egovernment.moa.ss.erechtclient.util.DOMUtils; -import at.gv.egovernment.moa.ss.erechtclient.util.Utils; -import at.gv.egovernment.moa.ss.erechtclient.util.XPathUtils; - -public class RequestBuilder -{ - private static final String XPATH_KEYID_ = - "/" + Constants.NSPRE_MOA_13_ + ":" + "CreateXMLSignatureRequest" + - "/" + Constants.NSPRE_MOA_13_ + ":" + "KeyIdentifier"; - - private static final String XPATH_XMLDOC_ = - "/" + Constants.NSPRE_MOA_13_ + ":" + "CreateXMLSignatureRequest" + - "/" + Constants.NSPRE_MOA_13_ + ":" + "SingleSignatureInfo" + - "/" + Constants.NSPRE_MOA_13_ + ":" + "DataObjectInfo" + - "/" + Constants.NSPRE_MOA_13_ + ":" + "DataObject" + - "/" + Constants.NSPRE_MOA_13_ + ":" + "LocRefContent"; - - private static final String XPATH_STYLESHEET_ = - "/" + Constants.NSPRE_MOA_13_ + ":" + "CreateXMLSignatureRequest" + - "/" + Constants.NSPRE_MOA_13_ + ":" + "SingleSignatureInfo" + - "/" + Constants.NSPRE_MOA_13_ + ":" + "DataObjectInfo" + - "/" + Constants.NSPRE_MOA_13_ + ":" + "CreateTransformsInfoProfile" + - "/" + Constants.NSPRE_MOA_13_ + ":" + "Supplement" + - "/" + Constants.NSPRE_MOA_13_ + ":" + "Content" + "[@Reference=\"stylesheet.xsl\"]" + - "/" + Constants.NSPRE_MOA_13_ + ":" + "LocRefContent"; - - private static final String XPATH_IMAGE_ = - "/" + Constants.NSPRE_MOA_13_ + ":" + "CreateXMLSignatureRequest" + - "/" + Constants.NSPRE_MOA_13_ + ":" + "SingleSignatureInfo"; - - private static final String ELEM_NAME_DOI_ = "DataObjectInfo"; - - private static final String ATTR_VALUE_DO_STRUCTURE_ = "detached"; - - private static final String ELEM_NAME_DO_ = "DataObject"; - - private static final String ATTR_NAME_DOI_STRUCTURE_ = "Structure"; - - private static final String ATTR_NAME_DO_REFERENCE_ = "Reference"; - - private static final String ELEM_NAME_CTIP_ = "CreateTransformsInfoProfile"; - - private static final String ELEM_NAME_CTI_ = "CreateTransformsInfo"; - - private static final String ELEM_NAME_FDMI_ = "FinalDataMetaInfo"; - - private static final String ELEM_NAME_FDMIMIMETYPE_ = "MimeType"; - - private static final String ELEM_VALUE_FDMIMIMETYPE_ = "image"; - - private static final String ELEM_NAME_FDMITYPE_ = "Type"; - - private static final String ELEM_VALUE_FDMITYPE_ = "http://www.buergerkarte.at/specifications/" + - "Security-Layer/20031113?Name=SignedImage&InstanceDocRef=0"; - - private static final String ELEM_NAME_LOCREF_ = "LocRefContent"; - - private Document requestDoc_; - - private String contextPath_; - - private Properties initProps_; - - private ServletContext context_; - - private static Logger logger_ = Logger.getLogger(Constants.LH_MOAINVOKER_); - - public RequestBuilder(ServletContext context, String contextPath) throws ERechtClientException - { - contextPath_ = contextPath; - context_ = context; - initProps_ = (Properties) context.getAttribute(Constants.WSCP_INIT_PROPS_); - - // Load template - String requestTemplateLocation = Utils.readInitProperty(initProps_, Constants.IP_SS_REQUEST_TEMPLATE_, logger_); - try - { - InputStream requestTemplateIS = context_.getResourceAsStream(requestTemplateLocation); - requestDoc_ = DOMUtils.parseWellFormed(requestTemplateIS); - } catch (Exception e) - { - String message = "Could not parse MOA SS signature creation request template."; - logger_.error(message, e); - throw new ERechtClientException(message, e); - } - - // Insert key identifier - Element keyIdentifierElem = xPathGetElement(XPATH_KEYID_, requestDoc_); - String keyIdentifierStr = Utils.readInitProperty(initProps_, Constants.IP_SS_KEYID_, logger_); - keyIdentifierElem.appendChild(requestDoc_.createTextNode(keyIdentifierStr)); - } - - public void setXMLDocument(String locationRef) throws ERechtClientException - { - // Set XML document location reference - Element xMLDocLocRefElem = xPathGetElement(XPATH_XMLDOC_, requestDoc_); - String webAppHostPortFromMOASS = Utils.readInitProperty(initProps_, Constants.IP_WEBAPP_HOST_PORT_FROM_MOA_SS_, logger_); - xMLDocLocRefElem.appendChild(requestDoc_.createTextNode(webAppHostPortFromMOASS + contextPath_ + locationRef)); - } - - public void setStylesheet(String locationRef) throws ERechtClientException - { - Element stylesheetLocRefElem = xPathGetElement(XPATH_STYLESHEET_, requestDoc_); - String webAppHostPortFromMOASS = Utils.readInitProperty(initProps_, Constants.IP_WEBAPP_HOST_PORT_FROM_MOA_SS_, logger_); - String stylesheetLocRefStr = webAppHostPortFromMOASS + contextPath_ + locationRef; - stylesheetLocRefElem.appendChild(requestDoc_.createTextNode(webAppHostPortFromMOASS + contextPath_ + locationRef)); - logger_.debug("Setting stylesheet location to: " + stylesheetLocRefStr); - } - - public void useDefaultStylesheet() throws ERechtClientException - { - // Insert stylesheet reference, if it has not been set explicitly - Element stylesheetLocRefElem = xPathGetElement(XPATH_STYLESHEET_, requestDoc_); - String stylesheetLocRefStr = Utils.readInitProperty(initProps_, Constants.IP_SS_STYLESHEET_, logger_); - String webAppHostPortFromMOASS = Utils.readInitProperty(initProps_, Constants.IP_WEBAPP_HOST_PORT_FROM_MOA_SS_, logger_); - stylesheetLocRefStr = webAppHostPortFromMOASS + contextPath_ + stylesheetLocRefStr; - stylesheetLocRefElem.appendChild(requestDoc_.createTextNode(stylesheetLocRefStr)); - logger_.debug("No stylesheet set explicitly, using default one: " + stylesheetLocRefStr); - } - - public void addImage(String name, String locationRef) throws ERechtClientException - { - // Add supplement for image to be signed - Element parentElem = xPathGetElement(XPATH_IMAGE_, requestDoc_); - String webAppHostPortFromMOASS = Utils.readInitProperty(initProps_, Constants.IP_WEBAPP_HOST_PORT_FROM_MOA_SS_, logger_); - - Element dataObjInfo = requestDoc_.createElementNS(Constants.NSURI_MOA_13_, ELEM_NAME_DOI_); - dataObjInfo.setAttributeNS(null, ATTR_NAME_DOI_STRUCTURE_, ATTR_VALUE_DO_STRUCTURE_); - Element dataObj = requestDoc_.createElementNS(Constants.NSURI_MOA_13_, ELEM_NAME_DO_); - Element locRefCont = requestDoc_.createElementNS(Constants.NSURI_MOA_13_, ELEM_NAME_LOCREF_); - locRefCont.appendChild(requestDoc_.createTextNode(webAppHostPortFromMOASS + contextPath_ + locationRef)); - dataObj.appendChild(locRefCont); - dataObj.setAttributeNS(null, ATTR_NAME_DO_REFERENCE_, name); - dataObjInfo.appendChild(dataObj); - Element createTIProf = requestDoc_.createElementNS(Constants.NSURI_MOA_13_, ELEM_NAME_CTIP_); - Element createTI = requestDoc_.createElementNS(Constants.NSURI_MOA_13_, ELEM_NAME_CTI_); - Element finalDataMI = requestDoc_.createElementNS(Constants.NSURI_MOA_13_, ELEM_NAME_FDMI_); - Element finalDataMIMimeType = requestDoc_.createElementNS(Constants.NSURI_MOA_13_, ELEM_NAME_FDMIMIMETYPE_); - finalDataMIMimeType.appendChild(requestDoc_.createTextNode(ELEM_VALUE_FDMIMIMETYPE_)); - finalDataMI.appendChild(finalDataMIMimeType); - Element finalDataMIType = requestDoc_.createElementNS(Constants.NSURI_MOA_13_, ELEM_NAME_FDMITYPE_); - finalDataMIType.appendChild(requestDoc_.createTextNode(ELEM_VALUE_FDMITYPE_)); - finalDataMI.appendChild(finalDataMIType); - - createTI.appendChild(finalDataMI); - createTIProf.appendChild(createTI); - dataObjInfo.appendChild(createTIProf); - - parentElem.appendChild(dataObjInfo); - } - - public Document getRequest() - { - return requestDoc_; - } - - private Element xPathGetElement(String xPath, Document doc) throws ERechtClientException - { - try { - XPathUtils xpUtils = new XPathUtils(); - String additionalNSPrefixes = Constants.NSPRE_MOA_13_ + " " + Constants.NSURI_MOA_13_; - xpUtils.setupContext(xPath, doc.getDocumentElement(), additionalNSPrefixes); - NodeList nodeList = xpUtils.selectNodeSet(doc); - if (nodeList == null) return null; - if (nodeList.getLength() < 1) return null; - if (!(nodeList.item(0) instanceof Element)) return null; - return (Element) nodeList.item(0); - } - catch (Exception e) - { - String message = "MOA SS signature request template seems to be corrupted."; - logger_.error(message, e); - throw new ERechtClientException(message, e); - } - } -}
\ No newline at end of file |