summaryrefslogtreecommitdiff
path: root/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl
diff options
context:
space:
mode:
Diffstat (limited to 'bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl')
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractAssocArrayInfobox.java16
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractBinaryFileInfobox.java8
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractInfoboxCommandFactory.java40
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractInfoboxCommandImpl.java26
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractInfoboxFactory.java24
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CardChannelInfoboxFactory.java27
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CardChannelInfoboxImpl.java12
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CertificatesInfoboxFactory.java27
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CertificatesInfoboxImpl.java6
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureCommandFactory.java65
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureCommandImpl.java77
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureResultImpl.java27
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DomCreateXMLSignatureResultImpl.java47
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DomErrorResultImpl.java70
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DomInfoboxReadResultImpl.java105
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DomSLResult.java41
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/ErrorResultImpl.java18
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/GetStatusCommandFactory.java37
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/GetStatusCommandImpl.java24
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/IdentityLinkInfoboxFactory.java48
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/IdentityLinkInfoboxImpl.java28
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxFactory.java103
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadCommandFactory.java37
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadCommandImpl.java84
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadResultFileImpl.java40
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadResultImpl.java18
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxUpdateCommandFactory.java37
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxUpdateCommandImpl.java16
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/NullOperationCommandFactory.java37
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/NullOperationCommandImpl.java3
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SLCommandImpl.java33
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SLResultImpl.java18
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/STALHelper.java17
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SVPersonendatenInfoboxFactory.java27
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SVPersonendatenInfoboxImpl.java10
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/AlgorithmMethodFactoryImpl.java3
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/DataObject.java191
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/LocRefDereferencer.java189
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALPrivateKey.java3
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALProvider.java71
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALSignature.java184
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALSignatureException.java2
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALSignatureMethod.java127
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/Signature.java43
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/SignatureContext.java50
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/SignatureLocation.java418
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/URIDereferncerAdapter.java14
47 files changed, 1571 insertions, 977 deletions
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractAssocArrayInfobox.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractAssocArrayInfobox.java
index 9a4536e6..4da9abb7 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractAssocArrayInfobox.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractAssocArrayInfobox.java
@@ -26,8 +26,8 @@ import java.util.regex.Pattern;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import at.buergerkarte.namespaces.securitylayer._1.InfoboxAssocArrayPairType;
import at.buergerkarte.namespaces.securitylayer._1.InfoboxReadDataAssocArrayType;
@@ -54,7 +54,7 @@ public abstract class AbstractAssocArrayInfobox extends AbstractInfoboxImpl
/**
* Logging facility.
*/
- private static Log log = LogFactory.getLog(AbstractAssocArrayInfobox.class);
+ private final Logger log = LoggerFactory.getLogger(AbstractAssocArrayInfobox.class);
/**
* The search string pattern.
@@ -113,7 +113,7 @@ public abstract class AbstractAssocArrayInfobox extends AbstractInfoboxImpl
// TODO : build pattern
return Collections.emptyList();
} else {
- log.info("Got invalid search string '" + searchString + "'");
+ log.info("Got invalid search string '{}'.", searchString);
throw new SLCommandException(4010);
}
@@ -170,14 +170,14 @@ public abstract class AbstractAssocArrayInfobox extends AbstractInfoboxImpl
protected InfoboxReadResult readPairs(ReadPairs readPairs, SLCommandContext cmdCtx) throws SLCommandException {
if (readPairs.isValuesAreXMLEntities() && !isValuesAreXMLEntities()) {
- log.info("Got valuesAreXMLEntities=" + readPairs.isValuesAreXMLEntities() + " but infobox type is binary.");
+ log.info("Got valuesAreXMLEntities={} but infobox type is binary.", readPairs.isValuesAreXMLEntities());
throw new SLCommandException(4010);
}
List<String> selectedKeys = selectKeys(readPairs.getSearchString());
if (readPairs.isUserMakesUnique() && selectedKeys.size() > 1) {
- log.info("UserMakesUnique not supported");
+ log.info("UserMakesUnique not supported.");
// TODO: give more specific error message
throw new SLCommandException(4010);
}
@@ -202,7 +202,7 @@ public abstract class AbstractAssocArrayInfobox extends AbstractInfoboxImpl
protected InfoboxReadResult readValue(ReadValue readValue, SLCommandContext cmdCtx) throws SLCommandException {
if (readValue.isValueIsXMLEntity() && !isValuesAreXMLEntities()) {
- log.info("Got valuesAreXMLEntities=" + readValue.isValueIsXMLEntity() + " but infobox type is binary.");
+ log.info("Got valuesAreXMLEntities={} but infobox type is binary.", readValue.isValueIsXMLEntity());
throw new SLCommandException(4010);
}
@@ -232,7 +232,7 @@ public abstract class AbstractAssocArrayInfobox extends AbstractInfoboxImpl
Object value = values.get(key);
if (areXMLEntities) {
if (value instanceof byte[]) {
- log.info("Got valuesAreXMLEntities=" + areXMLEntities + " but infobox type is binary.");
+ log.info("Got valuesAreXMLEntities={} but infobox type is binary.", areXMLEntities);
throw new SLCommandException(4122);
} else {
XMLContentType contentType = objectFactory.createXMLContentType();
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractBinaryFileInfobox.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractBinaryFileInfobox.java
index 23394bd5..feead9e5 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractBinaryFileInfobox.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractBinaryFileInfobox.java
@@ -16,8 +16,8 @@
*/
package at.gv.egiz.bku.slcommands.impl;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import at.buergerkarte.namespaces.securitylayer._1.InfoboxReadParamsBinaryFileType;
import at.buergerkarte.namespaces.securitylayer._1.InfoboxReadRequestType;
@@ -32,7 +32,7 @@ public abstract class AbstractBinaryFileInfobox extends AbstractInfoboxImpl impl
/**
* Logging facility.
*/
- private static Log log = LogFactory.getLog(AbstractBinaryFileInfobox.class);
+ private final Logger log = LoggerFactory.getLogger(AbstractBinaryFileInfobox.class);
/**
* Is this infobox' content an XML entity?
@@ -57,7 +57,7 @@ public abstract class AbstractBinaryFileInfobox extends AbstractInfoboxImpl impl
InfoboxReadParamsBinaryFileType binaryFileParameters = request.getBinaryFileParameters();
if (binaryFileParameters != null) {
isXMLEntity = binaryFileParameters.isContentIsXMLEntity();
- log.debug("Got ContentIsXMLEntity=" + isXMLEntity + ".");
+ log.debug("Got ContentIsXMLEntity={}.", isXMLEntity);
}
}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractInfoboxCommandFactory.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractInfoboxCommandFactory.java
new file mode 100644
index 00000000..547f7eda
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractInfoboxCommandFactory.java
@@ -0,0 +1,40 @@
+/*
+* Copyright 2009 Federal Chancellery Austria and
+* Graz University of Technology
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package at.gv.egiz.bku.slcommands.impl;
+
+import at.gv.egiz.bku.slcommands.AbstractSLCommandFactory;
+
+public abstract class AbstractInfoboxCommandFactory extends AbstractSLCommandFactory {
+
+ protected InfoboxFactory infoboxFactory;
+
+ /**
+ * @return the infoboxFactory
+ */
+ public InfoboxFactory getInfoboxFactory() {
+ return infoboxFactory;
+ }
+
+ /**
+ * @param infoboxFactory the infoboxFactory to set
+ */
+ public void setInfoboxFactory(InfoboxFactory infoboxFactory) {
+ this.infoboxFactory = infoboxFactory;
+ }
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractInfoboxCommandImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractInfoboxCommandImpl.java
index 8a7edb71..8a54260f 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractInfoboxCommandImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractInfoboxCommandImpl.java
@@ -16,7 +16,6 @@
*/
package at.gv.egiz.bku.slcommands.impl;
-import at.gv.egiz.bku.slcommands.SLCommandContext;
import at.gv.egiz.bku.slexceptions.SLCommandException;
/**
@@ -32,15 +31,34 @@ public abstract class AbstractInfoboxCommandImpl<T> extends SLCommandImpl<T> {
* The infobox implementation.
*/
protected Infobox infobox;
+
+ /**
+ * The infobox factory.
+ */
+ protected InfoboxFactory infoboxFactory;
+
+ /**
+ * @return the infoboxFactory
+ */
+ public InfoboxFactory getInfoboxFactory() {
+ return infoboxFactory;
+ }
+
+ /**
+ * @param infoboxFactory the infoboxFactory to set
+ */
+ public void setInfoboxFactory(InfoboxFactory infoboxFactory) {
+ this.infoboxFactory = infoboxFactory;
+ }
@Override
- public void init(SLCommandContext ctx, Object request)
+ public void init(Object request)
throws SLCommandException {
- super.init(ctx, request);
+ super.init(request);
String infoboxIdentifier = getInfoboxIdentifier(getRequestValue());
- infobox = InfoboxFactory.getInstance().createInfobox(infoboxIdentifier);
+ infobox = infoboxFactory.createInfobox(infoboxIdentifier);
}
/**
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractInfoboxFactory.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractInfoboxFactory.java
new file mode 100644
index 00000000..410d0cf8
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/AbstractInfoboxFactory.java
@@ -0,0 +1,24 @@
+/*
+* Copyright 2009 Federal Chancellery Austria and
+* Graz University of Technology
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package at.gv.egiz.bku.slcommands.impl;
+
+public abstract class AbstractInfoboxFactory {
+
+ public abstract Infobox createInfobox();
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CardChannelInfoboxFactory.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CardChannelInfoboxFactory.java
new file mode 100644
index 00000000..ec46f8ac
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CardChannelInfoboxFactory.java
@@ -0,0 +1,27 @@
+/*
+* Copyright 2009 Federal Chancellery Austria and
+* Graz University of Technology
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package at.gv.egiz.bku.slcommands.impl;
+
+public class CardChannelInfoboxFactory extends AbstractInfoboxFactory {
+
+ @Override
+ public Infobox createInfobox() {
+ return new CardChannelInfoboxImpl();
+ }
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CardChannelInfoboxImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CardChannelInfoboxImpl.java
index 19b84ac7..a7851b1e 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CardChannelInfoboxImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CardChannelInfoboxImpl.java
@@ -30,8 +30,8 @@ import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import at.buergerkarte.namespaces.cardchannel.ATRType;
import at.buergerkarte.namespaces.cardchannel.CommandAPDUType;
@@ -58,7 +58,7 @@ import at.gv.egiz.stal.ext.APDUScriptResponse.ResponseScriptElement;
public class CardChannelInfoboxImpl extends AbstractBinaryFileInfobox {
- private static Log log = LogFactory.getLog(CardChannelInfoboxImpl.class);
+ private final Logger log = LoggerFactory.getLogger(CardChannelInfoboxImpl.class);
private static WeakHashMap<STAL, JAXBElement<ResponseType>> scriptResults = new WeakHashMap<STAL, JAXBElement<ResponseType>>();
@@ -149,7 +149,7 @@ public class CardChannelInfoboxImpl extends AbstractBinaryFileInfobox {
}
- log.info("Infobox identifier is '" + getIdentifier() + "' but XMLContent does not contain 'Script'.");
+ log.info("Infobox identifier is '{}' but XMLContent does not contain 'Script'.", getIdentifier());
throw new SLCommandException(4010);
}
@@ -217,9 +217,7 @@ public class CardChannelInfoboxImpl extends AbstractBinaryFileInfobox {
ResponseAPDUType responseAPDUType = objectFactory.createResponseAPDUType();
responseAPDUType.setSequence(BigInteger.valueOf(response.getSequence()));
-// if (response.getRc() != 0) {
- responseAPDUType.setRc(BigInteger.valueOf(response.getRc()));
-// }
+ responseAPDUType.setRc(BigInteger.valueOf(response.getRc()));
responseAPDUType.setSw(response.getSw());
responseAPDUType.setValue(response.getApdu());
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CertificatesInfoboxFactory.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CertificatesInfoboxFactory.java
new file mode 100644
index 00000000..5474f249
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CertificatesInfoboxFactory.java
@@ -0,0 +1,27 @@
+/*
+* Copyright 2009 Federal Chancellery Austria and
+* Graz University of Technology
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package at.gv.egiz.bku.slcommands.impl;
+
+public class CertificatesInfoboxFactory extends AbstractInfoboxFactory {
+
+ @Override
+ public Infobox createInfobox() {
+ return new CertificatesInfoboxImpl();
+ }
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CertificatesInfoboxImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CertificatesInfoboxImpl.java
index 0208f137..8a80e824 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CertificatesInfoboxImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CertificatesInfoboxImpl.java
@@ -23,8 +23,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import at.gv.egiz.bku.slcommands.SLCommandContext;
import at.gv.egiz.bku.slexceptions.SLCommandException;
@@ -42,7 +42,7 @@ public class CertificatesInfoboxImpl extends AbstractAssocArrayInfobox {
/**
* Logging facility.
*/
- private static Log log = LogFactory.getLog(CertificatesInfoboxImpl.class);
+ private final Logger log = LoggerFactory.getLogger(CertificatesInfoboxImpl.class);
/**
* The valid keys.
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureCommandFactory.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureCommandFactory.java
new file mode 100644
index 00000000..750c2838
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureCommandFactory.java
@@ -0,0 +1,65 @@
+/*
+* Copyright 2009 Federal Chancellery Austria and
+* Graz University of Technology
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package at.gv.egiz.bku.slcommands.impl;
+
+import javax.xml.bind.JAXBElement;
+
+import org.apache.commons.configuration.Configuration;
+
+import at.gv.egiz.bku.conf.MoccaConfigurationFacade;
+import at.gv.egiz.bku.slcommands.AbstractSLCommandFactory;
+import at.gv.egiz.bku.slcommands.SLCommand;
+import at.gv.egiz.bku.slcommands.impl.xsect.DataObject;
+import at.gv.egiz.bku.slexceptions.SLCommandException;
+
+public class CreateXMLSignatureCommandFactory extends AbstractSLCommandFactory {
+
+ private ConfigurationFacade configurationFacade = new ConfigurationFacade();
+
+ private class ConfigurationFacade implements MoccaConfigurationFacade {
+
+ public static final String VALIDATE_HASH_DATA_INPUTS = "ValidateHashDataInputs";
+
+ public boolean getValidateHashDataInputs() {
+ return configuration.getBoolean(VALIDATE_HASH_DATA_INPUTS, true);
+ }
+
+ }
+
+ @Override
+ public SLCommand createSLCommand(JAXBElement<?> element) throws SLCommandException {
+
+ CreateXMLSignatureCommandImpl command = new CreateXMLSignatureCommandImpl();
+ command.init(element);
+ return command;
+
+ }
+
+ /* (non-Javadoc)
+ * @see at.gv.egiz.bku.slcommands.AbstractSLCommandFactory#setConfiguration(org.apache.commons.configuration.Configuration)
+ */
+ @Override
+ public void setConfiguration(Configuration configuration) {
+ // static configuration
+ super.setConfiguration(configuration);
+ DataObject.enableHashDataInputValidation(configurationFacade.getValidateHashDataInputs());
+ }
+
+
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureCommandImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureCommandImpl.java
index 01686641..d52027b2 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureCommandImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureCommandImpl.java
@@ -26,8 +26,8 @@ import javax.xml.crypto.MarshalException;
import javax.xml.crypto.URIReferenceException;
import javax.xml.crypto.dsig.XMLSignatureException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSSerializer;
@@ -62,8 +62,7 @@ public class CreateXMLSignatureCommandImpl extends
/**
* Logging facility.
*/
- protected static Log log = LogFactory
- .getLog(CreateXMLSignatureCommandImpl.class);
+ private final Logger log = LoggerFactory.getLogger(CreateXMLSignatureCommandImpl.class);
/**
* The signing certificate.
@@ -79,23 +78,22 @@ public class CreateXMLSignatureCommandImpl extends
* The to-be signed signature.
*/
protected Signature signature;
-
- @Override
- public void init(SLCommandContext ctx, Object unmarshalledRequest)
- throws SLCommandException {
- super.init(ctx, unmarshalledRequest);
- }
-
+
+ /**
+ * Disable hash data input validation?
+ */
+ protected boolean disableHashdataInputValidation;
+
@Override
- public void prepareXMLSignature() throws SLCommandException,
+ public void prepareXMLSignature(SLCommandContext commandContext) throws SLCommandException,
SLRequestException {
CreateXMLSignatureRequestType request = getRequestValue();
- // TODO: make configurable?
+ // TODO: make configurable?
IdValueFactory idValueFactory = new IdValueFactoryImpl();
- // TODO: make configurable?
+ // TODO: make configurable?
AlgorithmMethodFactory algorithmMethodFactory;
try {
algorithmMethodFactory = new AlgorithmMethodFactoryImpl(
@@ -105,21 +103,21 @@ public class CreateXMLSignatureCommandImpl extends
throw new SLCommandException(4006);
}
- signature = new Signature(getCmdCtx().getURLDereferencerContext(),
+ signature = new Signature(commandContext.getURLDereferencer(),
idValueFactory, algorithmMethodFactory);
- // SigningTime
+ // SigningTime
signature.setSigningTime(new Date());
- // SigningCertificate
+ // SigningCertificate
signature.setSignerCeritifcate(signingCertificate);
- // SignatureInfo
+ // SignatureInfo
if (request.getSignatureInfo() != null) {
signature.setSignatureInfo(request.getSignatureInfo());
}
- // DataObjects
+ // DataObjects
for (DataObjectInfoType dataObjectInfo : request.getDataObjectInfo()) {
signature.addDataObject(dataObjectInfo);
}
@@ -130,11 +128,12 @@ public class CreateXMLSignatureCommandImpl extends
/**
* Gets the signing certificate from STAL.
+ * @param commandContext TODO
*
* @throws SLCommandException
* if getting the singing certificate fails
*/
- private void getSigningCertificate() throws SLCommandException {
+ private void getSigningCertificate(SLCommandContext commandContext) throws SLCommandException {
CreateXMLSignatureRequestType request = getRequestValue();
keyboxIdentifier = request.getKeyboxIdentifier();
@@ -142,6 +141,8 @@ public class CreateXMLSignatureCommandImpl extends
InfoboxReadRequest stalRequest = new InfoboxReadRequest();
stalRequest.setInfoboxIdentifier(keyboxIdentifier);
+ STALHelper stalHelper = new STALHelper(commandContext.getSTAL());
+
stalHelper.transmitSTALRequest(Collections.singletonList((STALRequest) stalRequest));
List<X509Certificate> certificates = stalHelper.getCertificatesFromResponses();
if (certificates == null || certificates.size() != 1) {
@@ -154,15 +155,16 @@ public class CreateXMLSignatureCommandImpl extends
/**
* Signs the signature.
+ * @param commandContext TODO
*
* @throws SLCommandException
* if signing the signature fails
* @throws SLViewerException
*/
- private void signXMLSignature() throws SLCommandException, SLViewerException {
+ private void signXMLSignature(SLCommandContext commandContext) throws SLCommandException, SLViewerException {
try {
- signature.sign(getCmdCtx().getSTAL(), keyboxIdentifier);
+ signature.sign(commandContext.getSTAL(), keyboxIdentifier);
} catch (MarshalException e) {
log.error("Failed to marshall XMLSignature.", e);
throw new SLCommandException(4000);
@@ -181,33 +183,42 @@ public class CreateXMLSignatureCommandImpl extends
}
@Override
- public SLResult execute() {
+ public SLResult execute(SLCommandContext commandContext) {
try {
// get certificate in order to select appropriate algorithms for hashing
- // and signing
- getSigningCertificate();
-
- // prepare the XMLSignature for signing
- prepareXMLSignature();
+ // and signing
+ log.info("Requesting signing certificate.");
+ getSigningCertificate(commandContext);
+ if (log.isDebugEnabled()) {
+ log.debug("Got signing certificate. {}", signingCertificate);
+ } else {
+ log.info("Got signing certificate.");
+ }
- // sign the XMLSignature
- signXMLSignature();
+ // prepare the XMLSignature for signing
+ log.info("Preparing XML signature.");
+ prepareXMLSignature(commandContext);
- if (log.isTraceEnabled()) {
+ // sign the XMLSignature
+ log.info("Signing XML signature.");
+ signXMLSignature(commandContext);
+ if (log.isDebugEnabled()) {
DOMImplementationLS domImplLS = DOMUtils.getDOMImplementationLS();
LSSerializer serializer = domImplLS.createLSSerializer();
String debugString = serializer.writeToString(signature.getDocument());
- log.trace(debugString);
+ log.debug(debugString);
+ } else {
+ log.info("XML signature signed.");
}
return new CreateXMLSignatureResultImpl(signature.getDocument());
} catch (SLException e) {
- return new ErrorResultImpl(e, cmdCtx.getLocale());
+ return new ErrorResultImpl(e, commandContext.getLocale());
}
}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureResultImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureResultImpl.java
index 19df4334..51b54a37 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureResultImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureResultImpl.java
@@ -22,8 +22,8 @@ import javax.xml.bind.Marshaller;
import javax.xml.transform.Result;
import javax.xml.transform.Templates;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Element;
@@ -31,6 +31,7 @@ import org.w3c.dom.Node;
import at.buergerkarte.namespaces.securitylayer._1.CreateXMLSignatureResponseType;
import at.buergerkarte.namespaces.securitylayer._1.ObjectFactory;
+import at.gv.egiz.bku.slcommands.CreateXMLSignatureResult;
import at.gv.egiz.bku.slcommands.SLMarshallerFactory;
import at.gv.egiz.bku.slexceptions.SLRuntimeException;
@@ -39,12 +40,12 @@ import at.gv.egiz.bku.slexceptions.SLRuntimeException;
*
* @author mcentner
*/
-public class CreateXMLSignatureResultImpl extends SLResultImpl {
+public class CreateXMLSignatureResultImpl extends SLResultImpl implements CreateXMLSignatureResult {
/**
* Logging facility.
*/
- private static Log log = LogFactory.getLog(CreateXMLSignatureResultImpl.class);
+ private final Logger log = LoggerFactory.getLogger(CreateXMLSignatureResultImpl.class);
/**
* The document containing the XMLSignature.
@@ -52,6 +53,11 @@ public class CreateXMLSignatureResultImpl extends SLResultImpl {
protected Document doc;
/**
+ * The content of the CreateXMLSignatureResponse.
+ */
+ protected Element content;
+
+ /**
* Creates a new instance of this CreateXMLSignatureResultImpl with the given
* signature <code>document</code>.
*
@@ -67,6 +73,7 @@ public class CreateXMLSignatureResultImpl extends SLResultImpl {
}
this.doc = document;
+ this.content = document.getDocumentElement();
marshallCreateXMLSignatureResponse();
}
@@ -78,7 +85,7 @@ public class CreateXMLSignatureResultImpl extends SLResultImpl {
ObjectFactory factory = new ObjectFactory();
- CreateXMLSignatureResponseType createCreateXMLSignatureResponseType = factory.createCreateXMLSignatureResponseType();
+ at.gv.egiz.slbinding.impl.CreateXMLSignatureResponseType createCreateXMLSignatureResponseType = factory.createCreateXMLSignatureResponseType();
JAXBElement<CreateXMLSignatureResponseType> createCreateXMLSignatureResponse = factory.createCreateXMLSignatureResponse(createCreateXMLSignatureResponseType);
DocumentFragment fragment = doc.createDocumentFragment();
@@ -87,14 +94,13 @@ public class CreateXMLSignatureResultImpl extends SLResultImpl {
try {
marshaller.marshal(createCreateXMLSignatureResponse, fragment);
} catch (JAXBException e) {
- log.error("Failed to marshall 'CreateXMLSignatureResponse'", e);
+ log.error("Failed to marshall 'CreateXMLSignatureResponse'.", e);
throw new SLRuntimeException(e);
}
Node child = fragment.getFirstChild();
if (child instanceof Element) {
- Node node = doc.replaceChild(child, doc.getDocumentElement());
- child.appendChild(node);
+ child.appendChild(doc.replaceChild(child, content));
}
}
@@ -104,4 +110,9 @@ public class CreateXMLSignatureResultImpl extends SLResultImpl {
writeTo(doc, result, templates, fragment);
}
+ @Override
+ public Element getContent() {
+ return content;
+ }
+
}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DomCreateXMLSignatureResultImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DomCreateXMLSignatureResultImpl.java
new file mode 100644
index 00000000..6d8537d6
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DomCreateXMLSignatureResultImpl.java
@@ -0,0 +1,47 @@
+/*
+* Copyright 2009 Federal Chancellery Austria and
+* Graz University of Technology
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package at.gv.egiz.bku.slcommands.impl;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import at.gv.egiz.bku.slcommands.CreateXMLSignatureResult;
+
+public class DomCreateXMLSignatureResultImpl extends DomSLResult implements
+ CreateXMLSignatureResult {
+
+ public DomCreateXMLSignatureResultImpl(Element resultElement) {
+ super(resultElement);
+ }
+
+ @Override
+ public Element getContent() {
+
+ NodeList children = resultElement.getChildNodes();
+ for (int i = 0; i < children.getLength(); i++) {
+ Node child = children.item(i);
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ return (Element) child;
+ }
+ }
+
+ return null;
+ }
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DomErrorResultImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DomErrorResultImpl.java
new file mode 100644
index 00000000..6bb52a00
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DomErrorResultImpl.java
@@ -0,0 +1,70 @@
+/*
+* Copyright 2009 Federal Chancellery Austria and
+* Graz University of Technology
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package at.gv.egiz.bku.slcommands.impl;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import at.gv.egiz.bku.slcommands.ErrorResult;
+import at.gv.egiz.bku.slcommands.SLCommand;
+
+public class DomErrorResultImpl extends DomSLResult implements
+ ErrorResult {
+
+ public DomErrorResultImpl(Element resultElement) {
+ super(resultElement);
+ }
+
+ @Override
+ public int getErrorCode() {
+
+ NodeList childNodes = resultElement.getChildNodes();
+ for (int i = 0; i < childNodes.getLength(); i++) {
+ Node n = childNodes.item(i);
+ if (n.getNodeType() == Node.ELEMENT_NODE
+ && SLCommand.NAMESPACE_URI.equals(n.getNamespaceURI())
+ && "ErrorCode".equals(n.getLocalName())) {
+ try {
+ return Integer.parseInt(n.getTextContent());
+ } catch (NumberFormatException e) { }
+ }
+ }
+
+ return 0;
+
+ }
+
+ @Override
+ public String getInfo() {
+
+ NodeList childNodes = resultElement.getChildNodes();
+ for (int i = 0; i < childNodes.getLength(); i++) {
+ Node n = childNodes.item(i);
+ if (n.getNodeType() == Node.ELEMENT_NODE
+ && SLCommand.NAMESPACE_URI.equals(n.getNamespaceURI())
+ && "Info".equals(n.getLocalName())) {
+ return n.getTextContent();
+ }
+ }
+
+ return null;
+
+ }
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DomInfoboxReadResultImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DomInfoboxReadResultImpl.java
new file mode 100644
index 00000000..ce69c852
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DomInfoboxReadResultImpl.java
@@ -0,0 +1,105 @@
+/*
+* Copyright 2009 Federal Chancellery Austria and
+* Graz University of Technology
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package at.gv.egiz.bku.slcommands.impl;
+
+import iaik.utils.Base64InputStream;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import at.gv.egiz.bku.slcommands.InfoboxReadResult;
+import at.gv.egiz.bku.slcommands.SLCommand;
+import at.gv.egiz.bku.slexceptions.SLRuntimeException;
+import at.gv.egiz.bku.utils.StreamUtil;
+
+public class DomInfoboxReadResultImpl extends DomSLResult implements
+ InfoboxReadResult {
+
+ public DomInfoboxReadResultImpl(Element resultElement) {
+ super(resultElement);
+ }
+
+ private List<Node> getXMLContent(Node node) {
+ ArrayList<Node> content = new ArrayList<Node>();
+ NodeList xmlContent = node.getChildNodes();
+ for (int i = 0; i < xmlContent.getLength(); i++) {
+ content.add(xmlContent.item(i));
+ }
+ return content;
+ }
+
+ private byte[] getBase64Content(Node node) {
+ String content = node.getTextContent();
+ if (content != null) {
+ try {
+ byte[] bytes = content.getBytes("ASCII");
+ Base64InputStream bis = new Base64InputStream(new ByteArrayInputStream(bytes));
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ StreamUtil.copyStream(bis, bos);
+ return bos.toByteArray();
+ } catch (UnsupportedEncodingException e) {
+ throw new SLRuntimeException(e);
+ } catch (IOException e) {
+ throw new SLRuntimeException(e);
+ }
+ } else {
+ return new byte[] {};
+ }
+ }
+
+ private Object getBinaryFileDataContent(Node node) {
+ NodeList childNodes = node.getChildNodes();
+ for (int i = 0; i < childNodes.getLength(); i++) {
+ Node n = childNodes.item(i);
+ if (n.getNodeType() == Node.ELEMENT_NODE && SLCommand.NAMESPACE_URI.equals(n.getNamespaceURI())) {
+ if ("XMLContent".equals(n.getLocalName())) {
+ return getXMLContent(n);
+ } else if ("Base64Content".equals(n.getLocalName())) {
+ return getBase64Content(n);
+ }
+ }
+ }
+ return Collections.EMPTY_LIST;
+ }
+
+ @Override
+ public Object getContent() {
+
+ NodeList childNodes = resultElement.getChildNodes();
+ for (int i = 0; i < childNodes.getLength(); i++) {
+ Node node = childNodes.item(i);
+ if (node.getNodeType() == Node.ELEMENT_NODE
+ && SLCommand.NAMESPACE_URI.equals(node.getNamespaceURI())
+ && "BinaryFileData".equals(node.getLocalName())) {
+ return getBinaryFileDataContent(node);
+ }
+ }
+ return Collections.EMPTY_LIST;
+
+ }
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DomSLResult.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DomSLResult.java
new file mode 100644
index 00000000..ad81b388
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DomSLResult.java
@@ -0,0 +1,41 @@
+/*
+* Copyright 2009 Federal Chancellery Austria and
+* Graz University of Technology
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package at.gv.egiz.bku.slcommands.impl;
+
+import javax.xml.transform.Result;
+import javax.xml.transform.Templates;
+
+import org.w3c.dom.Element;
+
+
+public abstract class DomSLResult extends SLResultImpl {
+
+ protected Element resultElement;
+
+ public DomSLResult(Element resultElement) {
+ this.resultElement= resultElement;
+ }
+
+ @Override
+ public void writeTo(Result result, Templates templates, boolean fragment) {
+ writeTo(resultElement.getOwnerDocument(), result, templates, fragment);
+ }
+
+
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/ErrorResultImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/ErrorResultImpl.java
index aedde238..4eb01490 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/ErrorResultImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/ErrorResultImpl.java
@@ -63,5 +63,23 @@ public class ErrorResultImpl extends SLResultImpl implements ErrorResult {
writeErrorTo(slException, result, templates, locale, fragment);
}
}
+
+ @Override
+ public int getErrorCode() {
+ if (slException != null) {
+ return slException.getErrorCode();
+ } else {
+ return -1;
+ }
+ }
+
+ @Override
+ public String getInfo() {
+ if (slException != null) {
+ return slException.getLocalizedMessage(locale);
+ } else {
+ return null;
+ }
+ }
} \ No newline at end of file
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/GetStatusCommandFactory.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/GetStatusCommandFactory.java
new file mode 100644
index 00000000..2a29b8da
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/GetStatusCommandFactory.java
@@ -0,0 +1,37 @@
+/*
+* Copyright 2009 Federal Chancellery Austria and
+* Graz University of Technology
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package at.gv.egiz.bku.slcommands.impl;
+
+import javax.xml.bind.JAXBElement;
+
+import at.gv.egiz.bku.slcommands.AbstractSLCommandFactory;
+import at.gv.egiz.bku.slcommands.SLCommand;
+import at.gv.egiz.bku.slexceptions.SLCommandException;
+
+public class GetStatusCommandFactory extends AbstractSLCommandFactory {
+
+ @Override
+ public SLCommand createSLCommand(JAXBElement<?> element) throws SLCommandException {
+
+ GetStatusCommandImpl command = new GetStatusCommandImpl();
+ command.init(element);
+ return command;
+
+ }
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/GetStatusCommandImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/GetStatusCommandImpl.java
index 0c2b96f9..d58141a1 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/GetStatusCommandImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/GetStatusCommandImpl.java
@@ -19,6 +19,7 @@ package at.gv.egiz.bku.slcommands.impl;
import at.buergerkarte.namespaces.securitylayer._1.GetStatusRequestType;
import at.gv.egiz.bku.slcommands.GetStatusCommand;
+import at.gv.egiz.bku.slcommands.SLCommandContext;
import at.gv.egiz.bku.slcommands.SLResult;
import at.gv.egiz.bku.slexceptions.SLCommandException;
import at.gv.egiz.stal.ErrorResponse;
@@ -28,8 +29,8 @@ import at.gv.egiz.stal.StatusRequest;
import at.gv.egiz.stal.StatusResponse;
import java.util.Collections;
import java.util.List;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
*
@@ -37,7 +38,7 @@ import org.apache.commons.logging.LogFactory;
*/
public class GetStatusCommandImpl extends SLCommandImpl<GetStatusRequestType> implements GetStatusCommand {
- protected static Log log = LogFactory.getLog(GetStatusCommandImpl.class);
+ protected final Logger log = LoggerFactory.getLogger(GetStatusCommandImpl.class);
@Override
public String getName() {
@@ -45,16 +46,15 @@ public class GetStatusCommandImpl extends SLCommandImpl<GetStatusRequestType> im
}
@Override
- public SLResult execute() {
+ public SLResult execute(SLCommandContext commandContext) {
//ignore maxDelay and TokenStatus
-// GetStatusRequestType req = getRequestValue();
- log.debug("execute GetStatusRequest");
+ log.debug("Execute GetStatusRequest.");
StatusRequest stalRequest = new StatusRequest();
- STAL stal = cmdCtx.getSTAL();
+ STAL stal = commandContext.getSTAL();
List<STALResponse> responses = stal.handleRequest(Collections.singletonList(stalRequest));
@@ -62,16 +62,16 @@ public class GetStatusCommandImpl extends SLCommandImpl<GetStatusRequestType> im
STALResponse stalResponse = responses.get(0);
if (stalResponse instanceof StatusResponse) {
boolean ready = ((StatusResponse) stalResponse).isCardReady();
- log.trace("received status response cardReady: " + ready);
+ log.trace("Received status response cardReady: {}.", ready);
return new GetStatusResultImpl(ready);
} else if (stalResponse instanceof ErrorResponse) {
- log.debug("received error response");
+ log.debug("Received error response.");
SLCommandException ex = new SLCommandException(((ErrorResponse) stalResponse).getErrorCode());
- return new ErrorResultImpl(ex, cmdCtx.getLocale());
+ return new ErrorResultImpl(ex, commandContext.getLocale());
}
}
- log.error("received unexpected responses");
- return new ErrorResultImpl(new SLCommandException(4000), cmdCtx.getLocale());
+ log.error("Received unexpected responses.");
+ return new ErrorResultImpl(new SLCommandException(4000), commandContext.getLocale());
}
}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/IdentityLinkInfoboxFactory.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/IdentityLinkInfoboxFactory.java
new file mode 100644
index 00000000..c19f52ac
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/IdentityLinkInfoboxFactory.java
@@ -0,0 +1,48 @@
+/*
+* Copyright 2009 Federal Chancellery Austria and
+* Graz University of Technology
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package at.gv.egiz.bku.slcommands.impl;
+
+import at.gv.egiz.idlink.IdentityLinkTransformer;
+
+public class IdentityLinkInfoboxFactory extends AbstractInfoboxFactory {
+
+ private IdentityLinkTransformer identityLinkTransformer;
+
+ @Override
+ public Infobox createInfobox() {
+ IdentityLinkInfoboxImpl infoboxImpl = new IdentityLinkInfoboxImpl();
+ infoboxImpl.setIdentityLinkTransformer(identityLinkTransformer);
+ return infoboxImpl;
+ }
+
+ /**
+ * @return the identityLinkTransformer
+ */
+ public IdentityLinkTransformer getIdentityLinkTransformer() {
+ return identityLinkTransformer;
+ }
+
+ /**
+ * @param identityLinkTransformer the identityLinkTransformer to set
+ */
+ public void setIdentityLinkTransformer(
+ IdentityLinkTransformer identityLinkTransformer) {
+ this.identityLinkTransformer = identityLinkTransformer;
+ }
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/IdentityLinkInfoboxImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/IdentityLinkInfoboxImpl.java
index 160e9589..ec873e20 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/IdentityLinkInfoboxImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/IdentityLinkInfoboxImpl.java
@@ -37,8 +37,8 @@ import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
@@ -68,13 +68,30 @@ public class IdentityLinkInfoboxImpl extends AbstractBinaryFileInfobox {
/**
* Logging facility.
*/
- private static Log log = LogFactory.getLog(IdentityLinkInfoboxImpl.class);
+ private final Logger log = LoggerFactory.getLogger(IdentityLinkInfoboxImpl.class);
/**
* The box specific parameter <code>IdentityLinkDomainIdentifier</code>.
*/
public static final String BOX_SPECIFIC_PARAMETER_IDENTITY_LINK_DOMAIN_IDENTIFIER = "IdentityLinkDomainIdentifier";
+ private IdentityLinkTransformer identityLinkTransformer;
+
+ /**
+ * @return the identityLinkTransformer
+ */
+ public IdentityLinkTransformer getIdentityLinkTransformer() {
+ return identityLinkTransformer;
+ }
+
+ /**
+ * @param identityLinkTransformer the identityLinkTransformer to set
+ */
+ public void setIdentityLinkTransformer(
+ IdentityLinkTransformer identityLinkTransformer) {
+ this.identityLinkTransformer = identityLinkTransformer;
+ }
+
/**
* The value of the box specific parameter <code>IdentityLinkDomainIdentifier</code>.
*/
@@ -147,7 +164,6 @@ public class IdentityLinkInfoboxImpl extends AbstractBinaryFileInfobox {
JAXBElement<CompressedIdentityLinkType> compressedIdentityLink = idLinkFactory
.createCompressedIdentityLink(identityLink, certificates, getDomainIdentifier());
- IdentityLinkTransformer identityLinkTransformer = IdentityLinkTransformer.getInstance();
String issuerTemplate = identityLink.getIssuerTemplate();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
@@ -262,12 +278,12 @@ public class IdentityLinkInfoboxImpl extends AbstractBinaryFileInfobox {
Transformer transformer = transformerFactory.newTransformer();
transformer.transform(xmlSource, new StreamResult(resultBytes));
} catch (TransformerConfigurationException e) {
- log.error(e);
+ log.error("Failed to transform identity link.", e);
throw new SLCommandException(4000,
SLExceptionMessages.EC4000_UNCLASSIFIED_IDLINK_TRANSFORMATION_FAILED,
new Object[] { issuerTemplate });
} catch (TransformerException e) {
- log.error(e);
+ log.error("Failed to transform identity link.", e);
throw new SLCommandException(4000,
SLExceptionMessages.EC4000_UNCLASSIFIED_IDLINK_TRANSFORMATION_FAILED,
new Object[] { issuerTemplate });
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxFactory.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxFactory.java
index e9736f6d..5ba06ac4 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxFactory.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxFactory.java
@@ -17,10 +17,9 @@
package at.gv.egiz.bku.slcommands.impl;
import java.util.HashMap;
-import java.util.Map;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import at.gv.egiz.bku.slexceptions.SLCommandException;
import at.gv.egiz.bku.slexceptions.SLExceptionMessages;
@@ -36,71 +35,27 @@ public class InfoboxFactory {
/**
* Logging facility.
*/
- private static Log log = LogFactory.getLog(InfoboxFactory.class);
+ private final Logger log = LoggerFactory.getLogger(InfoboxFactory.class);
/**
- * The singleton instance of this InfoboxFactory.
+ * The mapping of Infobox name to concrete Infobox factory.
*/
- private static InfoboxFactory instance;
-
- /**
- * @return an instance of this InfoboxFactory
- */
- public synchronized static InfoboxFactory getInstance() {
- if (instance == null) {
- instance = new InfoboxFactory();
- }
- return instance;
- }
-
- /**
- * The mapping of infobox identifier to implementation class.
- */
- private HashMap<String, Class<? extends Infobox>> implementations;
-
- /**
- * Private constructor.
- */
- private InfoboxFactory() {
- }
-
- /**
- * Sets the mapping of infobox identifier to implementation class name.
- *
- * @param infoboxImplMap
- * a mapping of infobox identifiers to implementation class names
- *
- * @throws ClassNotFoundException
- * if implementation class is not an instance of {@link Infobox}
- */
- @SuppressWarnings("unchecked")
- public void setInfoboxImpl(Map<String, String> infoboxImplMap) throws ClassNotFoundException {
- HashMap<String, Class<? extends Infobox>> implMap = new HashMap<String, Class<? extends Infobox>>();
- ClassLoader cl = getClass().getClassLoader();
- for (String key : infoboxImplMap.keySet()) {
- Class<? extends Infobox> impl = (Class<? extends Infobox>) cl.loadClass(infoboxImplMap.get(key));
- log.debug("Registering infobox '" + key + "' implementation '" + impl.getCanonicalName() + "'.");
- implMap.put(key, impl);
- }
- implementations = implMap;
- }
-
+ private HashMap<String, AbstractInfoboxFactory> infoboxFactories = new HashMap<String, AbstractInfoboxFactory>();
+
/**
- * Returns the configured implementation class for the given
- * <code>infoboxIdentifier</code>.
- *
- * @param infoboxIdentifier
- * the infobox identifier
- *
- * @return the implementation class for the given infobox identifier or
- * <code>null</code> if there is no implementation class configured
+ * @param infoboxFactories the infoboxFactories to set
*/
- public Class<? extends Infobox> getImplClass(String infoboxIdentifier) {
- if (implementations != null) {
- return implementations.get(infoboxIdentifier);
- } else {
- return null;
+ public void setInfoboxFactories(
+ HashMap<String, AbstractInfoboxFactory> factories) {
+ if (log.isDebugEnabled()) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Registered infobox factories for");
+ for (String name : factories.keySet()) {
+ sb.append("\n " + name + " : " + factories.get(name).getClass());
+ }
+ log.debug(sb.toString());
}
+ this.infoboxFactories = factories;
}
/**
@@ -119,31 +74,15 @@ public class InfoboxFactory {
*/
public Infobox createInfobox(String infoboxIdentifier) throws SLCommandException, SLRuntimeException {
- Class<? extends Infobox> implClass = getImplClass(infoboxIdentifier);
- if (implClass == null) {
- // infobox not supported
- log.info("Unsupported infobox '" + infoboxIdentifier + ".");
+ AbstractInfoboxFactory factory = infoboxFactories.get(infoboxIdentifier);
+ if (factory == null) {
+ log.info("Unsupported infobox '{}'.", infoboxIdentifier);
throw new SLCommandException(4002,
SLExceptionMessages.EC4002_INFOBOX_UNKNOWN,
new Object[] { infoboxIdentifier });
}
- // try to instantiate
- Infobox infobox;
- try {
- infobox = implClass.newInstance();
- log.debug("Infobox '" + infobox.getIdentifier() + "' created.");
- } catch (InstantiationException e) {
- // unexpected error
- log.error("Failed to instantiate infobox implementation.", e);
- throw new SLRuntimeException(e);
- } catch (IllegalAccessException e) {
- // unexpected error
- log.error("Failed to instantiate infobox implementation.", e);
- throw new SLRuntimeException(e);
- }
-
- return infobox;
+ return factory.createInfobox();
}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadCommandFactory.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadCommandFactory.java
new file mode 100644
index 00000000..a9ba28e4
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadCommandFactory.java
@@ -0,0 +1,37 @@
+/*
+* Copyright 2009 Federal Chancellery Austria and
+* Graz University of Technology
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package at.gv.egiz.bku.slcommands.impl;
+
+import javax.xml.bind.JAXBElement;
+
+import at.gv.egiz.bku.slcommands.SLCommand;
+import at.gv.egiz.bku.slexceptions.SLCommandException;
+
+public class InfoboxReadCommandFactory extends AbstractInfoboxCommandFactory {
+
+ @Override
+ public SLCommand createSLCommand(JAXBElement<?> element) throws SLCommandException {
+
+ InfoboxReadCommandImpl command = new InfoboxReadCommandImpl();
+ command.setInfoboxFactory(infoboxFactory);
+ command.init(element);
+ return command;
+
+ }
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadCommandImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadCommandImpl.java
index 693f444f..736e7cbb 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadCommandImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadCommandImpl.java
@@ -14,50 +14,50 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package at.gv.egiz.bku.slcommands.impl;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+package at.gv.egiz.bku.slcommands.impl;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import at.buergerkarte.namespaces.securitylayer._1.InfoboxReadRequestType;
import at.gv.egiz.bku.slcommands.InfoboxReadCommand;
import at.gv.egiz.bku.slcommands.SLCommandContext;
import at.gv.egiz.bku.slcommands.SLResult;
import at.gv.egiz.bku.slexceptions.SLCommandException;
-
-/**
- * This class implements the security layer command
- * <code>InfoboxReadRequest</code>.
- * <p>
- * <b>NOTE:</b> Currently the only supported infobox identifier is '
- * <code>IdentityLink</code>'.
- * </p>
- *
- * @author mcentner
- */
-public class InfoboxReadCommandImpl extends AbstractInfoboxCommandImpl<InfoboxReadRequestType> implements
- InfoboxReadCommand {
-
- /**
- * Logging facility.
- */
- protected static Log log = LogFactory.getLog(InfoboxReadCommandImpl.class);
+
+/**
+ * This class implements the security layer command
+ * <code>InfoboxReadRequest</code>.
+ * <p>
+ * <b>NOTE:</b> Currently the only supported infobox identifier is '
+ * <code>IdentityLink</code>'.
+ * </p>
+ *
+ * @author mcentner
+ */
+public class InfoboxReadCommandImpl extends AbstractInfoboxCommandImpl<InfoboxReadRequestType> implements
+ InfoboxReadCommand {
+
+ /**
+ * Logging facility.
+ */
+ protected final Logger log = LoggerFactory.getLogger(InfoboxReadCommandImpl.class);
- @Override
- public String getName() {
- return "InfoboxReadRequest";
- }
-
+ @Override
+ public String getName() {
+ return "InfoboxReadRequest";
+ }
+
@Override
protected String getInfoboxIdentifier(InfoboxReadRequestType request) {
return request.getInfoboxIdentifier();
}
- @Override
- public void init(SLCommandContext ctx, Object request) throws SLCommandException {
- super.init(ctx, request);
-
- InfoboxReadRequestType req = getRequestValue();
+ @Override
+ public void init(Object request) throws SLCommandException {
+ super.init(request);
+
+ InfoboxReadRequestType req = getRequestValue();
if (req.getAssocArrayParameters() != null &&
!(infobox instanceof AssocArrayInfobox)) {
@@ -70,20 +70,20 @@ public class InfoboxReadCommandImpl extends AbstractInfoboxCommandImpl<InfoboxRe
log.info("Got BinaryFileParameters but Infobox type is not BinaryFile.");
throw new SLCommandException(4010);
}
-
- }
-
- @Override
- public SLResult execute() {
+
+ }
+
+ @Override
+ public SLResult execute(SLCommandContext commandContext) {
try {
- return infobox.read(getRequestValue(), getCmdCtx());
+ return infobox.read(getRequestValue(), commandContext);
} catch (SLCommandException e) {
- return new ErrorResultImpl(e, getCmdCtx().getLocale());
+ return new ErrorResultImpl(e, commandContext.getLocale());
}
- }
-
+ }
+
@Override
public String getIdentityLinkDomainId() {
if (infobox instanceof IdentityLinkInfoboxImpl) {
@@ -93,4 +93,4 @@ public class InfoboxReadCommandImpl extends AbstractInfoboxCommandImpl<InfoboxRe
}
}
-}
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadResultFileImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadResultFileImpl.java
index 422b424f..ddbbcadc 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadResultFileImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadResultFileImpl.java
@@ -16,6 +16,9 @@
*/
package at.gv.egiz.bku.slcommands.impl;
+import java.util.ArrayList;
+import java.util.Collections;
+
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
@@ -25,8 +28,8 @@ import javax.xml.transform.Result;
import javax.xml.transform.Templates;
import javax.xml.transform.dom.DOMResult;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -51,12 +54,17 @@ public class InfoboxReadResultFileImpl extends SLResultImpl implements
/**
* Logging facility.
*/
- protected static Log log = LogFactory.getLog(InfoboxReadResultFileImpl.class);
+ protected final Logger log = LoggerFactory.getLogger(InfoboxReadResultFileImpl.class);
/**
* The XML document containing the infobox content.
*/
protected Document xmlDocument;
+
+ /**
+ * Binary content of the infobox (may be <code>null</code>).
+ */
+ protected byte[] binaryContent;
/**
* Creates the response document from the given <code>binaryContent</code>.
@@ -147,14 +155,34 @@ public class InfoboxReadResultFileImpl extends SLResultImpl implements
* @param resultBytes
*/
public void setResultBytes(byte[] resultBytes) {
-
- xmlDocument = createResponseDocument(resultBytes, false);
-
+ this.binaryContent = resultBytes;
}
@Override
public void writeTo(Result result, Templates templates, boolean fragment) {
+ if (xmlDocument == null) {
+ xmlDocument = createResponseDocument(binaryContent, false);
+ }
writeTo(xmlDocument, result, templates, fragment);
}
+ @Override
+ public Object getContent() {
+ if (xmlDocument != null) {
+ NodeList nodes = xmlDocument.getElementsByTagNameNS(SLCommand.NAMESPACE_URI, "XMLContent");
+ if (nodes.getLength() > 0) {
+ NodeList children = nodes.item(0).getChildNodes();
+ ArrayList<Node> content = new ArrayList<Node>();
+ for (int i = 0; i < children.getLength(); i++) {
+ content.add(children.item(i));
+ }
+ return Collections.unmodifiableList(content);
+ } else {
+ return null;
+ }
+ } else {
+ return binaryContent;
+ }
+ }
+
}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadResultImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadResultImpl.java
index 271ec955..3be6c8f8 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadResultImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadResultImpl.java
@@ -61,4 +61,22 @@ public class InfoboxReadResultImpl extends SLResultImpl implements InfoboxReadRe
writeTo(response, result, templates, fragment);
}
+ @Override
+ public Object getContent() {
+ if (infoboxReadResponse != null) {
+ if (infoboxReadResponse.getAssocArrayData() != null) {
+ return infoboxReadResponse.getAssocArrayData();
+ } else {
+ Base64XMLContentType binaryFileData = infoboxReadResponse.getBinaryFileData();
+ if (binaryFileData.getBase64Content() != null) {
+ return binaryFileData.getBase64Content();
+ } else {
+ return binaryFileData.getXMLContent().getContent();
+ }
+ }
+ } else {
+ return null;
+ }
+ }
+
}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxUpdateCommandFactory.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxUpdateCommandFactory.java
new file mode 100644
index 00000000..0d421b2f
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxUpdateCommandFactory.java
@@ -0,0 +1,37 @@
+/*
+* Copyright 2009 Federal Chancellery Austria and
+* Graz University of Technology
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package at.gv.egiz.bku.slcommands.impl;
+
+import javax.xml.bind.JAXBElement;
+
+import at.gv.egiz.bku.slcommands.SLCommand;
+import at.gv.egiz.bku.slexceptions.SLCommandException;
+
+public class InfoboxUpdateCommandFactory extends AbstractInfoboxCommandFactory {
+
+ @Override
+ public SLCommand createSLCommand(JAXBElement<?> element) throws SLCommandException {
+
+ InfoboxUpdateCommandImpl command = new InfoboxUpdateCommandImpl();
+ command.setInfoboxFactory(infoboxFactory);
+ command.init(element);
+ return command;
+
+ }
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxUpdateCommandImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxUpdateCommandImpl.java
index 1cdeda94..100be13b 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxUpdateCommandImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxUpdateCommandImpl.java
@@ -16,8 +16,8 @@
*/
package at.gv.egiz.bku.slcommands.impl;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import at.buergerkarte.namespaces.securitylayer._1.InfoboxUpdateRequestType;
import at.gv.egiz.bku.slcommands.InfoboxUpdateCommand;
@@ -28,7 +28,7 @@ import at.gv.egiz.bku.slexceptions.SLCommandException;
public class InfoboxUpdateCommandImpl extends
AbstractInfoboxCommandImpl<InfoboxUpdateRequestType> implements InfoboxUpdateCommand {
- private static Log log = LogFactory.getLog(InfoboxUpdateCommandImpl.class);
+ private final Logger log = LoggerFactory.getLogger(InfoboxUpdateCommandImpl.class);
@Override
public String getName() {
@@ -41,8 +41,8 @@ public class InfoboxUpdateCommandImpl extends
}
@Override
- public void init(SLCommandContext ctx, Object request) throws SLCommandException {
- super.init(ctx, request);
+ public void init(Object request) throws SLCommandException {
+ super.init(request);
InfoboxUpdateRequestType req = getRequestValue();
@@ -61,12 +61,12 @@ public class InfoboxUpdateCommandImpl extends
}
@Override
- public SLResult execute() {
+ public SLResult execute(SLCommandContext commandContext) {
try {
- return infobox.update(getRequestValue(), getCmdCtx());
+ return infobox.update(getRequestValue(), commandContext);
} catch (SLCommandException e) {
- return new ErrorResultImpl(e, getCmdCtx().getLocale());
+ return new ErrorResultImpl(e, commandContext.getLocale());
}
}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/NullOperationCommandFactory.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/NullOperationCommandFactory.java
new file mode 100644
index 00000000..4b5ba381
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/NullOperationCommandFactory.java
@@ -0,0 +1,37 @@
+/*
+* Copyright 2009 Federal Chancellery Austria and
+* Graz University of Technology
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package at.gv.egiz.bku.slcommands.impl;
+
+import javax.xml.bind.JAXBElement;
+
+import at.gv.egiz.bku.slcommands.AbstractSLCommandFactory;
+import at.gv.egiz.bku.slcommands.SLCommand;
+import at.gv.egiz.bku.slexceptions.SLCommandException;
+
+public class NullOperationCommandFactory extends AbstractSLCommandFactory {
+
+ @Override
+ public SLCommand createSLCommand(JAXBElement<?> element) throws SLCommandException {
+
+ NullOperationCommandImpl command = new NullOperationCommandImpl();
+ command.init(element);
+ return command;
+
+ }
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/NullOperationCommandImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/NullOperationCommandImpl.java
index 1b6fb237..4d326157 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/NullOperationCommandImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/NullOperationCommandImpl.java
@@ -19,6 +19,7 @@ package at.gv.egiz.bku.slcommands.impl;
import at.buergerkarte.namespaces.securitylayer._1.NullOperationRequestType;
import at.gv.egiz.bku.slcommands.NullOperationCommand;
import at.gv.egiz.bku.slcommands.NullOperationResult;
+import at.gv.egiz.bku.slcommands.SLCommandContext;
import at.gv.egiz.bku.slcommands.SLResult;
/**
@@ -31,7 +32,7 @@ public class NullOperationCommandImpl extends SLCommandImpl<NullOperationRequest
protected static NullOperationResult RESULT = new NullOperationResultImpl();
@Override
- public SLResult execute() {
+ public SLResult execute(SLCommandContext commandContext) {
return RESULT;
}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SLCommandImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SLCommandImpl.java
index ed055b69..41783c34 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SLCommandImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SLCommandImpl.java
@@ -19,7 +19,6 @@ package at.gv.egiz.bku.slcommands.impl;
import javax.xml.bind.JAXBElement;
import at.gv.egiz.bku.slcommands.SLCommand;
-import at.gv.egiz.bku.slcommands.SLCommandContext;
import at.gv.egiz.bku.slexceptions.SLCommandException;
/**
@@ -34,30 +33,15 @@ import at.gv.egiz.bku.slexceptions.SLCommandException;
public abstract class SLCommandImpl<T> implements SLCommand {
/**
- * The <code>SLCommandContext</code> for this <code>SLCommand</code>.
- */
- protected SLCommandContext cmdCtx;
-
- /**
- * The STAL helper.
- */
- protected STALHelper stalHelper;
-
- /**
* The request element of this command.
*/
protected JAXBElement<T> request;
@SuppressWarnings("unchecked")
@Override
- public void init(SLCommandContext ctx, Object request)
+ public void init(Object request)
throws SLCommandException {
-
this.request = (JAXBElement<T>) request;
-
- this.cmdCtx = ctx;
- stalHelper = new STALHelper(cmdCtx.getSTAL());
-
}
/**
@@ -70,12 +54,13 @@ public abstract class SLCommandImpl<T> implements SLCommand {
*/
protected T getRequestValue() {
return request.getValue();
- }
+ }
+
+ /**
+ * @return the request
+ */
+ public JAXBElement<T> getRequest() {
+ return request;
+ }
- /**
- * @return the corresponding <code>SLCommandContext</code>
- */
- protected SLCommandContext getCmdCtx() {
- return cmdCtx;
- }
}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SLResultImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SLResultImpl.java
index 0077b7b2..1a2dcb52 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SLResultImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SLResultImpl.java
@@ -37,8 +37,8 @@ import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.w3c.dom.Node;
import at.buergerkarte.namespaces.securitylayer._1.ErrorResponseType;
@@ -64,7 +64,7 @@ public abstract class SLResultImpl implements SLResult {
/**
* Logging facility.
*/
- private static Log log = LogFactory.getLog(SLResult.class);
+ private final Logger log = LoggerFactory.getLogger(SLResult.class);
/**
* The security layer result type (default = XML).
@@ -158,21 +158,21 @@ public abstract class SLResultImpl implements SLResult {
marshaller.marshal(response, result);
}
} catch (JAXBException e) {
- log.info("Failed to marshall " + response.getName() + " result." , e);
+ log.info("Failed to marshall {} result.", response.getName(), e);
SLCommandException commandException = new SLCommandException(4000);
writeErrorTo(commandException, result, templates, fragment);
}
if (ds != null) {
try {
- log.trace("Marshalled result:\n" + new String(ds.getBufferedBytes(), "UTF-8"));
+ log.trace("Marshalled result:\n{}", new String(ds.getBufferedBytes(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
log.trace(e.getMessage());
}
}
if (dw != null) {
- log.trace("Marshalled result:\n" + dw.getBufferedString());
+ log.trace("Marshalled result:\n{}", dw.getBufferedString());
}
}
@@ -226,14 +226,14 @@ public abstract class SLResultImpl implements SLResult {
if (ds != null) {
try {
- log.trace("Marshalled result:\n" + new String(ds.getBufferedBytes(), "UTF-8"));
+ log.trace("Marshalled result:\n{}", new String(ds.getBufferedBytes(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
log.trace(e.getMessage());
}
}
if (dw != null) {
- log.trace("Marshalled result:\n" + dw.getBufferedString());
+ log.trace("Marshalled result:\n{}", dw.getBufferedString());
}
}
@@ -288,7 +288,7 @@ public abstract class SLResultImpl implements SLResult {
marshaller.marshal(response, result);
}
} catch (JAXBException e) {
- log.fatal("Failed to marshall error result." , e);
+ log.error("Failed to marshall error result." , e);
throw new SLRuntimeException("Failed to marshall error result.");
}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/STALHelper.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/STALHelper.java
index e903c608..fd20acb4 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/STALHelper.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/STALHelper.java
@@ -22,11 +22,8 @@ import iaik.utils.Base64OutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
-import java.io.StringWriter;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
@@ -35,8 +32,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import at.gv.egiz.bku.slexceptions.SLCommandException;
import at.gv.egiz.bku.slexceptions.SLExceptionMessages;
@@ -59,7 +56,7 @@ public class STALHelper {
/**
* Logging facility.
*/
- private static Log log = LogFactory.getLog(STALHelper.class);
+ private final Logger log = LoggerFactory.getLogger(STALHelper.class);
/**
* The STAL implementation.
@@ -95,11 +92,11 @@ public class STALHelper {
public void transmitSTALRequest(List<? extends STALRequest> stalRequests) throws SLCommandException {
List<STALResponse> responses = stal.handleRequest(stalRequests);
if (responses == null) {
- Log log = LogFactory.getLog(this.getClass());
+ Logger log = LoggerFactory.getLogger(this.getClass());
log.info("Received no responses from STAL.");
throw new SLCommandException(4000);
} else if (responses.size() != stalRequests.size()) {
- Log log = LogFactory.getLog(this.getClass());
+ Logger log = LoggerFactory.getLogger(this.getClass());
log.info("Received invalid count of responses from STAL. Expected "
+ stalRequests.size() + ", but got " + responses.size() + ".");
// throw new SLCommandException(4000);
@@ -144,7 +141,7 @@ public class STALHelper {
}
if (!(responseClass.isAssignableFrom(response.getClass()))) {
- Log log = LogFactory.getLog(this.getClass());
+ Logger log = LoggerFactory.getLogger(this.getClass());
log.info("Received " + response.getClass() + " from STAL but expected "
+ responseClass);
throw new SLCommandException(4000);
@@ -195,7 +192,7 @@ public class STALHelper {
} catch (IOException e1) {
log.info("Failed to decode certificate.", e);
}
- log.debug("Failed to decode certificate.\n" + certDump.toString(), e);
+ log.debug("Failed to decode certificate.\n{}", certDump.toString(), e);
} else {
log.info("Failed to decode certificate.", e);
}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SVPersonendatenInfoboxFactory.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SVPersonendatenInfoboxFactory.java
new file mode 100644
index 00000000..ea892ea9
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SVPersonendatenInfoboxFactory.java
@@ -0,0 +1,27 @@
+/*
+* Copyright 2009 Federal Chancellery Austria and
+* Graz University of Technology
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package at.gv.egiz.bku.slcommands.impl;
+
+public class SVPersonendatenInfoboxFactory extends AbstractInfoboxFactory {
+
+ @Override
+ public Infobox createInfobox() {
+ return new SVPersonendatenInfoboxImpl();
+ }
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SVPersonendatenInfoboxImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SVPersonendatenInfoboxImpl.java
index 7e204632..4a94b627 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SVPersonendatenInfoboxImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SVPersonendatenInfoboxImpl.java
@@ -44,8 +44,8 @@ import java.util.TimeZone;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import at.buergerkarte.namespaces.cardchannel.AttributeList;
import at.buergerkarte.namespaces.cardchannel.AttributeType;
@@ -68,7 +68,7 @@ public class SVPersonendatenInfoboxImpl extends AbstractAssocArrayInfobox {
/**
* Logging facility.
*/
- private static Log log = LogFactory.getLog(SVPersonendatenInfoboxImpl.class);
+ private final Logger log = LoggerFactory.getLogger(SVPersonendatenInfoboxImpl.class);
public static final String EHIC = "EHIC";
@@ -145,7 +145,7 @@ public class SVPersonendatenInfoboxImpl extends AbstractAssocArrayInfobox {
}
} catch (CodingException e) {
- log.info("Failed to decode '" + getIdentifier() + "' infobox.", e);
+ log.info("Failed to decode '{}' infobox.", getIdentifier(), e);
throw new SLCommandException(4000,
SLExceptionMessages.EC4000_UNCLASSIFIED_INFOBOX_INVALID,
new Object[] { "IdentityLink" });
@@ -256,6 +256,8 @@ public class SVPersonendatenInfoboxImpl extends AbstractAssocArrayInfobox {
private static void setAttributeValue(AttributeType attributeType, ASN1Object value) {
+ Logger log = LoggerFactory.getLogger(SVPersonendatenInfoboxImpl.class);
+
if (value.isA(ASN.OCTET_STRING)) {
try {
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/AlgorithmMethodFactoryImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/AlgorithmMethodFactoryImpl.java
index 8391e450..f1219a6c 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/AlgorithmMethodFactoryImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/AlgorithmMethodFactoryImpl.java
@@ -165,8 +165,7 @@ public class AlgorithmMethodFactoryImpl implements AlgorithmMethodFactory {
public SignatureMethod createSignatureMethod(SignatureContext signatureContext)
throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
- return signatureContext.getSignatureFactory().newSignatureMethod(
- signatureAlgorithmURI, signatureMethodParameterSpec);
+ return new STALSignatureMethod(signatureAlgorithmURI, signatureMethodParameterSpec);
}
}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/DataObject.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/DataObject.java
index 2cae41d6..a3f913de 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/DataObject.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/DataObject.java
@@ -20,11 +20,13 @@ import iaik.xml.crypto.dom.DOMCryptoContext;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.SequenceInputStream;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
+import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.security.InvalidAlgorithmParameterException;
@@ -36,6 +38,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
import javax.xml.crypto.MarshalException;
import javax.xml.crypto.dom.DOMStructure;
import javax.xml.crypto.dsig.CanonicalizationMethod;
@@ -46,15 +51,17 @@ import javax.xml.crypto.dsig.XMLObject;
import javax.xml.crypto.dsig.spec.TransformParameterSpec;
import javax.xml.crypto.dsig.spec.XPathFilter2ParameterSpec;
import javax.xml.crypto.dsig.spec.XPathType;
+import javax.xml.namespace.QName;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.w3c.dom.DOMConfiguration;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.ls.DOMImplementationLS;
@@ -70,6 +77,7 @@ import at.buergerkarte.namespaces.securitylayer._1.MetaInfoType;
import at.buergerkarte.namespaces.securitylayer._1.TransformsInfoType;
import at.gv.egiz.bku.binding.HttpUtil;
import at.gv.egiz.bku.gui.viewer.MimeTypes;
+import at.gv.egiz.bku.slcommands.SLMarshallerFactory;
import at.gv.egiz.bku.slexceptions.SLCommandException;
import at.gv.egiz.bku.slexceptions.SLRequestException;
import at.gv.egiz.bku.slexceptions.SLRuntimeException;
@@ -81,10 +89,6 @@ import at.gv.egiz.bku.viewer.Validator;
import at.gv.egiz.bku.viewer.ValidatorFactory;
import at.gv.egiz.dom.DOMUtils;
import at.gv.egiz.slbinding.impl.XMLContentType;
-import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URL;
/**
* This class represents a <code>DataObject</code> of an XML-Signature
@@ -97,7 +101,7 @@ public class DataObject {
/**
* Logging facility.
*/
- private static Log log = LogFactory.getLog(DataObject.class);
+ private final Logger log = LoggerFactory.getLogger(DataObject.class);
/**
* DOM Implementation.
@@ -205,7 +209,7 @@ public class DataObject {
domImplLS = (DOMImplementationLS) registry.getDOMImplementation(DOM_LS_3_0);
if (domImplLS == null) {
- log.error("Failed to get DOMImplementation " + DOM_LS_3_0);
+ log.error("Failed to get DOMImplementation {}.", DOM_LS_3_0);
throw new SLRuntimeException("Failed to get DOMImplementation " + DOM_LS_3_0);
}
@@ -276,7 +280,7 @@ public class DataObject {
try {
validator = ValidatorFactory.newValidator(mediaType);
} catch (IllegalArgumentException e) {
- log.error("No validator found for mime type '" + mediaType + "'.");
+ log.error("No validator found for mime type '{}'.", mediaType, e);
throw new SLViewerException(5000);
}
@@ -299,7 +303,7 @@ public class DataObject {
}
} else {
- log.debug("MIME media type '" + mediaType + "' is not a s/valid/SUPPORTED digest input, omitting validation.");
+ log.debug("MIME media type '{}' is not a s/valid/SUPPORTED digest input, omitting validation.", mediaType);
}
}
@@ -359,12 +363,12 @@ public class DataObject {
if (reference != null) {
if (reference.getURI() != null && !"".equals(reference.getURI())) {
try {
- log.info("deriving filename from reference URI " + reference.getURI());
+ log.info("Deriving filename from reference URI {}.", reference.getURI());
URI refURI = new URI(reference.getURI());
if (refURI.isOpaque()) {
// could check scheme component, but also allow other schemes (e.g. testlocal)
- log.trace("opaque reference URI, use scheme-specific part as filename");
+ log.trace("Opaque reference URI, use scheme-specific part as filename.");
filename = refURI.getSchemeSpecificPart();
if (!hasExtension(filename)) {
filename += MimeTypes.getExtension(mimeType);
@@ -376,34 +380,34 @@ public class DataObject {
} else if ("".equals(refURI.getPath()) &&
refURI.getFragment() != null &&
refURI.getFragment().indexOf('(') < 0) { // exclude (schemebased) xpointer expressions
- log.trace("fragment (shorthand xpointer) URI, use fragment as filename");
+ log.trace("Fragment (shorthand xpointer) URI, use fragment as filename.");
filename = refURI.getFragment();
if(!hasExtension(filename)) {
filename += MimeTypes.getExtension(mimeType);
}
} else if (!"".equals(refURI.getPath())) {
- log.trace("hierarchical URI with path component, use path as filename");
+ log.trace("Hierarchical URI with path component, use path as filename.");
File refFile = new File(refURI.getPath());
filename = refFile.getName();
if(!hasExtension(filename)) {
filename += MimeTypes.getExtension(mimeType);
}
} else {
- log.debug("failed to derive filename from URI '" + refURI + "', derive filename from reference ID");
+ log.debug("Failed to derive filename from URI '{}', derive filename from reference ID.", refURI);
filename = reference.getId() + MimeTypes.getExtension(mimeType);
}
} catch (URISyntaxException ex) {
- log.error("failed to derive filename from invalid URI " + ex.getMessage());
+ log.error("Failed to derive filename from invalid URI {}.", ex.getMessage());
filename = reference.getId() + MimeTypes.getExtension(mimeType);
}
} else {
- log.debug("same-document URI, derive filename from reference ID");
+ log.debug("Same-document URI, derive filename from reference ID.");
filename = reference.getId() + MimeTypes.getExtension(mimeType);
}
} else {
- log.error("failed to derive filename, no reference created");
+ log.error("Failed to derive filename, no reference created.");
}
- log.debug("derived filename for reference " + reference.getId() + ": " + filename);
+ log.debug("Derived filename for reference {}: {}.", reference.getId(), filename);
return filename;
}
@@ -413,30 +417,12 @@ public class DataObject {
}
private byte[] getTransformsBytes(at.gv.egiz.slbinding.impl.TransformsInfoType ti) {
- return ti.getRedirectedStream().toByteArray();
-// byte[] transformsBytes = ti.getRedirectedStream().toByteArray();
-//
-// if (transformsBytes == null || transformsBytes.length == 0) {
-// return null;
-// }
-//
-// String dsigPrefix = ti.getNamespaceContext().getNamespaceURI("http://www.w3.org/2000/09/xmldsig#");
-// byte[] pre, post;
-// if (dsigPrefix == null) {
-// log.trace("XMLDSig not declared in outside dsig:Transforms");
-// pre = "<AssureDSigNS>".getBytes();
-// post = "</AssureDSigNS>".getBytes();
-// } else {
-// log.trace("XMLDSig bound to prefix " + dsigPrefix);
-// pre = ("<AssureDSigNS xmlns:" + dsigPrefix + "=\"http://www.w3.org/2000/09/xmldsig#\">").getBytes();
-// post = "</AssureDSigNS>".getBytes();
-// }
-//
-// byte[] workaround = new byte[pre.length + transformsBytes.length + post.length];
-// System.arraycopy(pre, 0, workaround, 0, pre.length);
-// System.arraycopy(transformsBytes, 0, workaround, pre.length, transformsBytes.length);
-// System.arraycopy(post, 0, workaround, pre.length + transformsBytes.length, post.length);
-// return workaround;
+ ByteArrayOutputStream redirectedStream = ti.getRedirectedStream();
+ if (redirectedStream != null) {
+ return redirectedStream.toByteArray();
+ } else {
+ return null;
+ }
}
/**
@@ -487,9 +473,8 @@ public class DataObject {
// create XMLObject
DocumentFragment content = parseDataObject((XMLContentType) dataObject.getXMLContent());
- XMLObject xmlObject = createXMLObject(content);
- setXMLObjectAndReferenceXML(xmlObject, transforms);
+ setXMLObjectAndReferenceXML(createXMLObject(content), transforms);
} else if (dataObject.getLocRefContent() != null) {
@@ -521,7 +506,7 @@ public class DataObject {
// The content of sl:DataObject remains empty
//
- log.debug("Adding DataObject from reference URI '" + reference + "'.");
+ log.debug("Adding DataObject from reference URI '{}'.", reference);
setEnvelopedDataObject(reference, transforms);
@@ -564,13 +549,13 @@ public class DataObject {
}
// dereference URL
- URLDereferencer dereferencer = URLDereferencer.getInstance();
+ URLDereferencer dereferencer = ctx.getUrlDereferencer();
StreamData streamData;
try {
- streamData = dereferencer.dereference(reference, ctx.getDereferencerContext());
+ streamData = dereferencer.dereference(reference);
} catch (IOException e) {
- log.info("Failed to dereference XMLObject from '" + reference + "'.", e);
+ log.info("Failed to dereference XMLObject from '{}'.", reference, e);
throw new SLCommandException(4110);
}
@@ -587,7 +572,7 @@ public class DataObject {
childNode = doc.getDocumentElement();
if (childNode == null) {
- log.info("Failed to parse XMLObject from '" + reference + "'.");
+ log.info("Failed to parse XMLObject from '{}'.", reference);
throw new SLCommandException(4111);
}
@@ -666,12 +651,12 @@ public class DataObject {
if (dataObject.getLocRefContent() != null) {
String locRef = dataObject.getLocRefContent();
try {
- this.reference.setDereferencer(new LocRefDereferencer(ctx.getDereferencerContext(), locRef));
+ this.reference.setDereferencer(new LocRefDereferencer(ctx.getUrlDereferencer(), locRef));
} catch (URISyntaxException e) {
- log.info("Invalid URI '" + locRef + "' in DataObject.", e);
+ log.info("Invalid URI '{}' in DataObject.", locRef, e);
throw new SLCommandException(4003);
} catch (IllegalArgumentException e) {
- log.info("LocRef URI of '" + locRef + "' not supported in DataObject. ", e);
+ log.info("LocRef URI of '{}' not supported in DataObject. ", locRef, e);
throw new SLCommandException(4003);
}
} else if (dataObject.getBase64Content() != null) {
@@ -734,7 +719,7 @@ public class DataObject {
}
if (debugString != null) {
- log.debug(debugString);
+ log.debug(debugString.toString());
}
// look for preferred transform
@@ -778,7 +763,7 @@ public class DataObject {
StringBuilder sb = new StringBuilder();
sb.append("Trying to parse transforms:\n");
sb.append(new String(transforms, Charset.forName("UTF-8")));
- log.trace(sb);
+ log.trace(sb.toString());
}
DOMImplementationLS domImplLS = DOMUtils.getDOMImplementationLS();
@@ -933,8 +918,7 @@ public class DataObject {
} catch (MarshalException e) {
String mimeType = preferredTransformsInfo.getFinalDataMetaInfo().getMimeType();
- log.info("Failed to unmarshal preferred transformation path (MIME-Type="
- + mimeType + ").", e);
+ log.info("Failed to unmarshal preferred transformation path (MIME-Type={}).", mimeType, e);
}
@@ -950,8 +934,7 @@ public class DataObject {
} catch (MarshalException e) {
String mimeType = transformsInfoType.getFinalDataMetaInfo().getMimeType();
- log.info("Failed to unmarshal transformation path (MIME-Type="
- + mimeType + ").", e);
+ log.info("Failed to unmarshal transformation path (MIME-Type={}).", mimeType, e);
}
}
@@ -975,7 +958,7 @@ public class DataObject {
try {
textNode = at.gv.egiz.dom.DOMUtils.createBase64Text(content, ctx.getDocument());
} catch (IOException e) {
- log.error(e);
+ log.error("Failed to create XMLObject.", e);
throw new SLRuntimeException(e);
}
@@ -1170,36 +1153,68 @@ public class DataObject {
// content of the redirect stream as the content has already been parsed
// and serialized again to the redirect stream.
- List<InputStream> inputStreams = new ArrayList<InputStream>();
- try {
- // dummy start element
- inputStreams.add(new ByteArrayInputStream("<dummy>".getBytes("UTF-8")));
-
- // content
- inputStreams.add(new ByteArrayInputStream(redirectedStream.toByteArray()));
-
- // dummy end element
- inputStreams.add(new ByteArrayInputStream("</dummy>".getBytes("UTF-8")));
- } catch (UnsupportedEncodingException e) {
- throw new SLRuntimeException(e);
- }
+ DocumentFragment fragment;
+ if (redirectedStream != null) {
- SequenceInputStream inputStream = new SequenceInputStream(Collections.enumeration(inputStreams));
-
- // parse DataObject
- Document doc = parseDataObject(inputStream, "UTF-8");
+ List<InputStream> inputStreams = new ArrayList<InputStream>();
+ try {
+ // dummy start element
+ inputStreams.add(new ByteArrayInputStream("<dummy>".getBytes("UTF-8")));
- Element documentElement = doc.getDocumentElement();
-
- if (documentElement == null ||
- !"dummy".equals(documentElement.getLocalName())) {
- log.info("Failed to parse DataObject XMLContent.");
- throw new SLCommandException(4111);
- }
+ // content
+ inputStreams.add(new ByteArrayInputStream(redirectedStream.toByteArray()));
+
+ // dummy end element
+ inputStreams.add(new ByteArrayInputStream("</dummy>".getBytes("UTF-8")));
+ } catch (UnsupportedEncodingException e) {
+ throw new SLRuntimeException(e);
+ }
+
+ SequenceInputStream inputStream = new SequenceInputStream(Collections.enumeration(inputStreams));
- DocumentFragment fragment = doc.createDocumentFragment();
- while (documentElement.getFirstChild() != null) {
- fragment.appendChild(documentElement.getFirstChild());
+ // parse DataObject
+ Document doc = parseDataObject(inputStream, "UTF-8");
+
+ Element documentElement = doc.getDocumentElement();
+
+ if (documentElement == null ||
+ !"dummy".equals(documentElement.getLocalName())) {
+ log.info("Failed to parse DataObject XMLContent.");
+ throw new SLCommandException(4111);
+ }
+
+ fragment = doc.createDocumentFragment();
+ while (documentElement.getFirstChild() != null) {
+ fragment.appendChild(documentElement.getFirstChild());
+ }
+
+ } else {
+
+ fragment = ctx.getDocument().createDocumentFragment();
+ Marshaller marshaller = SLMarshallerFactory.getInstance().createMarshaller(false);
+
+ JAXBElement<at.buergerkarte.namespaces.securitylayer._1.XMLContentType> element =
+ new JAXBElement<at.buergerkarte.namespaces.securitylayer._1.XMLContentType>(
+ new QName("dummy"),
+ at.buergerkarte.namespaces.securitylayer._1.XMLContentType.class,
+ xmlContent);
+
+ try {
+ marshaller.marshal(element, fragment);
+ } catch (JAXBException e) {
+ log.info("Failed to marshal DataObject (XMLContent).", e);
+ throw new SLCommandException(4111);
+ }
+
+ Node dummy = fragment.getFirstChild();
+ if (dummy != null) {
+ NodeList nodes = dummy.getChildNodes();
+ for (int i = 0; i < nodes.getLength(); i++) {
+ fragment.appendChild(nodes.item(i));
+ }
+ fragment.removeChild(dummy);
+ }
+
}
// log parsed document
@@ -1256,6 +1271,8 @@ public class DataObject {
SimpleDOMErrorHandler errorHandler = new SimpleDOMErrorHandler();
domConfig.setParameter("error-handler", errorHandler);
domConfig.setParameter("validate", Boolean.FALSE);
+ domConfig.setParameter("entities", Boolean.TRUE);
+
Document doc;
try {
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/LocRefDereferencer.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/LocRefDereferencer.java
index f5394157..e513738c 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/LocRefDereferencer.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/LocRefDereferencer.java
@@ -14,99 +14,96 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package at.gv.egiz.bku.slcommands.impl.xsect;
-
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import javax.xml.crypto.Data;
-import javax.xml.crypto.OctetStreamData;
-import javax.xml.crypto.URIDereferencer;
-import javax.xml.crypto.URIReference;
-import javax.xml.crypto.URIReferenceException;
-import javax.xml.crypto.XMLCryptoContext;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import at.gv.egiz.bku.utils.urldereferencer.StreamData;
-import at.gv.egiz.bku.utils.urldereferencer.URLDereferencer;
-import at.gv.egiz.bku.utils.urldereferencer.URLDereferencerContext;
-
-/**
- * An URIDereferencer implementation that dereferences <code>LocRef</code>
- * references.
- *
- * @author mcentner
- */
-public class LocRefDereferencer implements URIDereferencer {
-
- /**
- * Logging facility.
- */
- private static Log log = LogFactory.getLog(LocRefDereferencer.class);
-
- /**
- * The <code>LocRef</code>-reference to be dereferenced by
- * {@link #dereference(URIReference, XMLCryptoContext)}.
- */
- protected String locRef;
-
- /**
- * The context to be used for dereferencing.
- */
- protected URLDereferencerContext dereferencerContext;
-
- /**
- * Creates a new instance of this LocRefDereferencer with the given
- * <code>dereferencerContext</code> and <code>locRef</code> reference.
- *
- * @param dereferencerContext
- * the context to be used for dereferencing
- * @param locRef
- * the <code>LocRef</code>-reference (must be an absolute URI)
- *
- * @throws URISyntaxException
- * if <code>LocRef</code> is not an absolute URI
- */
- public LocRefDereferencer(URLDereferencerContext dereferencerContext,
- String locRef) throws URISyntaxException {
-
- this.dereferencerContext = dereferencerContext;
-
- URI locRefUri = new URI(locRef);
- if (locRefUri.isAbsolute()) {
- this.locRef = locRef;
- } else {
- throw new IllegalArgumentException(
- "Parameter 'locRef' must be an absolut URI.");
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * javax.xml.crypto.URIDereferencer#dereference(javax.xml.crypto.URIReference,
- * javax.xml.crypto.XMLCryptoContext)
- */
- @Override
- public Data dereference(URIReference uriReference, XMLCryptoContext context)
- throws URIReferenceException {
-
- URLDereferencer dereferencer = URLDereferencer.getInstance();
- StreamData streamData;
- try {
- streamData = dereferencer.dereference(locRef, dereferencerContext);
- } catch (IOException e) {
- log.info("Failed to dereference URI'" + locRef + "'. " + e.getMessage(),
- e);
- throw new URIReferenceException("Failed to dereference URI '" + locRef
- + "'. " + e.getMessage(), e);
- }
- return new OctetStreamData(streamData.getStream(), locRef, streamData
- .getContentType());
- }
-
-}
+package at.gv.egiz.bku.slcommands.impl.xsect;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import javax.xml.crypto.Data;
+import javax.xml.crypto.OctetStreamData;
+import javax.xml.crypto.URIDereferencer;
+import javax.xml.crypto.URIReference;
+import javax.xml.crypto.URIReferenceException;
+import javax.xml.crypto.XMLCryptoContext;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.gv.egiz.bku.utils.urldereferencer.StreamData;
+import at.gv.egiz.bku.utils.urldereferencer.URLDereferencer;
+
+/**
+ * An URIDereferencer implementation that dereferences <code>LocRef</code>
+ * references.
+ *
+ * @author mcentner
+ */
+public class LocRefDereferencer implements URIDereferencer {
+
+ /**
+ * Logging facility.
+ */
+ private final Logger log = LoggerFactory.getLogger(LocRefDereferencer.class);
+
+ /**
+ * The <code>LocRef</code>-reference to be dereferenced by
+ * {@link #dereference(URIReference, XMLCryptoContext)}.
+ */
+ protected String locRef;
+
+ /**
+ * The URLDereferencer to be used for dereferencing.
+ */
+ protected URLDereferencer dereferencer;
+
+ /**
+ * Creates a new instance of this LocRefDereferencer with the given
+ * <code>dereferencerContext</code> and <code>locRef</code> reference.
+ *
+ * @param dereferencer
+ * the context to be used for dereferencing
+ * @param locRef
+ * the <code>LocRef</code>-reference (must be an absolute URI)
+ *
+ * @throws URISyntaxException
+ * if <code>LocRef</code> is not an absolute URI
+ */
+ public LocRefDereferencer(URLDereferencer dereferencer,
+ String locRef) throws URISyntaxException {
+
+ this.dereferencer = dereferencer;
+
+ URI locRefUri = new URI(locRef);
+ if (locRefUri.isAbsolute()) {
+ this.locRef = locRef;
+ } else {
+ throw new IllegalArgumentException(
+ "Parameter 'locRef' must be an absolut URI.");
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * javax.xml.crypto.URIDereferencer#dereference(javax.xml.crypto.URIReference,
+ * javax.xml.crypto.XMLCryptoContext)
+ */
+ @Override
+ public Data dereference(URIReference uriReference, XMLCryptoContext context)
+ throws URIReferenceException {
+
+ StreamData streamData;
+ try {
+ streamData = dereferencer.dereference(locRef);
+ } catch (IOException e) {
+ log.info("Failed to dereference URI '{}'.", locRef, e);
+ throw new URIReferenceException("Failed to dereference URI '" + locRef
+ + "'. " + e.getMessage(), e);
+ }
+ return new OctetStreamData(streamData.getStream(), locRef, streamData
+ .getContentType());
+ }
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALPrivateKey.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALPrivateKey.java
index 25e2d4e5..87a165cf 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALPrivateKey.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALPrivateKey.java
@@ -16,7 +16,6 @@
*/
package at.gv.egiz.bku.slcommands.impl.xsect;
-import at.gv.egiz.stal.HashDataInput;
import java.security.PrivateKey;
import at.gv.egiz.stal.STAL;
@@ -24,7 +23,7 @@ import at.gv.egiz.stal.STAL;
import java.util.List;
/**
- * This class implements a private key used by the {@link STALSignature} class.
+ * This class implements a private key used by the {@link STALSignatureMethod} class.
*
* @author mcentner
*/
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALProvider.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALProvider.java
deleted file mode 100644
index 9fb9a3f1..00000000
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALProvider.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
-* Copyright 2008 Federal Chancellery Austria and
-* Graz University of Technology
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package at.gv.egiz.bku.slcommands.impl.xsect;
-
-import iaik.xml.crypto.XmldsigMore;
-
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.security.Provider;
-import java.security.Signature;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.xml.crypto.dsig.SignatureMethod;
-
-/**
- * A security provider implementation that provides {@link Signature} implementations
- * based on STAL.
- *
- * @author mcentner
- */
-public class STALProvider extends Provider {
-
- private static final long serialVersionUID = 1L;
-
- private static String IMPL_PACKAGE_NAME = "at.gv.egiz.bku.slcommands.impl.xsect";
-
- public STALProvider() {
-
- super("STAL", 1.0, "Security Token Abstraction Layer Provider");
-
- final Map<String, String> map = new HashMap<String, String>();
-
- // TODO: register further algorithms
- map.put("Signature." + SignatureMethod.RSA_SHA1,
- IMPL_PACKAGE_NAME + ".STALSignature");
- map.put("Signature." + XmldsigMore.SIGNATURE_ECDSA_SHA1,
- IMPL_PACKAGE_NAME + ".STALSignature");
- map.put("Signature." + XmldsigMore.SIGNATURE_RSA_SHA256,
- IMPL_PACKAGE_NAME + ".STALSignature");
- map.put("Signature." + XmldsigMore.SIGNATURE_ECDSA_SHA256,
- IMPL_PACKAGE_NAME + ".STALSignature");
- map.put("Signature." + XmldsigMore.SIGNATURE_ECDSA_SHA512,
- IMPL_PACKAGE_NAME + ".STALSignature");
-
-
- AccessController.doPrivileged(new PrivilegedAction<Void>() {
- @Override
- public Void run() {
- putAll(map);
- return null;
- }
- });
-
- }
-
-}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALSignature.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALSignature.java
deleted file mode 100644
index dd7c7d8a..00000000
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALSignature.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
-* Copyright 2008 Federal Chancellery Austria and
-* Graz University of Technology
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package at.gv.egiz.bku.slcommands.impl.xsect;
-
-import at.gv.egiz.bku.slcommands.impl.DataObjectHashDataInput;
-import at.gv.egiz.bku.slexceptions.SLViewerException;
-
-import java.io.ByteArrayOutputStream;
-import java.security.InvalidKeyException;
-import java.security.InvalidParameterException;
-import java.security.PrivateKey;
-import java.security.PublicKey;
-import java.security.SignatureException;
-import java.security.SignatureSpi;
-import java.util.Collections;
-import java.util.List;
-
-import at.gv.egiz.stal.ErrorResponse;
-import at.gv.egiz.stal.HashDataInput;
-import at.gv.egiz.stal.STAL;
-import at.gv.egiz.stal.STALRequest;
-import at.gv.egiz.stal.STALResponse;
-import at.gv.egiz.stal.SignRequest;
-import at.gv.egiz.stal.SignResponse;
-//import at.gv.egiz.stal.HashDataInputCallback;
-import java.util.ArrayList;
-
-/**
- * A signature service provider implementation that uses STAL to sign.
- *
- * @author mcentner
- */
-public class STALSignature extends SignatureSpi {
-
-// private static final Log log = LogFactory.getLog(STALSignature.class);
-
- /**
- * The private key.
- */
- protected STALPrivateKey privateKey;
-
- /**
- * The to-be signed data.
- */
- protected ByteArrayOutputStream data = new ByteArrayOutputStream();
-
- /* (non-Javadoc)
- * @see java.security.SignatureSpi#engineGetParameter(java.lang.String)
- */
- @Override
- protected Object engineGetParameter(String param)
- throws InvalidParameterException {
- throw new InvalidParameterException();
- }
-
- /* (non-Javadoc)
- * @see java.security.SignatureSpi#engineInitSign(java.security.PrivateKey)
- */
- @Override
- protected void engineInitSign(PrivateKey privateKey)
- throws InvalidKeyException {
-
- if (!(privateKey instanceof STALPrivateKey)) {
- throw new InvalidKeyException("STALSignature supports STALKeys only.");
- }
-
- this.privateKey = (STALPrivateKey) privateKey;
-
- }
-
- /* (non-Javadoc)
- * @see java.security.SignatureSpi#engineInitVerify(java.security.PublicKey)
- */
- @Override
- protected void engineInitVerify(PublicKey publicKey)
- throws InvalidKeyException {
-
- throw new UnsupportedOperationException("STALSignature does not support signature verification.");
- }
-
- /* (non-Javadoc)
- * @see java.security.SignatureSpi#engineSetParameter(java.lang.String, java.lang.Object)
- */
- @Override
- protected void engineSetParameter(String param, Object value)
- throws InvalidParameterException {
- }
-
- /* (non-Javadoc)
- * @see java.security.SignatureSpi#engineSign()
- */
- @Override
- protected byte[] engineSign() throws SignatureException {
-
- STAL stal = privateKey.getStal();
-
- if (stal == null) {
- throw new SignatureException("STALSignature requires the STALPrivateKey " +
- "to provide a STAL implementation reference.");
- }
-
- String keyboxIdentifier = privateKey.getKeyboxIdentifier();
-
- if (keyboxIdentifier == null) {
- throw new SignatureException("STALSignature requires the STALPrivateKey " +
- "to provide a KeyboxIdentifier.");
- }
-
- // get hashDataInputs (DigestInputStreams) once slcommands.impl.xsect.Signature::sign() was called
- List<DataObject> dataObjects = privateKey.getDataObjects();
-// log.debug("got " + dataObjects.size() + " DataObjects, passing HashDataInputs to STAL SignRequest");
-
- List<HashDataInput> hashDataInputs = new ArrayList<HashDataInput>();
- for (DataObject dataObject : dataObjects) {
- try {
- dataObject.validateHashDataInput();
- } catch (SLViewerException e) {
- throw new STALSignatureException(e);
- }
- hashDataInputs.add(new DataObjectHashDataInput(dataObject));
- }
-
- SignRequest signRequest = new SignRequest();
- signRequest.setKeyIdentifier(keyboxIdentifier);
- signRequest.setSignedInfo(data.toByteArray());
- signRequest.setHashDataInput(hashDataInputs);
-
- List<STALResponse> responses = stal.handleRequest(Collections.singletonList((STALRequest) signRequest));
-
- if (responses == null || responses.size() != 1) {
- throw new SignatureException("Failed to access STAL.");
- }
-
- STALResponse response = responses.get(0);
- if (response instanceof SignResponse) {
- return ((SignResponse) response).getSignatureValue();
- } else if (response instanceof ErrorResponse) {
- throw new STALSignatureException(((ErrorResponse) response).getErrorCode());
- } else {
- throw new SignatureException("Failed to access STAL.");
- }
-
- }
-
- /* (non-Javadoc)
- * @see java.security.SignatureSpi#engineUpdate(byte)
- */
- @Override
- protected void engineUpdate(byte b) throws SignatureException {
- data.write(b);
- }
-
- /* (non-Javadoc)
- * @see java.security.SignatureSpi#engineUpdate(byte[], int, int)
- */
- @Override
- protected void engineUpdate(byte[] b, int off, int len)
- throws SignatureException {
- data.write(b, off, len);
- }
-
- /* (non-Javadoc)
- * @see java.security.SignatureSpi#engineVerify(byte[])
- */
- @Override
- protected boolean engineVerify(byte[] sigBytes) throws SignatureException {
- throw new UnsupportedOperationException("STALSignature des not support signature verification.");
- }
-
-}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALSignatureException.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALSignatureException.java
index 4e86b07c..b727600f 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALSignatureException.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALSignatureException.java
@@ -19,7 +19,7 @@ package at.gv.egiz.bku.slcommands.impl.xsect;
import java.security.SignatureException;
/**
- * A SignatureException thrown by the {@link STALSignature}.
+ * A SignatureException thrown by the {@link STALSignatureMethod}.
*
* @author mcentner
*/
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALSignatureMethod.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALSignatureMethod.java
new file mode 100644
index 00000000..a9bb8e04
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALSignatureMethod.java
@@ -0,0 +1,127 @@
+/*
+* Copyright 2009 Federal Chancellery Austria and
+* Graz University of Technology
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package at.gv.egiz.bku.slcommands.impl.xsect;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.xml.crypto.XMLCryptoContext;
+import javax.xml.crypto.dsig.XMLSignatureException;
+import javax.xml.crypto.dsig.spec.SignatureMethodParameterSpec;
+
+import at.gv.egiz.bku.slcommands.impl.DataObjectHashDataInput;
+import at.gv.egiz.bku.slexceptions.SLViewerException;
+import at.gv.egiz.bku.utils.StreamUtil;
+import at.gv.egiz.stal.ErrorResponse;
+import at.gv.egiz.stal.HashDataInput;
+import at.gv.egiz.stal.STAL;
+import at.gv.egiz.stal.STALRequest;
+import at.gv.egiz.stal.STALResponse;
+import at.gv.egiz.stal.SignRequest;
+import at.gv.egiz.stal.SignResponse;
+
+import iaik.xml.crypto.dsig.AbstractSignatureMethodImpl;
+
+public class STALSignatureMethod extends AbstractSignatureMethodImpl {
+
+ /**
+ * Creates a new instance of this <code>STALSignatureMethod</code>
+ * with the given <code>algorithm</code> and <code>params</code>.
+ *
+ * @param algorithm the algorithm URI
+ * @param params optional algorithm parameters
+ * @throws InvalidAlgorithmParameterException if the specified parameters
+ * are inappropriate for the requested algorithm
+ * @throws NoSuchAlgorithmException if an implementation of the specified
+ * algorithm cannot be found
+ * @throws NullPointerException if <code>algorithm</code> is <code>null</code>
+ */
+ public STALSignatureMethod(String algorithm,
+ SignatureMethodParameterSpec params)
+ throws InvalidAlgorithmParameterException, NoSuchAlgorithmException {
+ super(algorithm, params);
+ }
+
+ @Override
+ public byte[] calculateSignatureValue(XMLCryptoContext context, Key key, InputStream message)
+ throws XMLSignatureException, IOException {
+
+ if (!(key instanceof STALPrivateKey)) {
+ throw new XMLSignatureException("STALSignatureMethod expects STALPrivateKey.");
+ }
+
+ STAL stal = ((STALPrivateKey) key).getStal();
+ String keyboxIdentifier = ((STALPrivateKey) key).getKeyboxIdentifier();
+ List<DataObject> dataObjects = ((STALPrivateKey) key).getDataObjects();
+
+ List<HashDataInput> hashDataInputs = new ArrayList<HashDataInput>();
+ for (DataObject dataObject : dataObjects) {
+ try {
+ dataObject.validateHashDataInput();
+ } catch (SLViewerException e) {
+ throw new XMLSignatureException(e);
+ }
+ hashDataInputs.add(new DataObjectHashDataInput(dataObject));
+ }
+
+ ByteArrayOutputStream m = new ByteArrayOutputStream();
+ StreamUtil.copyStream(message, m);
+
+ SignRequest signRequest = new SignRequest();
+ signRequest.setKeyIdentifier(keyboxIdentifier);
+ signRequest.setSignedInfo(m.toByteArray());
+ signRequest.setHashDataInput(hashDataInputs);
+
+ List<STALResponse> responses =
+ stal.handleRequest(Collections.singletonList((STALRequest) signRequest));
+
+ if (responses == null || responses.size() != 1) {
+ throw new XMLSignatureException("Failed to access STAL.");
+ }
+
+ STALResponse response = responses.get(0);
+ if (response instanceof SignResponse) {
+ return ((SignResponse) response).getSignatureValue();
+ } else if (response instanceof ErrorResponse) {
+ STALSignatureException se = new STALSignatureException(((ErrorResponse) response).getErrorCode());
+ throw new XMLSignatureException(se);
+ } else {
+ throw new XMLSignatureException("Failed to access STAL.");
+ }
+
+ }
+
+ @Override
+ public boolean validateSignatureValue(XMLCryptoContext context, Key key, byte[] value,
+ InputStream message) throws XMLSignatureException, IOException {
+ throw new XMLSignatureException("The STALSignatureMethod does not support validation.");
+ }
+
+ @Override
+ protected Class<?> getParameterSpecClass() {
+ return null;
+ }
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/Signature.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/Signature.java
index 3cebb6a3..b4ce0e79 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/Signature.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/Signature.java
@@ -51,8 +51,8 @@ import javax.xml.crypto.dsig.keyinfo.KeyInfoFactory;
import javax.xml.crypto.dsig.keyinfo.X509Data;
import javax.xml.stream.XMLStreamException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.etsi.uri._01903.v1_1.DataObjectFormatType;
import org.etsi.uri._01903.v1_1.QualifyingPropertiesType;
import org.w3c.dom.DOMConfiguration;
@@ -82,7 +82,6 @@ import at.gv.egiz.bku.slexceptions.SLViewerException;
import at.gv.egiz.bku.utils.HexDump;
import at.gv.egiz.bku.utils.urldereferencer.StreamData;
import at.gv.egiz.bku.utils.urldereferencer.URLDereferencer;
-import at.gv.egiz.bku.utils.urldereferencer.URLDereferencerContext;
import at.gv.egiz.dom.DOMUtils;
import at.gv.egiz.slbinding.impl.XMLContentType;
import at.gv.egiz.stal.STAL;
@@ -101,7 +100,7 @@ public class Signature {
/**
* Logging facility.
*/
- private static Log log = LogFactory.getLog(Signature.class);
+ private final Logger log = LoggerFactory.getLogger(Signature.class);
/**
* The DOM implementation used.
@@ -151,8 +150,9 @@ public class Signature {
/**
* Creates a new SLXMLSignature instance.
+ * @param urlDereferencer TODO
*/
- public Signature(URLDereferencerContext dereferencerContext,
+ public Signature(URLDereferencer urlDereferencer,
IdValueFactory idValueFactory,
AlgorithmMethodFactory algorithmMethodFactory) {
@@ -162,7 +162,7 @@ public class Signature {
ctx.setSignatureFactory(XMLSignatureFactory.getInstance());
- ctx.setDereferencerContext(dereferencerContext);
+ ctx.setUrlDereferencer(urlDereferencer);
ctx.setIdValueFactory(idValueFactory);
ctx.setAlgorithmMethodFactory(algorithmMethodFactory);
@@ -408,7 +408,7 @@ public class Signature {
signContext.putNamespacePrefix(XMLSignature.XMLNS,XMLDSIG_PREFIX);
- signContext.setURIDereferencer(new URIDereferncerAdapter(ctx.getDereferencerContext()));
+ signContext.setURIDereferencer(new URIDereferncerAdapter(ctx.getUrlDereferencer()));
try {
xmlSignature.sign(signContext);
@@ -455,7 +455,7 @@ public class Signature {
sb.append(HexDump.hexDump(digestInputStream));
}
} catch (IOException e) {
- log.error(e);
+ log.error("Failed to log DigestInput.", e);
}
log.trace(sb.toString());
} else {
@@ -478,7 +478,7 @@ public class Signature {
sb.append(new String(b, 0, l));
}
} catch (IOException e) {
- log.error(e);
+ log.error("Failed to log DigestInput.", e);
}
log.trace(sb.toString());
} else {
@@ -735,7 +735,7 @@ public class Signature {
LSInput input;
try {
if (signatureEnvironment.getReference() != null) {
- log.debug("SignatureEnvironment contains Reference " + signatureEnvironment.getReference() + ".");
+ log.debug("SignatureEnvironment contains Reference '{}'.", signatureEnvironment.getReference());
input = createLSInput(signatureEnvironment.getReference());
} else if (signatureEnvironment.getBase64Content() != null) {
log.debug("SignatureEnvironment contains Base64Content.");
@@ -784,11 +784,12 @@ public class Signature {
if (log.isInfoEnabled()) {
List<String> errorMessages = errorHandler.getErrorMessages();
StringBuffer sb = new StringBuffer();
+ sb.append("XML document in which the signature is to be integrated cannot be parsed.");
for (String errorMessage : errorMessages) {
sb.append(" ");
sb.append(errorMessage);
}
- log.info("XML document in which the signature is to be integrated cannot be parsed." + sb.toString());
+ log.info(sb.toString());
}
throw new SLCommandException(4101);
}
@@ -826,8 +827,8 @@ public class Signature {
*/
private LSInput createLSInput(String reference) throws IOException {
- URLDereferencer urlDereferencer = URLDereferencer.getInstance();
- StreamData streamData = urlDereferencer.dereference(reference, ctx.getDereferencerContext());
+ URLDereferencer urlDereferencer = ctx.getUrlDereferencer();
+ StreamData streamData = urlDereferencer.dereference(reference);
String contentType = streamData.getContentType();
String charset = HttpUtil.getCharset(contentType, true);
@@ -835,7 +836,7 @@ public class Signature {
try {
streamReader = new InputStreamReader(streamData.getStream(), charset);
} catch (UnsupportedEncodingException e) {
- log.info("Charset " + charset + " not supported. Using default.");
+ log.info("Charset {} not supported. Using default.", charset);
streamReader = new InputStreamReader(streamData.getStream());
}
@@ -942,7 +943,7 @@ public class Signature {
if (systemId != null) {
- log.debug("Resolve resource '" + systemId + "'.");
+ log.debug("Resolve resource '{}'.", systemId);
for (DataObjectAssociationType supplement : supplements) {
@@ -954,23 +955,23 @@ public class Signature {
try {
if (content.getLocRefContent() != null) {
- log.trace("Resolved resource '" + reference + "' to supplement with LocRefContent.");
+ log.trace("Resolved resource '{}' to supplement with LocRefContent.", reference);
return createLSInput(content.getLocRefContent());
} else if (content.getBase64Content() != null) {
- log.trace("Resolved resource '" + reference + "' to supplement with Base64Content.");
+ log.trace("Resolved resource '{}' to supplement with Base64Content.", reference);
return createLSInput(content.getBase64Content());
} else if (content.getXMLContent() != null) {
- log.trace("Resolved resource '" + reference + "' to supplement with XMLContent.");
+ log.trace("Resolved resource '{}' to supplement with XMLContent.", reference);
return createLSInput((XMLContentType) content.getXMLContent());
} else {
return null;
}
} catch (IOException e) {
- log.info("Failed to resolve resource '" + systemId + "' to supplement.", e);
+ log.info("Failed to resolve resource '{}' to supplement.", systemId, e);
error = e;
return null;
} catch (XMLStreamException e) {
- log.info("Failed to resolve resource '" + systemId + "' to supplement.", e);
+ log.info("Failed to resolve resource '{}' to supplement.", systemId, e);
error = e;
return null;
}
@@ -981,7 +982,7 @@ public class Signature {
}
- log.info("Failed to resolve resource '" + systemId + "' to supplement. No such supplement.");
+ log.info("Failed to resolve resource '{}' to supplement. No such supplement.", systemId);
}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/SignatureContext.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/SignatureContext.java
index 0925f2fd..48c82bd5 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/SignatureContext.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/SignatureContext.java
@@ -16,12 +16,12 @@
*/
package at.gv.egiz.bku.slcommands.impl.xsect;
-import javax.xml.crypto.dsig.DigestMethod;
+import javax.xml.crypto.AlgorithmMethod;
import javax.xml.crypto.dsig.XMLSignatureFactory;
import org.w3c.dom.Document;
-import at.gv.egiz.bku.utils.urldereferencer.URLDereferencerContext;
+import at.gv.egiz.bku.utils.urldereferencer.URLDereferencer;
/**
* An instance of this class carries context information for a XML-Signature
@@ -45,16 +45,16 @@ public class SignatureContext {
* The XMLSignatureFactory to create XML signature objects.
*/
private XMLSignatureFactory signatureFactory;
+
+ /**
+ * The URLDereferencer to dereference URLs with.
+ */
+ private URLDereferencer urlDereferencer;
/**
- * The URLDereferencerContext for dereferencing URLs.
+ * The AlgorithmMethodFactory to create {@link AlgorithmMethod} objects.
*/
- private URLDereferencerContext dereferencerContext;
-
- /**
- * The DigestMethodFactory to create {@link DigestMethod} objects.
- */
- private AlgorithmMethodFactory digestMethodFactory;
+ private AlgorithmMethodFactory algorithmMethodFactory;
/**
* @return the document
@@ -99,31 +99,31 @@ public class SignatureContext {
}
/**
- * @return the dereferencerContext
- */
- public URLDereferencerContext getDereferencerContext() {
- return dereferencerContext;
- }
-
- /**
- * @param dereferencerContext the dereferencerContext to set
- */
- public void setDereferencerContext(URLDereferencerContext dereferencerContext) {
- this.dereferencerContext = dereferencerContext;
- }
-
- /**
* @return the digestMethodFactory
*/
public AlgorithmMethodFactory getAlgorithmMethodFactory() {
- return digestMethodFactory;
+ return algorithmMethodFactory;
}
/**
* @param digestMethodFactory the digestMethodFactory to set
*/
public void setAlgorithmMethodFactory(AlgorithmMethodFactory digestMethodFactory) {
- this.digestMethodFactory = digestMethodFactory;
+ this.algorithmMethodFactory = digestMethodFactory;
+ }
+
+ /**
+ * @return the urlDereferencer
+ */
+ public URLDereferencer getUrlDereferencer() {
+ return urlDereferencer;
+ }
+
+ /**
+ * @param urlDereferencer the urlDereferencer to set
+ */
+ public void setUrlDereferencer(URLDereferencer urlDereferencer) {
+ this.urlDereferencer = urlDereferencer;
}
}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/SignatureLocation.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/SignatureLocation.java
index ebe50b3f..26a4aa4e 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/SignatureLocation.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/SignatureLocation.java
@@ -14,212 +14,212 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package at.gv.egiz.bku.slcommands.impl.xsect;
-
-import java.util.Iterator;
-
-import javax.xml.XMLConstants;
-import javax.xml.namespace.NamespaceContext;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpression;
-import javax.xml.xpath.XPathExpressionException;
-import javax.xml.xpath.XPathFactory;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.w3c.dom.Node;
-
-import at.buergerkarte.namespaces.securitylayer._1.SignatureInfoCreationType;
-import at.gv.egiz.bku.slexceptions.SLCommandException;
-import at.gv.egiz.slbinding.impl.SignatureLocationType;
-
-/**
- * This class implements the <code>SignatureLocation</code> of an XML-Signature
- * to be created by the security layer command <code>CreateXMLSignature</code>.
- *
- * @author mcentner
- */
-public class SignatureLocation {
-
- /**
- * Logging facility.
- */
- private static Log log = LogFactory.getLog(SignatureLocation.class);
-
- /**
- * The SignatureContext for the XML signature
- */
- private SignatureContext ctx;
-
- /**
- * The parent node for the XML signature.
- */
- private Node parent;
-
- /**
- * The next sibling node for the XML signature.
- */
- private Node nextSibling;
-
- /**
- * Creates a new SignatureLocation with the given <code>signatureContext</code>
- *
- * @param signatureContext the context for the XML signature creation
- */
- public SignatureLocation(SignatureContext signatureContext) {
- this.ctx = signatureContext;
- }
-
- /**
- * @return the parent node for the XML signature
- */
- public Node getParent() {
- return parent;
- }
-
- /**
- * @param parent the parent for the XML signature
- */
- public void setParent(Node parent) {
- this.parent = parent;
- }
-
- /**
- * @return the next sibling node for the XML signature
- */
- public Node getNextSibling() {
- return nextSibling;
- }
-
- /**
- * @param nextSibling the next sibling node for the XML signature
- */
- public void setNextSibling(Node nextSibling) {
- this.nextSibling = nextSibling;
- }
-
- /**
- * Configures this SignatureLocation with the information provided by the
- * given <code>SignatureInfo</code> element.
- *
- * @param signatureInfo
- * the <code>SignatureInfo</code> element
- *
- * @throws SLCommandException
- * if configuring this SignatureLocation with given
- * <code>signatureInfo</code>fails
- */
- public void setSignatureInfo(SignatureInfoCreationType signatureInfo)
- throws SLCommandException {
-
- // evaluate signature location XPath ...
- SignatureLocationType signatureLocation = (SignatureLocationType) signatureInfo
- .getSignatureLocation();
-
- NamespaceContext namespaceContext = new MOAIDWorkaroundNamespaceContext(
- signatureLocation.getNamespaceContext());
-
- parent = evaluateSignatureLocation(signatureInfo.getSignatureLocation()
- .getValue(), namespaceContext, ctx.getDocument().getDocumentElement());
-
- // ... and index
- nextSibling = findNextSibling(parent, signatureInfo.getSignatureLocation()
- .getIndex().intValue());
-
- }
-
- /**
- * Evaluates the given <code>xpath</code> with the document element as context node
- * and returns the resulting node.
- *
- * @param xpath the XPath expression
- * @param nsContext the namespace context of the XPath expression
- * @param contextNode the context node for the XPath evaluation
- *
- * @return the result of evaluating the XPath expression
- *
- * @throws SLCommandException
- */
- private Node evaluateSignatureLocation(String xpath, NamespaceContext nsContext, Node contextNode) throws SLCommandException {
-
- Node node = null;
- try {
- XPathFactory xpathFactory = XPathFactory.newInstance();
- XPath xPath = xpathFactory.newXPath();
- xPath.setNamespaceContext(nsContext);
- XPathExpression xpathExpr = xPath.compile(xpath);
- node = (Node) xpathExpr.evaluate(contextNode, XPathConstants.NODE);
- } catch (XPathExpressionException e) {
- log.info("Failed to evaluate SignatureLocation XPath expression '" + xpath + "' on context node.", e);
- throw new SLCommandException(4102);
- }
-
- if (node == null) {
- log.info("Failed to evaluate SignatureLocation XPath expression '" + xpath + "'. Result is empty.");
- throw new SLCommandException(4102);
- }
-
- return node;
-
- }
-
- /**
- * Finds the next sibling node of the <code>parent</code>'s <code>n</code>-th child node
- * or <code>null</code> if there is no next sibling.
- *
- * @param parent the parent node
- * @param n the index of the child node
- *
- * @return the next sibling node of the node specified by <code>parent</code> and index <code>n</code>,
- * or <code>null</code> if there is no next sibling node.
- *
- * @throws SLCommandException if the <code>n</code>-th child of <code>parent</code> does not exist
- */
- private Node findNextSibling(Node parent, int n) throws SLCommandException {
- return parent.getChildNodes().item(n);
- }
-
- /**
- * Workaround for a missing namespace prefix declaration in MOA-ID.
- *
- * @author mcentner
- */
- private class MOAIDWorkaroundNamespaceContext implements NamespaceContext {
-
- private NamespaceContext namespaceContext;
-
- public MOAIDWorkaroundNamespaceContext(NamespaceContext namespaceContext) {
- super();
- this.namespaceContext = namespaceContext;
- }
-
- @Override
- public String getNamespaceURI(String prefix) {
-
- String namespaceURI = namespaceContext.getNamespaceURI(prefix);
-
- if ((namespaceURI == null || XMLConstants.NULL_NS_URI.equals(namespaceURI)) && "saml".equals(prefix)) {
- namespaceURI = "urn:oasis:names:tc:SAML:1.0:assertion";
- log.debug("Namespace prefix '" + prefix + "' resolved to '" + namespaceURI + "' (MOA-ID Workaround).");
- } else {
- log.trace("Namespace prefix '" + prefix + "' resolved to '" + namespaceURI + "'.");
- }
-
- return namespaceURI;
- }
-
- @Override
- public String getPrefix(String namespaceURI) {
- return namespaceContext.getPrefix(namespaceURI);
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Iterator getPrefixes(String namespaceURI) {
- return namespaceContext.getPrefixes(namespaceURI);
- }
-
- }
-
-}
+package at.gv.egiz.bku.slcommands.impl.xsect;
+
+import java.util.Iterator;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Node;
+
+import at.buergerkarte.namespaces.securitylayer._1.SignatureInfoCreationType;
+import at.gv.egiz.bku.slexceptions.SLCommandException;
+import at.gv.egiz.slbinding.impl.SignatureLocationType;
+
+/**
+ * This class implements the <code>SignatureLocation</code> of an XML-Signature
+ * to be created by the security layer command <code>CreateXMLSignature</code>.
+ *
+ * @author mcentner
+ */
+public class SignatureLocation {
+
+ /**
+ * Logging facility.
+ */
+ private final Logger log = LoggerFactory.getLogger(SignatureLocation.class);
+
+ /**
+ * The SignatureContext for the XML signature
+ */
+ private SignatureContext ctx;
+
+ /**
+ * The parent node for the XML signature.
+ */
+ private Node parent;
+
+ /**
+ * The next sibling node for the XML signature.
+ */
+ private Node nextSibling;
+
+ /**
+ * Creates a new SignatureLocation with the given <code>signatureContext</code>
+ *
+ * @param signatureContext the context for the XML signature creation
+ */
+ public SignatureLocation(SignatureContext signatureContext) {
+ this.ctx = signatureContext;
+ }
+
+ /**
+ * @return the parent node for the XML signature
+ */
+ public Node getParent() {
+ return parent;
+ }
+
+ /**
+ * @param parent the parent for the XML signature
+ */
+ public void setParent(Node parent) {
+ this.parent = parent;
+ }
+
+ /**
+ * @return the next sibling node for the XML signature
+ */
+ public Node getNextSibling() {
+ return nextSibling;
+ }
+
+ /**
+ * @param nextSibling the next sibling node for the XML signature
+ */
+ public void setNextSibling(Node nextSibling) {
+ this.nextSibling = nextSibling;
+ }
+
+ /**
+ * Configures this SignatureLocation with the information provided by the
+ * given <code>SignatureInfo</code> element.
+ *
+ * @param signatureInfo
+ * the <code>SignatureInfo</code> element
+ *
+ * @throws SLCommandException
+ * if configuring this SignatureLocation with given
+ * <code>signatureInfo</code>fails
+ */
+ public void setSignatureInfo(SignatureInfoCreationType signatureInfo)
+ throws SLCommandException {
+
+ // evaluate signature location XPath ...
+ SignatureLocationType signatureLocation = (SignatureLocationType) signatureInfo
+ .getSignatureLocation();
+
+ NamespaceContext namespaceContext = new MOAIDWorkaroundNamespaceContext(
+ signatureLocation.getNamespaceContext());
+
+ parent = evaluateSignatureLocation(signatureInfo.getSignatureLocation()
+ .getValue(), namespaceContext, ctx.getDocument().getDocumentElement());
+
+ // ... and index
+ nextSibling = findNextSibling(parent, signatureInfo.getSignatureLocation()
+ .getIndex().intValue());
+
+ }
+
+ /**
+ * Evaluates the given <code>xpath</code> with the document element as context node
+ * and returns the resulting node.
+ *
+ * @param xpath the XPath expression
+ * @param nsContext the namespace context of the XPath expression
+ * @param contextNode the context node for the XPath evaluation
+ *
+ * @return the result of evaluating the XPath expression
+ *
+ * @throws SLCommandException
+ */
+ private Node evaluateSignatureLocation(String xpath, NamespaceContext nsContext, Node contextNode) throws SLCommandException {
+
+ Node node = null;
+ try {
+ XPathFactory xpathFactory = XPathFactory.newInstance();
+ XPath xPath = xpathFactory.newXPath();
+ xPath.setNamespaceContext(nsContext);
+ XPathExpression xpathExpr = xPath.compile(xpath);
+ node = (Node) xpathExpr.evaluate(contextNode, XPathConstants.NODE);
+ } catch (XPathExpressionException e) {
+ log.info("Failed to evaluate SignatureLocation XPath expression '{}' on context node.", xpath, e);
+ throw new SLCommandException(4102);
+ }
+
+ if (node == null) {
+ log.info("Failed to evaluate SignatureLocation XPath expression '{}'. Result is empty.", xpath);
+ throw new SLCommandException(4102);
+ }
+
+ return node;
+
+ }
+
+ /**
+ * Finds the next sibling node of the <code>parent</code>'s <code>n</code>-th child node
+ * or <code>null</code> if there is no next sibling.
+ *
+ * @param parent the parent node
+ * @param n the index of the child node
+ *
+ * @return the next sibling node of the node specified by <code>parent</code> and index <code>n</code>,
+ * or <code>null</code> if there is no next sibling node.
+ *
+ * @throws SLCommandException if the <code>n</code>-th child of <code>parent</code> does not exist
+ */
+ private Node findNextSibling(Node parent, int n) throws SLCommandException {
+ return parent.getChildNodes().item(n);
+ }
+
+ /**
+ * Workaround for a missing namespace prefix declaration in MOA-ID.
+ *
+ * @author mcentner
+ */
+ private class MOAIDWorkaroundNamespaceContext implements NamespaceContext {
+
+ private NamespaceContext namespaceContext;
+
+ public MOAIDWorkaroundNamespaceContext(NamespaceContext namespaceContext) {
+ super();
+ this.namespaceContext = namespaceContext;
+ }
+
+ @Override
+ public String getNamespaceURI(String prefix) {
+
+ String namespaceURI = namespaceContext.getNamespaceURI(prefix);
+
+ if ((namespaceURI == null || XMLConstants.NULL_NS_URI.equals(namespaceURI)) && "saml".equals(prefix)) {
+ namespaceURI = "urn:oasis:names:tc:SAML:1.0:assertion";
+ log.debug("Namespace prefix '{}' resolved to '{}' (MOA-ID Workaround).", prefix, namespaceURI);
+ } else {
+ log.trace("Namespace prefix '{}' resolved to '{}'.", prefix, namespaceURI);
+ }
+
+ return namespaceURI;
+ }
+
+ @Override
+ public String getPrefix(String namespaceURI) {
+ return namespaceContext.getPrefix(namespaceURI);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterator getPrefixes(String namespaceURI) {
+ return namespaceContext.getPrefixes(namespaceURI);
+ }
+
+ }
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/URIDereferncerAdapter.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/URIDereferncerAdapter.java
index c94937be..5ae728b3 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/URIDereferncerAdapter.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/URIDereferncerAdapter.java
@@ -30,8 +30,7 @@ import javax.xml.crypto.URIReferenceException;
import javax.xml.crypto.XMLCryptoContext;
import at.gv.egiz.bku.utils.urldereferencer.StreamData;
-import at.gv.egiz.bku.utils.urldereferencer.URLDereferencer;
-import at.gv.egiz.bku.utils.urldereferencer.URLDereferencerContext;
+import at.gv.egiz.bku.utils.urldereferencer.URLDereferencer;
/**
* An URIDereferencer implementation that uses an {@link URLDereferencer} to
@@ -44,17 +43,17 @@ public class URIDereferncerAdapter implements URIDereferencer {
/**
* The context for dereferencing.
*/
- protected URLDereferencerContext urlDereferencerContext;
+ protected URLDereferencer dereferencer;
/**
* Creates a new URIDereferencerAdapter instance with the given
* <code>urlDereferencerContext</code>.
*
- * @param urlDereferencerContext the context to be used for dereferencing
+ * @param urlDereferencer the context to be used for dereferencing
*/
- public URIDereferncerAdapter(URLDereferencerContext urlDereferencerContext) {
+ public URIDereferncerAdapter(URLDereferencer urlDereferencer) {
super();
- this.urlDereferencerContext = urlDereferencerContext;
+ this.dereferencer = urlDereferencer;
}
/* (non-Javadoc)
@@ -78,10 +77,9 @@ public class URIDereferncerAdapter implements URIDereferencer {
if (uri.isAbsolute()) {
- URLDereferencer dereferencer = URLDereferencer.getInstance();
StreamData streamData;
try {
- streamData = dereferencer.dereference(uriString, urlDereferencerContext);
+ streamData = dereferencer.dereference(uriString);
} catch (IOException e) {
throw new URIReferenceException(e.getMessage(), e);
}