aboutsummaryrefslogtreecommitdiff
path: root/spss.server/src/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureCreationInvoker.java
diff options
context:
space:
mode:
Diffstat (limited to 'spss.server/src/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureCreationInvoker.java')
-rw-r--r--spss.server/src/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureCreationInvoker.java542
1 files changed, 0 insertions, 542 deletions
diff --git a/spss.server/src/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureCreationInvoker.java b/spss.server/src/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureCreationInvoker.java
deleted file mode 100644
index 7de8ba48f..000000000
--- a/spss.server/src/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureCreationInvoker.java
+++ /dev/null
@@ -1,542 +0,0 @@
-package at.gv.egovernment.moa.spss.server.invoke;
-
-import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-import iaik.IAIKException;
-import iaik.IAIKRuntimeException;
-import iaik.server.modules.xml.DataObject;
-import iaik.server.modules.xml.XMLDataObject;
-import iaik.server.modules.xml.XMLSignature;
-import iaik.server.modules.xmlsign.XMLSignatureCreationModule;
-import iaik.server.modules.xmlsign.XMLSignatureCreationModuleFactory;
-import iaik.server.modules.xmlsign.XMLSignatureCreationProfile;
-
-import at.gv.egovernment.moa.logging.Logger;
-import at.gv.egovernment.moa.logging.LoggingContext;
-import at.gv.egovernment.moa.logging.LoggingContextManager;
-import at.gv.egovernment.moa.util.DateTimeUtils;
-
-import at.gv.egovernment.moa.spss.MOAApplicationException;
-import at.gv.egovernment.moa.spss.MOAException;
-import at.gv.egovernment.moa.spss.MOASystemException;
-import at.gv.egovernment.moa.spss.api.common.Content;
-import at.gv.egovernment.moa.spss.api.common.MetaInfo;
-import at.gv.egovernment.moa.spss.api.xmlsign.CreateSignatureEnvironmentProfileExplicit;
-import at.gv.egovernment.moa.spss.api.xmlsign.CreateSignatureInfo;
-import at.gv.egovernment.moa.spss.api.xmlsign.CreateSignatureLocation;
-import at.gv.egovernment.moa.spss.api.xmlsign.CreateTransformsInfoProfileExplicit;
-import at.gv.egovernment.moa.spss.api.xmlsign.CreateXMLSignatureRequest;
-import at.gv.egovernment.moa.spss.api.xmlsign.CreateXMLSignatureResponse;
-import at.gv.egovernment.moa.spss.api.xmlsign.DataObjectInfo;
-import at.gv.egovernment.moa.spss.api.xmlsign.SingleSignatureInfo;
-import at.gv.egovernment.moa.spss.server.config.ConfigurationProvider;
-import at.gv.egovernment.moa.spss.server.iaik.xml.SigningTimeImpl;
-import at.gv.egovernment.moa.spss.server.iaik.xml.XMLDataObjectImpl;
-import at.gv.egovernment.moa.spss.server.logging.IaikLog;
-import at.gv.egovernment.moa.spss.server.logging.TransactionId;
-import at.gv.egovernment.moa.spss.server.transaction.TransactionContext;
-import at.gv.egovernment.moa.spss.server.transaction.TransactionContextManager;
-import at.gv.egovernment.moa.spss.server.util.IdGenerator;
-
-/**
- * A class providing an API based interface to the
- * <code>XMLSignatureCreationModule</code>.
- *
- * This class performs the invocation of the
- * <code>iaik.server.modules.xmlsign.XMLSignatureCreationModule</code> from a
- * <code>CreateXMLSignatureRequest</code> given as an API object. The result of
- * the invocation is integrated into a <code>CreateXMLSignatureResponse</code>
- * and returned.
- *
- * @author Patrick Peck
- * @version $Id$
- */
-public class XMLSignatureCreationInvoker {
-
- /** The single instance of this class. */
- private static XMLSignatureCreationInvoker instance = null;
-
- /**
- * Get the only instance of this class.
- *
- * @return The only instance of this class.
- */
- public static synchronized XMLSignatureCreationInvoker getInstance() {
- if (instance == null) {
- instance = new XMLSignatureCreationInvoker();
- }
- return instance;
- }
-
- /**
- * Create a new <code>XMLSignatureCreationInvoker</code>.
- *
- * Protected to disallow multiple instances.
- */
- protected XMLSignatureCreationInvoker() {
- }
-
- /**
- * Process the <code>CreateXMLSignatureRequest<code> message and invoke the
- * <code>XMLSignatureCreationModule</code> for every
- * <code>SingleSignatureInfo</code> contained in the request.
- *
- * @param request A <code>CreateXMLSignatureRequest<code> API object
- * containing the information for creating the signature(s).
- * @param reserved A <code>Set</code> of reserved object IDs.
- *
- * @return A <code>CreateXMLSignatureResponse</code> API object containing
- * the created signature(s). The response contains either a
- * <code>SignatureEnvironment</code> or a <code>ErrorResponse</code>
- * for each <code>SingleSignatureInfo</code> in the request.
- * @throws MOAException An error occurred during signature creation.
- */
- public CreateXMLSignatureResponse createXMLSignature(
- CreateXMLSignatureRequest request,
- Set reserved)
- throws MOAException {
-
- TransactionContext context =
- TransactionContextManager.getInstance().getTransactionContext();
- LoggingContext loggingCtx =
- LoggingContextManager.getInstance().getLoggingContext();
- Set reservedIDs = new HashSet(reserved);
- XMLSignatureCreationProfileFactory profileFactory =
- new XMLSignatureCreationProfileFactory(request, reservedIDs);
- CreateXMLSignatureResponseBuilder responseBuilder =
- new CreateXMLSignatureResponseBuilder();
- int createCount = 1;
- IdGenerator refIdGen;
- XMLSignatureCreationModule module;
- Iterator singleSignatureInfoIter;
-
- // create the XMLSignatureCreationModule and configure it
- module = XMLSignatureCreationModuleFactory.getInstance();
- module.setLog(new IaikLog(loggingCtx.getNodeID()));
-
- // select the SingleSignatureInfo elements
- singleSignatureInfoIter = request.getSingleSignatureInfos().iterator();
-
- // iterate over all the SingleSignatureInfo elements in the request
- while (singleSignatureInfoIter.hasNext()) {
- SingleSignatureInfo singleSignatureInfo =
- (SingleSignatureInfo) singleSignatureInfoIter.next();
- CreateSignatureInfo createSignatureInfo;
- List dataObjectList;
- XMLSignatureCreationProfile profile;
- XMLDataObject signatureEnvironment;
- XMLDataObject signatureParent;
- XMLSignature signature;
- List additionalSignedProperties;
- Node signatureEnvironmentParent = null;
- Element requestElement = null;
-
- try {
- // create the reference id generator
- refIdGen = new IdGenerator("reference-" + createCount++, reservedIDs);
-
- // build the signature environment
- createSignatureInfo = singleSignatureInfo.getCreateSignatureInfo();
- if (createSignatureInfo != null) {
- DataObjectFactory dataObjFactory = DataObjectFactory.getInstance();
-
- signatureEnvironment =
- dataObjFactory.createSignatureEnvironment(
- createSignatureInfo.getCreateSignatureEnvironment(),
- getCreateSignatureEnvironmentProfileSupplements(singleSignatureInfo));
- } else {
- signatureEnvironment = null;
- }
-
- // build the list of DataObjects
- List createTransformsProfiles = profileFactory.getCreateTransformsInfoProfiles(singleSignatureInfo);
- dataObjectList =
- buildDataObjectList(
- singleSignatureInfo,
- createTransformsProfiles,
- signatureEnvironment,
- refIdGen);
-
- // build the XMLSignatureCreationProfile
- profile = profileFactory.createProfile(singleSignatureInfo);
-
- // build the additionalSignedProperties
- additionalSignedProperties = buildAdditionalSignedProperties();
-
- // build the signatureParentElement
- if (signatureEnvironment != null) {
- signatureParent =
- buildSignatureParentElement(
- signatureEnvironment.getElement(),
- singleSignatureInfo);
- } else {
- signatureParent = null;
- }
-
- // make the signature environment the root of the document, if it is
- // not a separate document anyway; this is done to assure that
- // canonicalization of the signature environment contains the correct
- // namespace declarations
- if (signatureEnvironment != null) {
- Document requestDoc =
- signatureEnvironment.getElement().getOwnerDocument();
- requestElement = requestDoc.getDocumentElement();
- if (requestElement != signatureEnvironment.getElement()) {
- signatureEnvironmentParent =
- signatureEnvironment.getElement().getParentNode();
- requestElement.getOwnerDocument().replaceChild(
- signatureEnvironment.getElement(),
- requestElement);
- }
- }
-
- try {
- // create the signature
- signature =
- module.createSignature(
- dataObjectList,
- profile,
- additionalSignedProperties,
- signatureParent,
- new TransactionId(context.getTransactionID()));
-
- // insert the result into the response
- if (signatureParent != null) {
- responseBuilder.addSignatureEnvironment(
- signatureEnvironment.getElement());
- } else {
- responseBuilder.addSignatureEnvironment(signature.getElement());
- }
-
- } catch (IAIKException e) {
- MOAException moaException = IaikExceptionMapper.getInstance().map(e);
-
- responseBuilder.addError(
- moaException.getMessageId(),
- moaException.getMessage());
- Logger.warn(moaException.getMessage(), e);
- } catch (IAIKRuntimeException e) {
- MOAException moaException = IaikExceptionMapper.getInstance().map(e);
-
- responseBuilder.addError(
- moaException.getMessageId(),
- moaException.getMessage());
- Logger.warn(moaException.getMessage(), e);
- }
-
- // swap back in the request as root document
- if (signatureEnvironment != null) {
- if (requestElement != signatureEnvironment.getElement()) {
- requestElement.getOwnerDocument().replaceChild(
- requestElement,
- signatureEnvironment.getElement());
- signatureEnvironmentParent.appendChild(
- signatureEnvironment.getElement());
- }
- }
-
- } catch (MOAException e) {
- responseBuilder.addError(e.getMessageId(), e.getMessage());
- Logger.warn(e.getMessage(), e);
- }
-
- }
-
- return responseBuilder.getResponse();
- }
-
- /**
- * Build the list of <code>DataObject</code>s from the given
- * <code>SingleSignatureInfo</code> object.
- *
- * <p>
- * Only the following cases of <code>DataObject</code>s are
- * valid in case of an enveloping signature:
- *
- * <ul>
- * <li><code>Reference == null && Content != null</code>: The
- * <code>Content</code> will be used in the <code>DataObject</code>.</li>
- * <li><code>Reference != null && Content == null</code>: Resolve the
- * <code>Reference</code> and use it as <code>DataObject</code>.
- * Set the <code>Reference</code> in the <code>DataObject</code> as well.</li>
- * </ul>
- * </p>
- *
- * <p>
- * Only the following cases of <code>DataObject</code>s are valid in case
- * of a detached signature:
- *
- * <ul>
- * <li><code>Reference != null && Content == null</code>: Resolve the
- * <code>Reference</code> and use it as <code>DataObject</code>.
- * Set the <code>Reference</code> in the <code>DataObject</code> as well.</li>
- * <li><code>Reference != null && Content != null</code>: The
- * <code>Content</code> will be used in the <code>DataObject</code>.
- * Set the <code>Reference</code> in the <code>DataObject</code> as well.</li>
- * </ul>
- * </p>
- *
- * <p>
- * All other cases will lead to an error.
- * </p>
- *
- * @param singleSignatureInfo The <code>SingleSignatureInfo</code> object
- * containing the <code>DataObjectInfo</code> objects.
- * @param createTransformsProfiles A list of objects of type {@link CreateTransformsInfoProfileExplicit},
- * each representing the transforms info profile information for the corresponding <code>DataObject</code>.
- * @param signatureEnvironment The
- * @param idGen The ID generator for <code>DataObject</code> references.
- * @return The <code>List</code> of <code>DataObject</code>s contained in the
- * given <code>singleSignatureInfo</code>.
- * @throws MOASystemException A system error occurred building the data
- * objects.
- * @throws MOAApplicationException An error occurred building the data
- * objects.
- */
- private List buildDataObjectList(
- SingleSignatureInfo singleSignatureInfo,
- List createTransformsProfiles,
- XMLDataObject signatureEnvironment,
- IdGenerator idGen)
- throws MOASystemException, MOAApplicationException {
-
- List dataObjInfos = singleSignatureInfo.getDataObjectInfos();
- List dataObjects = new ArrayList();
- Iterator dtIter;
- Iterator ctpIter = createTransformsProfiles.iterator();
-
- for (dtIter = dataObjInfos.iterator(); dtIter.hasNext();)
- {
- DataObjectInfo dataObjInfo = (DataObjectInfo) dtIter.next();
- String structure = dataObjInfo.getStructure();
-
- CreateTransformsInfoProfileExplicit transformsProfile =
- (CreateTransformsInfoProfileExplicit) ctpIter.next();
- MetaInfo finalDataMetaInfo = transformsProfile.getCreateTransformsInfo().getFinalDataMetaInfo();
-
- if (DataObjectInfo.STRUCTURE_ENVELOPING.equals(structure)) {
- dataObjects.add(
- buildEnvelopingDataObject(
- dataObjInfo.getDataObject(),
- finalDataMetaInfo,
- idGen.nextId()));
- } else if (DataObjectInfo.STRUCTURE_DETACHED.equals(structure)) {
- dataObjects.add(
- buildDetachedDataObject(
- dataObjInfo.getDataObject(),
- finalDataMetaInfo,
- signatureEnvironment,
- idGen.nextId()));
- } else {
- throw new MOAApplicationException("1103", new Object[] { structure });
- }
- }
-
- return dataObjects;
-
- }
-
- /**
- * Build a <code>DataObject</code> to be used in an enveloping
- * signature.
- *
- * @param content The <code>Content</code> object containing the data object.
- * <code>ContentOptionalRefType</code>.
- * @param finalDataMetaInfo The meta information corresponding with <code>content</code>.
- * @param referenceID The reference ID to use in the signature for the
- * <code>DataObject</code> created.
- * @return The <code>DataObject</code> representing the data contained in
- * <code>dataObjectElem</code>.
- * @throws MOAApplicationException An error occurred during the creation of
- * the <code>DataObject</code>.
- * @throws MOASystemException A system error occurred during the creation of
- * the <code>DataObject</code>.
- */
- private DataObject buildEnvelopingDataObject(
- Content content,
- MetaInfo finalDataMetaInfo,
- String referenceID)
- throws MOASystemException, MOAApplicationException {
-
- DataObjectFactory factory = DataObjectFactory.getInstance();
- DataObject dataObject;
-
- dataObject =
- factory.createFromContentOptionalRefType(
- content,
- finalDataMetaInfo,
- referenceID,
- false,
- false,
- true,
- false);
-
- return dataObject;
- }
-
- /**
- * Build a <code>DataObject</code> to be used in a detached signature.
- *
- * @param content The <code>Content</code> object containing an the data.
- * @param finalDataMetaInfo The meta information corresponding with <code>content</code>.
- * @param signatureEnvironment The signature environment where the signature
- * will be inserted.
- * @param referenceID The reference ID to use in the signature for the
- * <code>DataObject</code> created.
- * @return The <code>DataObject</code> representing the data contained in
- * <code>dataObjectElem</code>.
- * @throws MOAApplicationException An error occurred during the creation of
- * the <code>DataObject</code>.
- * @throws MOASystemException A system error occurred during the creation of
- * the <code>DataObject</code>.
- */
- private DataObject buildDetachedDataObject(
- Content content,
- MetaInfo finalDataMetaInfo,
- XMLDataObject signatureEnvironment,
- String referenceID)
- throws MOASystemException, MOAApplicationException {
-
- String reference = content.getReference();
- DataObjectFactory factory = DataObjectFactory.getInstance();
- DataObject dataObject;
-
- if (reference == null) {
- throw new MOAApplicationException("1102", null);
- } else if ("".equals(reference) || reference.startsWith("#")) {
- dataObject =
- factory.createFromSignatureEnvironment(
- signatureEnvironment.getElement(),
- reference,
- referenceID);
- } else {
- dataObject =
- factory.createFromContentOptionalRefType(
- content,
- finalDataMetaInfo,
- referenceID,
- true,
- false,
- true,
- false);
- }
- return dataObject;
- }
-
- /**
- * Build the signature parent element.
- *
- * @param signatureEnvironment The signature environment containing the
- * document in which to insert the signature.
- * @param singleSignatureInfo The <code>SingleSignatureInfo</code>
- * containing the signature parent element.
- * @return An <code>XMLDataObject</code> containing the signature parent
- * element or <code>null</code>, if the <code>CreateSignatureInfo</code> is
- * <code>null</code>.
- * @throws MOAApplicationException An error occurred during the creation of
- * the signature parent.
- */
- private XMLDataObject buildSignatureParentElement(
- Element signatureEnvironment,
- SingleSignatureInfo singleSignatureInfo)
- throws MOAApplicationException {
-
- CreateSignatureInfo createInfo =
- singleSignatureInfo.getCreateSignatureInfo();
-
- // evaluate the CreateSignatureLocation
- if (createInfo != null) {
- TransactionContext context =
- TransactionContextManager.getInstance().getTransactionContext();
- ConfigurationProvider config = context.getConfiguration();
- CreateSignatureEnvironmentProfileExplicit createProfile =
- ProfileMapper.mapCreateSignatureEnvironmentProfile(
- createInfo.getCreateSignatureEnvironmentProfile(),
- config);
- CreateSignatureLocation location =
- createProfile.getCreateSignatureLocation();
- Element signatureParent =
- InvokerUtils.evaluateSignatureLocation(signatureEnvironment, location);
-
- return new XMLDataObjectImpl(signatureParent);
- } else {
- return null;
- }
- }
-
- /**
- * Get the supplements contained in the
- * <code>CreateSignatureEnvironmentProfile</code> of the given
- * <code>SingleSignatureInfo</code>.
- *
- * @param singleSigInfo The <code>SingleSignatureInfo</code> from which
- * to extract the supplements.
- * @return A <code>List</code> of <code>XMLDataObjectAssociation</code>s
- * or <code>null</code>, if the <code>singleSigInfo</code> does not contain
- * supplements.
- * @throws MOAApplicationException An error occurred parsing the
- * <code>CreateSignatureEnvironmentProfile</code>.
- */
- private List getCreateSignatureEnvironmentProfileSupplements(SingleSignatureInfo singleSigInfo)
- throws MOAApplicationException {
- CreateSignatureInfo sigInfo = singleSigInfo.getCreateSignatureInfo();
-
- if (sigInfo != null) {
- TransactionContext context =
- TransactionContextManager.getInstance().getTransactionContext();
- ConfigurationProvider config = context.getConfiguration();
- CreateSignatureEnvironmentProfileExplicit profile =
- ProfileMapper.mapCreateSignatureEnvironmentProfile(
- sigInfo.getCreateSignatureEnvironmentProfile(),
- config);
- List supplements = profile.getSupplements();
-
- return supplements;
- }
- return null;
- }
-
- /**
- * Build the list of additional signed properties.
- *
- * Based on the generic configuration setting
- * <code>ConfigurationProvider.TEST_SIGNING_TIME_PROPERTY</code>, a
- * constant <code>SigningTime</code> will be added to the properties.
- *
- * @return The <code>List</code> of additional signed properties.
- */
- private List buildAdditionalSignedProperties() {
- TransactionContext context =
- TransactionContextManager.getInstance().getTransactionContext();
- ConfigurationProvider config = context.getConfiguration();
- List additionalSignedProperties = Collections.EMPTY_LIST;
- String testSigningTime =
- config.getGenericConfiguration(
- ConfigurationProvider.TEST_SIGNING_TIME_PROPERTY);
-
- if (testSigningTime != null) {
- try {
- SigningTimeImpl signingTime =
- new SigningTimeImpl(DateTimeUtils.parseDateTime(testSigningTime));
- additionalSignedProperties = new ArrayList();
- additionalSignedProperties.add(signingTime);
- } catch (ParseException e) {
- // if we fail here, the signing time will simply not be added to
- // the list of signed properties
- }
- }
-
- return additionalSignedProperties;
- }
-
-} \ No newline at end of file