();
+ }
+ return this.chain;
+ }
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Command.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Command.java
new file mode 100644
index 00000000..fcba969f
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Command.java
@@ -0,0 +1,108 @@
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-520
+// See http://java.sun.com/xml/jaxb
+// Any modifications to this file will be lost upon recompilation of the source schema.
+// Generated on: 2008.09.03 at 01:53:08 PM GMT
+//
+
+
+package at.gv.egiz.bku.accesscontrol.config;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlSchemaType;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * Java class for anonymous complex type.
+ *
+ *
The following schema fragment specifies the expected content contained within this class.
+ *
+ *
+ * <complexType>
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element ref="{}Param" maxOccurs="unbounded" minOccurs="0"/>
+ * </sequence>
+ * <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}anySimpleType" />
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ *
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "", propOrder = {
+ "param"
+})
+@XmlRootElement(name = "Command")
+public class Command {
+
+ @XmlElement(name = "Param")
+ protected List param;
+ @XmlAttribute(name = "Name", required = true)
+ @XmlSchemaType(name = "anySimpleType")
+ protected String name;
+
+ /**
+ * Gets the value of the param property.
+ *
+ *
+ * This accessor method returns a reference to the live list,
+ * not a snapshot. Therefore any modification you make to the
+ * returned list will be present inside the JAXB object.
+ * This is why there is not a set
method for the param property.
+ *
+ *
+ * For example, to add a new item, do as follows:
+ *
+ * getParam().add(newItem);
+ *
+ *
+ *
+ *
+ * Objects of the following type(s) are allowed in the list
+ * {@link Param }
+ *
+ *
+ */
+ public List getParam() {
+ if (param == null) {
+ param = new ArrayList();
+ }
+ return this.param;
+ }
+
+ /**
+ * Gets the value of the name property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the value of the name property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setName(String value) {
+ this.name = value;
+ }
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/ObjectFactory.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/ObjectFactory.java
new file mode 100644
index 00000000..7291d759
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/ObjectFactory.java
@@ -0,0 +1,134 @@
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-520
+// See http://java.sun.com/xml/jaxb
+// Any modifications to this file will be lost upon recompilation of the source schema.
+// Generated on: 2008.09.03 at 01:53:08 PM GMT
+//
+
+
+package at.gv.egiz.bku.accesscontrol.config;
+
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.annotation.XmlElementDecl;
+import javax.xml.bind.annotation.XmlRegistry;
+import javax.xml.namespace.QName;
+
+
+/**
+ * This object contains factory methods for each
+ * Java content interface and Java element interface
+ * generated in the at.gv.egiz.bku.accesscontrol.config package.
+ *
An ObjectFactory allows you to programatically
+ * construct new instances of the Java representation
+ * for XML content. The Java representation of XML
+ * content can consist of schema derived interfaces
+ * and classes representing the binding of schema
+ * type definitions, element declarations and model
+ * groups. Factory methods for each of these are
+ * provided in this class.
+ *
+ */
+@XmlRegistry
+public class ObjectFactory {
+
+ private final static QName _UserInteraction_QNAME = new QName("", "UserInteraction");
+ private final static QName _AuthClass_QNAME = new QName("", "AuthClass");
+
+ /**
+ * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: at.gv.egiz.bku.accesscontrol.config
+ *
+ */
+ public ObjectFactory() {
+ }
+
+ /**
+ * Create an instance of {@link AccessControl }
+ *
+ */
+ public AccessControl createAccessControl() {
+ return new AccessControl();
+ }
+
+ /**
+ * Create an instance of {@link Chain }
+ *
+ */
+ public Chain createChain() {
+ return new Chain();
+ }
+
+ /**
+ * Create an instance of {@link Command }
+ *
+ */
+ public Command createCommand() {
+ return new Command();
+ }
+
+ /**
+ * Create an instance of {@link Chains }
+ *
+ */
+ public Chains createChains() {
+ return new Chains();
+ }
+
+ /**
+ * Create an instance of {@link Rule }
+ *
+ */
+ public Rule createRule() {
+ return new Rule();
+ }
+
+ /**
+ * Create an instance of {@link Rule.AnyPeer }
+ *
+ */
+ public Rule.AnyPeer createRuleAnyPeer() {
+ return new Rule.AnyPeer();
+ }
+
+ /**
+ * Create an instance of {@link Rules }
+ *
+ */
+ public Rules createRules() {
+ return new Rules();
+ }
+
+ /**
+ * Create an instance of {@link Param }
+ *
+ */
+ public Param createParam() {
+ return new Param();
+ }
+
+ /**
+ * Create an instance of {@link Action }
+ *
+ */
+ public Action createAction() {
+ return new Action();
+ }
+
+ /**
+ * Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >}}
+ *
+ */
+ @XmlElementDecl(namespace = "", name = "UserInteraction")
+ public JAXBElement createUserInteraction(String value) {
+ return new JAXBElement(_UserInteraction_QNAME, String.class, null, value);
+ }
+
+ /**
+ * Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >}}
+ *
+ */
+ @XmlElementDecl(namespace = "", name = "AuthClass")
+ public JAXBElement createAuthClass(String value) {
+ return new JAXBElement(_AuthClass_QNAME, String.class, null, value);
+ }
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Param.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Param.java
new file mode 100644
index 00000000..44afc196
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Param.java
@@ -0,0 +1,101 @@
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-520
+// See http://java.sun.com/xml/jaxb
+// Any modifications to this file will be lost upon recompilation of the source schema.
+// Generated on: 2008.09.03 at 01:53:08 PM GMT
+//
+
+
+package at.gv.egiz.bku.accesscontrol.config;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlSchemaType;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlValue;
+import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+
+/**
+ * Java class for anonymous complex type.
+ *
+ *
The following schema fragment specifies the expected content contained within this class.
+ *
+ *
+ * <complexType>
+ * <simpleContent>
+ * <extension base="<http://www.w3.org/2001/XMLSchema>string">
+ * <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}NCName" />
+ * </extension>
+ * </simpleContent>
+ * </complexType>
+ *
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "", propOrder = {
+ "value"
+})
+@XmlRootElement(name = "Param")
+public class Param {
+
+ @XmlValue
+ protected String value;
+ @XmlAttribute(name = "Name", required = true)
+ @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
+ @XmlSchemaType(name = "NCName")
+ protected String name;
+
+ /**
+ * Gets the value of the value property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * Sets the value of the value property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ /**
+ * Gets the value of the name property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the value of the name property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setName(String value) {
+ this.name = value;
+ }
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Rule.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Rule.java
new file mode 100644
index 00000000..3c85f256
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Rule.java
@@ -0,0 +1,342 @@
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-520
+// See http://java.sun.com/xml/jaxb
+// Any modifications to this file will be lost upon recompilation of the source schema.
+// Generated on: 2008.09.03 at 01:53:08 PM GMT
+//
+
+
+package at.gv.egiz.bku.accesscontrol.config;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlID;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlSchemaType;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+
+/**
+ * Java class for anonymous complex type.
+ *
+ *
The following schema fragment specifies the expected content contained within this class.
+ *
+ *
+ * <complexType>
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element ref="{}AuthClass"/>
+ * <choice>
+ * <element name="AnyPeer">
+ * <complexType>
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </element>
+ * <element name="DomainName" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ * <element name="IPv4Address" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ * <element name="URL" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ * </choice>
+ * <element ref="{}Command" minOccurs="0"/>
+ * <element ref="{}Action" maxOccurs="unbounded"/>
+ * <element ref="{}UserInteraction"/>
+ * </sequence>
+ * <attribute name="Id" type="{http://www.w3.org/2001/XMLSchema}ID" />
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ *
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "", propOrder = {
+ "authClass",
+ "anyPeer",
+ "domainName",
+ "iPv4Address",
+ "url",
+ "command",
+ "action",
+ "userInteraction"
+})
+@XmlRootElement(name = "Rule")
+public class Rule {
+
+ @XmlElement(name = "AuthClass", required = true)
+ protected String authClass;
+ @XmlElement(name = "AnyPeer")
+ protected Rule.AnyPeer anyPeer;
+ @XmlElement(name = "DomainName")
+ protected String domainName;
+ @XmlElement(name = "IPv4Address")
+ protected String iPv4Address;
+ @XmlElement(name = "URL")
+ protected String url;
+ @XmlElement(name = "Command")
+ protected Command command;
+ @XmlElement(name = "Action", required = true)
+ protected List action;
+ @XmlElement(name = "UserInteraction", required = true)
+ protected String userInteraction;
+ @XmlAttribute(name = "Id")
+ @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
+ @XmlID
+ @XmlSchemaType(name = "ID")
+ protected String id;
+
+ /**
+ * Gets the value of the authClass property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getAuthClass() {
+ return authClass;
+ }
+
+ /**
+ * Sets the value of the authClass property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setAuthClass(String value) {
+ this.authClass = value;
+ }
+
+ /**
+ * Gets the value of the anyPeer property.
+ *
+ * @return
+ * possible object is
+ * {@link Rule.AnyPeer }
+ *
+ */
+ public Rule.AnyPeer getAnyPeer() {
+ return anyPeer;
+ }
+
+ /**
+ * Sets the value of the anyPeer property.
+ *
+ * @param value
+ * allowed object is
+ * {@link Rule.AnyPeer }
+ *
+ */
+ public void setAnyPeer(Rule.AnyPeer value) {
+ this.anyPeer = value;
+ }
+
+ /**
+ * Gets the value of the domainName property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getDomainName() {
+ return domainName;
+ }
+
+ /**
+ * Sets the value of the domainName property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setDomainName(String value) {
+ this.domainName = value;
+ }
+
+ /**
+ * Gets the value of the iPv4Address property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getIPv4Address() {
+ return iPv4Address;
+ }
+
+ /**
+ * Sets the value of the iPv4Address property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setIPv4Address(String value) {
+ this.iPv4Address = value;
+ }
+
+ /**
+ * Gets the value of the url property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getURL() {
+ return url;
+ }
+
+ /**
+ * Sets the value of the url property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setURL(String value) {
+ this.url = value;
+ }
+
+ /**
+ * Gets the value of the command property.
+ *
+ * @return
+ * possible object is
+ * {@link Command }
+ *
+ */
+ public Command getCommand() {
+ return command;
+ }
+
+ /**
+ * Sets the value of the command property.
+ *
+ * @param value
+ * allowed object is
+ * {@link Command }
+ *
+ */
+ public void setCommand(Command value) {
+ this.command = value;
+ }
+
+ /**
+ * Gets the value of the action property.
+ *
+ *
+ * This accessor method returns a reference to the live list,
+ * not a snapshot. Therefore any modification you make to the
+ * returned list will be present inside the JAXB object.
+ * This is why there is not a set
method for the action property.
+ *
+ *
+ * For example, to add a new item, do as follows:
+ *
+ * getAction().add(newItem);
+ *
+ *
+ *
+ *
+ * Objects of the following type(s) are allowed in the list
+ * {@link Action }
+ *
+ *
+ */
+ public List getAction() {
+ if (action == null) {
+ action = new ArrayList();
+ }
+ return this.action;
+ }
+
+ /**
+ * Gets the value of the userInteraction property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getUserInteraction() {
+ return userInteraction;
+ }
+
+ /**
+ * Sets the value of the userInteraction property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setUserInteraction(String value) {
+ this.userInteraction = value;
+ }
+
+ /**
+ * Gets the value of the id property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * Sets the value of the id property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setId(String value) {
+ this.id = value;
+ }
+
+
+ /**
+ * Java class for anonymous complex type.
+ *
+ *
The following schema fragment specifies the expected content contained within this class.
+ *
+ *
+ * <complexType>
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ *
+ *
+ *
+ */
+ @XmlAccessorType(XmlAccessType.FIELD)
+ @XmlType(name = "")
+ public static class AnyPeer {
+
+
+ }
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Rules.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Rules.java
new file mode 100644
index 00000000..5a5fa11f
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Rules.java
@@ -0,0 +1,78 @@
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-520
+// See http://java.sun.com/xml/jaxb
+// Any modifications to this file will be lost upon recompilation of the source schema.
+// Generated on: 2008.09.03 at 01:53:08 PM GMT
+//
+
+
+package at.gv.egiz.bku.accesscontrol.config;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * Java class for anonymous complex type.
+ *
+ *
The following schema fragment specifies the expected content contained within this class.
+ *
+ *
+ * <complexType>
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element ref="{}Rule" maxOccurs="unbounded"/>
+ * </sequence>
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ *
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "", propOrder = {
+ "rule"
+})
+@XmlRootElement(name = "Rules")
+public class Rules {
+
+ @XmlElement(name = "Rule", required = true)
+ protected List rule;
+
+ /**
+ * Gets the value of the rule property.
+ *
+ *
+ * This accessor method returns a reference to the live list,
+ * not a snapshot. Therefore any modification you make to the
+ * returned list will be present inside the JAXB object.
+ * This is why there is not a set
method for the rule property.
+ *
+ *
+ * For example, to add a new item, do as follows:
+ *
+ * getRule().add(newItem);
+ *
+ *
+ *
+ *
+ * Objects of the following type(s) are allowed in the list
+ * {@link Rule }
+ *
+ *
+ */
+ public List getRule() {
+ if (rule == null) {
+ rule = new ArrayList();
+ }
+ return this.rule;
+ }
+
+}
--
cgit v1.2.3
From 838aaacdd713d262801aa99ff161866a8939ec11 Mon Sep 17 00:00:00 2001
From: clemenso
Date: Wed, 3 Sep 2008 14:53:43 +0000
Subject: accesscontrol config
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@10 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
---
.../bku/accesscontrol/config/AccessControl.java | 2 +-
.../gv/egiz/bku/accesscontrol/config/Action.java | 2 +-
.../at/gv/egiz/bku/accesscontrol/config/Chain.java | 2 +-
.../gv/egiz/bku/accesscontrol/config/Chains.java | 2 +-
.../gv/egiz/bku/accesscontrol/config/Command.java | 2 +-
.../bku/accesscontrol/config/ObjectFactory.java | 52 +++++-----
.../at/gv/egiz/bku/accesscontrol/config/Param.java | 2 +-
.../at/gv/egiz/bku/accesscontrol/config/Rule.java | 108 ++++-----------------
.../at/gv/egiz/bku/accesscontrol/config/Rules.java | 2 +-
9 files changed, 50 insertions(+), 124 deletions(-)
(limited to 'bkucommon/src/main/java')
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/AccessControl.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/AccessControl.java
index c9efaca6..90271231 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/AccessControl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/AccessControl.java
@@ -2,7 +2,7 @@
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-520
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
-// Generated on: 2008.09.03 at 01:53:08 PM GMT
+// Generated on: 2008.09.03 at 02:52:44 PM GMT
//
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Action.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Action.java
index 8d457d1c..b9c8fa83 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Action.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Action.java
@@ -2,7 +2,7 @@
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-520
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
-// Generated on: 2008.09.03 at 01:53:08 PM GMT
+// Generated on: 2008.09.03 at 02:52:44 PM GMT
//
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Chain.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Chain.java
index aa0b920b..1408c8d8 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Chain.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Chain.java
@@ -2,7 +2,7 @@
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-520
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
-// Generated on: 2008.09.03 at 01:53:08 PM GMT
+// Generated on: 2008.09.03 at 02:52:44 PM GMT
//
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Chains.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Chains.java
index f75c8dba..d58f7bad 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Chains.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Chains.java
@@ -2,7 +2,7 @@
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-520
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
-// Generated on: 2008.09.03 at 01:53:08 PM GMT
+// Generated on: 2008.09.03 at 02:52:44 PM GMT
//
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Command.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Command.java
index fcba969f..0d25ca1c 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Command.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Command.java
@@ -2,7 +2,7 @@
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-520
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
-// Generated on: 2008.09.03 at 01:53:08 PM GMT
+// Generated on: 2008.09.03 at 02:52:44 PM GMT
//
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/ObjectFactory.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/ObjectFactory.java
index 7291d759..0efa4beb 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/ObjectFactory.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/ObjectFactory.java
@@ -2,7 +2,7 @@
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-520
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
-// Generated on: 2008.09.03 at 01:53:08 PM GMT
+// Generated on: 2008.09.03 at 02:52:44 PM GMT
//
@@ -42,19 +42,19 @@ public class ObjectFactory {
}
/**
- * Create an instance of {@link AccessControl }
+ * Create an instance of {@link Param }
*
*/
- public AccessControl createAccessControl() {
- return new AccessControl();
+ public Param createParam() {
+ return new Param();
}
/**
- * Create an instance of {@link Chain }
+ * Create an instance of {@link AccessControl }
*
*/
- public Chain createChain() {
- return new Chain();
+ public AccessControl createAccessControl() {
+ return new AccessControl();
}
/**
@@ -66,51 +66,43 @@ public class ObjectFactory {
}
/**
- * Create an instance of {@link Chains }
- *
- */
- public Chains createChains() {
- return new Chains();
- }
-
- /**
- * Create an instance of {@link Rule }
+ * Create an instance of {@link Rules }
*
*/
- public Rule createRule() {
- return new Rule();
+ public Rules createRules() {
+ return new Rules();
}
/**
- * Create an instance of {@link Rule.AnyPeer }
+ * Create an instance of {@link Action }
*
*/
- public Rule.AnyPeer createRuleAnyPeer() {
- return new Rule.AnyPeer();
+ public Action createAction() {
+ return new Action();
}
/**
- * Create an instance of {@link Rules }
+ * Create an instance of {@link Chains }
*
*/
- public Rules createRules() {
- return new Rules();
+ public Chains createChains() {
+ return new Chains();
}
/**
- * Create an instance of {@link Param }
+ * Create an instance of {@link Chain }
*
*/
- public Param createParam() {
- return new Param();
+ public Chain createChain() {
+ return new Chain();
}
/**
- * Create an instance of {@link Action }
+ * Create an instance of {@link Rule }
*
*/
- public Action createAction() {
- return new Action();
+ public Rule createRule() {
+ return new Rule();
}
/**
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Param.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Param.java
index 44afc196..94e190ff 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Param.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Param.java
@@ -2,7 +2,7 @@
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-520
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
-// Generated on: 2008.09.03 at 01:53:08 PM GMT
+// Generated on: 2008.09.03 at 02:52:44 PM GMT
//
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Rule.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Rule.java
index 3c85f256..512cced9 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Rule.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Rule.java
@@ -2,14 +2,12 @@
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-520
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
-// Generated on: 2008.09.03 at 01:53:08 PM GMT
+// Generated on: 2008.09.03 at 02:52:44 PM GMT
//
package at.gv.egiz.bku.accesscontrol.config;
-import java.util.ArrayList;
-import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
@@ -33,21 +31,13 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element ref="{}AuthClass"/>
- * <choice>
- * <element name="AnyPeer">
- * <complexType>
- * <complexContent>
- * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- * </restriction>
- * </complexContent>
- * </complexType>
- * </element>
+ * <choice minOccurs="0">
* <element name="DomainName" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="IPv4Address" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="URL" type="{http://www.w3.org/2001/XMLSchema}string"/>
* </choice>
* <element ref="{}Command" minOccurs="0"/>
- * <element ref="{}Action" maxOccurs="unbounded"/>
+ * <element ref="{}Action"/>
* <element ref="{}UserInteraction"/>
* </sequence>
* <attribute name="Id" type="{http://www.w3.org/2001/XMLSchema}ID" />
@@ -61,7 +51,6 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"authClass",
- "anyPeer",
"domainName",
"iPv4Address",
"url",
@@ -74,8 +63,6 @@ public class Rule {
@XmlElement(name = "AuthClass", required = true)
protected String authClass;
- @XmlElement(name = "AnyPeer")
- protected Rule.AnyPeer anyPeer;
@XmlElement(name = "DomainName")
protected String domainName;
@XmlElement(name = "IPv4Address")
@@ -85,7 +72,7 @@ public class Rule {
@XmlElement(name = "Command")
protected Command command;
@XmlElement(name = "Action", required = true)
- protected List action;
+ protected Action action;
@XmlElement(name = "UserInteraction", required = true)
protected String userInteraction;
@XmlAttribute(name = "Id")
@@ -118,30 +105,6 @@ public class Rule {
this.authClass = value;
}
- /**
- * Gets the value of the anyPeer property.
- *
- * @return
- * possible object is
- * {@link Rule.AnyPeer }
- *
- */
- public Rule.AnyPeer getAnyPeer() {
- return anyPeer;
- }
-
- /**
- * Sets the value of the anyPeer property.
- *
- * @param value
- * allowed object is
- * {@link Rule.AnyPeer }
- *
- */
- public void setAnyPeer(Rule.AnyPeer value) {
- this.anyPeer = value;
- }
-
/**
* Gets the value of the domainName property.
*
@@ -241,30 +204,25 @@ public class Rule {
/**
* Gets the value of the action property.
*
- *
- * This accessor method returns a reference to the live list,
- * not a snapshot. Therefore any modification you make to the
- * returned list will be present inside the JAXB object.
- * This is why there is not a set
method for the action property.
- *
- *
- * For example, to add a new item, do as follows:
- *
- * getAction().add(newItem);
- *
- *
- *
- *
- * Objects of the following type(s) are allowed in the list
- * {@link Action }
- *
+ * @return
+ * possible object is
+ * {@link Action }
+ *
+ */
+ public Action getAction() {
+ return action;
+ }
+
+ /**
+ * Sets the value of the action property.
*
+ * @param value
+ * allowed object is
+ * {@link Action }
+ *
*/
- public List getAction() {
- if (action == null) {
- action = new ArrayList();
- }
- return this.action;
+ public void setAction(Action value) {
+ this.action = value;
}
/**
@@ -315,28 +273,4 @@ public class Rule {
this.id = value;
}
-
- /**
- * Java class for anonymous complex type.
- *
- *
The following schema fragment specifies the expected content contained within this class.
- *
- *
- * <complexType>
- * <complexContent>
- * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- * </restriction>
- * </complexContent>
- * </complexType>
- *
- *
- *
- */
- @XmlAccessorType(XmlAccessType.FIELD)
- @XmlType(name = "")
- public static class AnyPeer {
-
-
- }
-
}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Rules.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Rules.java
index 5a5fa11f..6429e58a 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Rules.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Rules.java
@@ -2,7 +2,7 @@
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-520
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
-// Generated on: 2008.09.03 at 01:53:08 PM GMT
+// Generated on: 2008.09.03 at 02:52:44 PM GMT
//
--
cgit v1.2.3
From 3099f0f157d6a1f6c9df2183833b3279b44211f0 Mon Sep 17 00:00:00 2001
From: clemenso
Date: Wed, 3 Sep 2008 15:06:39 +0000
Subject: accesscontrol config
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@11 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
---
.../at/gv/egiz/bku/accesscontrol/config/Action.java | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
(limited to 'bkucommon/src/main/java')
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Action.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Action.java
index b9c8fa83..b4ae938c 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Action.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Action.java
@@ -2,7 +2,7 @@
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-520
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
-// Generated on: 2008.09.03 at 02:52:44 PM GMT
+// Generated on: 2008.09.03 at 03:06:11 PM GMT
//
@@ -11,9 +11,7 @@ package at.gv.egiz.bku.accesscontrol.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlIDREF;
import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
@@ -27,7 +25,7 @@ import javax.xml.bind.annotation.XmlType;
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <choice>
- * <element name="ChainRef" type="{http://www.w3.org/2001/XMLSchema}IDREF"/>
+ * <element name="ChainRef" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="RuleAction">
* <simpleType>
* <restriction base="{http://www.w3.org/2001/XMLSchema}string">
@@ -53,9 +51,7 @@ import javax.xml.bind.annotation.XmlType;
public class Action {
@XmlElement(name = "ChainRef")
- @XmlIDREF
- @XmlSchemaType(name = "IDREF")
- protected Object chainRef;
+ protected String chainRef;
@XmlElement(name = "RuleAction")
protected String ruleAction;
@@ -64,10 +60,10 @@ public class Action {
*
* @return
* possible object is
- * {@link Object }
+ * {@link String }
*
*/
- public Object getChainRef() {
+ public String getChainRef() {
return chainRef;
}
@@ -76,10 +72,10 @@ public class Action {
*
* @param value
* allowed object is
- * {@link Object }
+ * {@link String }
*
*/
- public void setChainRef(Object value) {
+ public void setChainRef(String value) {
this.chainRef = value;
}
--
cgit v1.2.3
From 2f029b9cb3ebc11abe28e0b2801bacc40cb584b1 Mon Sep 17 00:00:00 2001
From: wbauer
Date: Wed, 3 Sep 2008 15:19:48 +0000
Subject: Just a backup of updated accesscontroller files
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@12 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
---
.../accesscontroller/AccessControllerFactory.java | 68 ++++++++++++-
.../gv/egiz/bku/accesscontroller/ChainResult.java | 1 +
.../bku/accesscontroller/InfoboxRuleChecker.java | 14 +++
.../gv/egiz/bku/accesscontroller/RuleChecker.java | 112 ++++++++++++++++++---
4 files changed, 179 insertions(+), 16 deletions(-)
create mode 100644 bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/InfoboxRuleChecker.java
(limited to 'bkucommon/src/main/java')
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AccessControllerFactory.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AccessControllerFactory.java
index 9b3e563d..3b75a5f2 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AccessControllerFactory.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AccessControllerFactory.java
@@ -1,10 +1,38 @@
package at.gv.egiz.bku.accesscontroller;
+import java.io.InputStream;
import java.util.Hashtable;
+import java.util.List;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import at.gv.egiz.bku.accesscontrol.config.AccessControl;
+import at.gv.egiz.bku.accesscontrol.config.Chain;
+import at.gv.egiz.bku.accesscontrol.config.Command;
+import at.gv.egiz.bku.accesscontrol.config.ObjectFactory;
+import at.gv.egiz.bku.accesscontrol.config.Rule;
+import at.gv.egiz.bku.slcommands.impl.InfoboxReadCommandImpl;
+import at.gv.egiz.bku.slexceptions.SLRuntimeException;
public class AccessControllerFactory {
- private static AccessControllerFactory instance;
+ private static AccessControllerFactory instance = new AccessControllerFactory();
+ private static Log log = LogFactory.getLog(AccessControllerFactory.class);
+ private static JAXBContext jaxbContext;
+
+ static {
+ try {
+ jaxbContext = JAXBContext.newInstance(ObjectFactory.class.getPackage()
+ .getName());
+ } catch (JAXBException e) {
+ log.fatal("Cannot init jaxbContext", e);
+ }
+ }
private Hashtable chainTable = new Hashtable();
@@ -35,5 +63,43 @@ public class AccessControllerFactory {
public void registerChainChecker(ChainChecker cc) {
chainTable.put(cc.getId(), cc);
}
+
+ public RuleChecker createRuleChecker(Rule rule) {
+ RuleChecker rc;
+ Command cmd = rule.getCommand();
+ if (cmd != null) {
+ if ((cmd.getParam() != null) && (cmd.getParam().size()>0)) {
+ if (cmd.getName().startsWith("Infobox")) {
+ rc = new InfoboxRuleChecker(rule.getId());
+ } else {
+ throw new SLRuntimeException("Cannot handle parameters for command "+cmd.getName());
+ }
+ } else {
+ rc = new RuleChecker(rule.getId());
+ }
+ } else {
+ rc = new RuleChecker(rule.getId());
+ }
+ // FIXME TODO cont. here
+
+
+ return rc;
+ }
+
+
+ public void init(InputStream is) throws JAXBException {
+ Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+ AccessControl ac = (AccessControl) unmarshaller.unmarshal(is);
+ List chainList = ac.getChains().getChain();
+ log.debug("Found "+chainList.size()+" chains in config");
+ for (Chain chain : chainList) {
+ List ruleList = chain.getRules().getRule();
+ log.debug("Found "+ruleList.size()+" rules in chain "+chain.getId());
+ for (Rule rule : ruleList) {
+ //rule.g
+ }
+ }
+
+ }
}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/ChainResult.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/ChainResult.java
index a534f4e5..a8fb789e 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/ChainResult.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/ChainResult.java
@@ -12,6 +12,7 @@ public class ChainResult {
public ChainResult(Action action, UserAction userAction, boolean matchFound) {
this.action = action;
this.userAction = userAction;
+ this.matchFound = matchFound;
}
public Action getAction() {
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/InfoboxRuleChecker.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/InfoboxRuleChecker.java
new file mode 100644
index 00000000..2981d24e
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/InfoboxRuleChecker.java
@@ -0,0 +1,14 @@
+package at.gv.egiz.bku.accesscontroller;
+
+/**
+ * Adds infobox parameter checks
+ * @author wbauer
+ *
+ */
+public class InfoboxRuleChecker extends RuleChecker {
+
+ public InfoboxRuleChecker(String id) {
+ super(id);
+ }
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/RuleChecker.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/RuleChecker.java
index bf46034d..c59f5b70 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/RuleChecker.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/RuleChecker.java
@@ -1,23 +1,36 @@
package at.gv.egiz.bku.accesscontroller;
+import java.net.InetAddress;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.UnknownHostException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import at.gv.egiz.bku.slcommands.SLCommand;
import at.gv.egiz.bku.slexceptions.SLRuntimeException;
public class RuleChecker implements AccessChecker {
-
+
private static Log log = LogFactory.getLog(RuleChecker.class);
-
- public static enum PEER_TYPE {HOST, IP, URL};
+
+ public static enum PEER_TYPE {
+ HOST, IP, URL
+ };
protected String id;
protected AuthenticationClass authenticationClass;
protected String commandName;
+ protected Pattern commandNamePattern;
protected String peerId;
+ protected Pattern peerIdPattern;
protected PEER_TYPE peerType;
protected Action action;
protected UserAction userAction;
+ protected String chainId;
public RuleChecker(String id) {
if (id == null) {
@@ -27,43 +40,112 @@ public class RuleChecker implements AccessChecker {
}
public void setAuthenticationClass(String ac) {
- AuthenticationClass tmp = AuthenticationClass.fromString(ac);
+ AuthenticationClass tmp = AuthenticationClass.fromString(ac);
if (tmp == null) {
- throw new SLRuntimeException("Unknown authentication class "+ac);
+ throw new SLRuntimeException("Unknown authentication class " + ac);
}
authenticationClass = tmp;
}
-
+
public void setAction(String ac) {
Action tmp = Action.fromString(ac);
if (tmp == null) {
- throw new SLRuntimeException("Unknown action "+ac);
+ throw new SLRuntimeException("Unknown action " + ac);
}
action = tmp;
}
-
+
public void setUserAction(String uac) {
- UserAction tmp = UserAction.fromString(uac);
+ UserAction tmp = UserAction.fromString(uac);
if (tmp == null) {
- throw new SLRuntimeException("Unknown user action "+uac);
+ throw new SLRuntimeException("Unknown user action " + uac);
}
userAction = tmp;
}
-
+
+ public void setChainId(String chainId) {
+ this.chainId = chainId;
+ }
+
public void setPeerId(String peerId, PEER_TYPE type) {
this.peerType = type;
this.peerId = peerId;
+ peerIdPattern = Pattern.compile(peerId);
}
-
+
+ public void setCommandName(String commandName) {
+ this.commandName = commandName;
+ commandNamePattern = Pattern.compile(commandName);
+ }
+
public String getId() {
return id;
}
+ protected boolean matchAuthenticationClass(AuthenticationClass cls) {
+ if (this.authenticationClass == null) {
+ return true;
+ }
+ return this.authenticationClass.compareTo(cls) <= 0;
+ }
+
+ protected boolean matchCommandName(SLCommand cmd) {
+ if (commandName == null) {
+ return true;
+ }
+ Matcher matcher = commandNamePattern.matcher(cmd.getName());
+ return matcher.matches();
+ }
+
+ protected boolean matchPeerId(String peerUrl) {
+ if (peerId == null) {
+ return true;
+ }
+ if (peerType == PEER_TYPE.URL) {
+ Matcher matcher = peerIdPattern.matcher(peerUrl);
+ return matcher.matches();
+ } else {
+ try {
+ URL url = new URL(peerUrl);
+ if (peerType == PEER_TYPE.HOST) {
+ try {
+ String host = url.getHost();
+ String hostName = InetAddress.getByName(host).getCanonicalHostName();
+ Matcher matcher = peerIdPattern.matcher(hostName);
+ return matcher.matches();
+ } catch (UnknownHostException e) {
+ log.error("Cannot resolve hostname", e);
+ return false;
+ }
+ } else {
+ try {
+ String hostAddr = InetAddress.getByName(url.getHost())
+ .getHostAddress();
+ Matcher matcher = peerIdPattern.matcher(hostAddr);
+ return matcher.matches();
+ } catch (UnknownHostException e) {
+ log.error("Cannot resolve host address", e);
+ return false;
+ }
+ }
+ } catch (MalformedURLException e) {
+ log.error("Cannot parse url", e);
+ return false;
+ }
+ }
+ }
+
@Override
public RuleResult check(AccessCheckerContext checkCtx) {
- log.debug("Processing rule: "+id);
- // TODO Auto-generated method stub
- return null;
+ log.debug("Processing rule: " + id);
+ if (matchAuthenticationClass(checkCtx.getAuthenticationClass())
+ && matchCommandName(checkCtx.getCommand())
+ && matchPeerId(checkCtx.getPeerUrl())) {
+ log.debug("Match found for rule: " + id);
+ return new RuleResult(action, userAction, true, chainId);
+ }
+ log.debug("No match found for rule: " + id);
+ return new RuleResult(action, userAction, false, chainId);
}
}
--
cgit v1.2.3
From e0f2c64ad6360e2ecec983cb5e0a60f812672106 Mon Sep 17 00:00:00 2001
From: wbauer
Date: Thu, 4 Sep 2008 14:56:54 +0000
Subject: finished access controller, accessed it from command invoker and
configured everything within onlinebku
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@14 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
---
.../accesscontroller/AccessControllerFactory.java | 76 +-
.../gv/egiz/bku/accesscontroller/ChainChecker.java | 6 +-
.../bku/accesscontroller/CommandParamChecker.java | 52 +
.../bku/accesscontroller/InfoboxParamChecker.java | 58 +
.../bku/accesscontroller/InfoboxRuleChecker.java | 14 -
.../gv/egiz/bku/accesscontroller/RuleChecker.java | 72 +-
.../accesscontroller/SecurityManagerFacade.java | 102 ++
.../egiz/bku/binding/BindingProcessorManager.java | 15 +-
.../bku/binding/BindingProcessorManagerImpl.java | 20 +-
.../at/gv/egiz/bku/binding/DataUrlConnection.java | 17 +-
.../gv/egiz/bku/binding/DataUrlConnectionImpl.java | 7 +-
.../gv/egiz/bku/binding/HTTPBindingProcessor.java | 1634 ++++++++++----------
.../gv/egiz/bku/binding/SLCommandInvokerImpl.java | 157 +-
.../gv/egiz/bku/slcommands/InfoboxReadCommand.java | 10 +-
.../gv/egiz/bku/slcommands/SLCommandInvoker.java | 7 +-
.../at/gv/egiz/bku/slcommands/SLSourceContext.java | 11 +-
.../at/gv/egiz/bku/slcommands/SLTargetContext.java | 13 +-
.../slcommands/impl/InfoboxReadCommandImpl.java | 7 +-
18 files changed, 1302 insertions(+), 976 deletions(-)
create mode 100644 bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/CommandParamChecker.java
create mode 100644 bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/InfoboxParamChecker.java
delete mode 100644 bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/InfoboxRuleChecker.java
create mode 100644 bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/SecurityManagerFacade.java
(limited to 'bkucommon/src/main/java')
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AccessControllerFactory.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AccessControllerFactory.java
index 3b75a5f2..cd837cd7 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AccessControllerFactory.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AccessControllerFactory.java
@@ -15,8 +15,9 @@ import at.gv.egiz.bku.accesscontrol.config.AccessControl;
import at.gv.egiz.bku.accesscontrol.config.Chain;
import at.gv.egiz.bku.accesscontrol.config.Command;
import at.gv.egiz.bku.accesscontrol.config.ObjectFactory;
+import at.gv.egiz.bku.accesscontrol.config.Param;
import at.gv.egiz.bku.accesscontrol.config.Rule;
-import at.gv.egiz.bku.slcommands.impl.InfoboxReadCommandImpl;
+import at.gv.egiz.bku.accesscontroller.RuleChecker.PEER_TYPE;
import at.gv.egiz.bku.slexceptions.SLRuntimeException;
public class AccessControllerFactory {
@@ -24,6 +25,8 @@ public class AccessControllerFactory {
private static AccessControllerFactory instance = new AccessControllerFactory();
private static Log log = LogFactory.getLog(AccessControllerFactory.class);
private static JAXBContext jaxbContext;
+ public static String INPUT_CHAIN = "InputChain";
+ public static String OUTPUT_CHAIN = "OutputChain";
static {
try {
@@ -63,43 +66,72 @@ public class AccessControllerFactory {
public void registerChainChecker(ChainChecker cc) {
chainTable.put(cc.getId(), cc);
}
-
+
+ public CommandParamChecker createParamChecker(String cmd) {
+ if ((cmd != null) && (cmd.startsWith("Infobox"))) {
+ return new InfoboxParamChecker();
+ } else {
+ return null;
+ }
+ }
+
public RuleChecker createRuleChecker(Rule rule) {
RuleChecker rc;
+ rc = new RuleChecker(rule.getId());
Command cmd = rule.getCommand();
if (cmd != null) {
- if ((cmd.getParam() != null) && (cmd.getParam().size()>0)) {
- if (cmd.getName().startsWith("Infobox")) {
- rc = new InfoboxRuleChecker(rule.getId());
- } else {
- throw new SLRuntimeException("Cannot handle parameters for command "+cmd.getName());
- }
- } else {
- rc = new RuleChecker(rule.getId());
+ rc.setCommandName(cmd.getName());
+ for (Param p : cmd.getParam()) {
+ rc.addParameter(p.getName(), p.getValue());
}
- } else {
- rc = new RuleChecker(rule.getId());
}
- // FIXME TODO cont. here
-
-
- return rc;
+ rc.setAuthenticationClass(rule.getAuthClass());
+ if (rule.getIPv4Address() != null) {
+ rc.setPeerId(rule.getIPv4Address(), PEER_TYPE.IP);
+ } else if (rule.getDomainName() != null) {
+ rc.setPeerId(rule.getDomainName(), PEER_TYPE.HOST);
+ } else if (rule.getURL() != null) {
+ rc.setPeerId(rule.getURL(), PEER_TYPE.URL);
+ }
+ rc.setAction(rule.getAction().getRuleAction());
+ rc.setChainId(rule.getAction().getChainRef());
+ rc.setUserAction(rule.getUserInteraction());
+ return rc;
}
-
-
+
public void init(InputStream is) throws JAXBException {
+ chainTable.clear();
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
AccessControl ac = (AccessControl) unmarshaller.unmarshal(is);
List chainList = ac.getChains().getChain();
- log.debug("Found "+chainList.size()+" chains in config");
+ log.debug("Found " + chainList.size() + " chains in config");
for (Chain chain : chainList) {
+ log.trace("Creating chain: " + chain.getId());
+ ChainChecker cc = createChainChecker(chain.getId(), false);
List ruleList = chain.getRules().getRule();
- log.debug("Found "+ruleList.size()+" rules in chain "+chain.getId());
+ log
+ .debug("Found " + ruleList.size() + " rules in chain "
+ + chain.getId());
for (Rule rule : ruleList) {
- //rule.g
+ log.trace("Creating rule: " + rule.getId());
+ cc.addRule(createRuleChecker(rule));
+ }
+ registerChainChecker(cc);
+ }
+ validate();
+ }
+
+ private void validate() {
+ for (ChainChecker chain : chainTable.values()) {
+ for (RuleChecker rule : chain.getRules()) {
+ if (rule.getChainId() != null) {
+ log.trace("Checking reference to chain: "+rule.getChainId());
+ if (getChainChecker(rule.getChainId()) == null) {
+ throw new SLRuntimeException("Invalid reference to unknown chain: "+rule.getChainId());
+ }
+ }
}
}
-
}
}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/ChainChecker.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/ChainChecker.java
index 242d9b02..a290fe8d 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/ChainChecker.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/ChainChecker.java
@@ -1,5 +1,6 @@
package at.gv.egiz.bku.accesscontroller;
+import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@@ -35,6 +36,10 @@ public class ChainChecker implements AccessChecker {
rules.add(rule);
}
}
+
+ public List getRules() {
+ return Collections.unmodifiableList(rules);
+ }
@Override
public ChainResult check(AccessCheckerContext checkCtx) throws SLException {
@@ -43,7 +48,6 @@ public class ChainChecker implements AccessChecker {
log.trace("Checking rule: "+rule.getId());
RuleResult result = rule.check(checkCtx);
if (result.matchFound()) {
- log.debug("Found matching rule: "+rule.getId());
if (result.getDelegateChainId() != null) {
// process chain
ChainChecker cc = AccessControllerFactory.getInstance().getChainChecker(result.getDelegateChainId());
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/CommandParamChecker.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/CommandParamChecker.java
new file mode 100644
index 00000000..3927c3c9
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/CommandParamChecker.java
@@ -0,0 +1,52 @@
+package at.gv.egiz.bku.accesscontroller;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import at.gv.egiz.bku.slcommands.SLCommand;
+
+public abstract class CommandParamChecker {
+
+ protected List> paramList = new LinkedList>();
+
+ public static class Tupel {
+ private T key;
+ private Q val;
+
+ public Tupel(T key, Q val) {
+ if ((key == null) || (val == null)) {
+ throw new NullPointerException("Tupel key and value must not be null");
+ }
+ this.key = key;
+ this.val = val;
+ }
+
+ public T getKey() {
+ return key;
+ }
+
+ public Q getVal() {
+ return val;
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean equals(Object other) {
+ if (other instanceof Tupel) {
+ Tupel ot = (Tupel) other;
+ return (key.equals(ot.key) && val.equals(ot.val));
+ }
+ return false;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ public void addParameter(String key, String value) {
+ paramList.add(new Tupel(key, value));
+ }
+
+ public abstract boolean checkParameter(SLCommand cmd);
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/InfoboxParamChecker.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/InfoboxParamChecker.java
new file mode 100644
index 00000000..33689ae0
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/InfoboxParamChecker.java
@@ -0,0 +1,58 @@
+package at.gv.egiz.bku.accesscontroller;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import at.gv.egiz.bku.slcommands.InfoboxReadCommand;
+import at.gv.egiz.bku.slcommands.SLCommand;
+import at.gv.egiz.bku.slexceptions.SLRuntimeException;
+
+public class InfoboxParamChecker extends CommandParamChecker {
+ private static Log log = LogFactory.getLog(InfoboxParamChecker.class);
+
+ public final static String INFOBOX_ID = "InfoboxIdentifier";
+ public final static String PERSON_ID = "PersonIdentifier";
+ public final static String DERIVED = "derived";
+
+ @Override
+ public boolean checkParameter(SLCommand cmd) {
+ if (paramList.size() == 0) {
+ return true;
+ }
+
+ if (cmd instanceof InfoboxReadCommand) {
+ InfoboxReadCommand irc = (InfoboxReadCommand) cmd;
+ for (Tupel param : paramList) {
+ if (param.getKey().equals(INFOBOX_ID)) {
+ if (!param.getVal().equals(irc.getInfoboxIdentifier())) {
+ return false;
+ }
+ } else if (param.getKey().equals(PERSON_ID)) {
+ if (param.getVal().equals(DERIVED)) {
+ if (irc.getIdentityLinkDomainId() == null) {
+ return false;
+ }
+ } else {
+ Pattern p = Pattern.compile(param.getVal());
+ Matcher m = p.matcher(irc.getIdentityLinkDomainId());
+ if (!m.matches()) {
+ return false;
+ }
+ }
+
+ } else {
+ throw new SLRuntimeException("Cannot handle parameter "
+ + param.getKey());
+ }
+ }
+ return true;
+ } else {
+ log.error("Cannot handle parameter for command: " + cmd.getName());
+ throw new SLRuntimeException("Cannot handle parameters for command: "
+ + cmd.getName());
+ }
+ }
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/InfoboxRuleChecker.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/InfoboxRuleChecker.java
deleted file mode 100644
index 2981d24e..00000000
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/InfoboxRuleChecker.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package at.gv.egiz.bku.accesscontroller;
-
-/**
- * Adds infobox parameter checks
- * @author wbauer
- *
- */
-public class InfoboxRuleChecker extends RuleChecker {
-
- public InfoboxRuleChecker(String id) {
- super(id);
- }
-
-}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/RuleChecker.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/RuleChecker.java
index c59f5b70..b0bf7fac 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/RuleChecker.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/RuleChecker.java
@@ -31,6 +31,7 @@ public class RuleChecker implements AccessChecker {
protected Action action;
protected UserAction userAction;
protected String chainId;
+ protected CommandParamChecker paramChecker;
public RuleChecker(String id) {
if (id == null) {
@@ -40,27 +41,33 @@ public class RuleChecker implements AccessChecker {
}
public void setAuthenticationClass(String ac) {
- AuthenticationClass tmp = AuthenticationClass.fromString(ac);
- if (tmp == null) {
- throw new SLRuntimeException("Unknown authentication class " + ac);
+ if (ac != null) {
+ AuthenticationClass tmp = AuthenticationClass.fromString(ac);
+ if (tmp == null) {
+ throw new SLRuntimeException("Unknown authentication class " + ac);
+ }
+ authenticationClass = tmp;
}
- authenticationClass = tmp;
}
public void setAction(String ac) {
- Action tmp = Action.fromString(ac);
- if (tmp == null) {
- throw new SLRuntimeException("Unknown action " + ac);
+ if (ac != null) {
+ Action tmp = Action.fromString(ac);
+ if (tmp == null) {
+ throw new SLRuntimeException("Unknown action " + ac);
+ }
+ action = tmp;
}
- action = tmp;
}
public void setUserAction(String uac) {
- UserAction tmp = UserAction.fromString(uac);
- if (tmp == null) {
- throw new SLRuntimeException("Unknown user action " + uac);
+ if (uac != null) {
+ UserAction tmp = UserAction.fromString(uac);
+ if (tmp == null) {
+ throw new SLRuntimeException("Unknown user action " + uac);
+ }
+ userAction = tmp;
}
- userAction = tmp;
}
public void setChainId(String chainId) {
@@ -76,6 +83,22 @@ public class RuleChecker implements AccessChecker {
public void setCommandName(String commandName) {
this.commandName = commandName;
commandNamePattern = Pattern.compile(commandName);
+ paramChecker = AccessControllerFactory.getInstance().createParamChecker(
+ commandName);
+ }
+
+ /**
+ * Make sure to set the commandName first
+ *
+ * @param key
+ * @param value
+ */
+ public void addParameter(String key, String value) {
+ if (paramChecker == null) {
+ throw new IllegalArgumentException("Cannot set parameters for command "
+ + commandName);
+ }
+ paramChecker.addParameter(key, value);
}
public String getId() {
@@ -83,22 +106,30 @@ public class RuleChecker implements AccessChecker {
}
protected boolean matchAuthenticationClass(AuthenticationClass cls) {
- if (this.authenticationClass == null) {
+ if ((this.authenticationClass == null) || (cls == null)) {
return true;
}
return this.authenticationClass.compareTo(cls) <= 0;
}
protected boolean matchCommandName(SLCommand cmd) {
- if (commandName == null) {
+ if ((commandName == null) || (cmd == null)) {
return true;
}
Matcher matcher = commandNamePattern.matcher(cmd.getName());
- return matcher.matches();
+ if (matcher.matches()) {
+ if (paramChecker != null) {
+ return paramChecker.checkParameter(cmd);
+ } else {
+ return true;
+ }
+ } else {
+ return false;
+ }
}
protected boolean matchPeerId(String peerUrl) {
- if (peerId == null) {
+ if ((peerId == null) || (peerUrl == null)) {
return true;
}
if (peerType == PEER_TYPE.URL) {
@@ -110,7 +141,8 @@ public class RuleChecker implements AccessChecker {
if (peerType == PEER_TYPE.HOST) {
try {
String host = url.getHost();
- String hostName = InetAddress.getByName(host).getCanonicalHostName();
+ String hostName = InetAddress.getByName(host)
+ .getCanonicalHostName();
Matcher matcher = peerIdPattern.matcher(hostName);
return matcher.matches();
} catch (UnknownHostException e) {
@@ -143,9 +175,13 @@ public class RuleChecker implements AccessChecker {
&& matchPeerId(checkCtx.getPeerUrl())) {
log.debug("Match found for rule: " + id);
return new RuleResult(action, userAction, true, chainId);
- }
+ }
log.debug("No match found for rule: " + id);
return new RuleResult(action, userAction, false, chainId);
}
+ public String getChainId() {
+ return chainId;
+ }
+
}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/SecurityManagerFacade.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/SecurityManagerFacade.java
new file mode 100644
index 00000000..32242772
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/SecurityManagerFacade.java
@@ -0,0 +1,102 @@
+package at.gv.egiz.bku.accesscontroller;
+
+import java.io.InputStream;
+
+import javax.xml.bind.JAXBException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import at.gv.egiz.bku.slcommands.SLCommand;
+import at.gv.egiz.bku.slcommands.SLSourceContext;
+import at.gv.egiz.bku.slcommands.SLTargetContext;
+
+/**
+ * Facade for the access controller
+ */
+public class SecurityManagerFacade {
+
+ private static Log log = LogFactory.getLog(SecurityManagerFacade.class);
+
+ private boolean allowUnmatched = false;
+ private ChainChecker inputFilter = null;
+ private ChainChecker outputFilter = null;
+
+ public boolean mayInvokeCommand(SLCommand cmd, SLSourceContext ctx) {
+ if (inputFilter != null) {
+ AuthenticationClass ac = AuthenticationClassifier.getAuthenticationClass(
+ ctx.isSourceIsDataURL(), ctx.getSourceUrl(), ctx
+ .getSourceCertificate());
+ AccessCheckerContext acc = new AccessCheckerContext(cmd, ac, ctx
+ .getSourceUrl().toString());
+ try {
+ ChainResult cr = inputFilter.check(acc);
+ if (cr.matchFound()) {
+ if (cr.getAction() == Action.ALLOW) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return allowUnmatched;
+ }
+ } catch (Exception e) {
+ log.error(e);
+ return false;
+ }
+ } else {
+ log.warn("No input chain defined");
+ return allowUnmatched;
+ }
+ }
+
+ public boolean maySendResult(SLCommand cmd, SLTargetContext ctx) {
+ if (outputFilter != null) {
+ AuthenticationClass ac = AuthenticationClassifier.getAuthenticationClass(
+ ctx.isTargetIsDataURL(), ctx.getTargetUrl(), ctx
+ .getTargetCertificate());
+ AccessCheckerContext acc = new AccessCheckerContext(cmd, ac, ctx
+ .getTargetUrl().toString());
+ try {
+ ChainResult cr = outputFilter.check(acc);
+ if (cr.matchFound()) {
+ if (cr.getAction() == Action.ALLOW) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return allowUnmatched;
+ }
+ } catch (Exception e) {
+ log.error(e);
+ return false;
+ }
+ } else {
+ log.warn("No output chain defined");
+ return allowUnmatched;
+ }
+ }
+
+ /**
+ * Default policy if not match was found
+ *
+ * @param allow
+ */
+ public void setAllowUnmatched(boolean allow) {
+ this.allowUnmatched = allow;
+ }
+
+ public void init(InputStream is) {
+ inputFilter = null;
+ outputFilter = null;
+ AccessControllerFactory fab = AccessControllerFactory.getInstance();
+ try {
+ fab.init(is);
+ } catch (JAXBException e) {
+ log.error(e);
+ }
+ inputFilter = fab.getChainChecker(AccessControllerFactory.INPUT_CHAIN);
+ outputFilter = fab.getChainChecker(AccessControllerFactory.OUTPUT_CHAIN);
+ }
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManager.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManager.java
index a4e5bd90..ed37f08f 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManager.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManager.java
@@ -16,6 +16,7 @@
*/
package at.gv.egiz.bku.binding;
+import java.net.MalformedURLException;
import java.util.Locale;
import java.util.Set;
@@ -34,28 +35,28 @@ public interface BindingProcessorManager {
* FactoryMethod creating a new BindingProcessor object.
* The created binding processor must be passed to the process method to execute.
*
- * @param protcol
- * the transport binding protocol
+ * @param urlString
+ * the source url
* @param aSessionId
* optional an external sessionId (e.g. http session) could be
* provided. This parameter may be null.
* @param locale the locale used for user interaction, may be null
*/
- public BindingProcessor createBindingProcessor(String protcol,
- String aSessionId, Locale locale);
+ public BindingProcessor createBindingProcessor(String urlString,
+ String aSessionId, Locale locale) throws MalformedURLException;
/**
* FactoryMethod creating a new BindingProcessor object.
* The created binding processor must be passed to the process method to execute.
*
* @param protcol
- * the transport binding protocol
+ * the source url
* @param aSessionId
* optional an external sessionId (e.g. http session) could be
* provided. This parameter may be null.
*/
- public BindingProcessor createBindingProcessor(String protcol,
- String aSessionId);
+ public BindingProcessor createBindingProcessor(String urlString,
+ String aSessionId) throws MalformedURLException;
/**
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManagerImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManagerImpl.java
index 7a3b1bb9..6f5ca2d2 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManagerImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManagerImpl.java
@@ -16,6 +16,8 @@
*/
package at.gv.egiz.bku.binding;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -152,20 +154,22 @@ public class BindingProcessorManagerImpl implements BindingProcessorManager {
/**
* Uses the default locale
*/
- public BindingProcessor createBindingProcessor(String protocol,
- String aSessionId) {
- return createBindingProcessor(protocol, aSessionId, null);
+ public BindingProcessor createBindingProcessor(String srcUrl,
+ String aSessionId) throws MalformedURLException {
+ return createBindingProcessor(srcUrl, aSessionId, null);
}
/**
* FactoryMethod creating a new BindingProcessor object.
*
* @param protocol
- * must not be null
+ * must not be null
+ * @throws MalformedURLException
*/
- public BindingProcessor createBindingProcessor(String protocol,
- String aSessionId, Locale locale) {
- String low = protocol.toLowerCase();
+ public BindingProcessor createBindingProcessor(String srcUrl,
+ String aSessionId, Locale locale) throws MalformedURLException {
+ URL url = new URL(srcUrl);
+ String low = url.getProtocol().toLowerCase();
Protocol proto = null;
for (int i = 0; i < SUPPORTED_PROTOCOLS.length; i++) {
if (SUPPORTED_PROTOCOLS[i].toString().equals(low)) {
@@ -177,7 +181,7 @@ public class BindingProcessorManagerImpl implements BindingProcessorManager {
throw new UnsupportedOperationException();
}
BindingProcessor bindingProcessor = new HTTPBindingProcessor(aSessionId,
- commandInvokerClass.newInstance(), proto);
+ commandInvokerClass.newInstance(), url);
STAL stal = stalFactory.createSTAL();
bindingProcessor.init(stal, commandInvokerClass.newInstance());
if (locale != null) {
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnection.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnection.java
index e6d5e075..6d654639 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnection.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnection.java
@@ -16,12 +16,13 @@
*/
package at.gv.egiz.bku.binding;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.SocketTimeoutException;
-import java.security.cert.X509Certificate;
-
-import at.gv.egiz.bku.slcommands.SLResult;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.SocketTimeoutException;
+import java.net.URL;
+import java.security.cert.X509Certificate;
+
+import at.gv.egiz.bku.slcommands.SLResult;
/**
* Transmit a security layer result to DataURL via HTTP POST, encoded as multipart/form-data.
@@ -41,7 +42,9 @@ public interface DataUrlConnection {
public static final String XML_RESPONSE_ENCODING = "UTF-8";
- public String getProtocol();
+ public String getProtocol();
+
+ public URL getUrl();
/**
* Set a HTTP Header.
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java
index 134d765e..9f5d70cb 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java
@@ -212,5 +212,10 @@ public class DataUrlConnectionImpl implements DataUrlConnectionSPI {
@Override
public DataUrlConnectionSPI newInstance() {
return new DataUrlConnectionImpl();
- }
+ }
+
+ @Override
+ public URL getUrl() {
+ return url;
+ }
}
\ No newline at end of file
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java
index b79f7d55..19f22126 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java
@@ -1,820 +1,818 @@
/*
-* 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.binding;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Reader;
-import java.security.cert.X509Certificate;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-
-import javax.net.ssl.SSLHandshakeException;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.URIResolver;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import at.gv.egiz.bku.slcommands.SLCommand;
-import at.gv.egiz.bku.slcommands.SLCommandContext;
-import at.gv.egiz.bku.slcommands.SLCommandFactory;
-import at.gv.egiz.bku.slcommands.SLCommandInvoker;
-import at.gv.egiz.bku.slcommands.SLResult;
-import at.gv.egiz.bku.slcommands.SLSourceContext;
-import at.gv.egiz.bku.slcommands.SLTargetContext;
-import at.gv.egiz.bku.slcommands.impl.ErrorResultImpl;
-import at.gv.egiz.bku.slexceptions.SLBindingException;
-import at.gv.egiz.bku.slexceptions.SLCanceledException;
-import at.gv.egiz.bku.slexceptions.SLException;
-import at.gv.egiz.bku.slexceptions.SLRuntimeException;
-import at.gv.egiz.bku.utils.StreamUtil;
-import at.gv.egiz.bku.utils.binding.Protocol;
-import at.gv.egiz.bku.utils.urldereferencer.FormDataURLSupplier;
-import at.gv.egiz.bku.utils.urldereferencer.SimpleFormDataContextImpl;
-import at.gv.egiz.bku.utils.urldereferencer.StreamData;
-import at.gv.egiz.bku.utils.urldereferencer.URIResolverAdapter;
-import at.gv.egiz.bku.utils.urldereferencer.URLDereferencer;
-import at.gv.egiz.bku.utils.urldereferencer.URLDereferencerContext;
-import at.gv.egiz.stal.QuitRequest;
-import at.gv.egiz.stal.STALRequest;
-
-/**
- * Class performing the HTTP binding as defined by the CCE specification.
- * Currently a huge monolithic class.
- * @TODO refactor
- */
-@SuppressWarnings("unchecked")
-public class HTTPBindingProcessor extends AbstractBindingProcessor implements
- FormDataURLSupplier {
-
- private static Log log = LogFactory.getLog(HTTPBindingProcessor.class);
-
- private static enum State {
- INIT, PROCESS, DATAURL, TRANSFORM, FINISHED
- };
-
- public final static Collection XML_REQ_TRANSFER_ENCODING = Arrays
- .asList(new String[] { "binary" });
-
- /**
- * Defines the maximum number of dataurl connects that are allowed within a
- * single SL Request processing.
- */
- protected static int MAX_DATAURL_HOPS = 10;
-
- protected static String XML_MIME_TYPE = "text/xml";
- protected static String BINARY_MIME_TYPE = "application/octet-stream";
-
- /**
- * If null everything is ok and the result is taken from the command invoker.
- */
- protected SLException bindingProcessorError;
- protected SLCommandInvoker commandInvoker;
- protected DataUrlResponse dataUrlResponse;
- protected Map headerMap = Collections.EMPTY_MAP;
- protected SLCommand slCommand;
- protected Map formParameterMap = new HashMap();
- protected SLSourceContext srcContex = new SLSourceContext();
- protected SLTargetContext targetContext = new SLTargetContext();
- protected Protocol protocol;
- protected State currentState = State.INIT;
- protected Transformer transformer = null;
- protected String resultContentType = null;
- protected SLResult slResult = null;
- protected int responseCode = 200;
- protected Map responseHeaders = Collections.EMPTY_MAP;
- protected Locale locale = Locale.getDefault();
-
- /**
- *
- * @param id
- * may be null. In this case a new session id will be created.
- * @param cmdInvoker
- * must not be null;
- */
- public HTTPBindingProcessor(String id, SLCommandInvoker cmdInvoker,
- Protocol protocol) {
- super(id);
- if ((protocol != Protocol.HTTP) && (protocol != Protocol.HTTPS)) {
- throw new SLRuntimeException("Protocol not supported: " + protocol);
- }
- if (cmdInvoker == null) {
- throw new NullPointerException("Commandinvoker cannot be set to null");
- }
- commandInvoker = cmdInvoker;
- this.protocol = protocol;
- srcContex.setSourceProtocol(protocol);
- srcContex.setSourceIsDataURL(false);
- }
-
- //----------------------------------------------------------------------------
- // ----------- BEGIN CONVENIENCE METHODS -----------
-
- protected void sendSTALQuit() {
- log.info("Sending QUIT command to STAL");
- List quit = new ArrayList(1);
- quit.add(new QuitRequest());
- getSTAL().handleRequest(quit);
- }
-
- protected String getFormParameterAsString(String formParameterName) {
- FormParameter fp = formParameterMap.get(formParameterName);
- return getFormParameterAsString(fp);
- }
-
- protected String getFormParameterAsString(FormParameter fp) {
- if (fp == null) {
- return null;
- }
- try {
- return StreamUtil.asString(fp.getFormParameterValue(), HttpUtil
- .getCharset(fp.getFormParameterContentType(), true));
- } catch (IOException e) {
- return null;
- }
- }
-
- protected String getDataUrl() {
- return getFormParameterAsString(FixedFormParameters.DATAURL);
- }
-
- protected String getStyleSheetUrl() {
- return getFormParameterAsString(FixedFormParameters.STYLESHEETURL);
- }
-
- protected List getFormParameters(String parameterNamePostfix) {
- List resultList = new ArrayList();
- for (Iterator fpi = formParameterMap.keySet().iterator(); fpi
- .hasNext();) {
- String paramName = fpi.next();
- if (paramName.endsWith(parameterNamePostfix)) {
- resultList.add(formParameterMap.get(paramName));
- }
- }
- return resultList;
- }
-
- protected List getTransferHeaders() {
- return getFormParameters("__");
- }
-
- protected List getTransferForms() {
- List resultList = new ArrayList();
- for (Iterator fpi = formParameterMap.keySet().iterator(); fpi
- .hasNext();) {
- String paramName = fpi.next();
- if ((paramName.endsWith("_")) && (!paramName.endsWith("__"))) {
- resultList.add(formParameterMap.get(paramName));
- }
- }
- return resultList;
- }
-
- protected void closeDataUrlConnection() {
- log.debug("Closing data url input stream");
- if (dataUrlResponse == null) {
- return;
- }
- InputStream is = dataUrlResponse.getStream();
- if (is != null) {
- try {
- is.close();
- } catch (IOException e) {
- log.info("Error closing input stream to dataurl server:" + e);
- }
- }
- }
-
- //----------------------------------------------------------------------------
- // ----------- END CONVENIENCE METHODS -----------
-
- //----------------------------------------------------------------------------
- // -- BEGIN Methods that handle the http binding activities as defined in the
- // activity diagram --
-
- protected void init() {
- log.info("Starting Bindingprocessor in Thread: "
- + Thread.currentThread().getId());
- if (bindingProcessorError != null) {
- log.debug("Detected binding processor error, sending quit command");
- // sendSTALQuit();
- currentState = State.FINISHED;
- } else if (slCommand == null) {
- log.error("SLCommand not set (consumeRequest not called ??)");
- bindingProcessorError = new SLException(2000);
- // sendSTALQuit();
- currentState = State.FINISHED;
- } else {
- currentState = State.PROCESS;
- }
- }
-
- protected void processRequest() {
- log.debug("Entered State: " + State.PROCESS);
- log.debug("Processing command: " + slCommand);
- commandInvoker.setCommand(slCommand);
- responseCode = 200;
- responseHeaders = Collections.EMPTY_MAP;
- try {
- commandInvoker.invoke(srcContex);
- } catch (SLCanceledException e) {
- log.info("Caught exception: " + e);
- bindingProcessorError = e;
- currentState = State.TRANSFORM;
- }
- dataUrlResponse = null;
- if (getDataUrl() != null) {
- log.debug("Data Url set to: " + getDataUrl());
- currentState = State.DATAURL;
- } else {
- log.debug("No data url set");
- currentState = State.TRANSFORM;
- }
- }
-
- protected void handleDataUrl() {
- log.debug("Entered State: " + State.DATAURL);
- try {
- DataUrl dataUrl = new DataUrl(getDataUrl());
- DataUrlConnection conn = dataUrl.openConnection();
-
- // set transfer headers
- for (FormParameter fp : getTransferHeaders()) {
- String paramString = getFormParameterAsString(fp);
- if (paramString == null) {
- log.error("Got empty transfer header, ignoring this");
- } else {
- String[] keyVal = paramString.split(":", 2);
- String key = keyVal[0];
- String val = null;
- if (keyVal.length == 2) {
- val = keyVal[1];
- }
- val = val.trim();
- log.debug("Setting header " + key + " to value " + val);
- conn.setHTTPHeader(key, val);
- }
- }
-
- // set transfer form parameters
- for (FormParameter fp : getTransferForms()) {
- String contentTransferEncoding = null;
- String contentType = fp.getFormParameterContentType();
- String charSet = HttpUtil.getCharset(contentType, false);
- if (charSet != null) {
- contentType = contentType.substring(0, contentType
- .lastIndexOf(HttpUtil.SEPERATOR[0]));
- }
- for (Iterator header = fp.getHeaderNames(); header.hasNext();) {
- if (HttpUtil.CONTENT_TRANSFER_ENCODING
- .equalsIgnoreCase(header.next())) {
- contentTransferEncoding = getFormParameterAsString(fp);
- }
- }
- log.debug("Setting form: " + fp.getFormParameterName()
- + " contentType: " + contentType + " charset: " + charSet
- + " contentTransferEncoding: " + contentTransferEncoding);
- conn.setHTTPFormParameter(fp.getFormParameterName(), fp
- .getFormParameterValue(), contentType, charSet,
- contentTransferEncoding);
- }
-
- // connect
- conn.connect();
- // fetch and set SL result
- targetContext.setTargetIsDataURL(true);
- targetContext.setTargetCertificate(conn.getServerCertificate());
- targetContext.setTargetProtocol(conn.getProtocol());
- SLResult result = commandInvoker.getResult(targetContext);
-
- // transfer result
- conn.transmit(result);
-
- // process Dataurl response
- dataUrlResponse = conn.getResponse();
- log.debug("Received data url response code: "
- + dataUrlResponse.getResponseCode());
- protocol = Protocol.fromString(conn.getProtocol());
-
- switch (dataUrlResponse.getResponseCode()) {
- case 200:
- String contentType = dataUrlResponse.getContentType();
- log.debug("Got dataurl response content type: " + contentType);
- if (contentType != null) {
- if ((contentType.startsWith(HttpUtil.APPLICATION_URL_ENCODED))
- || (contentType.startsWith(HttpUtil.MULTIPART_FOTMDATA))) {
- log.debug("Detected SL Request in dataurl response");
- // process headers and request
- setHTTPHeaders(dataUrlResponse.getResponseHeaders());
- consumeRequestStream(dataUrlResponse.getStream());
- closeDataUrlConnection();
- srcContex.setSourceCertificate(conn.getServerCertificate());
- srcContex.setSourceIsDataURL(true);
- srcContex
- .setSourceProtocol(Protocol.fromString(conn.getProtocol()));
- currentState = State.PROCESS;
- } else if (((contentType.startsWith(HttpUtil.TXT_HTML))
- || (contentType.startsWith(HttpUtil.TXT_PLAIN)) || (contentType
- .startsWith(HttpUtil.TXT_XML)))
- && (dataUrlResponse.isHttpResponseXMLOK())) {
- log.info("Dataurl response matches with content type: "
- + contentType);
- currentState = State.TRANSFORM;
-
- } else if ((contentType.startsWith(HttpUtil.TXT_XML))
- && (!dataUrlResponse.isHttpResponseXMLOK())) {
- log
- .debug("Detected text/xml dataurl response with content != ");
- headerMap.put(HttpUtil.HTTP_HEADER_CONTENT_TYPE, contentType);
- assignXMLRequest(dataUrlResponse.getStream(), HttpUtil.getCharset(
- contentType, true));
- closeDataUrlConnection();
- srcContex.setSourceCertificate(conn.getServerCertificate());
- srcContex.setSourceIsDataURL(true);
- srcContex
- .setSourceProtocol(Protocol.fromString(conn.getProtocol()));
- currentState = State.PROCESS;
- // just to be complete, actually not used
- srcContex.setSourceHTTPReferer(dataUrlResponse.getResponseHeaders()
- .get(HttpUtil.HTTP_HEADER_REFERER));
- } else {
- resultContentType = contentType;
- responseHeaders = dataUrlResponse.getResponseHeaders();
- responseCode = dataUrlResponse.getResponseCode();
- currentState = State.FINISHED;
- }
- } else {
- log.debug("Content type not set in dataurl response");
- closeDataUrlConnection();
- throw new SLBindingException(2007);
- }
-
- break;
- case 307:
- contentType = dataUrlResponse.getContentType();
- if ((contentType != null) && (contentType.startsWith(HttpUtil.TXT_XML))) {
- log.debug("Received dataurl response code 307 with XML content");
- String location = dataUrlResponse.getResponseHeaders().get(
- HttpUtil.HTTP_HEADER_LOCATION);
- if (location == null) {
- log
- .error("Did not get a location header for a 307 data url response");
- throw new SLBindingException(2003);
- }
- // consumeRequestStream(dataUrlResponse.getStream());
- FormParameterStore fp = new FormParameterStore();
- fp.init(location.getBytes(HttpUtil.DEFAULT_CHARSET),
- FixedFormParameters.DATAURL, null, null);
- formParameterMap.put(FixedFormParameters.DATAURL, fp);
- headerMap.put(HttpUtil.HTTP_HEADER_CONTENT_TYPE, contentType);
- assignXMLRequest(dataUrlResponse.getStream(), HttpUtil.getCharset(
- dataUrlResponse.getContentType(), true));
- closeDataUrlConnection();
- srcContex.setSourceCertificate(conn.getServerCertificate());
- srcContex.setSourceIsDataURL(true);
- srcContex.setSourceProtocol(Protocol.fromString(conn.getProtocol()));
- currentState = State.PROCESS;
- // just to be complete, actually not used
- srcContex.setSourceHTTPReferer(dataUrlResponse.getResponseHeaders()
- .get(HttpUtil.HTTP_HEADER_REFERER));
-
- } else {
- log.debug("Received dataurl response code 307 non XML content: "
- + dataUrlResponse.getContentType());
- resultContentType = dataUrlResponse.getContentType();
- currentState = State.FINISHED;
- }
- responseHeaders = dataUrlResponse.getResponseHeaders();
- responseCode = dataUrlResponse.getResponseCode();
- break;
-
- case 301:
- case 302:
- case 303:
- responseHeaders = dataUrlResponse.getResponseHeaders();
- responseCode = dataUrlResponse.getResponseCode();
- resultContentType = dataUrlResponse.getContentType();
- currentState = State.FINISHED;
- break;
-
- default:
- // issue error
- log.info("Unexpected response code from dataurl server: "
- + dataUrlResponse.getResponseCode());
- throw new SLBindingException(2007);
- }
-
- } catch (SLException slx) {
- bindingProcessorError = slx;
- log.error("Error during dataurl communication");
- resultContentType = HttpUtil.TXT_XML;
- currentState = State.TRANSFORM;
- } catch (SSLHandshakeException hx) {
- bindingProcessorError = new SLException(2010);
- log.info("Error during dataurl communication", hx);
- resultContentType = HttpUtil.TXT_XML;
- currentState = State.TRANSFORM;
- } catch (IOException e) {
- bindingProcessorError = new SLBindingException(2001);
- log.error("Error while data url handling", e);
- resultContentType = HttpUtil.TXT_XML;
- currentState = State.TRANSFORM;
- return;
- }
- }
-
- protected void transformResult() {
- log.debug("Entered State: " + State.TRANSFORM);
- if (bindingProcessorError != null) {
- resultContentType = HttpUtil.TXT_XML;
- } else if (dataUrlResponse != null) {
- resultContentType = dataUrlResponse.getContentType();
- } else {
- targetContext.setTargetIsDataURL(false);
- targetContext.setTargetProtocol(protocol.toString());
- try {
- slResult = commandInvoker.getResult(targetContext);
- resultContentType = slResult.getMimeType();
- log
- .debug("Successfully got SLResult from commandinvoker, setting mimetype to: "
- + resultContentType);
- } catch (SLCanceledException e) {
- log.info("Cannot get result from invoker:", e);
- bindingProcessorError = new SLException(6002);
- resultContentType = HttpUtil.TXT_XML;
- }
- }
- transformer = getTransformer(getStyleSheetUrl());
- if (transformer != null) {
- log.debug("Output transformation required");
- resultContentType = transformer.getOutputProperty("media-type");
- log.debug("Got media type from stylesheet: " + resultContentType);
- if (resultContentType == null) {
- log.debug("Setting to default text/xml result conent type");
- resultContentType = "text/xml";
- }
- log.debug("Deferring sytylesheet processing");
- }
- currentState = State.FINISHED;
- }
-
- protected void finished() {
- log.debug("Entered State: " + State.FINISHED);
- if (bindingProcessorError != null) {
- log.debug("Binding processor error, sending quit command");
- resultContentType = HttpUtil.TXT_XML;
- }
- sendSTALQuit();
- log.info("Terminating Bindingprocessor; Thread: "
- + Thread.currentThread().getId());
- }
-
- // -- END Methods that handle the http binding activities as defined in the
- // activity diagram --
- //----------------------------------------------------------------------------
-
- /**
- * Sets the headers of the SL Request. IMPORTANT: make sure to set all headers
- * before invoking {@link #consumeRequestStream(InputStream)}
- *
- * @param aHeaderMap
- * if null all header will be cleared.
- */
- public void setHTTPHeaders(Map aHeaderMap) {
- headerMap = new HashMap();
- // ensure lowercase keys
- if (aHeaderMap != null) {
- for (String s : aHeaderMap.keySet()) {
- if (s != null) {
- headerMap.put(s.toLowerCase(), aHeaderMap.get(s));
- if (s.equalsIgnoreCase(HttpUtil.HTTP_HEADER_REFERER)) {
- String referer = aHeaderMap.get(s);
- log.debug("Got referer header: " + referer);
- srcContex.setSourceHTTPReferer(referer);
- }
- }
- }
- }
- }
-
- public void setSourceCertificate(X509Certificate aCert) {
- srcContex.setSourceCertificate(aCert);
- }
-
- /**
- * The HTTPBindingProcessor does not handle redirect URLs. It only provides
- * the parameter.
- *
- * @return null if redirect url is not set.
- */
- public String getRedirectURL() {
- return getFormParameterAsString(FixedFormParameters.REDIRECTURL);
- }
-
- public String getFormDataContentType(String aParameterName) {
- FormParameter fp = formParameterMap.get(aParameterName);
- if (fp != null) {
- return fp.getFormParameterContentType();
- }
- return null;
- }
-
- public InputStream getFormData(String aParameterName) {
- FormParameter fp = formParameterMap.get(aParameterName);
- if (fp != null) {
- return fp.getFormParameterValue();
- }
- return null;
- }
-
- protected void assignXMLRequest(InputStream is, String charset)
- throws IOException, SLException {
- Reader r = new InputStreamReader(is, charset);
- StreamSource source = new StreamSource(r);
- SLCommandContext commandCtx = new SLCommandContext();
- commandCtx.setSTAL(getSTAL());
- commandCtx.setURLDereferencerContext(new SimpleFormDataContextImpl(this));
- slCommand = SLCommandFactory.getInstance().createSLCommand(source,
- commandCtx);
- log.debug("Created new command: " + slCommand);
- }
-
- @Override
- public void run() {
- boolean done = false;
- int hopcounter = 0;
- if (bindingProcessorError != null) {
- currentState = State.FINISHED;
- }
- try {
- while (!done) {
- try {
- switch (currentState) {
- case INIT:
- init();
- break;
- case PROCESS:
- processRequest();
- break;
- case DATAURL:
- handleDataUrl();
- if (++hopcounter > MAX_DATAURL_HOPS) {
- log.error("Maximum number of dataurl hops reached");
- bindingProcessorError = new SLBindingException(2000);
- currentState = State.FINISHED;
- }
- break;
- case TRANSFORM:
- transformResult();
- break;
- case FINISHED:
- done = true;
- finished();
- break;
- }
- } catch (RuntimeException rte) {
- throw rte;
- } catch (Exception t) {
- log.error("Caught unexpected exception", t);
- responseCode = 200;
- resultContentType = HttpUtil.TXT_XML;
- responseHeaders = Collections.EMPTY_MAP;
- bindingProcessorError = new SLException(2000);
- currentState = State.FINISHED;
- }
- }
- } catch (Throwable t) {
- log.error("Caught unexpected exception", t);
- responseCode = 200;
- resultContentType = HttpUtil.TXT_XML;
- responseHeaders = Collections.EMPTY_MAP;
- bindingProcessorError = new SLException(2000);
- currentState = State.FINISHED;
- }
- log.debug("Terminated http binding processor");
- }
-
- @Override
- public void consumeRequestStream(InputStream is) {
- try {
- log.debug("Start consuming request stream");
- formParameterMap.clear();
- String cl = headerMap
- .get(HttpUtil.HTTP_HEADER_CONTENT_TYPE.toLowerCase());
- if (cl == null) {
- log.info("No content type set in http header");
- throw new SLBindingException(2006);
- }
- InputDecoder id = InputDecoderFactory.getDecoder(cl, is);
- id.setContentType(cl);
- if (id == null) {
- log.error("Cannot get inputdecoder for is");
- throw new SLException(2006);
- }
- for (Iterator fpi = id.getFormParameterIterator(); fpi
- .hasNext();) {
- FormParameter fp = fpi.next();
- log.debug("Got request parameter with name: "
- + fp.getFormParameterName());
- if (fp.getFormParameterName().equals(FixedFormParameters.XMLREQUEST)) {
- log.debug("Creating XML Request");
- for (Iterator headerIterator = fp.getHeaderNames(); headerIterator
- .hasNext();) {
- String headerName = headerIterator.next();
- if (HttpUtil.CONTENT_TRANSFER_ENCODING.equalsIgnoreCase(headerName)) {
- String transferEncoding = fp.getHeaderValue(headerName);
- log.debug("Got transfer encoding for xmlrequest: "
- + transferEncoding);
- if (XML_REQ_TRANSFER_ENCODING.contains(transferEncoding)) {
- log.debug("Supported transfer encoding: " + transferEncoding);
- } else {
- log
- .error("Transferencoding not supported: "
- + transferEncoding);
- throw new SLBindingException(2005);
- }
- }
- }
- String charset = HttpUtil.getCharset(cl, true);
- assignXMLRequest(fp.getFormParameterValue(), charset);
- } else {
- FormParameterStore fps = new FormParameterStore();
- fps.init(fp);
- if (!fps.isEmpty()) {
- log.debug("Setting from parameter: " + fps.getFormParameterName());
- formParameterMap.put(fps.getFormParameterName(), fps);
- }
- }
- }
- if (slCommand == null) {
- throw new SLBindingException(2004);
- }
- if (is.read() != -1) {
- log.error("Request input stream not completely read");
- // consume rest of stream, should never occur
- throw new SLRuntimeException(
- "request input stream not consumed till end");
- }
- } catch (SLException slx) {
- log.info("Error while consuming input stream " + slx);
- bindingProcessorError = slx;
- } catch (Throwable t) {
- log.info("Error while consuming input stream " + t, t);
- bindingProcessorError = new SLException(2000);
- } finally {
- try {
- while (is.read() != -1)
- ;
- } catch (IOException e) {
- log.error(e);
- }
- }
- }
-
- @Override
- public String getResultContentType() {
- return resultContentType;
- }
-
- protected Transformer getTransformer(String styleSheetURL) {
- if (styleSheetURL == null) {
- log.debug("Stylesheet URL not set");
- return null;
- }
- try {
- URLDereferencerContext urlCtx = new SimpleFormDataContextImpl(this);
- URIResolver resolver = new URIResolverAdapter(URLDereferencer
- .getInstance(), urlCtx);
- TransformerFactory factory = TransformerFactory.newInstance();
- StreamData sd = URLDereferencer.getInstance().dereference(styleSheetURL,
- urlCtx);
- Transformer t = factory.newTransformer(new StreamSource(sd.getStream()));
- t.setURIResolver(resolver);
- return t;
- } catch (Exception ex) {
- log.info("Cannot instantiate transformer", ex);
- bindingProcessorError = new SLException(2002);
- return null;
- }
- }
-
- protected void handleBindingProcessorError(OutputStream os, String encoding,
- Transformer transformer) throws IOException {
- log.debug("Writing error as result");
- ErrorResultImpl error = new ErrorResultImpl(bindingProcessorError);
- try {
- error.writeTo(new StreamResult(new OutputStreamWriter(os, encoding)),
- transformer);
- } catch (TransformerException e) {
- log.fatal("Cannot write error result to stream", e);
- }
- }
-
- @Override
- public void writeResultTo(OutputStream os, String encoding)
- throws IOException {
- if (encoding == null) {
- encoding = HttpUtil.DEFAULT_CHARSET;
- }
- if (bindingProcessorError != null) {
- log.debug("Detected error in binding processor, writing error as result");
- handleBindingProcessorError(os, encoding, transformer);
- return;
- } else if (dataUrlResponse != null) {
- log.debug("Writing data url response as result");
- String charEnc = HttpUtil.getCharset(dataUrlResponse.getContentType(),
- true);
- InputStreamReader isr = new InputStreamReader(
- dataUrlResponse.getStream(), charEnc);
- OutputStreamWriter osw = new OutputStreamWriter(os, encoding);
- if (transformer == null) {
- StreamUtil.copyStream(isr, osw);
- } else {
- try {
- transformer.transform(new StreamSource(isr), new StreamResult(osw));
- } catch (TransformerException e) {
- log.fatal("Exception occured during result transformation", e);
- // bindingProcessorError = new SLException(2008);
- // handleBindingProcessorError(os, encoding, null);
- return;
- }
- }
- osw.flush();
- isr.close();
- } else if (slResult == null) {
- // result not yet assigned -> must be a cancel
- bindingProcessorError = new SLException(6001);
- handleBindingProcessorError(os, encoding, transformer);
- return;
- } else {
- log.debug("Getting result from invoker");
- OutputStreamWriter osw = new OutputStreamWriter(os, encoding);
- try {
- slResult.writeTo(new StreamResult(osw), transformer);
- } catch (TransformerException e) {
- log.fatal("Cannot write result to stream", e);
- // bindingProcessorError = new SLException(2008);
- // handleBindingProcessorError(os, encoding, transformer);
- }
- osw.flush();
- }
- }
-
- /**
- * The response code from the dataurl server or 200 if no dataurl server
- * created the result
- *
- * @return
- */
- public int getResponseCode() {
- return responseCode;
- }
-
- /**
- * All headers from the data url server in case of a direct forward from the
- * dataurl server.
- *
- * @return
- */
- public Map getResponseHeaders() {
- return responseHeaders;
- }
-
- @Override
- public void setLocale(Locale locale) {
- if (locale == null) {
- throw new NullPointerException("Locale must not be set to null");
- }
- this.locale = locale;
- }
-
+ * 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.binding;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.net.URL;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.net.ssl.SSLHandshakeException;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.URIResolver;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import at.gv.egiz.bku.slcommands.SLCommand;
+import at.gv.egiz.bku.slcommands.SLCommandContext;
+import at.gv.egiz.bku.slcommands.SLCommandFactory;
+import at.gv.egiz.bku.slcommands.SLCommandInvoker;
+import at.gv.egiz.bku.slcommands.SLResult;
+import at.gv.egiz.bku.slcommands.SLSourceContext;
+import at.gv.egiz.bku.slcommands.SLTargetContext;
+import at.gv.egiz.bku.slcommands.impl.ErrorResultImpl;
+import at.gv.egiz.bku.slexceptions.SLBindingException;
+import at.gv.egiz.bku.slexceptions.SLException;
+import at.gv.egiz.bku.slexceptions.SLRuntimeException;
+import at.gv.egiz.bku.utils.StreamUtil;
+import at.gv.egiz.bku.utils.binding.Protocol;
+import at.gv.egiz.bku.utils.urldereferencer.FormDataURLSupplier;
+import at.gv.egiz.bku.utils.urldereferencer.SimpleFormDataContextImpl;
+import at.gv.egiz.bku.utils.urldereferencer.StreamData;
+import at.gv.egiz.bku.utils.urldereferencer.URIResolverAdapter;
+import at.gv.egiz.bku.utils.urldereferencer.URLDereferencer;
+import at.gv.egiz.bku.utils.urldereferencer.URLDereferencerContext;
+import at.gv.egiz.stal.QuitRequest;
+import at.gv.egiz.stal.STALRequest;
+
+/**
+ * Class performing the HTTP binding as defined by the CCE specification.
+ * Currently a huge monolithic class.
+ *
+ * @TODO refactor
+ */
+@SuppressWarnings("unchecked")
+public class HTTPBindingProcessor extends AbstractBindingProcessor implements
+ FormDataURLSupplier {
+
+ private static Log log = LogFactory.getLog(HTTPBindingProcessor.class);
+
+ private static enum State {
+ INIT, PROCESS, DATAURL, TRANSFORM, FINISHED
+ };
+
+ public final static Collection XML_REQ_TRANSFER_ENCODING = Arrays
+ .asList(new String[] { "binary" });
+
+ /**
+ * Defines the maximum number of dataurl connects that are allowed within a
+ * single SL Request processing.
+ */
+ protected static int MAX_DATAURL_HOPS = 10;
+
+ protected static String XML_MIME_TYPE = "text/xml";
+ protected static String BINARY_MIME_TYPE = "application/octet-stream";
+
+ /**
+ * If null everything is ok and the result is taken from the command invoker.
+ */
+ protected SLException bindingProcessorError;
+ protected SLCommandInvoker commandInvoker;
+ protected DataUrlResponse dataUrlResponse;
+ protected Map headerMap = Collections.EMPTY_MAP;
+ protected SLCommand slCommand;
+ protected Map formParameterMap = new HashMap();
+ protected SLSourceContext srcContex = new SLSourceContext();
+ protected SLTargetContext targetContext = new SLTargetContext();
+ protected URL srcUrl;
+ protected State currentState = State.INIT;
+ protected Transformer transformer = null;
+ protected String resultContentType = null;
+ protected SLResult slResult = null;
+ protected int responseCode = 200;
+ protected Map responseHeaders = Collections.EMPTY_MAP;
+ protected Locale locale = Locale.getDefault();
+
+ /**
+ *
+ * @param id
+ * may be null. In this case a new session id will be created.
+ * @param cmdInvoker
+ * must not be null;
+ */
+ public HTTPBindingProcessor(String id, SLCommandInvoker cmdInvoker, URL source) {
+ super(id);
+ this.srcUrl = source;
+ Protocol protocol = Protocol.fromString(source.getProtocol());
+ if ((protocol != Protocol.HTTP) && (protocol != Protocol.HTTPS)) {
+ throw new SLRuntimeException("Protocol not supported: " + protocol);
+ }
+ if (cmdInvoker == null) {
+ throw new NullPointerException("Commandinvoker cannot be set to null");
+ }
+ commandInvoker = cmdInvoker;
+ srcContex.setSourceUrl(source);
+ srcContex.setSourceIsDataURL(false);
+ }
+
+ //----------------------------------------------------------------------------
+ // ----------- BEGIN CONVENIENCE METHODS -----------
+
+ protected void sendSTALQuit() {
+ log.info("Sending QUIT command to STAL");
+ List quit = new ArrayList(1);
+ quit.add(new QuitRequest());
+ getSTAL().handleRequest(quit);
+ }
+
+ protected String getFormParameterAsString(String formParameterName) {
+ FormParameter fp = formParameterMap.get(formParameterName);
+ return getFormParameterAsString(fp);
+ }
+
+ protected String getFormParameterAsString(FormParameter fp) {
+ if (fp == null) {
+ return null;
+ }
+ try {
+ return StreamUtil.asString(fp.getFormParameterValue(), HttpUtil
+ .getCharset(fp.getFormParameterContentType(), true));
+ } catch (IOException e) {
+ return null;
+ }
+ }
+
+ protected String getDataUrl() {
+ return getFormParameterAsString(FixedFormParameters.DATAURL);
+ }
+
+ protected String getStyleSheetUrl() {
+ return getFormParameterAsString(FixedFormParameters.STYLESHEETURL);
+ }
+
+ protected List getFormParameters(String parameterNamePostfix) {
+ List resultList = new ArrayList();
+ for (Iterator fpi = formParameterMap.keySet().iterator(); fpi
+ .hasNext();) {
+ String paramName = fpi.next();
+ if (paramName.endsWith(parameterNamePostfix)) {
+ resultList.add(formParameterMap.get(paramName));
+ }
+ }
+ return resultList;
+ }
+
+ protected List getTransferHeaders() {
+ return getFormParameters("__");
+ }
+
+ protected List getTransferForms() {
+ List resultList = new ArrayList();
+ for (Iterator fpi = formParameterMap.keySet().iterator(); fpi
+ .hasNext();) {
+ String paramName = fpi.next();
+ if ((paramName.endsWith("_")) && (!paramName.endsWith("__"))) {
+ resultList.add(formParameterMap.get(paramName));
+ }
+ }
+ return resultList;
+ }
+
+ protected void closeDataUrlConnection() {
+ log.debug("Closing data url input stream");
+ if (dataUrlResponse == null) {
+ return;
+ }
+ InputStream is = dataUrlResponse.getStream();
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ log.info("Error closing input stream to dataurl server:" + e);
+ }
+ }
+ }
+
+ //----------------------------------------------------------------------------
+ // ----------- END CONVENIENCE METHODS -----------
+
+ //----------------------------------------------------------------------------
+ // -- BEGIN Methods that handle the http binding activities as defined in the
+ // activity diagram --
+
+ protected void init() {
+ log.info("Starting Bindingprocessor in Thread: "
+ + Thread.currentThread().getId());
+ if (bindingProcessorError != null) {
+ log.debug("Detected binding processor error, sending quit command");
+ // sendSTALQuit();
+ currentState = State.FINISHED;
+ } else if (slCommand == null) {
+ log.error("SLCommand not set (consumeRequest not called ??)");
+ bindingProcessorError = new SLException(2000);
+ // sendSTALQuit();
+ currentState = State.FINISHED;
+ } else {
+ currentState = State.PROCESS;
+ }
+ }
+
+ protected void processRequest() {
+ log.debug("Entered State: " + State.PROCESS);
+ log.debug("Processing command: " + slCommand);
+ commandInvoker.setCommand(slCommand);
+ responseCode = 200;
+ responseHeaders = Collections.EMPTY_MAP;
+ try {
+ commandInvoker.invoke(srcContex);
+ } catch (SLException e) {
+ log.info("Caught exception: " + e);
+ bindingProcessorError = e;
+ currentState = State.TRANSFORM;
+ }
+ dataUrlResponse = null;
+ if (getDataUrl() != null) {
+ log.debug("Data Url set to: " + getDataUrl());
+ currentState = State.DATAURL;
+ } else {
+ log.debug("No data url set");
+ currentState = State.TRANSFORM;
+ }
+ }
+
+ protected void handleDataUrl() {
+ log.debug("Entered State: " + State.DATAURL);
+ try {
+ DataUrl dataUrl = new DataUrl(getDataUrl());
+ DataUrlConnection conn = dataUrl.openConnection();
+
+ // set transfer headers
+ for (FormParameter fp : getTransferHeaders()) {
+ String paramString = getFormParameterAsString(fp);
+ if (paramString == null) {
+ log.error("Got empty transfer header, ignoring this");
+ } else {
+ String[] keyVal = paramString.split(":", 2);
+ String key = keyVal[0];
+ String val = null;
+ if (keyVal.length == 2) {
+ val = keyVal[1];
+ }
+ val = val.trim();
+ log.debug("Setting header " + key + " to value " + val);
+ conn.setHTTPHeader(key, val);
+ }
+ }
+
+ // set transfer form parameters
+ for (FormParameter fp : getTransferForms()) {
+ String contentTransferEncoding = null;
+ String contentType = fp.getFormParameterContentType();
+ String charSet = HttpUtil.getCharset(contentType, false);
+ if (charSet != null) {
+ contentType = contentType.substring(0, contentType
+ .lastIndexOf(HttpUtil.SEPERATOR[0]));
+ }
+ for (Iterator header = fp.getHeaderNames(); header.hasNext();) {
+ if (HttpUtil.CONTENT_TRANSFER_ENCODING
+ .equalsIgnoreCase(header.next())) {
+ contentTransferEncoding = getFormParameterAsString(fp);
+ }
+ }
+ log.debug("Setting form: " + fp.getFormParameterName()
+ + " contentType: " + contentType + " charset: " + charSet
+ + " contentTransferEncoding: " + contentTransferEncoding);
+ conn.setHTTPFormParameter(fp.getFormParameterName(), fp
+ .getFormParameterValue(), contentType, charSet,
+ contentTransferEncoding);
+ }
+
+ // connect
+ conn.connect();
+ // fetch and set SL result
+ targetContext.setTargetIsDataURL(true);
+ targetContext.setTargetCertificate(conn.getServerCertificate());
+ targetContext.setTargetUrl(conn.getUrl());
+ SLResult result = commandInvoker.getResult(targetContext);
+
+ // transfer result
+ conn.transmit(result);
+
+ // process Dataurl response
+ dataUrlResponse = conn.getResponse();
+ log.debug("Received data url response code: "
+ + dataUrlResponse.getResponseCode());
+
+ switch (dataUrlResponse.getResponseCode()) {
+ case 200:
+ String contentType = dataUrlResponse.getContentType();
+ log.debug("Got dataurl response content type: " + contentType);
+ if (contentType != null) {
+ if ((contentType.startsWith(HttpUtil.APPLICATION_URL_ENCODED))
+ || (contentType.startsWith(HttpUtil.MULTIPART_FOTMDATA))) {
+ log.debug("Detected SL Request in dataurl response");
+ // process headers and request
+ setHTTPHeaders(dataUrlResponse.getResponseHeaders());
+ consumeRequestStream(dataUrlResponse.getStream());
+ closeDataUrlConnection();
+ srcContex.setSourceCertificate(conn.getServerCertificate());
+ srcContex.setSourceIsDataURL(true);
+ srcContex.setSourceUrl(conn.getUrl());
+ currentState = State.PROCESS;
+ } else if (((contentType.startsWith(HttpUtil.TXT_HTML))
+ || (contentType.startsWith(HttpUtil.TXT_PLAIN)) || (contentType
+ .startsWith(HttpUtil.TXT_XML)))
+ && (dataUrlResponse.isHttpResponseXMLOK())) {
+ log.info("Dataurl response matches with content type: "
+ + contentType);
+ currentState = State.TRANSFORM;
+
+ } else if ((contentType.startsWith(HttpUtil.TXT_XML))
+ && (!dataUrlResponse.isHttpResponseXMLOK())) {
+ log
+ .debug("Detected text/xml dataurl response with content != ");
+ headerMap.put(HttpUtil.HTTP_HEADER_CONTENT_TYPE, contentType);
+ assignXMLRequest(dataUrlResponse.getStream(), HttpUtil.getCharset(
+ contentType, true));
+ closeDataUrlConnection();
+ srcContex.setSourceCertificate(conn.getServerCertificate());
+ srcContex.setSourceIsDataURL(true);
+ srcContex.setSourceUrl(conn.getUrl());
+ currentState = State.PROCESS;
+ // just to be complete, actually not used
+ srcContex.setSourceHTTPReferer(dataUrlResponse.getResponseHeaders()
+ .get(HttpUtil.HTTP_HEADER_REFERER));
+ } else {
+ resultContentType = contentType;
+ responseHeaders = dataUrlResponse.getResponseHeaders();
+ responseCode = dataUrlResponse.getResponseCode();
+ currentState = State.FINISHED;
+ }
+ } else {
+ log.debug("Content type not set in dataurl response");
+ closeDataUrlConnection();
+ throw new SLBindingException(2007);
+ }
+
+ break;
+ case 307:
+ contentType = dataUrlResponse.getContentType();
+ if ((contentType != null) && (contentType.startsWith(HttpUtil.TXT_XML))) {
+ log.debug("Received dataurl response code 307 with XML content");
+ String location = dataUrlResponse.getResponseHeaders().get(
+ HttpUtil.HTTP_HEADER_LOCATION);
+ if (location == null) {
+ log
+ .error("Did not get a location header for a 307 data url response");
+ throw new SLBindingException(2003);
+ }
+ // consumeRequestStream(dataUrlResponse.getStream());
+ FormParameterStore fp = new FormParameterStore();
+ fp.init(location.getBytes(HttpUtil.DEFAULT_CHARSET),
+ FixedFormParameters.DATAURL, null, null);
+ formParameterMap.put(FixedFormParameters.DATAURL, fp);
+ headerMap.put(HttpUtil.HTTP_HEADER_CONTENT_TYPE, contentType);
+ assignXMLRequest(dataUrlResponse.getStream(), HttpUtil.getCharset(
+ dataUrlResponse.getContentType(), true));
+ closeDataUrlConnection();
+ srcContex.setSourceCertificate(conn.getServerCertificate());
+ srcContex.setSourceIsDataURL(true);
+ srcContex.setSourceUrl(conn.getUrl());
+ currentState = State.PROCESS;
+ // just to be complete, actually not used
+ srcContex.setSourceHTTPReferer(dataUrlResponse.getResponseHeaders()
+ .get(HttpUtil.HTTP_HEADER_REFERER));
+
+ } else {
+ log.debug("Received dataurl response code 307 non XML content: "
+ + dataUrlResponse.getContentType());
+ resultContentType = dataUrlResponse.getContentType();
+ currentState = State.FINISHED;
+ }
+ responseHeaders = dataUrlResponse.getResponseHeaders();
+ responseCode = dataUrlResponse.getResponseCode();
+ break;
+
+ case 301:
+ case 302:
+ case 303:
+ responseHeaders = dataUrlResponse.getResponseHeaders();
+ responseCode = dataUrlResponse.getResponseCode();
+ resultContentType = dataUrlResponse.getContentType();
+ currentState = State.FINISHED;
+ break;
+
+ default:
+ // issue error
+ log.info("Unexpected response code from dataurl server: "
+ + dataUrlResponse.getResponseCode());
+ throw new SLBindingException(2007);
+ }
+
+ } catch (SLException slx) {
+ bindingProcessorError = slx;
+ log.error("Error during dataurl communication");
+ resultContentType = HttpUtil.TXT_XML;
+ currentState = State.TRANSFORM;
+ } catch (SSLHandshakeException hx) {
+ bindingProcessorError = new SLException(2010);
+ log.info("Error during dataurl communication", hx);
+ resultContentType = HttpUtil.TXT_XML;
+ currentState = State.TRANSFORM;
+ } catch (IOException e) {
+ bindingProcessorError = new SLBindingException(2001);
+ log.error("Error while data url handling", e);
+ resultContentType = HttpUtil.TXT_XML;
+ currentState = State.TRANSFORM;
+ return;
+ }
+ }
+
+ protected void transformResult() {
+ log.debug("Entered State: " + State.TRANSFORM);
+ if (bindingProcessorError != null) {
+ resultContentType = HttpUtil.TXT_XML;
+ } else if (dataUrlResponse != null) {
+ resultContentType = dataUrlResponse.getContentType();
+ } else {
+ targetContext.setTargetIsDataURL(false);
+ targetContext.setTargetUrl(srcUrl);
+ try {
+ slResult = commandInvoker.getResult(targetContext);
+ resultContentType = slResult.getMimeType();
+ log
+ .debug("Successfully got SLResult from commandinvoker, setting mimetype to: "
+ + resultContentType);
+ } catch (SLException e) {
+ log.info("Cannot get result from invoker:", e);
+ bindingProcessorError = new SLException(6002);
+ resultContentType = HttpUtil.TXT_XML;
+ }
+ }
+ transformer = getTransformer(getStyleSheetUrl());
+ if (transformer != null) {
+ log.debug("Output transformation required");
+ resultContentType = transformer.getOutputProperty("media-type");
+ log.debug("Got media type from stylesheet: " + resultContentType);
+ if (resultContentType == null) {
+ log.debug("Setting to default text/xml result conent type");
+ resultContentType = "text/xml";
+ }
+ log.debug("Deferring sytylesheet processing");
+ }
+ currentState = State.FINISHED;
+ }
+
+ protected void finished() {
+ log.debug("Entered State: " + State.FINISHED);
+ if (bindingProcessorError != null) {
+ log.debug("Binding processor error, sending quit command");
+ resultContentType = HttpUtil.TXT_XML;
+ }
+ sendSTALQuit();
+ log.info("Terminating Bindingprocessor; Thread: "
+ + Thread.currentThread().getId());
+ }
+
+ // -- END Methods that handle the http binding activities as defined in the
+ // activity diagram --
+ //----------------------------------------------------------------------------
+
+ /**
+ * Sets the headers of the SL Request. IMPORTANT: make sure to set all headers
+ * before invoking {@link #consumeRequestStream(InputStream)}
+ *
+ * @param aHeaderMap
+ * if null all header will be cleared.
+ */
+ public void setHTTPHeaders(Map aHeaderMap) {
+ headerMap = new HashMap();
+ // ensure lowercase keys
+ if (aHeaderMap != null) {
+ for (String s : aHeaderMap.keySet()) {
+ if (s != null) {
+ headerMap.put(s.toLowerCase(), aHeaderMap.get(s));
+ if (s.equalsIgnoreCase(HttpUtil.HTTP_HEADER_REFERER)) {
+ String referer = aHeaderMap.get(s);
+ log.debug("Got referer header: " + referer);
+ srcContex.setSourceHTTPReferer(referer);
+ }
+ }
+ }
+ }
+ }
+
+ public void setSourceCertificate(X509Certificate aCert) {
+ srcContex.setSourceCertificate(aCert);
+ }
+
+ /**
+ * The HTTPBindingProcessor does not handle redirect URLs. It only provides
+ * the parameter.
+ *
+ * @return null if redirect url is not set.
+ */
+ public String getRedirectURL() {
+ return getFormParameterAsString(FixedFormParameters.REDIRECTURL);
+ }
+
+ public String getFormDataContentType(String aParameterName) {
+ FormParameter fp = formParameterMap.get(aParameterName);
+ if (fp != null) {
+ return fp.getFormParameterContentType();
+ }
+ return null;
+ }
+
+ public InputStream getFormData(String aParameterName) {
+ FormParameter fp = formParameterMap.get(aParameterName);
+ if (fp != null) {
+ return fp.getFormParameterValue();
+ }
+ return null;
+ }
+
+ protected void assignXMLRequest(InputStream is, String charset)
+ throws IOException, SLException {
+ Reader r = new InputStreamReader(is, charset);
+ StreamSource source = new StreamSource(r);
+ SLCommandContext commandCtx = new SLCommandContext();
+ commandCtx.setSTAL(getSTAL());
+ commandCtx.setURLDereferencerContext(new SimpleFormDataContextImpl(this));
+ slCommand = SLCommandFactory.getInstance().createSLCommand(source,
+ commandCtx);
+ log.debug("Created new command: " + slCommand);
+ }
+
+ @Override
+ public void run() {
+ boolean done = false;
+ int hopcounter = 0;
+ if (bindingProcessorError != null) {
+ currentState = State.FINISHED;
+ }
+ try {
+ while (!done) {
+ try {
+ switch (currentState) {
+ case INIT:
+ init();
+ break;
+ case PROCESS:
+ processRequest();
+ break;
+ case DATAURL:
+ handleDataUrl();
+ if (++hopcounter > MAX_DATAURL_HOPS) {
+ log.error("Maximum number of dataurl hops reached");
+ bindingProcessorError = new SLBindingException(2000);
+ currentState = State.FINISHED;
+ }
+ break;
+ case TRANSFORM:
+ transformResult();
+ break;
+ case FINISHED:
+ done = true;
+ finished();
+ break;
+ }
+ } catch (RuntimeException rte) {
+ throw rte;
+ } catch (Exception t) {
+ log.error("Caught unexpected exception", t);
+ responseCode = 200;
+ resultContentType = HttpUtil.TXT_XML;
+ responseHeaders = Collections.EMPTY_MAP;
+ bindingProcessorError = new SLException(2000);
+ currentState = State.FINISHED;
+ }
+ }
+ } catch (Throwable t) {
+ log.error("Caught unexpected exception", t);
+ responseCode = 200;
+ resultContentType = HttpUtil.TXT_XML;
+ responseHeaders = Collections.EMPTY_MAP;
+ bindingProcessorError = new SLException(2000);
+ currentState = State.FINISHED;
+ }
+ log.debug("Terminated http binding processor");
+ }
+
+ @Override
+ public void consumeRequestStream(InputStream is) {
+ try {
+ log.debug("Start consuming request stream");
+ formParameterMap.clear();
+ String cl = headerMap
+ .get(HttpUtil.HTTP_HEADER_CONTENT_TYPE.toLowerCase());
+ if (cl == null) {
+ log.info("No content type set in http header");
+ throw new SLBindingException(2006);
+ }
+ InputDecoder id = InputDecoderFactory.getDecoder(cl, is);
+ id.setContentType(cl);
+ if (id == null) {
+ log.error("Cannot get inputdecoder for is");
+ throw new SLException(2006);
+ }
+ for (Iterator fpi = id.getFormParameterIterator(); fpi
+ .hasNext();) {
+ FormParameter fp = fpi.next();
+ log.debug("Got request parameter with name: "
+ + fp.getFormParameterName());
+ if (fp.getFormParameterName().equals(FixedFormParameters.XMLREQUEST)) {
+ log.debug("Creating XML Request");
+ for (Iterator headerIterator = fp.getHeaderNames(); headerIterator
+ .hasNext();) {
+ String headerName = headerIterator.next();
+ if (HttpUtil.CONTENT_TRANSFER_ENCODING.equalsIgnoreCase(headerName)) {
+ String transferEncoding = fp.getHeaderValue(headerName);
+ log.debug("Got transfer encoding for xmlrequest: "
+ + transferEncoding);
+ if (XML_REQ_TRANSFER_ENCODING.contains(transferEncoding)) {
+ log.debug("Supported transfer encoding: " + transferEncoding);
+ } else {
+ log
+ .error("Transferencoding not supported: "
+ + transferEncoding);
+ throw new SLBindingException(2005);
+ }
+ }
+ }
+ String charset = HttpUtil.getCharset(cl, true);
+ assignXMLRequest(fp.getFormParameterValue(), charset);
+ } else {
+ FormParameterStore fps = new FormParameterStore();
+ fps.init(fp);
+ if (!fps.isEmpty()) {
+ log.debug("Setting from parameter: " + fps.getFormParameterName());
+ formParameterMap.put(fps.getFormParameterName(), fps);
+ }
+ }
+ }
+ if (slCommand == null) {
+ throw new SLBindingException(2004);
+ }
+ if (is.read() != -1) {
+ log.error("Request input stream not completely read");
+ // consume rest of stream, should never occur
+ throw new SLRuntimeException(
+ "request input stream not consumed till end");
+ }
+ } catch (SLException slx) {
+ log.info("Error while consuming input stream " + slx);
+ bindingProcessorError = slx;
+ } catch (Throwable t) {
+ log.info("Error while consuming input stream " + t, t);
+ bindingProcessorError = new SLException(2000);
+ } finally {
+ try {
+ while (is.read() != -1)
+ ;
+ } catch (IOException e) {
+ log.error(e);
+ }
+ }
+ }
+
+ @Override
+ public String getResultContentType() {
+ return resultContentType;
+ }
+
+ protected Transformer getTransformer(String styleSheetURL) {
+ if (styleSheetURL == null) {
+ log.debug("Stylesheet URL not set");
+ return null;
+ }
+ try {
+ URLDereferencerContext urlCtx = new SimpleFormDataContextImpl(this);
+ URIResolver resolver = new URIResolverAdapter(URLDereferencer
+ .getInstance(), urlCtx);
+ TransformerFactory factory = TransformerFactory.newInstance();
+ StreamData sd = URLDereferencer.getInstance().dereference(styleSheetURL,
+ urlCtx);
+ Transformer t = factory.newTransformer(new StreamSource(sd.getStream()));
+ t.setURIResolver(resolver);
+ return t;
+ } catch (Exception ex) {
+ log.info("Cannot instantiate transformer", ex);
+ bindingProcessorError = new SLException(2002);
+ return null;
+ }
+ }
+
+ protected void handleBindingProcessorError(OutputStream os, String encoding,
+ Transformer transformer) throws IOException {
+ log.debug("Writing error as result");
+ ErrorResultImpl error = new ErrorResultImpl(bindingProcessorError);
+ try {
+ error.writeTo(new StreamResult(new OutputStreamWriter(os, encoding)),
+ transformer);
+ } catch (TransformerException e) {
+ log.fatal("Cannot write error result to stream", e);
+ }
+ }
+
+ @Override
+ public void writeResultTo(OutputStream os, String encoding)
+ throws IOException {
+ if (encoding == null) {
+ encoding = HttpUtil.DEFAULT_CHARSET;
+ }
+ if (bindingProcessorError != null) {
+ log.debug("Detected error in binding processor, writing error as result");
+ handleBindingProcessorError(os, encoding, transformer);
+ return;
+ } else if (dataUrlResponse != null) {
+ log.debug("Writing data url response as result");
+ String charEnc = HttpUtil.getCharset(dataUrlResponse.getContentType(),
+ true);
+ InputStreamReader isr = new InputStreamReader(
+ dataUrlResponse.getStream(), charEnc);
+ OutputStreamWriter osw = new OutputStreamWriter(os, encoding);
+ if (transformer == null) {
+ StreamUtil.copyStream(isr, osw);
+ } else {
+ try {
+ transformer.transform(new StreamSource(isr), new StreamResult(osw));
+ } catch (TransformerException e) {
+ log.fatal("Exception occured during result transformation", e);
+ // bindingProcessorError = new SLException(2008);
+ // handleBindingProcessorError(os, encoding, null);
+ return;
+ }
+ }
+ osw.flush();
+ isr.close();
+ } else if (slResult == null) {
+ // result not yet assigned -> must be a cancel
+ bindingProcessorError = new SLException(6001);
+ handleBindingProcessorError(os, encoding, transformer);
+ return;
+ } else {
+ log.debug("Getting result from invoker");
+ OutputStreamWriter osw = new OutputStreamWriter(os, encoding);
+ try {
+ slResult.writeTo(new StreamResult(osw), transformer);
+ } catch (TransformerException e) {
+ log.fatal("Cannot write result to stream", e);
+ // bindingProcessorError = new SLException(2008);
+ // handleBindingProcessorError(os, encoding, transformer);
+ }
+ osw.flush();
+ }
+ }
+
+ /**
+ * The response code from the dataurl server or 200 if no dataurl server
+ * created the result
+ *
+ * @return
+ */
+ public int getResponseCode() {
+ return responseCode;
+ }
+
+ /**
+ * All headers from the data url server in case of a direct forward from the
+ * dataurl server.
+ *
+ * @return
+ */
+ public Map getResponseHeaders() {
+ return responseHeaders;
+ }
+
+ @Override
+ public void setLocale(Locale locale) {
+ if (locale == null) {
+ throw new NullPointerException("Locale must not be set to null");
+ }
+ this.locale = locale;
+ }
+
}
\ No newline at end of file
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/SLCommandInvokerImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/SLCommandInvokerImpl.java
index ef2affd1..a23d96e8 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/SLCommandInvokerImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/SLCommandInvokerImpl.java
@@ -1,66 +1,95 @@
/*
-* 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.binding;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import at.gv.egiz.bku.slcommands.SLCommand;
-import at.gv.egiz.bku.slcommands.SLCommandInvoker;
-import at.gv.egiz.bku.slcommands.SLResult;
-import at.gv.egiz.bku.slcommands.SLSourceContext;
-import at.gv.egiz.bku.slcommands.SLTargetContext;
-
-/**
- * This class implements the entry point for the CCEs security management.
- *
- * TODO the secuirty management is currently not implemented.
- */
-public class SLCommandInvokerImpl implements SLCommandInvoker {
-
- private static Log log = LogFactory.getLog(SLCommandInvokerImpl.class);
-
- protected SLCommand command;
- protected SLResult result;
-
- /**
- * Invokes a sl command.
- */
- public void invoke(SLSourceContext aContext) {
- // FIXXME add security policy here.
- log.warn("Security policy not implemented yet, invoking command: "+command);
- result = command.execute();
- }
-
- public SLResult getResult(SLTargetContext aContext) {
- // FIXXME
- log.warn("Security policy not implemented yet, getting result of command: "+command);
- return result;
- }
-
- public void setCommand(SLCommand aCmd) {
- command = aCmd;
- }
-
- @Override
- public SLCommandInvoker newInstance() {
- SLCommandInvokerImpl cmdInv = new SLCommandInvokerImpl();
- return cmdInv;
- }
-
-
+ * 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.binding;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import at.gv.egiz.bku.accesscontroller.SecurityManagerFacade;
+import at.gv.egiz.bku.slcommands.SLCommand;
+import at.gv.egiz.bku.slcommands.SLCommandInvoker;
+import at.gv.egiz.bku.slcommands.SLResult;
+import at.gv.egiz.bku.slcommands.SLSourceContext;
+import at.gv.egiz.bku.slcommands.SLTargetContext;
+import at.gv.egiz.bku.slexceptions.SLException;
+
+/**
+ * This class implements the entry point for the CCEs security management.
+ *
+ */
+public class SLCommandInvokerImpl implements SLCommandInvoker {
+
+ private static Log log = LogFactory.getLog(SLCommandInvokerImpl.class);
+
+ protected SLCommand command;
+ protected SLResult result;
+ protected SecurityManagerFacade securityManager;
+
+ /**
+ * Invokes a sl command.
+ *
+ * @throws SLException
+ */
+ public void invoke(SLSourceContext aContext) throws SLException {
+ if (securityManager == null) {
+ log.warn("Security policy not implemented yet, invoking command: "
+ + command);
+ result = command.execute();
+ } else {
+ if (securityManager.mayInvokeCommand(command, aContext)) {
+ result = command.execute();
+ } else {
+ throw new SLException(6002);
+ }
+ }
+ }
+
+ public SLResult getResult(SLTargetContext aContext) throws SLException {
+ if (securityManager == null) {
+ log
+ .warn("Security policy not implemented yet, getting result of command: "
+ + command);
+ return result;
+ } else {
+ if (securityManager.maySendResult(command, aContext)) {
+ return result;
+ } else {
+ throw new SLException(6002);
+ }
+ }
+ }
+
+ public void setCommand(SLCommand aCmd) {
+ command = aCmd;
+ }
+
+ @Override
+ public SLCommandInvoker newInstance() {
+ SLCommandInvokerImpl cmdInv = new SLCommandInvokerImpl();
+ cmdInv.setSecurityManager(securityManager);
+ return cmdInv;
+ }
+
+ public SecurityManagerFacade getSecurityManager() {
+ return securityManager;
+ }
+
+ public void setSecurityManager(SecurityManagerFacade securityManager) {
+ this.securityManager = securityManager;
+ }
+
}
\ No newline at end of file
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/InfoboxReadCommand.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/InfoboxReadCommand.java
index 77529a36..73fddf1f 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/InfoboxReadCommand.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/InfoboxReadCommand.java
@@ -16,5 +16,13 @@
*/
package at.gv.egiz.bku.slcommands;
-public interface InfoboxReadCommand extends SLCommand {
+public interface InfoboxReadCommand extends SLCommand {
+ public String getInfoboxIdentifier();
+
+ /**
+ * Convenience method to get the domain identifier if the infobox
+ * referes to a Identitylink.
+ * @return the domain id or null if the Infobox is not of type Identitylink or no domain parameter was specified
+ */
+ public String getIdentityLinkDomainId();
}
\ No newline at end of file
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLCommandInvoker.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLCommandInvoker.java
index 30c6b68f..c28288c9 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLCommandInvoker.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLCommandInvoker.java
@@ -16,7 +16,8 @@
*/
package at.gv.egiz.bku.slcommands;
-import at.gv.egiz.bku.slexceptions.SLCanceledException;
+import at.gv.egiz.bku.slexceptions.SLCanceledException;
+import at.gv.egiz.bku.slexceptions.SLException;
public interface SLCommandInvoker {
@@ -25,7 +26,7 @@ public interface SLCommandInvoker {
* @param aContext
* @throws SLCanceledException if the security management prevents execution of this command
*/
- public void invoke(SLSourceContext aContext) throws SLCanceledException;
+ public void invoke(SLSourceContext aContext) throws SLException;
/**
*
@@ -33,7 +34,7 @@ public interface SLCommandInvoker {
* @return
* @throws SLCanceledException if the security management prevents execution of this command
*/
- public SLResult getResult(SLTargetContext aContext) throws SLCanceledException;
+ public SLResult getResult(SLTargetContext aContext) throws SLException;
public void setCommand(at.gv.egiz.bku.slcommands.SLCommand aCmd);
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLSourceContext.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLSourceContext.java
index ded55b2a..f25a0ea4 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLSourceContext.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLSourceContext.java
@@ -16,6 +16,7 @@
*/
package at.gv.egiz.bku.slcommands;
+import java.net.URL;
import java.security.cert.X509Certificate;
import at.gv.egiz.bku.utils.binding.Protocol;
@@ -23,17 +24,17 @@ import at.gv.egiz.bku.utils.binding.Protocol;
public class SLSourceContext {
- private Protocol sourceProtocol;
+ private URL sourceUrl;
private boolean sourceIsDataURL;
private X509Certificate sourceCertificate;
private String sourceHTTPReferer;
- public Protocol getSourceProtocol() {
- return sourceProtocol;
+ public URL getSourceUrl() {
+ return sourceUrl;
}
- public void setSourceProtocol(Protocol sourceProtocol) {
- this.sourceProtocol = sourceProtocol;
+ public void setSourceUrl(URL sourceProtocol) {
+ this.sourceUrl = sourceProtocol;
}
public boolean isSourceIsDataURL() {
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLTargetContext.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLTargetContext.java
index cf800406..f9df3ced 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLTargetContext.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLTargetContext.java
@@ -16,19 +16,20 @@
*/
package at.gv.egiz.bku.slcommands;
-import java.security.cert.X509Certificate;
+import java.net.URL;
+import java.security.cert.X509Certificate;
public class SLTargetContext {
- private String targetProtocol;
+ private URL targetUrl;
private boolean targetIsDataURL;
private X509Certificate targetCertificate;
- public String getTargetProtocol() {
- return targetProtocol;
+ public URL getTargetUrl() {
+ return targetUrl;
}
- public void setTargetProtocol(String targetProtocol) {
- this.targetProtocol = targetProtocol;
+ public void setTargetUrl(URL targetUrl) {
+ this.targetUrl = targetUrl;
}
public boolean isTargetIsDataURL() {
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 93131cf4..b6745e1f 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
@@ -405,5 +405,10 @@ public class InfoboxReadCommandImpl extends SLCommandImpl
Date: Fri, 5 Sep 2008 12:05:55 +0000
Subject: added file headers
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@17 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
---
.../bku/accesscontrol/config/AccessControl.java | 24 ++++++++++++++--------
.../gv/egiz/bku/accesscontrol/config/Action.java | 24 ++++++++++++++--------
.../at/gv/egiz/bku/accesscontrol/config/Chain.java | 23 ++++++++++++++-------
.../gv/egiz/bku/accesscontrol/config/Chains.java | 24 ++++++++++++++--------
.../gv/egiz/bku/accesscontrol/config/Command.java | 24 ++++++++++++++--------
.../bku/accesscontrol/config/ObjectFactory.java | 23 ++++++++++++++-------
.../at/gv/egiz/bku/accesscontrol/config/Param.java | 24 ++++++++++++++--------
.../at/gv/egiz/bku/accesscontrol/config/Rule.java | 23 ++++++++++++++-------
.../at/gv/egiz/bku/accesscontrol/config/Rules.java | 24 ++++++++++++++--------
.../egiz/bku/accesscontroller/AccessChecker.java | 16 +++++++++++++++
.../bku/accesscontroller/AccessCheckerContext.java | 16 +++++++++++++++
.../accesscontroller/AccessControllerFactory.java | 16 +++++++++++++++
.../at/gv/egiz/bku/accesscontroller/Action.java | 16 +++++++++++++++
.../bku/accesscontroller/AuthenticationClass.java | 16 +++++++++++++++
.../accesscontroller/AuthenticationClassifier.java | 16 +++++++++++++++
.../gv/egiz/bku/accesscontroller/ChainChecker.java | 16 +++++++++++++++
.../gv/egiz/bku/accesscontroller/ChainResult.java | 16 +++++++++++++++
.../bku/accesscontroller/CommandParamChecker.java | 16 +++++++++++++++
.../bku/accesscontroller/InfoboxParamChecker.java | 16 +++++++++++++++
.../gv/egiz/bku/accesscontroller/RuleChecker.java | 16 +++++++++++++++
.../gv/egiz/bku/accesscontroller/RuleResult.java | 16 +++++++++++++++
.../accesscontroller/SecurityManagerFacade.java | 16 +++++++++++++++
.../gv/egiz/bku/accesscontroller/UserAction.java | 16 +++++++++++++++
23 files changed, 368 insertions(+), 69 deletions(-)
(limited to 'bkucommon/src/main/java')
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/AccessControl.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/AccessControl.java
index 90271231..a03505f6 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/AccessControl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/AccessControl.java
@@ -1,11 +1,19 @@
-//
-// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-520
-// See http://java.sun.com/xml/jaxb
-// Any modifications to this file will be lost upon recompilation of the source schema.
-// Generated on: 2008.09.03 at 02:52:44 PM GMT
-//
-
-
+/*
+* 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.accesscontrol.config;
import javax.xml.bind.annotation.XmlAccessType;
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Action.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Action.java
index b4ae938c..9b15f0fd 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Action.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Action.java
@@ -1,11 +1,19 @@
-//
-// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-520
-// See http://java.sun.com/xml/jaxb
-// Any modifications to this file will be lost upon recompilation of the source schema.
-// Generated on: 2008.09.03 at 03:06:11 PM GMT
-//
-
-
+/*
+* 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.accesscontrol.config;
import javax.xml.bind.annotation.XmlAccessType;
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Chain.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Chain.java
index 1408c8d8..92975e48 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Chain.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Chain.java
@@ -1,10 +1,19 @@
-//
-// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-520
-// See http://java.sun.com/xml/jaxb
-// Any modifications to this file will be lost upon recompilation of the source schema.
-// Generated on: 2008.09.03 at 02:52:44 PM GMT
-//
-
+/*
+* 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.accesscontrol.config;
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Chains.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Chains.java
index d58f7bad..ea8c36bd 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Chains.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Chains.java
@@ -1,11 +1,19 @@
-//
-// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-520
-// See http://java.sun.com/xml/jaxb
-// Any modifications to this file will be lost upon recompilation of the source schema.
-// Generated on: 2008.09.03 at 02:52:44 PM GMT
-//
-
-
+/*
+* 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.accesscontrol.config;
import java.util.ArrayList;
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Command.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Command.java
index 0d25ca1c..a2a9ebb4 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Command.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Command.java
@@ -1,11 +1,19 @@
-//
-// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-520
-// See http://java.sun.com/xml/jaxb
-// Any modifications to this file will be lost upon recompilation of the source schema.
-// Generated on: 2008.09.03 at 02:52:44 PM GMT
-//
-
-
+/*
+* 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.accesscontrol.config;
import java.util.ArrayList;
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/ObjectFactory.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/ObjectFactory.java
index 0efa4beb..2c6e2187 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/ObjectFactory.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/ObjectFactory.java
@@ -1,10 +1,19 @@
-//
-// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-520
-// See http://java.sun.com/xml/jaxb
-// Any modifications to this file will be lost upon recompilation of the source schema.
-// Generated on: 2008.09.03 at 02:52:44 PM GMT
-//
-
+/*
+* 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.accesscontrol.config;
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Param.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Param.java
index 94e190ff..daffa98d 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Param.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Param.java
@@ -1,11 +1,19 @@
-//
-// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-520
-// See http://java.sun.com/xml/jaxb
-// Any modifications to this file will be lost upon recompilation of the source schema.
-// Generated on: 2008.09.03 at 02:52:44 PM GMT
-//
-
-
+/*
+* 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.accesscontrol.config;
import javax.xml.bind.annotation.XmlAccessType;
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Rule.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Rule.java
index 512cced9..2ad1e660 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Rule.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Rule.java
@@ -1,10 +1,19 @@
-//
-// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-520
-// See http://java.sun.com/xml/jaxb
-// Any modifications to this file will be lost upon recompilation of the source schema.
-// Generated on: 2008.09.03 at 02:52:44 PM GMT
-//
-
+/*
+* 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.accesscontrol.config;
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Rules.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Rules.java
index 6429e58a..16150f0c 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Rules.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontrol/config/Rules.java
@@ -1,11 +1,19 @@
-//
-// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-520
-// See http://java.sun.com/xml/jaxb
-// Any modifications to this file will be lost upon recompilation of the source schema.
-// Generated on: 2008.09.03 at 02:52:44 PM GMT
-//
-
-
+/*
+* 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.accesscontrol.config;
import java.util.ArrayList;
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AccessChecker.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AccessChecker.java
index 81bf1795..d930c74e 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AccessChecker.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AccessChecker.java
@@ -1,3 +1,19 @@
+/*
+* 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.accesscontroller;
import at.gv.egiz.bku.slexceptions.SLException;
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AccessCheckerContext.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AccessCheckerContext.java
index 1206c022..60935678 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AccessCheckerContext.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AccessCheckerContext.java
@@ -1,3 +1,19 @@
+/*
+* 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.accesscontroller;
import at.gv.egiz.bku.slcommands.SLCommand;
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AccessControllerFactory.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AccessControllerFactory.java
index cd837cd7..19fec084 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AccessControllerFactory.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AccessControllerFactory.java
@@ -1,3 +1,19 @@
+/*
+* 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.accesscontroller;
import java.io.InputStream;
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/Action.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/Action.java
index 11a22c99..f3d15ad6 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/Action.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/Action.java
@@ -1,3 +1,19 @@
+/*
+* 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.accesscontroller;
public enum Action {
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AuthenticationClass.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AuthenticationClass.java
index 4d58df78..3c442a6d 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AuthenticationClass.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AuthenticationClass.java
@@ -1,3 +1,19 @@
+/*
+* 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.accesscontroller;
public enum AuthenticationClass {
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AuthenticationClassifier.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AuthenticationClassifier.java
index 2e856f06..ace8a75a 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AuthenticationClassifier.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AuthenticationClassifier.java
@@ -1,3 +1,19 @@
+/*
+* 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.accesscontroller;
import static at.gv.egiz.bku.accesscontroller.AuthenticationClass.ANONYMOUS;
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/ChainChecker.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/ChainChecker.java
index a290fe8d..716f81e4 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/ChainChecker.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/ChainChecker.java
@@ -1,3 +1,19 @@
+/*
+* 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.accesscontroller;
import java.util.Collections;
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/ChainResult.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/ChainResult.java
index a8fb789e..a5547cab 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/ChainResult.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/ChainResult.java
@@ -1,3 +1,19 @@
+/*
+* 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.accesscontroller;
/**
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/CommandParamChecker.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/CommandParamChecker.java
index 3927c3c9..003eb2f7 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/CommandParamChecker.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/CommandParamChecker.java
@@ -1,3 +1,19 @@
+/*
+* 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.accesscontroller;
import java.util.LinkedList;
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/InfoboxParamChecker.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/InfoboxParamChecker.java
index 33689ae0..8fa328de 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/InfoboxParamChecker.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/InfoboxParamChecker.java
@@ -1,3 +1,19 @@
+/*
+* 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.accesscontroller;
import java.util.regex.Matcher;
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/RuleChecker.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/RuleChecker.java
index b0bf7fac..1cba89ef 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/RuleChecker.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/RuleChecker.java
@@ -1,3 +1,19 @@
+/*
+* 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.accesscontroller;
import java.net.InetAddress;
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/RuleResult.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/RuleResult.java
index 26f42db0..706615c2 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/RuleResult.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/RuleResult.java
@@ -1,3 +1,19 @@
+/*
+* 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.accesscontroller;
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/SecurityManagerFacade.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/SecurityManagerFacade.java
index 32242772..482d3ecb 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/SecurityManagerFacade.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/SecurityManagerFacade.java
@@ -1,3 +1,19 @@
+/*
+* 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.accesscontroller;
import java.io.InputStream;
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/UserAction.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/UserAction.java
index 307ec1e5..c1f7028b 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/UserAction.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/UserAction.java
@@ -1,3 +1,19 @@
+/*
+* 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.accesscontroller;
public enum UserAction {
--
cgit v1.2.3
From 83ffb9a9e1ffcb57e2adda4d48a8f972148897e6 Mon Sep 17 00:00:00 2001
From: clemenso
Date: Fri, 5 Sep 2008 13:38:52 +0000
Subject: HashDataInput
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@20 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
---
.../bku/slcommands/impl/HashDataInputImpl.java | 42 +
.../bku/slcommands/impl/xsect/STALPrivateKey.java | 218 +--
.../bku/slcommands/impl/xsect/STALSignature.java | 310 ++--
.../egiz/bku/slcommands/impl/xsect/Signature.java | 1855 ++++++++++----------
4 files changed, 1251 insertions(+), 1174 deletions(-)
create mode 100644 bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/HashDataInputImpl.java
(limited to 'bkucommon/src/main/java')
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/HashDataInputImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/HashDataInputImpl.java
new file mode 100644
index 00000000..49d3c63f
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/HashDataInputImpl.java
@@ -0,0 +1,42 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package at.gv.egiz.bku.slcommands.impl;
+
+import at.gv.egiz.bku.slcommands.impl.xsect.DataObject;
+import at.gv.egiz.stal.HashDataInput;
+import java.io.InputStream;
+
+/**
+ *
+ * @author clemens
+ */
+public class HashDataInputImpl implements HashDataInput {
+
+ String refId;
+ String mimeType;
+ InputStream hashDataInput;
+
+ public HashDataInputImpl(DataObject dataObject) {
+ refId = dataObject.getReference().getId();
+ mimeType = dataObject.getMimeType();
+ hashDataInput = dataObject.getReference().getDigestInputStream();
+ }
+
+ @Override
+ public String getReferenceId() {
+ return refId;
+ }
+
+ @Override
+ public String getMimeType() {
+ return mimeType;
+ }
+
+ @Override
+ public InputStream getHashDataInput() {
+ return hashDataInput;
+ }
+
+}
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 64c758c9..25e2d4e5 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
@@ -14,109 +14,115 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package at.gv.egiz.bku.slcommands.impl.xsect;
-
-import java.security.PrivateKey;
-
-import at.gv.egiz.stal.STAL;
-import at.gv.egiz.stal.HashDataInputCallback;
-
-/**
- * This class implements a private key used by the {@link STALSignature} class.
- *
- * @author mcentner
- */
-public class STALPrivateKey implements PrivateKey {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * The STAL implementation.
- */
- private STAL stal;
-
- /**
- * The callback interface for obtaining the hash input data.
- */
- private HashDataInputCallback hashDataInputCallback;
-
- /**
- * The keybox identifier.
- */
- private String keyboxIdentifier;
-
- /**
- * The signature algorithm.
- */
- private String algorithm;
-
- /**
- * Creates a new instance of this STALPrivateKey
with the given
- * stal
implementation, signature algorithm
,
- * keyboxIdentifier
and hashDataInputCallback
- * interface.
- *
- * @param stal
- * the STAL implementation
- * @param algorithm
- * the signature algorithm
- * @param keyboxIdentifier
- * the keybox identifier
- * @param hashDataInputCallback
- * the interface for obtaining the has input data
- */
- public STALPrivateKey(STAL stal,
- String algorithm, String keyboxIdentifier, HashDataInputCallback hashDataInputCallback) {
- super();
- this.keyboxIdentifier = keyboxIdentifier;
- this.hashDataInputCallback = hashDataInputCallback;
- this.stal = stal;
- this.algorithm = algorithm;
- }
-
- /* (non-Javadoc)
- * @see java.security.Key#getAlgorithm()
- */
- @Override
- public String getAlgorithm() {
- return algorithm;
- }
-
- /* (non-Javadoc)
- * @see java.security.Key#getEncoded()
- */
- @Override
- public byte[] getEncoded() {
- throw new UnsupportedOperationException("STALPrivateKey does not support the getEncoded() method.");
- }
-
- /* (non-Javadoc)
- * @see java.security.Key#getFormat()
- */
- @Override
- public String getFormat() {
- return null;
- }
-
- /**
- * @return the STAL implementation
- */
- public STAL getStal() {
- return stal;
- }
-
- /**
- * @return the interface for obtaining the hash data input
- */
- public HashDataInputCallback getHashDataInputCallback() {
- return hashDataInputCallback;
- }
-
- /**
- * @return the keybox identifier
- */
- public String getKeyboxIdentifier() {
- return keyboxIdentifier;
- }
-
-}
+package at.gv.egiz.bku.slcommands.impl.xsect;
+
+import at.gv.egiz.stal.HashDataInput;
+import java.security.PrivateKey;
+
+import at.gv.egiz.stal.STAL;
+//import at.gv.egiz.stal.HashDataInputCallback;
+import java.util.List;
+
+/**
+ * This class implements a private key used by the {@link STALSignature} class.
+ *
+ * @author mcentner
+ */
+public class STALPrivateKey implements PrivateKey {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The STAL implementation.
+ */
+ private STAL stal;
+
+ /**
+ * The callback interface for obtaining the hash input data.
+ */
+// private HashDataInputCallback hashDataInputCallback;
+
+
+ private List dataObjects;
+
+ /**
+ * The keybox identifier.
+ */
+ private String keyboxIdentifier;
+
+ /**
+ * The signature algorithm.
+ */
+ private String algorithm;
+
+ /**
+ * Creates a new instance of this STALPrivateKey
with the given
+ * stal
implementation, signature algorithm
,
+ * keyboxIdentifier
and hashDataInputCallback
+ * interface.
+ *
+ * @param stal
+ * the STAL implementation
+ * @param algorithm
+ * the signature algorithm
+ * @param keyboxIdentifier
+ * the keybox identifier
+ * @param hashDataInputCallback
+ * the interface for obtaining the has input data
+ */
+ public STALPrivateKey(STAL stal,
+ String algorithm, String keyboxIdentifier, List dataObjects) {
+ super();
+ this.keyboxIdentifier = keyboxIdentifier;
+ this.dataObjects = dataObjects;
+ this.stal = stal;
+ this.algorithm = algorithm;
+ }
+
+ /* (non-Javadoc)
+ * @see java.security.Key#getAlgorithm()
+ */
+ @Override
+ public String getAlgorithm() {
+ return algorithm;
+ }
+
+ /* (non-Javadoc)
+ * @see java.security.Key#getEncoded()
+ */
+ @Override
+ public byte[] getEncoded() {
+ throw new UnsupportedOperationException("STALPrivateKey does not support the getEncoded() method.");
+ }
+
+ /* (non-Javadoc)
+ * @see java.security.Key#getFormat()
+ */
+ @Override
+ public String getFormat() {
+ return null;
+ }
+
+ /**
+ * @return the STAL implementation
+ */
+ public STAL getStal() {
+ return stal;
+ }
+
+ /**
+ * @return the interface for obtaining the hash data input
+ */
+ public List getDataObjects() {
+
+ return dataObjects;
+ }
+
+ /**
+ * @return the keybox identifier
+ */
+ public String getKeyboxIdentifier() {
+ return keyboxIdentifier;
+ }
+
+}
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
index f0fcb891..eba1d96d 100644
--- 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
@@ -14,152 +14,164 @@
* 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.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.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;
-
-/**
- * A signature service provider implementation that uses STAL to sign.
- *
- * @author mcentner
- */
-public class STALSignature extends SignatureSpi {
-
- /**
- * 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.");
- }
-
- HashDataInputCallback signRefDataSupplier = privateKey.getHashDataInputCallback();
-
- String keyboxIdentifier = privateKey.getKeyboxIdentifier();
-
- if (keyboxIdentifier == null) {
- throw new SignatureException("STALSignature requires the STALPrivateKey " +
- "to provide a KeyboxIdentifier.");
- }
-
- SignRequest signRequest = new SignRequest();
- signRequest.setKeyIdentifier(keyboxIdentifier);
- signRequest.setSignedInfo(data.toByteArray());
- signRequest.setHashDataInput(signRefDataSupplier);
-
- List 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.");
- }
-
-}
+package at.gv.egiz.bku.slcommands.impl.xsect;
+
+import at.gv.egiz.bku.slcommands.impl.HashDataInputImpl;
+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 dataObjects = privateKey.getDataObjects();
+// log.debug("got " + dataObjects.size() + " DataObjects, passing HashDataInputs to STAL SignRequest");
+
+ List hashDataInputs = new ArrayList();
+ for (DataObject dataObject : dataObjects) {
+ hashDataInputs.add(new HashDataInputImpl(dataObject));
+ }
+
+ SignRequest signRequest = new SignRequest();
+ signRequest.setKeyIdentifier(keyboxIdentifier);
+ signRequest.setSignedInfo(data.toByteArray());
+ signRequest.setHashDataInput(hashDataInputs);
+
+ List 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/Signature.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/Signature.java
index 94a4a066..191f8371 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
@@ -14,922 +14,939 @@
* 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.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.StringWriter;
-import java.io.UnsupportedEncodingException;
-import java.security.InvalidAlgorithmParameterException;
-import java.security.NoSuchAlgorithmException;
-import java.security.PrivateKey;
-import java.security.cert.X509Certificate;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-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.crypto.MarshalException;
-import javax.xml.crypto.dom.DOMStructure;
-import javax.xml.crypto.dsig.CanonicalizationMethod;
-import javax.xml.crypto.dsig.DigestMethod;
-import javax.xml.crypto.dsig.Reference;
-import javax.xml.crypto.dsig.SignatureMethod;
-import javax.xml.crypto.dsig.SignedInfo;
-import javax.xml.crypto.dsig.XMLObject;
-import javax.xml.crypto.dsig.XMLSignature;
-import javax.xml.crypto.dsig.XMLSignatureException;
-import javax.xml.crypto.dsig.XMLSignatureFactory;
-import javax.xml.crypto.dsig.dom.DOMSignContext;
-import javax.xml.crypto.dsig.keyinfo.KeyInfo;
-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.etsi.uri._01903.v1_1.DataObjectFormatType;
-import org.etsi.uri._01903.v1_1.QualifyingPropertiesType;
-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.ls.DOMImplementationLS;
-import org.w3c.dom.ls.LSException;
-import org.w3c.dom.ls.LSInput;
-import org.w3c.dom.ls.LSOutput;
-import org.w3c.dom.ls.LSParser;
-import org.w3c.dom.ls.LSResourceResolver;
-import org.w3c.dom.ls.LSSerializer;
-
-import at.buergerkarte.namespaces.securitylayer._1.Base64XMLLocRefReqRefContentType;
-import at.buergerkarte.namespaces.securitylayer._1.Base64XMLOptRefContentType;
-import at.buergerkarte.namespaces.securitylayer._1.DataObjectAssociationType;
-import at.buergerkarte.namespaces.securitylayer._1.DataObjectInfoType;
-import at.buergerkarte.namespaces.securitylayer._1.SignatureInfoCreationType;
-import at.gv.egiz.bku.binding.HttpUtil;
-import at.gv.egiz.bku.slexceptions.SLCommandException;
-import at.gv.egiz.bku.slexceptions.SLRequestException;
-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.HashDataInputCallback;
-import at.gv.egiz.stal.STAL;
-import at.gv.egiz.xades.QualifyingPropertiesException;
-import at.gv.egiz.xades.QualifyingPropertiesFactory;
-
-/**
- * This class represents an XML-Signature as to be created by the
- * security layer command CreateXMLSignatureRequest
.
- *
- * @author mcentner
- */
-public class Signature implements HashDataInputCallback {
-
- /**
- * Logging facility.
- */
- private static Log log = LogFactory.getLog(Signature.class);
-
- /**
- * The DOM implementation used.
- */
- private DOMImplementationLS domImplLS;
-
- /**
- * The SignatureContext for the XMLSignature.
- */
- private SignatureContext ctx;
-
- /**
- * The list of {@link DataObject}s for this signature.
- */
- private List dataObjects = new ArrayList();
-
- /**
- * A mapping from the Id
-attribute values of this signature's
- * ds:Reference
s to the corresponding {@link DataObject}s.
- */
- private Map dataObjectReferencIds = new HashMap();
-
- /**
- * The SignatureEnvironment for this signature.
- */
- private SignatureLocation signatureLocation;
-
- /**
- * The XML signature.
- */
- private XMLSignature xmlSignature;
-
- /**
- * A list of attributes of type xsd:ID
to be registered in the {@link DOMSignContext}.
- */
- private List idAttributes = new ArrayList();
-
- /**
- * The signer's X509 certificate.
- */
- private X509Certificate signerCertificate;
-
- /**
- * The signing time.
- */
- private Date signingTime;
-
- /**
- * Creates a new SLXMLSignature instance.
- */
- public Signature(URLDereferencerContext dereferencerContext,
- IdValueFactory idValueFactory,
- AlgorithmMethodFactory algorithmMethodFactory) {
-
- domImplLS = DOMUtils.getDOMImplementationLS();
-
- ctx = new SignatureContext();
-
- ctx.setSignatureFactory(XMLSignatureFactory.getInstance());
-
- ctx.setDereferencerContext(dereferencerContext);
- ctx.setIdValueFactory(idValueFactory);
- ctx.setAlgorithmMethodFactory(algorithmMethodFactory);
-
- }
-
- /**
- * @return the Document containing this Signature
- */
- public Document getDocument() {
- return ctx.getDocument();
- }
-
- /**
- * @return the parent Node for this Signature
- */
- public Node getParent() {
- return (signatureLocation != null) ? signatureLocation.getParent() : null;
- }
-
- /**
- * @return the next sibling Node for this Signature
- */
- public Node getNextSibling() {
- return (signatureLocation != null) ? signatureLocation.getNextSibling() : null;
- }
-
- /**
- * @return the XMLSignature
- */
- public XMLSignature getXMLSignature() {
- return xmlSignature;
- }
-
- /**
- * @return the list of {@link Reference}s of this Signature
- */
- @SuppressWarnings("unchecked")
- public List getReferences() {
- return (xmlSignature != null) ? xmlSignature.getSignedInfo().getReferences() : null;
- }
-
- /**
- * @return the list of {@link XMLObject}s of this Signature
- */
- @SuppressWarnings("unchecked")
- public List getXMLObjects() {
- return (xmlSignature != null) ? xmlSignature.getObjects() : null;
- }
-
- /**
- * Prepares the signature document with the information given by the
- * signatureInfo
provided.
- *
- * @param signatureInfo
- * the SignatureInfo
- *
- * @throws SLCommandException
- * if processing fails for any reason
- * @throws IllegalStateException
- * if the parent
node has already been set
- * @throws NullPointerException
- * if signatureInfo
is null
- */
- public void setSignatureInfo(SignatureInfoCreationType signatureInfo) throws SLCommandException {
-
- if (signatureLocation != null) {
- throw new IllegalStateException("SignatureEnvironment already set.");
- }
-
- Base64XMLOptRefContentType signatureEnvironment = signatureInfo.getSignatureEnvironment();
-
- if (signatureEnvironment == null) {
-
- // no SignatureEnvironment, so we use an empty document and the document as parent
- ensureSignatureLocation();
-
- } else {
-
- // parse SignatureEnvrionment and use as document
- Document document = parseSignatureEnvironment(signatureEnvironment, signatureInfo.getSupplement());
- ctx.setDocument(document);
-
- signatureLocation = new SignatureLocation(ctx);
- signatureLocation.setSignatureInfo(signatureInfo);
-
- }
-
- }
-
- /**
- * Ensures a SignatureLocation for this Signature.
- */
- private void ensureSignatureLocation() {
-
- if (signatureLocation == null) {
- Document document = DOMUtils.createDocument();
- ctx.setDocument(document);
-
- signatureLocation = new SignatureLocation(ctx);
- signatureLocation.setParent(document);
- }
-
- }
-
- /**
- * Adds a DataObject with the information given by the
- * dataObjectInfo
provided to this Signature.
- *
- * @param dataObjectInfo
- * the DataObjectInfo
element
- *
- * @throws SLCommandException
- * if adding the DataObject fails
- * @throws SLRequestException
- * if the information provided by the given
- * dataObjectInfo
does not conform to the security
- * layer specification
- * @throws NullPointerException
- * if dataObjectInfo
is null
- */
- public void addDataObject(DataObjectInfoType dataObjectInfo) throws SLCommandException, SLRequestException {
-
- ensureSignatureLocation();
-
- DataObject dataObject = new DataObject(ctx);
- dataObject.setDataObjectInfo(dataObjectInfo);
-
- dataObjects.add(dataObject);
-
- dataObjectReferencIds.put(dataObject.getReference().getId(), dataObject);
-
- }
-
- /**
- * Sets the SigningTime
qualifying property of this Signature.
- *
- * @param signingTime the signing time to set
- */
- public void setSigningTime(Date signingTime) {
- this.signingTime = signingTime;
- }
-
- /**
- * Sets the SignerCertificate
qualifying property of this Signature.
- *
- * @param certificate the signer's certificate
- */
- public void setSignerCeritifcate(X509Certificate certificate) {
- this.signerCertificate = certificate;
- }
-
- /**
- * Builds the XMLSignature data structure of this Signature as configured by
- * the various setter methods.
- *
- * @throws SLCommandException if building this signature fails
- */
- public void buildXMLSignature() throws SLCommandException {
-
- List objects = new ArrayList();
- List references = new ArrayList();
-
- // add all data objects
- for (DataObject dataObject : dataObjects) {
- if (dataObject.getXmlObject() != null) {
- objects.add(dataObject.getXmlObject());
- }
- if (dataObject.getReference() != null) {
- references.add(dataObject.getReference());
- }
- }
-
- addXAdESObjectAndReference(objects, references);
-
- XMLSignatureFactory signatureFactory = ctx.getSignatureFactory();
- AlgorithmMethodFactory algorithmMethodFactory = ctx.getAlgorithmMethodFactory();
-
- CanonicalizationMethod cm;
- SignatureMethod sm;
- try {
- cm = algorithmMethodFactory.createCanonicalizationMethod(ctx);
- sm = algorithmMethodFactory.createSignatureMethod(ctx);
- } catch (NoSuchAlgorithmException e) {
- log.error("Failed to get Canonicalization or Signature algorithm.", e);
- throw new SLCommandException(4006);
- } catch (InvalidAlgorithmParameterException e) {
- log.error("Failed to get Canonicalization or Signature algorithm.", e);
- throw new SLCommandException(4006);
- }
-
- String siId = ctx.getIdValueFactory().createIdValue("SignedInfo");
-
- SignedInfo si = signatureFactory.newSignedInfo(cm, sm, references, siId);
-
- KeyInfo ki = null;
- if (signerCertificate != null) {
- KeyInfoFactory kif = KeyInfoFactory.getInstance();
- X509Data x509Data = kif.newX509Data(Collections.singletonList(signerCertificate));
- ki = kif.newKeyInfo(Collections.singletonList(x509Data));
- }
-
- String signatureId = ctx.getIdValueFactory().createIdValue("Signature");
- String signatureValueId = ctx.getIdValueFactory().createIdValue("SignatureValue");
-
- xmlSignature = signatureFactory.newXMLSignature(si, ki, objects, signatureId, signatureValueId);
-
- }
-
- /**
- * Sign this Signature using the given signContext
.
- *
- * Call's {@link #buildXMLSignature()} if it has not been called yet.
- *
- *
- * @param signContext
- * the signing context
- *
- * @throws MarshalException
- * if marshalling the XMLSignature fails
- * @throws XMLSignatureException
- * if signing the XMLSignature fails
- * @throws SLCommandException
- * if building the XMLSignature fails
- * @throws NullPointerException
- * if signContext
is null
- */
- public void sign(DOMSignContext signContext) throws MarshalException, XMLSignatureException, SLCommandException {
-
- if (xmlSignature == null) {
- buildXMLSignature();
- }
-
- for (IdAttribute idAttribute : idAttributes) {
- signContext.setIdAttributeNS(idAttribute.element, idAttribute.namespaceURI, idAttribute.localName);
- }
-
- // DO NOT USE:
- // signContext.setProperty("iaik.xml.crypto.dsig.sign-over", Boolean.TRUE);
-
- signContext.setProperty("javax.xml.crypto.dsig.cacheReference", Boolean.TRUE);
-
- signContext.putNamespacePrefix(XMLSignature.XMLNS, "dsig");
-
- signContext.setURIDereferencer(new URIDereferncerAdapter(ctx.getDereferencerContext()));
-
- try {
- xmlSignature.sign(signContext);
- } catch (XMLSignatureException e) {
- Throwable cause = e.getCause();
- while (cause != null) {
- if (cause instanceof STALSignatureException) {
- int errorCode = ((STALSignatureException) cause).getErrorCode();
- SLCommandException commandException = new SLCommandException(errorCode);
- log.info("Failed to sign signature.", commandException);
- throw commandException;
- } else {
- cause = cause.getCause();
- }
- }
- throw e;
- }
-
- // debug
- if (log.isTraceEnabled()) {
- for (DataObject dataObject : dataObjects) {
- Reference reference = dataObject.getReference();
- InputStream digestInputStream = reference.getDigestInputStream();
- if (digestInputStream != null) {
- String mimeType = dataObject.getMimeType();
- StringBuilder sb = new StringBuilder();
- sb.append("DigestInput for Reference with id='");
- sb.append(reference.getId());
- sb.append("' (MIME-Type=");
- sb.append(dataObject.getMimeType());
- sb.append("):\n");
- try {
- if (mimeType != null && (
- mimeType.startsWith("text") ||
- "application/xhtml+xml".equals(mimeType))) {
- byte[] b = new byte[512];
- for (int l; (l = digestInputStream.read(b)) != -1;) {
- sb.append(new String(b, 0, l));
- }
- } else {
- sb.append(HexDump.hexDump(digestInputStream));
- }
- } catch (IOException e) {
- log.error(e);
- }
- log.trace(sb.toString());
- } else {
- log.trace("Reference caching is not enabled.");
- }
- }
- }
-
- }
-
- /**
- * Sign this Signature using the given stal
implementation and
- * keyboxIdentifier
.
- *
- * This method configures an appropriate {@link DOMSignContext} and calls
- * {@link #sign(DOMSignContext)}. If {@link #buildXMLSignature()} has not been
- * called yet, it is called by this method.
- *
- *
- * @param stal
- * the STAL implementation to use
- * @param keyboxIdentifier
- * the KeyboxIdentifier to use
- *
- * @throws MarshalException
- * if marshalling this Signature fails
- * @throws XMLSignatureException
- * if signing this Signature fails
- * @throws SLCommandException
- * if building this Signature fails
- * @throws NullPointerException
- * if stal
or keyboxIdentifier
is
- * null
- */
- public void sign(STAL stal, String keyboxIdentifier) throws MarshalException, XMLSignatureException, SLCommandException {
-
- if (stal == null) {
- throw new NullPointerException("Argument 'stal' must not be null.");
- }
-
- if (keyboxIdentifier == null) {
- throw new NullPointerException("Argument 'keyboxIdentifier' must not be null.");
- }
-
- if (xmlSignature == null) {
- buildXMLSignature();
- }
-
- SignatureMethod signatureMethod = xmlSignature.getSignedInfo().getSignatureMethod();
- String algorithm = signatureMethod.getAlgorithm();
-
- PrivateKey privateKey = new STALPrivateKey(stal, algorithm, keyboxIdentifier, this);
-
- DOMSignContext signContext;
- if (getNextSibling() == null) {
- signContext = new DOMSignContext(privateKey, getParent());
- } else {
- signContext = new DOMSignContext(privateKey, getParent(), getNextSibling());
- }
-
- sign(signContext);
- }
-
- @Override
- public InputStream getHashDataInput(String referenceId) {
-
- DataObject dataObject = dataObjectReferencIds.get(referenceId);
- if (dataObject != null) {
- return dataObject.getReference().getDigestInputStream();
- } else {
- return null;
- }
- }
-
- /**
- * Adds the XAdES QualifyingProperties
as an
- * ds:Object
and a corresponding ds:Reference
to
- * it's SignedProperties
element to this Signature.
- *
- * @param objects
- * the list of ds:Objects
to add the created
- * ds:Object
to
- * @param references
- * the list of ds:References
to add the created
- * ds:Reference
to
- *
- * @throws SLCommandException
- * if creating and adding the XAdES
- * QualifyingProperties
fails
- * @throws NullPointerException
- * if objects
or references
is
- * null
- */
- private void addXAdESObjectAndReference(List objects, List references) throws SLCommandException {
-
- QualifyingPropertiesFactory factory = QualifyingPropertiesFactory.getInstance();
-
- String idValue = ctx.getIdValueFactory().createIdValue("SignedProperties");
-
- Date date = (signingTime != null) ? signingTime : new Date();
-
- List signingCertificates;
- if (signerCertificate != null) {
- signingCertificates = Collections.singletonList(signerCertificate);
- } else {
- signingCertificates = Collections.emptyList();
- }
-
- // TODO: report MOA-SP bug
- //
- // The security layer specification mandates the use of version 1.2.2. of the
- // XAdES QualifyingProperties. However MOA-SP supports only version 1.1.1. Therefore,
- // the version 1.1.1 is used in order to be compatible with current MOA-SP versions.
-
- List dataObjectFormats = new ArrayList();
- for (DataObject dataObject : dataObjects) {
- if (dataObject.getMimeType() != null && dataObject.getReference() != null) {
- Reference reference = dataObject.getReference();
- if (reference.getId() != null) {
- String objectReference = "#" + reference.getId();
- dataObjectFormats.add(factory.createDataObjectFormatType(
- objectReference, dataObject.getMimeType(), dataObject
- .getDescription()));
- }
- }
- }
-
- JAXBElement qualifyingProperties;
- try {
- qualifyingProperties = factory.createQualifyingProperties111(date, signingCertificates, idValue, dataObjectFormats);
- } catch (QualifyingPropertiesException e) {
- log.error("Failed to create QualifyingProperties.", e);
- throw new SLCommandException(4000);
- }
-
- DocumentFragment fragment = ctx.getDocument().createDocumentFragment();
-
- try {
- factory.marshallQualifyingProperties(qualifyingProperties, fragment);
- } catch (JAXBException e) {
- log.error("Failed to marshal QualifyingProperties.", e);
- throw new SLCommandException(4000);
- }
-
- List content = Collections.singletonList(new DOMStructure(fragment.getFirstChild()));
-
- String objectIdValue = ctx.getIdValueFactory().createIdValue("Object");
-
- XMLObject object = ctx.getSignatureFactory().newXMLObject(content, objectIdValue, null, null);
-
- objects.add(object);
-
- // TODO: Report MOA-SP Bug
- //
- // Direct referencing of the SignedPorperties Id-attribute is not supported by MOA-SP
- // because the QualifyingProperties are parsed without the XAdES schema. Therefore,
- // the shorthand XPointer could not be resolved.
- //
- // The following workaround uses an XPointer to select the SignedProperties in order
- // to allow the signature to be verified with MOA-SP.
-
- String referenceURI = "#xmlns(xades=http://uri.etsi.org/01903/v1.1.1%23)%20xpointer(id('"
- + objectIdValue
- + "')/child::xades:QualifyingProperties/child::xades:SignedProperties)";
- DigestMethod dm;
- try {
- dm = ctx.getAlgorithmMethodFactory().createDigestMethod(ctx);
- } catch (NoSuchAlgorithmException e) {
- log.error("Failed to get DigestMethod algorithm.", e);
- throw new SLCommandException(4006);
- } catch (InvalidAlgorithmParameterException e) {
- log.error("Failed to get DigestMethod algorithm.", e);
- throw new SLCommandException(4006);
- }
-
- String referenceIdValue = ctx.getIdValueFactory().createIdValue("Reference");
- String referenceType = QualifyingPropertiesFactory.SIGNED_PROPERTIES_REFERENCE_TYPE_V1_1_1;
-
- Reference reference = ctx.getSignatureFactory().newReference(referenceURI, dm, null, referenceType, referenceIdValue);
-
- references.add(reference);
-
- Node child = fragment.getFirstChild();
- if (child instanceof Element) {
- NodeList nodes = ((Element) child).getElementsByTagNameNS(QualifyingPropertiesFactory.NS_URI_V1_1_1, "SignedProperties");
- if (nodes.getLength() > 0) {
- IdAttribute idAttribute = new IdAttribute();
- idAttribute.element = (Element) nodes.item(0);
- idAttribute.namespaceURI = null;
- idAttribute.localName = "Id";
- idAttributes.add(idAttribute);
- }
- }
-
- }
-
- /**
- * Parse the SignatureEnvironment.
- *
- * @param signatureEnvironment
- * the SignatureEnvironment
element
- * @param supplements
- * an optional list of Supplements
(may be
- * null
)
- *
- * @return the parsed SignatureEnvironment document
- *
- * @throws SLCommandException
- * if parsing the SignatureEnvironment fails
- * @throws NullPointerException
- * if signatureEnvironment
is null
- */
- private Document parseSignatureEnvironment(
- Base64XMLOptRefContentType signatureEnvironment,
- List supplements) throws SLCommandException {
-
- if (signatureEnvironment == null) {
- throw new NullPointerException("Argument 'signatureEnvironment' must not be null.");
- }
-
- LSInput input;
- try {
- if (signatureEnvironment.getReference() != null) {
- log.debug("SignatureEnvironment contains Reference " + signatureEnvironment.getReference() + ".");
- input = createLSInput(signatureEnvironment.getReference());
- } else if (signatureEnvironment.getBase64Content() != null) {
- log.debug("SignatureEnvironment contains Base64Content.");
- input = createLSInput(signatureEnvironment.getBase64Content());
- } else if (signatureEnvironment.getXMLContent() != null) {
- log.debug("SignatureEnvironment contains XMLContent.");
- input = createLSInput((XMLContentType) signatureEnvironment.getXMLContent());
- } else {
- // the schema does not allow us to reach this point
- throw new SLCommandException(4000);
- }
- } catch (IOException e) {
- log.info("XML document in which the signature is to be integrated cannot be resolved.", e);
- throw new SLCommandException(4100);
- } catch (XMLStreamException e) {
- log.info("XML document in which the signature is to be integrated cannot be resolved.", e);
- throw new SLCommandException(4100);
- }
-
- LSParser parser = domImplLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
- DOMConfiguration domConfig = parser.getDomConfig();
- SimpleDOMErrorHandler errorHandler = new SimpleDOMErrorHandler();
- domConfig.setParameter("error-handler", errorHandler);
- LSResourceResolverAdapter resourceResolver = new LSResourceResolverAdapter(supplements);
- domConfig.setParameter("resource-resolver", resourceResolver);
- domConfig.setParameter("validate", Boolean.TRUE);
-
- Document doc;
- try {
- doc = parser.parse(input);
- } catch (DOMException e) {
- log.info("XML document in which the signature is to be integrated cannot be parsed.", e);
- throw new SLCommandException(4101);
- } catch (LSException e) {
- log.info("XML document in which the signature is to be integrated cannot be parsed.", e);
- throw new SLCommandException(4101);
- }
-
- if (resourceResolver.getError() != null) {
- log.info("Failed to resolve resource while parsing SignatureEnvironment document.", resourceResolver.getError());
- // we don't stop here, as we only _try_ to parse validating
- }
-
- if (errorHandler.hasFatalErrors()) {
- // log fatal errors
- if (log.isInfoEnabled()) {
- List errorMessages = errorHandler.getErrorMessages();
- StringBuffer sb = new StringBuffer();
- 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());
- }
- throw new SLCommandException(4101);
- }
-
- // log parsed document
- if (log.isTraceEnabled()) {
-
- StringWriter writer = new StringWriter();
-
- writer.write("SignatureEnvironment:\n");
-
- LSOutput output = domImplLS.createLSOutput();
- output.setCharacterStream(writer);
- output.setEncoding("UTF-8");
- LSSerializer serializer = domImplLS.createLSSerializer();
- serializer.write(doc, output);
-
- log.trace(writer.toString());
- }
-
- return doc;
-
- }
-
- /**
- * Creates an LSInput from the given reference
URI.
- *
- * @param reference
- * the reference URL
- *
- * @return an LSInput from the given reference
URI
- *
- * @throws IOException
- * if dereferencing the given reference
fails
- */
- private LSInput createLSInput(String reference) throws IOException {
-
- URLDereferencer urlDereferencer = URLDereferencer.getInstance();
- StreamData streamData = urlDereferencer.dereference(reference, ctx.getDereferencerContext());
-
- String contentType = streamData.getContentType();
- String charset = HttpUtil.getCharset(contentType, true);
- InputStreamReader streamReader;
- try {
- streamReader = new InputStreamReader(streamData.getStream(), charset);
- } catch (UnsupportedEncodingException e) {
- log.info("Charset " + charset + " not supported. Using default.");
- streamReader = new InputStreamReader(streamData.getStream());
- }
-
- LSInput input = domImplLS.createLSInput();
- input = domImplLS.createLSInput();
- input.setCharacterStream(streamReader);
-
- return input;
-
- }
-
- /**
- * Creates an LSInput from the given content
bytes.
- *
- * @param content
- * the content bytes
- *
- * @return an LSInput from the givne content
bytes
- */
- private LSInput createLSInput(byte[] content) {
-
- ByteArrayInputStream inputStream = new ByteArrayInputStream(content);
- LSInput input = domImplLS.createLSInput();
- input.setByteStream(inputStream);
-
- return input;
-
- }
-
- /**
- * Creates an LSInput from the given XML content
.
- *
- * @param content
- * the XML content
- * @return an LSInput from the given XML content
- *
- * @throws XMLStreamException
- * if reading the XMLStream from the given XML content fails
- */
- private LSInput createLSInput(XMLContentType content) throws XMLStreamException {
-
- ByteArrayOutputStream redirectedStream = content.getRedirectedStream();
- if (redirectedStream != null) {
- LSInput input = domImplLS.createLSInput();
- input.setByteStream(new ByteArrayInputStream(redirectedStream.toByteArray()));
- return input;
- } else {
- return null;
- }
-
- }
-
- /**
- * Represents an xsd:Id
-attribute value.
- *
- * @author mcentner
- */
- private class IdAttribute {
-
- private Element element;
-
- private String namespaceURI;
-
- private String localName;
-
- }
-
- /**
- * An implementation of the LSResourceResolver that uses a list of supplements
- * to resolve resources.
- *
- * @author mcentner
- */
- private class LSResourceResolverAdapter implements LSResourceResolver {
-
- List supplements;
-
- private LSResourceResolverAdapter(
- List supplements) {
- this.supplements = supplements;
- }
-
- private Exception error;
-
- /**
- * @return the error
- */
- public Exception getError() {
- return error;
- }
-
- @Override
- public LSInput resolveResource(String type, String namespaceURI,
- String publicId, String systemId, String baseURI) {
-
- if (log.isTraceEnabled()) {
- log.trace("Resolve resource :" +
- "\n type=" + type +
- "\n namespaceURI=" + namespaceURI +
- "\n publicId=" + publicId +
- "\n systemId=" + systemId +
- "\n baseURI=" + baseURI);
- }
-
- if (systemId != null) {
-
- log.debug("Resolve resource '" + systemId + "'.");
-
- for (DataObjectAssociationType supplement : supplements) {
-
- Base64XMLLocRefReqRefContentType content = supplement.getContent();
- if (content != null) {
-
- String reference = content.getReference();
- if (systemId.equals(reference)) {
-
- try {
- if (content.getLocRefContent() != null) {
- log.trace("Resolved resource '" + reference + "' to supplement with LocRefContent.");
- return createLSInput(content.getLocRefContent());
- } else if (content.getBase64Content() != null) {
- log.trace("Resolved resource '" + reference + "' to supplement with Base64Content.");
- return createLSInput(content.getBase64Content());
- } else if (content.getXMLContent() != null) {
- log.trace("Resolved resource '" + reference + "' to supplement with XMLContent.");
- return createLSInput((XMLContentType) content.getXMLContent());
- } else {
- return null;
- }
- } catch (IOException e) {
- log.info("Failed to resolve resource '" + systemId + "' to supplement.", e);
- error = e;
- return null;
- } catch (XMLStreamException e) {
- log.info("Failed to resolve resource '" + systemId + "' to supplement.", e);
- error = e;
- return null;
- }
-
- }
-
- }
-
- }
-
- log.info("Failed to resolve resource '" + systemId + "' to supplement. No such supplement.");
-
- }
-
- return null;
-
- }
-
-
- }
-
-}
+package at.gv.egiz.bku.slcommands.impl.xsect;
+
+import at.gv.egiz.stal.HashDataInput;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+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.crypto.MarshalException;
+import javax.xml.crypto.dom.DOMStructure;
+import javax.xml.crypto.dsig.CanonicalizationMethod;
+import javax.xml.crypto.dsig.DigestMethod;
+import javax.xml.crypto.dsig.Reference;
+import javax.xml.crypto.dsig.SignatureMethod;
+import javax.xml.crypto.dsig.SignedInfo;
+import javax.xml.crypto.dsig.XMLObject;
+import javax.xml.crypto.dsig.XMLSignature;
+import javax.xml.crypto.dsig.XMLSignatureException;
+import javax.xml.crypto.dsig.XMLSignatureFactory;
+import javax.xml.crypto.dsig.dom.DOMSignContext;
+import javax.xml.crypto.dsig.keyinfo.KeyInfo;
+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.etsi.uri._01903.v1_1.DataObjectFormatType;
+import org.etsi.uri._01903.v1_1.QualifyingPropertiesType;
+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.ls.DOMImplementationLS;
+import org.w3c.dom.ls.LSException;
+import org.w3c.dom.ls.LSInput;
+import org.w3c.dom.ls.LSOutput;
+import org.w3c.dom.ls.LSParser;
+import org.w3c.dom.ls.LSResourceResolver;
+import org.w3c.dom.ls.LSSerializer;
+
+import at.buergerkarte.namespaces.securitylayer._1.Base64XMLLocRefReqRefContentType;
+import at.buergerkarte.namespaces.securitylayer._1.Base64XMLOptRefContentType;
+import at.buergerkarte.namespaces.securitylayer._1.DataObjectAssociationType;
+import at.buergerkarte.namespaces.securitylayer._1.DataObjectInfoType;
+import at.buergerkarte.namespaces.securitylayer._1.SignatureInfoCreationType;
+import at.gv.egiz.bku.binding.HttpUtil;
+import at.gv.egiz.bku.slexceptions.SLCommandException;
+import at.gv.egiz.bku.slexceptions.SLRequestException;
+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;
+import at.gv.egiz.xades.QualifyingPropertiesException;
+import at.gv.egiz.xades.QualifyingPropertiesFactory;
+
+/**
+ * This class represents an XML-Signature as to be created by the
+ * security layer command CreateXMLSignatureRequest
.
+ *
+ * @author mcentner
+ */
+public class Signature {
+
+ /**
+ * Logging facility.
+ */
+ private static Log log = LogFactory.getLog(Signature.class);
+
+ /**
+ * The DOM implementation used.
+ */
+ private DOMImplementationLS domImplLS;
+
+ /**
+ * The SignatureContext for the XMLSignature.
+ */
+ private SignatureContext ctx;
+
+ /**
+ * The list of {@link DataObject}s for this signature.
+ */
+ private List dataObjects = new ArrayList();
+
+ /**
+ * A mapping from the Id
-attribute values of this signature's
+ * ds:Reference
s to the corresponding {@link DataObject}s.
+ */
+// private Map dataObjectReferencIds = new HashMap();
+
+ /**
+ * The SignatureEnvironment for this signature.
+ */
+ private SignatureLocation signatureLocation;
+
+ /**
+ * The XML signature.
+ */
+ private XMLSignature xmlSignature;
+
+ /**
+ * A list of attributes of type xsd:ID
to be registered in the {@link DOMSignContext}.
+ */
+ private List idAttributes = new ArrayList();
+
+ /**
+ * The signer's X509 certificate.
+ */
+ private X509Certificate signerCertificate;
+
+ /**
+ * The signing time.
+ */
+ private Date signingTime;
+
+ /**
+ * Creates a new SLXMLSignature instance.
+ */
+ public Signature(URLDereferencerContext dereferencerContext,
+ IdValueFactory idValueFactory,
+ AlgorithmMethodFactory algorithmMethodFactory) {
+
+ domImplLS = DOMUtils.getDOMImplementationLS();
+
+ ctx = new SignatureContext();
+
+ ctx.setSignatureFactory(XMLSignatureFactory.getInstance());
+
+ ctx.setDereferencerContext(dereferencerContext);
+ ctx.setIdValueFactory(idValueFactory);
+ ctx.setAlgorithmMethodFactory(algorithmMethodFactory);
+
+ }
+
+ /**
+ * @return the Document containing this Signature
+ */
+ public Document getDocument() {
+ return ctx.getDocument();
+ }
+
+ /**
+ * @return the parent Node for this Signature
+ */
+ public Node getParent() {
+ return (signatureLocation != null) ? signatureLocation.getParent() : null;
+ }
+
+ /**
+ * @return the next sibling Node for this Signature
+ */
+ public Node getNextSibling() {
+ return (signatureLocation != null) ? signatureLocation.getNextSibling() : null;
+ }
+
+ /**
+ * @return the XMLSignature
+ */
+ public XMLSignature getXMLSignature() {
+ return xmlSignature;
+ }
+
+ /**
+ * @return the list of {@link Reference}s of this Signature
+ */
+ @SuppressWarnings("unchecked")
+ public List getReferences() {
+ return (xmlSignature != null) ? xmlSignature.getSignedInfo().getReferences() : null;
+ }
+
+ /**
+ * @return the list of {@link XMLObject}s of this Signature
+ */
+ @SuppressWarnings("unchecked")
+ public List getXMLObjects() {
+ return (xmlSignature != null) ? xmlSignature.getObjects() : null;
+ }
+
+ /**
+ * Prepares the signature document with the information given by the
+ * signatureInfo
provided.
+ *
+ * @param signatureInfo
+ * the SignatureInfo
+ *
+ * @throws SLCommandException
+ * if processing fails for any reason
+ * @throws IllegalStateException
+ * if the parent
node has already been set
+ * @throws NullPointerException
+ * if signatureInfo
is null
+ */
+ public void setSignatureInfo(SignatureInfoCreationType signatureInfo) throws SLCommandException {
+
+ if (signatureLocation != null) {
+ throw new IllegalStateException("SignatureEnvironment already set.");
+ }
+
+ Base64XMLOptRefContentType signatureEnvironment = signatureInfo.getSignatureEnvironment();
+
+ if (signatureEnvironment == null) {
+
+ // no SignatureEnvironment, so we use an empty document and the document as parent
+ ensureSignatureLocation();
+
+ } else {
+
+ // parse SignatureEnvrionment and use as document
+ Document document = parseSignatureEnvironment(signatureEnvironment, signatureInfo.getSupplement());
+ ctx.setDocument(document);
+
+ signatureLocation = new SignatureLocation(ctx);
+ signatureLocation.setSignatureInfo(signatureInfo);
+
+ }
+
+ }
+
+ /**
+ * Ensures a SignatureLocation for this Signature.
+ */
+ private void ensureSignatureLocation() {
+
+ if (signatureLocation == null) {
+ Document document = DOMUtils.createDocument();
+ ctx.setDocument(document);
+
+ signatureLocation = new SignatureLocation(ctx);
+ signatureLocation.setParent(document);
+ }
+
+ }
+
+ /**
+ * Adds a DataObject with the information given by the
+ * dataObjectInfo
provided to this Signature.
+ *
+ * @param dataObjectInfo
+ * the DataObjectInfo
element
+ *
+ * @throws SLCommandException
+ * if adding the DataObject fails
+ * @throws SLRequestException
+ * if the information provided by the given
+ * dataObjectInfo
does not conform to the security
+ * layer specification
+ * @throws NullPointerException
+ * if dataObjectInfo
is null
+ */
+ public void addDataObject(DataObjectInfoType dataObjectInfo) throws SLCommandException, SLRequestException {
+
+ ensureSignatureLocation();
+
+ DataObject dataObject = new DataObject(ctx);
+ dataObject.setDataObjectInfo(dataObjectInfo);
+
+ dataObjects.add(dataObject);
+
+// dataObjectReferencIds.put(dataObject.getReference().getId(), dataObject);
+
+ }
+
+ /**
+ * Sets the SigningTime
qualifying property of this Signature.
+ *
+ * @param signingTime the signing time to set
+ */
+ public void setSigningTime(Date signingTime) {
+ this.signingTime = signingTime;
+ }
+
+ /**
+ * Sets the SignerCertificate
qualifying property of this Signature.
+ *
+ * @param certificate the signer's certificate
+ */
+ public void setSignerCeritifcate(X509Certificate certificate) {
+ this.signerCertificate = certificate;
+ }
+
+ /**
+ * Builds the XMLSignature data structure of this Signature as configured by
+ * the various setter methods.
+ *
+ * @throws SLCommandException if building this signature fails
+ */
+ public void buildXMLSignature() throws SLCommandException {
+
+ List objects = new ArrayList();
+ List references = new ArrayList();
+
+ // add all data objects
+ for (DataObject dataObject : dataObjects) {
+ if (dataObject.getXmlObject() != null) {
+ objects.add(dataObject.getXmlObject());
+ }
+ if (dataObject.getReference() != null) {
+ references.add(dataObject.getReference());
+ }
+ }
+
+ addXAdESObjectAndReference(objects, references);
+
+ XMLSignatureFactory signatureFactory = ctx.getSignatureFactory();
+ AlgorithmMethodFactory algorithmMethodFactory = ctx.getAlgorithmMethodFactory();
+
+ CanonicalizationMethod cm;
+ SignatureMethod sm;
+ try {
+ cm = algorithmMethodFactory.createCanonicalizationMethod(ctx);
+ sm = algorithmMethodFactory.createSignatureMethod(ctx);
+ } catch (NoSuchAlgorithmException e) {
+ log.error("Failed to get Canonicalization or Signature algorithm.", e);
+ throw new SLCommandException(4006);
+ } catch (InvalidAlgorithmParameterException e) {
+ log.error("Failed to get Canonicalization or Signature algorithm.", e);
+ throw new SLCommandException(4006);
+ }
+
+ String siId = ctx.getIdValueFactory().createIdValue("SignedInfo");
+
+ SignedInfo si = signatureFactory.newSignedInfo(cm, sm, references, siId);
+
+ KeyInfo ki = null;
+ if (signerCertificate != null) {
+ KeyInfoFactory kif = KeyInfoFactory.getInstance();
+ X509Data x509Data = kif.newX509Data(Collections.singletonList(signerCertificate));
+ ki = kif.newKeyInfo(Collections.singletonList(x509Data));
+ }
+
+ String signatureId = ctx.getIdValueFactory().createIdValue("Signature");
+ String signatureValueId = ctx.getIdValueFactory().createIdValue("SignatureValue");
+
+ xmlSignature = signatureFactory.newXMLSignature(si, ki, objects, signatureId, signatureValueId);
+
+ }
+
+ /**
+ * Sign this Signature using the given signContext
.
+ *
+ * Call's {@link #buildXMLSignature()} if it has not been called yet.
+ *
+ *
+ * @param signContext
+ * the signing context
+ *
+ * @throws MarshalException
+ * if marshalling the XMLSignature fails
+ * @throws XMLSignatureException
+ * if signing the XMLSignature fails
+ * @throws SLCommandException
+ * if building the XMLSignature fails
+ * @throws NullPointerException
+ * if signContext
is null
+ */
+ public void sign(DOMSignContext signContext) throws MarshalException, XMLSignatureException, SLCommandException {
+
+ if (xmlSignature == null) {
+ buildXMLSignature();
+ }
+
+ for (IdAttribute idAttribute : idAttributes) {
+ signContext.setIdAttributeNS(idAttribute.element, idAttribute.namespaceURI, idAttribute.localName);
+ }
+
+ // DO NOT USE:
+ // signContext.setProperty("iaik.xml.crypto.dsig.sign-over", Boolean.TRUE);
+
+ signContext.setProperty("javax.xml.crypto.dsig.cacheReference", Boolean.TRUE);
+
+ signContext.putNamespacePrefix(XMLSignature.XMLNS, "dsig");
+
+ signContext.setURIDereferencer(new URIDereferncerAdapter(ctx.getDereferencerContext()));
+
+ try {
+ xmlSignature.sign(signContext);
+ } catch (XMLSignatureException e) {
+ Throwable cause = e.getCause();
+ while (cause != null) {
+ if (cause instanceof STALSignatureException) {
+ int errorCode = ((STALSignatureException) cause).getErrorCode();
+ SLCommandException commandException = new SLCommandException(errorCode);
+ log.info("Failed to sign signature.", commandException);
+ throw commandException;
+ } else {
+ cause = cause.getCause();
+ }
+ }
+ throw e;
+ }
+
+ // debug
+ if (log.isTraceEnabled()) {
+ for (DataObject dataObject : dataObjects) {
+ Reference reference = dataObject.getReference();
+ InputStream digestInputStream = reference.getDigestInputStream();
+ if (digestInputStream != null) {
+ String mimeType = dataObject.getMimeType();
+ StringBuilder sb = new StringBuilder();
+ sb.append("DigestInput for Reference with id='");
+ sb.append(reference.getId());
+ sb.append("' (MIME-Type=");
+ sb.append(dataObject.getMimeType());
+ sb.append("):\n");
+ try {
+ if (mimeType != null && (
+ mimeType.startsWith("text") ||
+ "application/xhtml+xml".equals(mimeType))) {
+ byte[] b = new byte[512];
+ for (int l; (l = digestInputStream.read(b)) != -1;) {
+ sb.append(new String(b, 0, l));
+ }
+ } else {
+ sb.append(HexDump.hexDump(digestInputStream));
+ }
+ } catch (IOException e) {
+ log.error(e);
+ }
+ log.trace(sb.toString());
+ } else {
+ log.trace("Reference caching is not enabled.");
+ }
+ }
+ }
+
+ }
+
+ /**
+ * Sign this Signature using the given stal
implementation and
+ * keyboxIdentifier
.
+ *
+ * This method configures an appropriate {@link DOMSignContext} and calls
+ * {@link #sign(DOMSignContext)}. If {@link #buildXMLSignature()} has not been
+ * called yet, it is called by this method.
+ *
+ *
+ * @param stal
+ * the STAL implementation to use
+ * @param keyboxIdentifier
+ * the KeyboxIdentifier to use
+ *
+ * @throws MarshalException
+ * if marshalling this Signature fails
+ * @throws XMLSignatureException
+ * if signing this Signature fails
+ * @throws SLCommandException
+ * if building this Signature fails
+ * @throws NullPointerException
+ * if stal
or keyboxIdentifier
is
+ * null
+ */
+ public void sign(STAL stal, String keyboxIdentifier) throws MarshalException, XMLSignatureException, SLCommandException {
+
+ if (stal == null) {
+ throw new NullPointerException("Argument 'stal' must not be null.");
+ }
+
+ if (keyboxIdentifier == null) {
+ throw new NullPointerException("Argument 'keyboxIdentifier' must not be null.");
+ }
+
+ if (xmlSignature == null) {
+ buildXMLSignature();
+ }
+
+ SignatureMethod signatureMethod = xmlSignature.getSignedInfo().getSignatureMethod();
+ String algorithm = signatureMethod.getAlgorithm();
+
+ //don't get hashDataInputs (digestInputStreams) now, only once Signature.sign() was called (cf STALSignature.engineSign)
+ PrivateKey privateKey = new STALPrivateKey(stal, algorithm, keyboxIdentifier, dataObjects); // hashDataInputs);
+
+ DOMSignContext signContext;
+ if (getNextSibling() == null) {
+ signContext = new DOMSignContext(privateKey, getParent());
+ } else {
+ signContext = new DOMSignContext(privateKey, getParent(), getNextSibling());
+ }
+
+ sign(signContext);
+ }
+
+// @Override
+// public HashDataInput getHashDataInput(final String referenceId) {
+// final DataObject dataObject = dataObjectReferencIds.get(referenceId);
+// if (dataObject != null) {
+// return new HashDataInput() {
+//
+// InputStream hashDataInput = dataObject.getReference().getDigestInputStream();
+//
+// @Override
+// public String getReferenceId() {
+// return referenceId;
+// }
+//
+// @Override
+// public String getMimeType() {
+// return dataObject.getMimeType();
+// }
+//
+// @Override
+// public InputStream getHashDataInput() {
+// return hashDataInput;
+// }
+// };
+// }
+// return null;
+// }
+
+ /**
+ * Adds the XAdES QualifyingProperties
as an
+ * ds:Object
and a corresponding ds:Reference
to
+ * it's SignedProperties
element to this Signature.
+ *
+ * @param objects
+ * the list of ds:Objects
to add the created
+ * ds:Object
to
+ * @param references
+ * the list of ds:References
to add the created
+ * ds:Reference
to
+ *
+ * @throws SLCommandException
+ * if creating and adding the XAdES
+ * QualifyingProperties
fails
+ * @throws NullPointerException
+ * if objects
or references
is
+ * null
+ */
+ private void addXAdESObjectAndReference(List objects, List references) throws SLCommandException {
+
+ QualifyingPropertiesFactory factory = QualifyingPropertiesFactory.getInstance();
+
+ String idValue = ctx.getIdValueFactory().createIdValue("SignedProperties");
+
+ Date date = (signingTime != null) ? signingTime : new Date();
+
+ List signingCertificates;
+ if (signerCertificate != null) {
+ signingCertificates = Collections.singletonList(signerCertificate);
+ } else {
+ signingCertificates = Collections.emptyList();
+ }
+
+ // TODO: report MOA-SP bug
+ //
+ // The security layer specification mandates the use of version 1.2.2. of the
+ // XAdES QualifyingProperties. However MOA-SP supports only version 1.1.1. Therefore,
+ // the version 1.1.1 is used in order to be compatible with current MOA-SP versions.
+
+ List dataObjectFormats = new ArrayList();
+ for (DataObject dataObject : dataObjects) {
+ if (dataObject.getMimeType() != null && dataObject.getReference() != null) {
+ Reference reference = dataObject.getReference();
+ if (reference.getId() != null) {
+ String objectReference = "#" + reference.getId();
+ dataObjectFormats.add(factory.createDataObjectFormatType(
+ objectReference, dataObject.getMimeType(), dataObject
+ .getDescription()));
+ }
+ }
+ }
+
+ JAXBElement qualifyingProperties;
+ try {
+ qualifyingProperties = factory.createQualifyingProperties111(date, signingCertificates, idValue, dataObjectFormats);
+ } catch (QualifyingPropertiesException e) {
+ log.error("Failed to create QualifyingProperties.", e);
+ throw new SLCommandException(4000);
+ }
+
+ DocumentFragment fragment = ctx.getDocument().createDocumentFragment();
+
+ try {
+ factory.marshallQualifyingProperties(qualifyingProperties, fragment);
+ } catch (JAXBException e) {
+ log.error("Failed to marshal QualifyingProperties.", e);
+ throw new SLCommandException(4000);
+ }
+
+ List content = Collections.singletonList(new DOMStructure(fragment.getFirstChild()));
+
+ String objectIdValue = ctx.getIdValueFactory().createIdValue("Object");
+
+ XMLObject object = ctx.getSignatureFactory().newXMLObject(content, objectIdValue, null, null);
+
+ objects.add(object);
+
+ // TODO: Report MOA-SP Bug
+ //
+ // Direct referencing of the SignedPorperties Id-attribute is not supported by MOA-SP
+ // because the QualifyingProperties are parsed without the XAdES schema. Therefore,
+ // the shorthand XPointer could not be resolved.
+ //
+ // The following workaround uses an XPointer to select the SignedProperties in order
+ // to allow the signature to be verified with MOA-SP.
+
+ String referenceURI = "#xmlns(xades=http://uri.etsi.org/01903/v1.1.1%23)%20xpointer(id('"
+ + objectIdValue
+ + "')/child::xades:QualifyingProperties/child::xades:SignedProperties)";
+ DigestMethod dm;
+ try {
+ dm = ctx.getAlgorithmMethodFactory().createDigestMethod(ctx);
+ } catch (NoSuchAlgorithmException e) {
+ log.error("Failed to get DigestMethod algorithm.", e);
+ throw new SLCommandException(4006);
+ } catch (InvalidAlgorithmParameterException e) {
+ log.error("Failed to get DigestMethod algorithm.", e);
+ throw new SLCommandException(4006);
+ }
+
+ String referenceIdValue = ctx.getIdValueFactory().createIdValue("Reference");
+ String referenceType = QualifyingPropertiesFactory.SIGNED_PROPERTIES_REFERENCE_TYPE_V1_1_1;
+
+ Reference reference = ctx.getSignatureFactory().newReference(referenceURI, dm, null, referenceType, referenceIdValue);
+
+ references.add(reference);
+
+ Node child = fragment.getFirstChild();
+ if (child instanceof Element) {
+ NodeList nodes = ((Element) child).getElementsByTagNameNS(QualifyingPropertiesFactory.NS_URI_V1_1_1, "SignedProperties");
+ if (nodes.getLength() > 0) {
+ IdAttribute idAttribute = new IdAttribute();
+ idAttribute.element = (Element) nodes.item(0);
+ idAttribute.namespaceURI = null;
+ idAttribute.localName = "Id";
+ idAttributes.add(idAttribute);
+ }
+ }
+
+ }
+
+ /**
+ * Parse the SignatureEnvironment.
+ *
+ * @param signatureEnvironment
+ * the SignatureEnvironment
element
+ * @param supplements
+ * an optional list of Supplements
(may be
+ * null
)
+ *
+ * @return the parsed SignatureEnvironment document
+ *
+ * @throws SLCommandException
+ * if parsing the SignatureEnvironment fails
+ * @throws NullPointerException
+ * if signatureEnvironment
is null
+ */
+ private Document parseSignatureEnvironment(
+ Base64XMLOptRefContentType signatureEnvironment,
+ List supplements) throws SLCommandException {
+
+ if (signatureEnvironment == null) {
+ throw new NullPointerException("Argument 'signatureEnvironment' must not be null.");
+ }
+
+ LSInput input;
+ try {
+ if (signatureEnvironment.getReference() != null) {
+ log.debug("SignatureEnvironment contains Reference " + signatureEnvironment.getReference() + ".");
+ input = createLSInput(signatureEnvironment.getReference());
+ } else if (signatureEnvironment.getBase64Content() != null) {
+ log.debug("SignatureEnvironment contains Base64Content.");
+ input = createLSInput(signatureEnvironment.getBase64Content());
+ } else if (signatureEnvironment.getXMLContent() != null) {
+ log.debug("SignatureEnvironment contains XMLContent.");
+ input = createLSInput((XMLContentType) signatureEnvironment.getXMLContent());
+ } else {
+ // the schema does not allow us to reach this point
+ throw new SLCommandException(4000);
+ }
+ } catch (IOException e) {
+ log.info("XML document in which the signature is to be integrated cannot be resolved.", e);
+ throw new SLCommandException(4100);
+ } catch (XMLStreamException e) {
+ log.info("XML document in which the signature is to be integrated cannot be resolved.", e);
+ throw new SLCommandException(4100);
+ }
+
+ LSParser parser = domImplLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
+ DOMConfiguration domConfig = parser.getDomConfig();
+ SimpleDOMErrorHandler errorHandler = new SimpleDOMErrorHandler();
+ domConfig.setParameter("error-handler", errorHandler);
+ LSResourceResolverAdapter resourceResolver = new LSResourceResolverAdapter(supplements);
+ domConfig.setParameter("resource-resolver", resourceResolver);
+ domConfig.setParameter("validate", Boolean.TRUE);
+
+ Document doc;
+ try {
+ doc = parser.parse(input);
+ } catch (DOMException e) {
+ log.info("XML document in which the signature is to be integrated cannot be parsed.", e);
+ throw new SLCommandException(4101);
+ } catch (LSException e) {
+ log.info("XML document in which the signature is to be integrated cannot be parsed.", e);
+ throw new SLCommandException(4101);
+ }
+
+ if (resourceResolver.getError() != null) {
+ log.info("Failed to resolve resource while parsing SignatureEnvironment document.", resourceResolver.getError());
+ // we don't stop here, as we only _try_ to parse validating
+ }
+
+ if (errorHandler.hasFatalErrors()) {
+ // log fatal errors
+ if (log.isInfoEnabled()) {
+ List errorMessages = errorHandler.getErrorMessages();
+ StringBuffer sb = new StringBuffer();
+ 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());
+ }
+ throw new SLCommandException(4101);
+ }
+
+ // log parsed document
+ if (log.isTraceEnabled()) {
+
+ StringWriter writer = new StringWriter();
+
+ writer.write("SignatureEnvironment:\n");
+
+ LSOutput output = domImplLS.createLSOutput();
+ output.setCharacterStream(writer);
+ output.setEncoding("UTF-8");
+ LSSerializer serializer = domImplLS.createLSSerializer();
+ serializer.write(doc, output);
+
+ log.trace(writer.toString());
+ }
+
+ return doc;
+
+ }
+
+ /**
+ * Creates an LSInput from the given reference
URI.
+ *
+ * @param reference
+ * the reference URL
+ *
+ * @return an LSInput from the given reference
URI
+ *
+ * @throws IOException
+ * if dereferencing the given reference
fails
+ */
+ private LSInput createLSInput(String reference) throws IOException {
+
+ URLDereferencer urlDereferencer = URLDereferencer.getInstance();
+ StreamData streamData = urlDereferencer.dereference(reference, ctx.getDereferencerContext());
+
+ String contentType = streamData.getContentType();
+ String charset = HttpUtil.getCharset(contentType, true);
+ InputStreamReader streamReader;
+ try {
+ streamReader = new InputStreamReader(streamData.getStream(), charset);
+ } catch (UnsupportedEncodingException e) {
+ log.info("Charset " + charset + " not supported. Using default.");
+ streamReader = new InputStreamReader(streamData.getStream());
+ }
+
+ LSInput input = domImplLS.createLSInput();
+ input = domImplLS.createLSInput();
+ input.setCharacterStream(streamReader);
+
+ return input;
+
+ }
+
+ /**
+ * Creates an LSInput from the given content
bytes.
+ *
+ * @param content
+ * the content bytes
+ *
+ * @return an LSInput from the givne content
bytes
+ */
+ private LSInput createLSInput(byte[] content) {
+
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(content);
+ LSInput input = domImplLS.createLSInput();
+ input.setByteStream(inputStream);
+
+ return input;
+
+ }
+
+ /**
+ * Creates an LSInput from the given XML content
.
+ *
+ * @param content
+ * the XML content
+ * @return an LSInput from the given XML content
+ *
+ * @throws XMLStreamException
+ * if reading the XMLStream from the given XML content fails
+ */
+ private LSInput createLSInput(XMLContentType content) throws XMLStreamException {
+
+ ByteArrayOutputStream redirectedStream = content.getRedirectedStream();
+ if (redirectedStream != null) {
+ LSInput input = domImplLS.createLSInput();
+ input.setByteStream(new ByteArrayInputStream(redirectedStream.toByteArray()));
+ return input;
+ } else {
+ return null;
+ }
+
+ }
+
+ /**
+ * Represents an xsd:Id
-attribute value.
+ *
+ * @author mcentner
+ */
+ private class IdAttribute {
+
+ private Element element;
+
+ private String namespaceURI;
+
+ private String localName;
+
+ }
+
+ /**
+ * An implementation of the LSResourceResolver that uses a list of supplements
+ * to resolve resources.
+ *
+ * @author mcentner
+ */
+ private class LSResourceResolverAdapter implements LSResourceResolver {
+
+ List supplements;
+
+ private LSResourceResolverAdapter(
+ List supplements) {
+ this.supplements = supplements;
+ }
+
+ private Exception error;
+
+ /**
+ * @return the error
+ */
+ public Exception getError() {
+ return error;
+ }
+
+ @Override
+ public LSInput resolveResource(String type, String namespaceURI,
+ String publicId, String systemId, String baseURI) {
+
+ if (log.isTraceEnabled()) {
+ log.trace("Resolve resource :" +
+ "\n type=" + type +
+ "\n namespaceURI=" + namespaceURI +
+ "\n publicId=" + publicId +
+ "\n systemId=" + systemId +
+ "\n baseURI=" + baseURI);
+ }
+
+ if (systemId != null) {
+
+ log.debug("Resolve resource '" + systemId + "'.");
+
+ for (DataObjectAssociationType supplement : supplements) {
+
+ Base64XMLLocRefReqRefContentType content = supplement.getContent();
+ if (content != null) {
+
+ String reference = content.getReference();
+ if (systemId.equals(reference)) {
+
+ try {
+ if (content.getLocRefContent() != null) {
+ log.trace("Resolved resource '" + reference + "' to supplement with LocRefContent.");
+ return createLSInput(content.getLocRefContent());
+ } else if (content.getBase64Content() != null) {
+ log.trace("Resolved resource '" + reference + "' to supplement with Base64Content.");
+ return createLSInput(content.getBase64Content());
+ } else if (content.getXMLContent() != null) {
+ log.trace("Resolved resource '" + reference + "' to supplement with XMLContent.");
+ return createLSInput((XMLContentType) content.getXMLContent());
+ } else {
+ return null;
+ }
+ } catch (IOException e) {
+ log.info("Failed to resolve resource '" + systemId + "' to supplement.", e);
+ error = e;
+ return null;
+ } catch (XMLStreamException e) {
+ log.info("Failed to resolve resource '" + systemId + "' to supplement.", e);
+ error = e;
+ return null;
+ }
+
+ }
+
+ }
+
+ }
+
+ log.info("Failed to resolve resource '" + systemId + "' to supplement. No such supplement.");
+
+ }
+
+ return null;
+
+ }
+
+
+ }
+
+}
--
cgit v1.2.3
From a3361b40aa8f92849c50db27e349e17b87bebb1e Mon Sep 17 00:00:00 2001
From: wbauer
Date: Tue, 9 Sep 2008 12:40:52 +0000
Subject: improved security handling and added shutdown handler
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@27 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
---
.../accesscontroller/AuthenticationClassifier.java | 82 +++++++++++++++-------
.../egiz/bku/binding/BindingProcessorManager.java | 4 +-
.../bku/binding/BindingProcessorManagerImpl.java | 11 ++-
3 files changed, 68 insertions(+), 29 deletions(-)
(limited to 'bkucommon/src/main/java')
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AuthenticationClassifier.java b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AuthenticationClassifier.java
index ace8a75a..ed4b9bda 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AuthenticationClassifier.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/accesscontroller/AuthenticationClassifier.java
@@ -1,30 +1,31 @@
/*
-* 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.
-*/
+ * 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.accesscontroller;
import static at.gv.egiz.bku.accesscontroller.AuthenticationClass.ANONYMOUS;
import static at.gv.egiz.bku.accesscontroller.AuthenticationClass.CERTIFIED;
-import static at.gv.egiz.bku.accesscontroller.AuthenticationClass.PSEUDO_ANONYMOUS;
import static at.gv.egiz.bku.accesscontroller.AuthenticationClass.CERTIFIED_GOV_AGENCY;
+import static at.gv.egiz.bku.accesscontroller.AuthenticationClass.PSEUDO_ANONYMOUS;
-import java.net.InetAddress;
import java.net.URL;
-import java.net.UnknownHostException;
+import java.security.cert.CertificateParsingException;
import java.security.cert.X509Certificate;
+import java.util.Collection;
+import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -37,6 +38,39 @@ public class AuthenticationClassifier {
private AuthenticationClassifier() {
}
+ public static boolean isGovAgency(X509Certificate cert) {
+ String[] rdns = (cert.getSubjectX500Principal().getName()).split(",");
+ for (String rdn : rdns) {
+ if (rdn.startsWith("CN=")) {
+ String dns = rdn.split("=")[1];
+ log.trace("Analyzing cn dn: " + dns);
+ if (dns.endsWith(GOV_DOMAIN)) {
+ return true;
+ }
+ }
+ }
+ try {
+ Collection> sanList = cert.getSubjectAlternativeNames();
+ if (sanList != null) {
+ for (List> san : sanList) {
+ log.trace("Analyzing subj. alt name: " + san);
+ if ((Integer) san.get(0) == 2) {
+ String dns = (String) san.get(1);
+ if (dns.endsWith(GOV_DOMAIN)) {
+ return true;
+ }
+ }
+ }
+ }
+ } catch (CertificateParsingException e) {
+ log.error(e);
+ }
+ if (cert.getExtensionValue("1.2.40.0.10.1.1.1") != null) {
+ return true;
+ }
+ return false;
+ }
+
/**
* Client Certificates are currently not supported
*
@@ -45,13 +79,8 @@ public class AuthenticationClassifier {
URL url, X509Certificate cert) {
if (isDataUrl) {
if (url.getProtocol().equalsIgnoreCase("https")) {
- try {
- if (InetAddress.getByName(url.getHost()).getCanonicalHostName()
- .endsWith(GOV_DOMAIN)) {
- return CERTIFIED_GOV_AGENCY;
- }
- } catch (UnknownHostException e) {
- log.error("Cannot determine host name", e);
+ if (isGovAgency(cert)) {
+ return CERTIFIED_GOV_AGENCY;
}
if (cert.getExtensionValue("1.2.40.0.10.1.1.1") != null) {
return CERTIFIED_GOV_AGENCY;
@@ -68,7 +97,8 @@ public class AuthenticationClassifier {
/**
*
* @param isDataUrl
- * @param url if the url's protocol is https a cert parameter must be provided.
+ * @param url
+ * if the url's protocol is https a cert parameter must be provided.
* @param cert
* @return
*/
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManager.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManager.java
index ed37f08f..aaf81e51 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManager.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManager.java
@@ -99,5 +99,7 @@ public interface BindingProcessorManager {
*/
public Set getManagedIds();
- public void shutdown();
+ public void shutdown();
+
+ public void shutdownNow();
}
\ No newline at end of file
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManagerImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManagerImpl.java
index 6f5ca2d2..0082de26 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManagerImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManagerImpl.java
@@ -149,6 +149,11 @@ public class BindingProcessorManagerImpl implements BindingProcessorManager {
public void shutdown() {
log.info("Shutting down the BindingProcessorManager");
executorService.shutdown();
+ }
+
+ public void shutdownNow() {
+ log.info("Shutting down the BindingProcessorManager NOW!");
+ executorService.shutdownNow();
}
/**
@@ -223,7 +228,8 @@ public class BindingProcessorManagerImpl implements BindingProcessorManager {
throw new SLRuntimeException(
"Clashing ids, cannot process bindingprocessor with id:"
+ aBindingProcessor.getId());
- }
+ }
+ log.debug("processing bindingprocessor: "+aBindingProcessor.getId());
Future> f = executorService.submit(aBindingProcessor);
bindingProcessorMap.put(aBindingProcessor.getId(), new MapEntityWrapper(f,
aBindingProcessor));
@@ -235,7 +241,8 @@ public class BindingProcessorManagerImpl implements BindingProcessorManager {
}
@Override
- public void removeBindingProcessor(Id sessionId) {
+ public void removeBindingProcessor(Id sessionId) {
+ log.debug("Removing binding processor: "+sessionId);
MapEntityWrapper wrapper = bindingProcessorMap
.get(sessionId);
if (wrapper == null) {
--
cgit v1.2.3
From 66cfb865fbfa7af514e803003f928d77f1156e46 Mon Sep 17 00:00:00 2001
From: mcentner
Date: Thu, 11 Sep 2008 12:16:35 +0000
Subject: Added to be signed data validation.
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@32 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
---
.../binding/multipart/InputStreamPartSource.java | 5 -
.../egiz/bku/binding/multipart/SLResultPart.java | 5 -
.../impl/CreateXMLSignatureCommandImpl.java | 13 +-
.../egiz/bku/slcommands/impl/xsect/DataObject.java | 119 ++++++++++++++-
.../bku/slcommands/impl/xsect/STALSignature.java | 11 +-
.../egiz/bku/slcommands/impl/xsect/Signature.java | 10 +-
.../egiz/bku/slexceptions/SLViewerException.java | 7 +-
.../at/gv/egiz/bku/viewer/ValidationException.java | 38 +++++
.../main/java/at/gv/egiz/bku/viewer/Validator.java | 25 ++++
.../at/gv/egiz/bku/viewer/ValidatorFactory.java | 165 +++++++++++++++++++++
10 files changed, 371 insertions(+), 27 deletions(-)
create mode 100644 bkucommon/src/main/java/at/gv/egiz/bku/viewer/ValidationException.java
create mode 100644 bkucommon/src/main/java/at/gv/egiz/bku/viewer/Validator.java
create mode 100644 bkucommon/src/main/java/at/gv/egiz/bku/viewer/ValidatorFactory.java
(limited to 'bkucommon/src/main/java')
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/multipart/InputStreamPartSource.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/multipart/InputStreamPartSource.java
index 253f8ff5..1a22f787 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/multipart/InputStreamPartSource.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/multipart/InputStreamPartSource.java
@@ -14,11 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
package at.gv.egiz.bku.binding.multipart;
import java.io.IOException;
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/multipart/SLResultPart.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/multipart/SLResultPart.java
index 566b77b3..5585f02e 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/multipart/SLResultPart.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/multipart/SLResultPart.java
@@ -14,11 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
package at.gv.egiz.bku.binding.multipart;
import at.gv.egiz.bku.slcommands.SLResult;
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 136fa6f3..628326cf 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
@@ -44,7 +44,9 @@ import at.gv.egiz.bku.slcommands.impl.xsect.IdValueFactory;
import at.gv.egiz.bku.slcommands.impl.xsect.IdValueFactoryImpl;
import at.gv.egiz.bku.slcommands.impl.xsect.Signature;
import at.gv.egiz.bku.slexceptions.SLCommandException;
+import at.gv.egiz.bku.slexceptions.SLException;
import at.gv.egiz.bku.slexceptions.SLRequestException;
+import at.gv.egiz.bku.slexceptions.SLViewerException;
import at.gv.egiz.dom.DOMUtils;
import at.gv.egiz.stal.InfoboxReadRequest;
import at.gv.egiz.stal.InfoboxReadResponse;
@@ -166,9 +168,10 @@ public class CreateXMLSignatureCommandImpl extends SLCommandImpltrue if validation should be enabled, or
+ * false
otherwise.
+ */
+ public static void enableHashDataInputValidation(boolean validate) {
+ DataObject.validate = validate;
+ }
+
+ /**
+ * @return true
if hash data input validation is enabled,
+ * or false
otherwise.
+ */
+ public static boolean isHashDataInputValidationEnabled() {
+ return validate;
+ }
+
+ /**
+ * Valid MIME types.
+ */
+ private static String[] validMimeTypes = DEFAULT_PREFFERED_MIME_TYPES;
+
+ /**
+ * Sets the list of valid hash data input media types.
+ * The array is also used for transformation path selection.
+ * The transformation path with a final type, that appears in the
+ * given array in the earliest position is used selected.
+ *
+ * @param mediaTypes an array of MIME media types.
+ */
+ public static void setValidHashDataInputMediaTypes(String[] mediaTypes) {
+ validMimeTypes = mediaTypes;
+ }
+
/**
* The DOM implementation used.
*/
@@ -184,7 +230,70 @@ public class DataObject {
public String getDescription() {
return description;
}
-
+
+ public void validateHashDataInput() throws SLViewerException {
+
+ if (validate) {
+
+ if (reference == null) {
+ log.error("Medthod validateHashDataInput() called before reference has been created.");
+ throw new SLViewerException(5000);
+ }
+
+ InputStream digestInputStream = reference.getDigestInputStream();
+ if (digestInputStream == null) {
+ log.error("Method validateHashDataInput() called before reference has been generated " +
+ "or reference caching is not enabled.");
+ throw new SLViewerException(5000);
+ }
+
+ if (mimeType == null) {
+ log.info("FinalDataMetaInfo does not specify MIME type of to be signed data.");
+ // TODO: add detailed message
+ throw new SLViewerException(5000);
+ }
+
+ // get MIME media type
+ String mediaType = mimeType.split(";")[0].trim();
+ // and optional charset
+ String charset = HttpUtil.getCharset(mimeType, false);
+
+ if (Arrays.asList(validMimeTypes).contains(mediaType)) {
+
+ Validator validator;
+ try {
+ validator = ValidatorFactory.newValidator(mediaType);
+ } catch (IllegalArgumentException e) {
+ log.error("No validator found for mime type '" + mediaType + "'.");
+ throw new SLViewerException(5000);
+ }
+
+ try {
+ validator.validate(digestInputStream, charset);
+ } catch (ValidationException e) {
+ if ("text/plain".equals(mediaType)) {
+ log.info("Data to be displayed contains unsupported characters.", e);
+ // TODO: add detailed message
+ throw new SLViewerException(5003);
+ } else if ("application/xhtml+xml".equals(mediaType)) {
+ // TODO: add detailed message
+ log.info("Standard display format: HTML does not conform to specification.", e);
+ throw new SLViewerException(5004);
+ } else {
+ // TODO: add detailed message
+ log.info("Data to be displayed is invalid.", e);
+ throw new SLViewerException(5000);
+ }
+ }
+
+ } else {
+ log.info("MIME media type '" + mediaType + "' is not a valid digest input.");
+ throw new SLViewerException(5001);
+ }
+ }
+
+ }
+
/**
* Configures this DataObject with the information provided within the given
* sl:DataObjectInfo
.
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
index eba1d96d..2d89c8ae 100644
--- 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
@@ -17,6 +17,8 @@
package at.gv.egiz.bku.slcommands.impl.xsect;
import at.gv.egiz.bku.slcommands.impl.HashDataInputImpl;
+import at.gv.egiz.bku.slexceptions.SLViewerException;
+
import java.io.ByteArrayOutputStream;
import java.security.InvalidKeyException;
import java.security.InvalidParameterException;
@@ -123,9 +125,14 @@ public class STALSignature extends SignatureSpi {
// log.debug("got " + dataObjects.size() + " DataObjects, passing HashDataInputs to STAL SignRequest");
List hashDataInputs = new ArrayList();
- for (DataObject dataObject : dataObjects) {
- hashDataInputs.add(new HashDataInputImpl(dataObject));
+ for (DataObject dataObject : dataObjects) {
+ try {
+ dataObject.validateHashDataInput();
+ } catch (SLViewerException e) {
+ throw new STALSignatureException(e);
}
+ hashDataInputs.add(new HashDataInputImpl(dataObject));
+ }
SignRequest signRequest = new SignRequest();
signRequest.setKeyIdentifier(keyboxIdentifier);
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 191f8371..2330ed3f 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
@@ -81,6 +81,7 @@ import at.buergerkarte.namespaces.securitylayer._1.SignatureInfoCreationType;
import at.gv.egiz.bku.binding.HttpUtil;
import at.gv.egiz.bku.slexceptions.SLCommandException;
import at.gv.egiz.bku.slexceptions.SLRequestException;
+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;
@@ -387,10 +388,11 @@ public class Signature {
* if signing the XMLSignature fails
* @throws SLCommandException
* if building the XMLSignature fails
+ * @throws SLViewerException
* @throws NullPointerException
* if signContext
is null
*/
- public void sign(DOMSignContext signContext) throws MarshalException, XMLSignatureException, SLCommandException {
+ public void sign(DOMSignContext signContext) throws MarshalException, XMLSignatureException, SLCommandException, SLViewerException {
if (xmlSignature == null) {
buildXMLSignature();
@@ -415,6 +417,9 @@ public class Signature {
Throwable cause = e.getCause();
while (cause != null) {
if (cause instanceof STALSignatureException) {
+ if (((STALSignatureException) cause).getCause() instanceof SLViewerException) {
+ throw (SLViewerException) ((STALSignatureException) cause).getCause();
+ }
int errorCode = ((STALSignatureException) cause).getErrorCode();
SLCommandException commandException = new SLCommandException(errorCode);
log.info("Failed to sign signature.", commandException);
@@ -482,11 +487,12 @@ public class Signature {
* if signing this Signature fails
* @throws SLCommandException
* if building this Signature fails
+ * @throws SLViewerException
* @throws NullPointerException
* if stal
or keyboxIdentifier
is
* null
*/
- public void sign(STAL stal, String keyboxIdentifier) throws MarshalException, XMLSignatureException, SLCommandException {
+ public void sign(STAL stal, String keyboxIdentifier) throws MarshalException, XMLSignatureException, SLCommandException, SLViewerException {
if (stal == null) {
throw new NullPointerException("Argument 'stal' must not be null.");
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slexceptions/SLViewerException.java b/bkucommon/src/main/java/at/gv/egiz/bku/slexceptions/SLViewerException.java
index 1d128a00..853328d5 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slexceptions/SLViewerException.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slexceptions/SLViewerException.java
@@ -17,9 +17,12 @@
package at.gv.egiz.bku.slexceptions;
public class SLViewerException extends SLException {
-
+
+ public SLViewerException(int errorCode) {
+ super(errorCode);
+ }
+
public SLViewerException(int errorCode, String msg, Object[] args) {
super(errorCode, msg, args);
- // TODO Auto-generated constructor stub
}
}
\ No newline at end of file
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/viewer/ValidationException.java b/bkucommon/src/main/java/at/gv/egiz/bku/viewer/ValidationException.java
new file mode 100644
index 00000000..fb332a09
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/viewer/ValidationException.java
@@ -0,0 +1,38 @@
+/*
+* 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.viewer;
+
+public class ValidationException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ public ValidationException() {
+ }
+
+ public ValidationException(String message) {
+ super(message);
+ }
+
+ public ValidationException(Throwable cause) {
+ super(cause);
+ }
+
+ public ValidationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/viewer/Validator.java b/bkucommon/src/main/java/at/gv/egiz/bku/viewer/Validator.java
new file mode 100644
index 00000000..08b21080
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/viewer/Validator.java
@@ -0,0 +1,25 @@
+/*
+* 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.viewer;
+
+import java.io.InputStream;
+
+public interface Validator {
+
+ public void validate(InputStream is, String charset) throws ValidationException;
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/viewer/ValidatorFactory.java b/bkucommon/src/main/java/at/gv/egiz/bku/viewer/ValidatorFactory.java
new file mode 100644
index 00000000..e16a261e
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/viewer/ValidatorFactory.java
@@ -0,0 +1,165 @@
+/*
+* 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.viewer;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class ValidatorFactory {
+
+ /**
+ * Logging facility.
+ */
+ protected static Log log = LogFactory.getLog(ValidatorFactory.class);
+
+ private static final Class VALIDATOR_CLASS = Validator.class;
+
+ private static final String SERVICE_ID = "META-INF/services/" + VALIDATOR_CLASS.getName();
+
+ /**
+ * Creates a new Validator for the given mimeType
.
+ *
+ * @param mimeType
+ *
+ * @return
+ *
+ * @throws IllegalArgumentException
+ * if no Validator for the mimeType
could be found
+ */
+ public static Validator newValidator(String mimeType) throws IllegalArgumentException {
+
+ ClassLoader classLoader = ValidatorFactory.class.getClassLoader();
+ ValidatorFactory factory = new ValidatorFactory(classLoader);
+
+ Validator validator = factory.createValidator(mimeType);
+
+ if (validator == null) {
+ throw new IllegalArgumentException("Validator for '" + mimeType
+ + "' could not be found.");
+ }
+
+ return validator;
+
+ }
+
+ private ClassLoader classLoader;
+
+ /**
+ * Private constructor.
+ *
+ * @param classLoader must not be null
+ */
+ private ValidatorFactory(ClassLoader classLoader) {
+
+ if (classLoader == null) {
+ throw new NullPointerException("Argument 'classLoader' must no be null.");
+ }
+
+ this.classLoader = classLoader;
+
+ }
+
+ private Validator createValidator(String mimeType) {
+
+ Iterator serviceIterator = createServiceIterator();
+ while (serviceIterator.hasNext()) {
+ URL url = serviceIterator.next();
+
+ Properties properties = new Properties();
+ try {
+ properties.load(url.openStream());
+ } catch (IOException e) {
+ log.error("Failed to load service properties " + url.toExternalForm());
+ continue;
+ }
+ String className = properties.getProperty(mimeType);
+ if (className != null) {
+ try {
+ return createValidatorInstance(className);
+ } catch (Exception e) {
+ continue;
+ }
+ }
+
+ }
+
+ return null;
+
+ }
+
+ private Validator createValidatorInstance(String className)
+ throws ClassNotFoundException, InstantiationException,
+ IllegalAccessException {
+
+ try {
+ Class> implClass = classLoader.loadClass(className);
+ return (Validator) implClass.newInstance();
+ } catch (ClassNotFoundException e) {
+ log.error("Validator class '" + className + "' not found.", e);
+ throw e;
+ } catch (InstantiationException e) {
+ log.error("Faild to initialize validator class '" + className + "'.", e);
+ throw e;
+ } catch (IllegalAccessException e) {
+ log.error("Faild to initialize validator class '" + className + "'.", e);
+ throw e;
+ } catch (ClassCastException e) {
+ log.error("Class '" + className + "' is not a validator implementation.", e);
+ throw e;
+ }
+
+ }
+
+ private Iterator createServiceIterator() {
+
+ try {
+ final Enumeration resources = classLoader.getResources(SERVICE_ID);
+ return new Iterator () {
+
+ @Override
+ public boolean hasNext() {
+ return resources.hasMoreElements();
+ }
+
+ @Override
+ public URL next() {
+ return resources.nextElement();
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ };
+ } catch (IOException e) {
+ log.error("Failed to enumerate resources " + SERVICE_ID);
+ List list = Collections.emptyList();
+ return list.iterator();
+ }
+
+ }
+
+}
--
cgit v1.2.3
From 76bb812a3254be530e403f8db8c01323a31b30c1 Mon Sep 17 00:00:00 2001
From: wbauer
Date: Thu, 11 Sep 2008 13:03:44 +0000
Subject: git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@33
8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
---
.../main/java/at/gv/egiz/bku/binding/DataUrl.java | 22 +-
.../at/gv/egiz/bku/binding/DataUrlConnection.java | 6 +-
.../gv/egiz/bku/binding/DataUrlConnectionImpl.java | 444 +++++++++++----------
.../gv/egiz/bku/binding/DataUrlConnectionSPI.java | 9 +-
.../egiz/bku/slcommands/impl/ErrorResultImpl.java | 14 +-
5 files changed, 263 insertions(+), 232 deletions(-)
(limited to 'bkucommon/src/main/java')
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrl.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrl.java
index 8eaeacbd..a8477ece 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrl.java
@@ -16,13 +16,14 @@
*/
package at.gv.egiz.bku.binding;
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import at.gv.egiz.bku.slexceptions.SLRuntimeException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import at.gv.egiz.bku.slexceptions.SLRuntimeException;
/**
* Used to handle DataUrl connections as specified in the CCE's HTTP protocol binding.
@@ -30,7 +31,8 @@ import at.gv.egiz.bku.slexceptions.SLRuntimeException;
*/
public class DataUrl {
private static DataUrlConnectionSPI defaultDataUrlConnection = new DataUrlConnectionImpl();
- private static Log log = LogFactory.getLog(DataUrl.class);
+ private static Log log = LogFactory.getLog(DataUrl.class);
+ private static Properties configuration;
private URL url;
@@ -58,5 +60,9 @@ public class DataUrl {
log.error(e);
throw new SLRuntimeException("Cannot instantiate a dataurlconnection:",e);
}
+ }
+
+ public static void setConfiguration(Properties props) {
+ configuration = props;
}
}
\ No newline at end of file
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnection.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnection.java
index 6d654639..c6ffa32a 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnection.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnection.java
@@ -34,14 +34,16 @@ import at.gv.egiz.bku.slcommands.SLResult;
*/
public interface DataUrlConnection {
- public static final String DEFAULT_USERAGENT = "citizen-card-environment/1.2 BKU2 1.0";
+ public static final String DEFAULT_USERAGENT = "citizen-card-environment/1.2 MOCCA Unknown";
public static final String FORMPARAM_RESPONSETYPE = "ResponseType";
public static final String DEFAULT_RESPONSETYPE = "HTTP-Security-Layer-RESPONSE";
public static final String FORMPARAM_XMLRESPONSE = "XMLResponse";
public static final String FORMPARAM_BINARYRESPONSE = "BinaryResponse";
public static final String XML_RESPONSE_ENCODING = "UTF-8";
-
+
+ public final static String USER_AGENT_PROPERTY_KEY="UserAgent";
+
public String getProtocol();
public URL getUrl();
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java
index 9f5d70cb..bb0314b5 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java
@@ -1,221 +1,235 @@
/*
-* 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.binding;
-
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.HttpURLConnection;
-import java.net.SocketTimeoutException;
-import java.net.URL;
-import java.security.cert.X509Certificate;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.net.ssl.HttpsURLConnection;
-
-import org.apache.commons.httpclient.methods.multipart.FilePart;
-import org.apache.commons.httpclient.methods.multipart.Part;
-import org.apache.commons.httpclient.methods.multipart.StringPart;
-
-import at.gv.egiz.bku.binding.multipart.InputStreamPartSource;
-import at.gv.egiz.bku.binding.multipart.SLResultPart;
-import at.gv.egiz.bku.slcommands.SLResult;
-import at.gv.egiz.bku.slcommands.SLResult.SLResultType;
-import at.gv.egiz.bku.slexceptions.SLRuntimeException;
-import at.gv.egiz.bku.utils.StreamUtil;
-import at.gv.egiz.bku.utils.binding.Protocol;
-
-/**
- * not thread-safe thus newInsance always returns a new object
- *
- */
-public class DataUrlConnectionImpl implements DataUrlConnectionSPI {
-
- public final static Protocol[] SUPPORTED_PROTOCOLS = { Protocol.HTTP,
- Protocol.HTTPS };
- protected X509Certificate serverCertificate;
- protected Protocol protocol;
- protected URL url;
- private HttpURLConnection connection;
- protected Map requestHttpHeaders;
- protected ArrayList formParams;
- protected String boundary;
-
- protected DataUrlResponse result;
-
- public String getProtocol() {
- if (protocol == null) {
- return null;
- }
- return protocol.toString();
- }
-
- /**
- * opens a connection sets the headers gets the server certificate
- *
- * @throws java.net.SocketTimeoutException
- * @throws java.io.IOException
- * @pre url != null
- * @pre httpHeaders != null
- */
- public void connect() throws SocketTimeoutException, IOException {
- connection = (HttpURLConnection) url.openConnection();
-
+ * 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.binding;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.SocketTimeoutException;
+import java.net.URL;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.net.ssl.HttpsURLConnection;
+
+import org.apache.commons.httpclient.methods.multipart.FilePart;
+import org.apache.commons.httpclient.methods.multipart.Part;
+import org.apache.commons.httpclient.methods.multipart.StringPart;
+
+import at.gv.egiz.bku.binding.multipart.InputStreamPartSource;
+import at.gv.egiz.bku.binding.multipart.SLResultPart;
+import at.gv.egiz.bku.slcommands.SLResult;
+import at.gv.egiz.bku.slcommands.SLResult.SLResultType;
+import at.gv.egiz.bku.slexceptions.SLRuntimeException;
+import at.gv.egiz.bku.utils.binding.Protocol;
+
+/**
+ * not thread-safe thus newInsance always returns a new object
+ *
+ */
+public class DataUrlConnectionImpl implements DataUrlConnectionSPI {
+
+ public final static Protocol[] SUPPORTED_PROTOCOLS = { Protocol.HTTP,
+ Protocol.HTTPS };
+ protected X509Certificate serverCertificate;
+ protected Protocol protocol;
+ protected URL url;
+ private HttpURLConnection connection;
+ protected Map requestHttpHeaders;
+ protected ArrayList formParams;
+ protected String boundary;
+ protected Properties config = null;
+
+ protected DataUrlResponse result;
+
+ public String getProtocol() {
+ if (protocol == null) {
+ return null;
+ }
+ return protocol.toString();
+ }
+
+ /**
+ * opens a connection sets the headers gets the server certificate
+ *
+ * @throws java.net.SocketTimeoutException
+ * @throws java.io.IOException
+ * @pre url != null
+ * @pre httpHeaders != null
+ */
+ public void connect() throws SocketTimeoutException, IOException {
+ connection = (HttpURLConnection) url.openConnection();
+
// FIXXME move this to config.
- HttpURLConnection.setFollowRedirects(false);
-
-
- connection.setDoOutput(true);
- Set headers = requestHttpHeaders.keySet();
- Iterator headerIt = headers.iterator();
- while (headerIt.hasNext()) {
- String name = headerIt.next();
- connection.setRequestProperty(name, requestHttpHeaders.get(name));
- }
- connection.connect();
- if (connection instanceof HttpsURLConnection) {
- HttpsURLConnection ssl = (HttpsURLConnection) connection;
- X509Certificate[] certs = (X509Certificate[]) ssl.getServerCertificates();
- if ((certs != null) && (certs.length >= 1)) {
- serverCertificate = certs[0];
- }
- }
- }
-
- public X509Certificate getServerCertificate() {
- return serverCertificate;
- }
-
- public void setHTTPHeader(String name, String value) {
- if (name != null && value != null) {
- requestHttpHeaders.put(name, value);
- }
- }
-
- public void setHTTPFormParameter(String name, InputStream data,
- String contentType, String charSet, String transferEncoding) {
- InputStreamPartSource source = new InputStreamPartSource(null, data);
- FilePart formParam = new FilePart(name, source, contentType, charSet);
- if (transferEncoding != null) {
- formParam.setTransferEncoding(transferEncoding);
- } else {
- formParam.setTransferEncoding(null);
- }
- formParams.add(formParam);
- }
-
- /**
- * send all formParameters
- *
- * @throws java.io.IOException
- */
- public void transmit(SLResult slResult) throws IOException {
- SLResultPart slResultPart = new SLResultPart(slResult,
- XML_RESPONSE_ENCODING);
- if (slResult.getResultType() == SLResultType.XML) {
- slResultPart.setTransferEncoding(null);
- slResultPart.setContentType(slResult.getMimeType());
- slResultPart.setCharSet(XML_RESPONSE_ENCODING);
- } else {
- slResultPart.setTransferEncoding(null);
- slResultPart.setContentType(slResult.getMimeType());
- }
- formParams.add(slResultPart);
-
- OutputStream os = connection.getOutputStream();
-
- Part[] parts = new Part[formParams.size()];
- Part.sendParts(os, formParams.toArray(parts), boundary.getBytes());
- os.close();
+ HttpURLConnection.setFollowRedirects(false);
+
+ connection.setDoOutput(true);
+ Set headers = requestHttpHeaders.keySet();
+ Iterator headerIt = headers.iterator();
+ while (headerIt.hasNext()) {
+ String name = headerIt.next();
+ connection.setRequestProperty(name, requestHttpHeaders.get(name));
+ }
+ connection.connect();
+ if (connection instanceof HttpsURLConnection) {
+ HttpsURLConnection ssl = (HttpsURLConnection) connection;
+ X509Certificate[] certs = (X509Certificate[]) ssl.getServerCertificates();
+ if ((certs != null) && (certs.length >= 1)) {
+ serverCertificate = certs[0];
+ }
+ }
+ }
+
+ public X509Certificate getServerCertificate() {
+ return serverCertificate;
+ }
+
+ public void setHTTPHeader(String name, String value) {
+ if (name != null && value != null) {
+ requestHttpHeaders.put(name, value);
+ }
+ }
+
+ public void setHTTPFormParameter(String name, InputStream data,
+ String contentType, String charSet, String transferEncoding) {
+ InputStreamPartSource source = new InputStreamPartSource(null, data);
+ FilePart formParam = new FilePart(name, source, contentType, charSet);
+ if (transferEncoding != null) {
+ formParam.setTransferEncoding(transferEncoding);
+ } else {
+ formParam.setTransferEncoding(null);
+ }
+ formParams.add(formParam);
+ }
+
+ /**
+ * send all formParameters
+ *
+ * @throws java.io.IOException
+ */
+ public void transmit(SLResult slResult) throws IOException {
+ SLResultPart slResultPart = new SLResultPart(slResult,
+ XML_RESPONSE_ENCODING);
+ if (slResult.getResultType() == SLResultType.XML) {
+ slResultPart.setTransferEncoding(null);
+ slResultPart.setContentType(slResult.getMimeType());
+ slResultPart.setCharSet(XML_RESPONSE_ENCODING);
+ } else {
+ slResultPart.setTransferEncoding(null);
+ slResultPart.setContentType(slResult.getMimeType());
+ }
+ formParams.add(slResultPart);
+
+ OutputStream os = connection.getOutputStream();
+
+ Part[] parts = new Part[formParams.size()];
+ Part.sendParts(os, formParams.toArray(parts), boundary.getBytes());
+ os.close();
// MultipartRequestEntity PostMethod
- result = new DataUrlResponse(url.toString(), connection.getResponseCode(),
- connection.getInputStream());
-
- Map responseHttpHeaders = new HashMap();
- Map> httpHeaders = connection.getHeaderFields();
- for (Iterator keyIt = httpHeaders.keySet().iterator(); keyIt
- .hasNext();) {
- String key = keyIt.next();
- StringBuffer value = new StringBuffer();
- for (String val : httpHeaders.get(key)) {
- value.append(val);
- value.append(HttpUtil.SEPERATOR[0]);
- }
- String valString = value.substring(0, value.length() - 1);
- if ((key != null)&&(value.length() > 0)) {
- responseHttpHeaders.put(key, valString);
- }
- }
- result.setResponseHttpHeaders(responseHttpHeaders);
- }
-
- @Override
- public DataUrlResponse getResponse() throws IOException {
- return result;
- }
-
- /**
- * inits protocol, url, httpHeaders, formParams
- *
- * @param url
- * must not be null
- */
- @Override
- public void init(URL url) {
-
- for (int i = 0; i < SUPPORTED_PROTOCOLS.length; i++) {
- if (SUPPORTED_PROTOCOLS[i].toString().equalsIgnoreCase(url.getProtocol())) {
- protocol = SUPPORTED_PROTOCOLS[i];
- break;
- }
- }
- if (protocol == null) {
- throw new SLRuntimeException("Protocol " + url.getProtocol()
- + " not supported for data url");
- }
- this.url = url;
- boundary = "--" + IdFactory.getInstance().createId().toString();
- requestHttpHeaders = new HashMap();
- requestHttpHeaders.put(HttpUtil.HTTP_HEADER_USER_AGENT, DEFAULT_USERAGENT);
- requestHttpHeaders.put(HttpUtil.HTTP_HEADER_CONTENT_TYPE,
- HttpUtil.MULTIPART_FOTMDATA + HttpUtil.SEPERATOR[0]
- + HttpUtil.MULTIPART_FOTMDATA_BOUNDARY + "=" + boundary);
-
- formParams = new ArrayList();
- StringPart responseType = new StringPart(FORMPARAM_RESPONSETYPE,
- DEFAULT_RESPONSETYPE);
- responseType.setCharSet("UTF-8");
- responseType.setTransferEncoding(null);
- formParams.add(responseType);
- }
-
- @Override
- public DataUrlConnectionSPI newInstance() {
- return new DataUrlConnectionImpl();
+ result = new DataUrlResponse(url.toString(), connection.getResponseCode(),
+ connection.getInputStream());
+
+ Map responseHttpHeaders = new HashMap();
+ Map> httpHeaders = connection.getHeaderFields();
+ for (Iterator keyIt = httpHeaders.keySet().iterator(); keyIt
+ .hasNext();) {
+ String key = keyIt.next();
+ StringBuffer value = new StringBuffer();
+ for (String val : httpHeaders.get(key)) {
+ value.append(val);
+ value.append(HttpUtil.SEPERATOR[0]);
+ }
+ String valString = value.substring(0, value.length() - 1);
+ if ((key != null) && (value.length() > 0)) {
+ responseHttpHeaders.put(key, valString);
+ }
+ }
+ result.setResponseHttpHeaders(responseHttpHeaders);
}
- @Override
- public URL getUrl() {
- return url;
- }
+ @Override
+ public DataUrlResponse getResponse() throws IOException {
+ return result;
+ }
+
+ /**
+ * inits protocol, url, httpHeaders, formParams
+ *
+ * @param url
+ * must not be null
+ */
+ @Override
+ public void init(URL url) {
+
+ for (int i = 0; i < SUPPORTED_PROTOCOLS.length; i++) {
+ if (SUPPORTED_PROTOCOLS[i].toString().equalsIgnoreCase(url.getProtocol())) {
+ protocol = SUPPORTED_PROTOCOLS[i];
+ break;
+ }
+ }
+ if (protocol == null) {
+ throw new SLRuntimeException("Protocol " + url.getProtocol()
+ + " not supported for data url");
+ }
+ this.url = url;
+ boundary = "--" + IdFactory.getInstance().createId().toString();
+ requestHttpHeaders = new HashMap();
+ if ((config != null)
+ && (config.getProperty(USER_AGENT_PROPERTY_KEY) != null)) {
+ requestHttpHeaders.put(HttpUtil.HTTP_HEADER_USER_AGENT, config
+ .getProperty(USER_AGENT_PROPERTY_KEY));
+ } else {
+ requestHttpHeaders
+ .put(HttpUtil.HTTP_HEADER_USER_AGENT, DEFAULT_USERAGENT);
+
+ }
+ requestHttpHeaders.put(HttpUtil.HTTP_HEADER_CONTENT_TYPE,
+ HttpUtil.MULTIPART_FOTMDATA + HttpUtil.SEPERATOR[0]
+ + HttpUtil.MULTIPART_FOTMDATA_BOUNDARY + "=" + boundary);
+
+ formParams = new ArrayList();
+ StringPart responseType = new StringPart(FORMPARAM_RESPONSETYPE,
+ DEFAULT_RESPONSETYPE);
+ responseType.setCharSet("UTF-8");
+ responseType.setTransferEncoding(null);
+ formParams.add(responseType);
+ }
+
+ @Override
+ public DataUrlConnectionSPI newInstance() {
+ DataUrlConnectionSPI uc = new DataUrlConnectionImpl();
+ uc.setConfiguration(config);
+ return uc;
+ }
+
+ @Override
+ public URL getUrl() {
+ return url;
+ }
+
+ @Override
+ public void setConfiguration(Properties config) {
+ this.config = config;
+ }
}
\ No newline at end of file
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionSPI.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionSPI.java
index 9e5a66f8..80cc3a0b 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionSPI.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionSPI.java
@@ -17,6 +17,7 @@
package at.gv.egiz.bku.binding;
import java.net.URL;
+import java.util.Properties;
/**
* Prototype of a DataurlconnectionSPI
@@ -36,7 +37,13 @@ public interface DataUrlConnectionSPI extends DataUrlConnection {
* Initializes the DataUrlConnection
* @param url
*/
- public void init(URL url);
+ public void init(URL url);
+
+ /**
+ * Sets configuration parameters for this connection
+ * @param config
+ */
+ public void setConfiguration(Properties config);
}
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 555f83bd..fb624211 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
@@ -16,12 +16,14 @@
*/
package at.gv.egiz.bku.slcommands.impl;
-import at.buergerkarte.namespaces.securitylayer._1.ErrorResponseType;
-import at.buergerkarte.namespaces.securitylayer._1.ObjectFactory;
-import at.gv.egiz.bku.slcommands.ErrorResult;
-import at.gv.egiz.bku.slexceptions.SLException;
-
-import javax.xml.transform.Result;
+import java.util.Locale;
+
+import javax.xml.transform.Result;
+
+import at.buergerkarte.namespaces.securitylayer._1.ErrorResponseType;
+import at.buergerkarte.namespaces.securitylayer._1.ObjectFactory;
+import at.gv.egiz.bku.slcommands.ErrorResult;
+import at.gv.egiz.bku.slexceptions.SLException;
/**
* This class implements the security layer result ErrorResponse
.
--
cgit v1.2.3
From 0df8bb10302989f41ed420ec0ff29b2fc2005471 Mon Sep 17 00:00:00 2001
From: wbauer
Date: Mon, 15 Sep 2008 14:18:53 +0000
Subject: Migrated BKULocal to BKUCommonGUI and minor bug fixes
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@37 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
---
.../bku/binding/BindingProcessorManagerImpl.java | 1 +
.../gv/egiz/bku/binding/DataUrlConnectionImpl.java | 20 ++++++++++-------
.../egiz/bku/slcommands/impl/xsect/Signature.java | 25 ++++++++++++++++++++++
3 files changed, 38 insertions(+), 8 deletions(-)
(limited to 'bkucommon/src/main/java')
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManagerImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManagerImpl.java
index 0082de26..22ee0d1d 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManagerImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManagerImpl.java
@@ -187,6 +187,7 @@ public class BindingProcessorManagerImpl implements BindingProcessorManager {
}
BindingProcessor bindingProcessor = new HTTPBindingProcessor(aSessionId,
commandInvokerClass.newInstance(), url);
+ stalFactory.setLocale(locale);
STAL stal = stalFactory.createSTAL();
bindingProcessor.init(stal, commandInvokerClass.newInstance());
if (locale != null) {
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java
index bb0314b5..775f4136 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java
@@ -36,6 +36,8 @@ import javax.net.ssl.HttpsURLConnection;
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import at.gv.egiz.bku.binding.multipart.InputStreamPartSource;
import at.gv.egiz.bku.binding.multipart.SLResultPart;
@@ -49,6 +51,8 @@ import at.gv.egiz.bku.utils.binding.Protocol;
*
*/
public class DataUrlConnectionImpl implements DataUrlConnectionSPI {
+
+ private final static Log log = LogFactory.getLog(DataUrlConnectionImpl.class);
public final static Protocol[] SUPPORTED_PROTOCOLS = { Protocol.HTTP,
Protocol.HTTPS };
@@ -80,10 +84,6 @@ public class DataUrlConnectionImpl implements DataUrlConnectionSPI {
*/
public void connect() throws SocketTimeoutException, IOException {
connection = (HttpURLConnection) url.openConnection();
-
- // FIXXME move this to config.
- HttpURLConnection.setFollowRedirects(false);
-
connection.setDoOutput(true);
Set headers = requestHttpHeaders.keySet();
Iterator headerIt = headers.iterator();
@@ -146,10 +146,14 @@ public class DataUrlConnectionImpl implements DataUrlConnectionSPI {
Part[] parts = new Part[formParams.size()];
Part.sendParts(os, formParams.toArray(parts), boundary.getBytes());
os.close();
- // MultipartRequestEntity PostMethod
- result = new DataUrlResponse(url.toString(), connection.getResponseCode(),
- connection.getInputStream());
-
+ // MultipartRequestEntity PostMethod
+ InputStream is = null;
+ try {
+ is = connection.getInputStream();
+ } catch (IOException iox) {
+ log.info(iox);
+ }
+ result = new DataUrlResponse(url.toString(), connection.getResponseCode(), is);
Map responseHttpHeaders = new HashMap();
Map> httpHeaders = connection.getHeaderFields();
for (Iterator keyIt = httpHeaders.keySet().iterator(); keyIt
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 2330ed3f..8baa0137 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
@@ -463,6 +463,31 @@ public class Signature {
log.trace("Reference caching is not enabled.");
}
}
+ for (Reference reference : getReferences()) {
+ if (reference.getType() != null) {
+ InputStream digestInputStream = reference.getDigestInputStream();
+ if (digestInputStream != null) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("DigestInput for Reference with id='");
+ sb.append(reference.getId());
+ sb.append("'; Type:");
+ sb.append(reference.getType());
+ sb.append("):\n");
+ try {
+ byte[] b = new byte[512];
+ for (int l; (l = digestInputStream.read(b)) != -1;) {
+ sb.append(new String(b, 0, l));
+ }
+ } catch (IOException e) {
+ log.error(e);
+ }
+ log.trace(sb.toString());
+ } else {
+ log.trace("Reference caching is not enabled.");
+ }
+
+ }
+ }
}
}
--
cgit v1.2.3
From fd1db02bdc9fbd2a5beca0cc2b214c1adbcc1a7a Mon Sep 17 00:00:00 2001
From: clemenso
Date: Mon, 15 Sep 2008 18:01:32 +0000
Subject: encoding
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@39 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
---
.../src/main/java/at/gv/egiz/bku/binding/Id.java | 24 ++--
.../main/java/at/gv/egiz/bku/binding/IdImpl.java | 129 +++++++++++----------
.../bku/slcommands/impl/HashDataInputImpl.java | 11 +-
3 files changed, 90 insertions(+), 74 deletions(-)
(limited to 'bkucommon/src/main/java')
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/Id.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/Id.java
index 93ab2e8b..fc7c35c3 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/Id.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/Id.java
@@ -14,14 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package at.gv.egiz.bku.binding;
-
-/**
- * The unique identifier for a BindingProcessor
- * @author wbauer
- *
- */
-public interface Id {
-
- public String toString();
+package at.gv.egiz.bku.binding;
+
+/**
+ * The unique identifier for a BindingProcessor
+ * @author wbauer
+ *
+ */
+public interface Id {
+
+ @Override
+ public String toString();
+
+ @Override
+ public boolean equals(Object id);
}
\ No newline at end of file
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/IdImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/IdImpl.java
index 5523992a..c8a76823 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/IdImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/IdImpl.java
@@ -14,67 +14,70 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package at.gv.egiz.bku.binding;
-
-import iaik.utils.Base64OutputStream;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.security.SecureRandom;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Implementation that uses a Base64 representation for self generated Ids.
- * @author wbauer
- *
- */
-public class IdImpl implements at.gv.egiz.bku.binding.Id {
- private static Log log = LogFactory.getLog(IdImpl.class);
-
- private String idString;
-
- public IdImpl(int bitNumber, SecureRandom random) {
- int byteSize = bitNumber/8;
- if (bitNumber % 8 != 0) {
- byteSize++;
- }
- byte[] randomBytes = new byte[byteSize];
- random.nextBytes(randomBytes);
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- Base64OutputStream b64 = new Base64OutputStream(baos);
- try {
- b64.write(randomBytes);
- b64.flush();
- b64.close();
- idString = new String(baos.toByteArray());
- } catch (IOException e) {
- log.error("Cannot create secure id: "+e);
- }
- }
-
- public IdImpl(String idString) {
- if (idString == null) {
- throw new NullPointerException("Provided idstring must not be null");
- }
- this.idString = idString;
- }
-
- public String toString() {
- return idString;
- }
-
- public int hashCode() {
- return idString.hashCode();
- }
-
- public boolean equals(Object other) {
- if (other instanceof Id) {
- Id otherId = (Id)other;
- return otherId.toString().equals(idString);
- } else {
- return false;
- }
- }
+package at.gv.egiz.bku.binding;
+
+import iaik.utils.Base64OutputStream;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.security.SecureRandom;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Implementation that uses a Base64 representation for self generated Ids.
+ * @author wbauer
+ *
+ */
+public class IdImpl implements at.gv.egiz.bku.binding.Id {
+ private static Log log = LogFactory.getLog(IdImpl.class);
+
+ private String idString;
+
+ public IdImpl(int bitNumber, SecureRandom random) {
+ int byteSize = bitNumber/8;
+ if (bitNumber % 8 != 0) {
+ byteSize++;
+ }
+ byte[] randomBytes = new byte[byteSize];
+ random.nextBytes(randomBytes);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ Base64OutputStream b64 = new Base64OutputStream(baos);
+ try {
+ b64.write(randomBytes);
+ b64.flush();
+ b64.close();
+ idString = new String(baos.toByteArray());
+ } catch (IOException e) {
+ log.error("Cannot create secure id: "+e);
+ }
+ }
+
+ public IdImpl(String idString) {
+ if (idString == null) {
+ throw new NullPointerException("Provided idstring must not be null");
+ }
+ this.idString = idString;
+ }
+
+ @Override
+ public String toString() {
+ return idString;
+ }
+
+ @Override
+ public int hashCode() {
+ return idString.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other instanceof Id) {
+ Id otherId = (Id)other;
+ return otherId.toString().equals(idString);
+ } else {
+ return false;
+ }
+ }
}
\ No newline at end of file
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/HashDataInputImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/HashDataInputImpl.java
index 49d3c63f..d6999404 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/HashDataInputImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/HashDataInputImpl.java
@@ -4,6 +4,7 @@
*/
package at.gv.egiz.bku.slcommands.impl;
+import at.gv.egiz.bku.binding.HttpUtil;
import at.gv.egiz.bku.slcommands.impl.xsect.DataObject;
import at.gv.egiz.stal.HashDataInput;
import java.io.InputStream;
@@ -16,11 +17,14 @@ public class HashDataInputImpl implements HashDataInput {
String refId;
String mimeType;
+ String encoding;
InputStream hashDataInput;
public HashDataInputImpl(DataObject dataObject) {
refId = dataObject.getReference().getId();
- mimeType = dataObject.getMimeType();
+ String contentType = dataObject.getMimeType();
+ mimeType = contentType.split(";")[0].trim();
+ encoding = HttpUtil.getCharset(dataObject.getMimeType(), false);
hashDataInput = dataObject.getReference().getDigestInputStream();
}
@@ -39,4 +43,9 @@ public class HashDataInputImpl implements HashDataInput {
return hashDataInput;
}
+ @Override
+ public String getEncoding() {
+ return encoding;
+ }
+
}
--
cgit v1.2.3
From f72d5842828ec072813eb30051d24f7cc8613606 Mon Sep 17 00:00:00 2001
From: clemenso
Date: Wed, 17 Sep 2008 17:18:14 +0000
Subject: hashdatainput digest verification
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@45 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
---
.../slcommands/impl/DataObjectHashDataInput.java | 50 +++++++++++++++++++++
.../bku/slcommands/impl/HashDataInputImpl.java | 51 ----------------------
.../bku/slcommands/impl/xsect/STALSignature.java | 4 +-
3 files changed, 52 insertions(+), 53 deletions(-)
create mode 100644 bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DataObjectHashDataInput.java
delete mode 100644 bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/HashDataInputImpl.java
(limited to 'bkucommon/src/main/java')
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DataObjectHashDataInput.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DataObjectHashDataInput.java
new file mode 100644
index 00000000..71b62911
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DataObjectHashDataInput.java
@@ -0,0 +1,50 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package at.gv.egiz.bku.slcommands.impl;
+
+import at.gv.egiz.bku.binding.HttpUtil;
+import at.gv.egiz.bku.slcommands.impl.xsect.DataObject;
+import at.gv.egiz.stal.HashDataInput;
+import java.io.InputStream;
+
+/**
+ *
+ * @author clemens
+ */
+public class DataObjectHashDataInput implements HashDataInput {
+
+ protected DataObject dataObject;
+
+ public DataObjectHashDataInput(DataObject dataObject) {
+ if (dataObject.getReference() == null)
+ throw new NullPointerException("DataObject reference must not be null");
+ this.dataObject = dataObject;
+ }
+
+ @Override
+ public String getReferenceId() {
+ return dataObject.getReference().getId();
+ }
+
+ @Override
+ public String getMimeType() {
+ return dataObject.getMimeType();
+ }
+
+ /**
+ *
+ * @return the pre-digested input stream if reference caching is enabled, null otherwise
+ */
+ @Override
+ public InputStream getHashDataInput() {
+ return dataObject.getReference().getDigestInputStream();
+ }
+
+ @Override
+ public String getEncoding() {
+ return HttpUtil.getCharset(dataObject.getMimeType(), false);
+ }
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/HashDataInputImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/HashDataInputImpl.java
deleted file mode 100644
index d6999404..00000000
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/HashDataInputImpl.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package at.gv.egiz.bku.slcommands.impl;
-
-import at.gv.egiz.bku.binding.HttpUtil;
-import at.gv.egiz.bku.slcommands.impl.xsect.DataObject;
-import at.gv.egiz.stal.HashDataInput;
-import java.io.InputStream;
-
-/**
- *
- * @author clemens
- */
-public class HashDataInputImpl implements HashDataInput {
-
- String refId;
- String mimeType;
- String encoding;
- InputStream hashDataInput;
-
- public HashDataInputImpl(DataObject dataObject) {
- refId = dataObject.getReference().getId();
- String contentType = dataObject.getMimeType();
- mimeType = contentType.split(";")[0].trim();
- encoding = HttpUtil.getCharset(dataObject.getMimeType(), false);
- hashDataInput = dataObject.getReference().getDigestInputStream();
- }
-
- @Override
- public String getReferenceId() {
- return refId;
- }
-
- @Override
- public String getMimeType() {
- return mimeType;
- }
-
- @Override
- public InputStream getHashDataInput() {
- return hashDataInput;
- }
-
- @Override
- public String getEncoding() {
- return encoding;
- }
-
-}
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
index 2d89c8ae..dd7c7d8a 100644
--- 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
@@ -16,7 +16,7 @@
*/
package at.gv.egiz.bku.slcommands.impl.xsect;
-import at.gv.egiz.bku.slcommands.impl.HashDataInputImpl;
+import at.gv.egiz.bku.slcommands.impl.DataObjectHashDataInput;
import at.gv.egiz.bku.slexceptions.SLViewerException;
import java.io.ByteArrayOutputStream;
@@ -131,7 +131,7 @@ public class STALSignature extends SignatureSpi {
} catch (SLViewerException e) {
throw new STALSignatureException(e);
}
- hashDataInputs.add(new HashDataInputImpl(dataObject));
+ hashDataInputs.add(new DataObjectHashDataInput(dataObject));
}
SignRequest signRequest = new SignRequest();
--
cgit v1.2.3
From a20fb683943ce0893302b6dc25015c998cd9687f Mon Sep 17 00:00:00 2001
From: clemenso
Date: Thu, 18 Sep 2008 09:25:55 +0000
Subject: hashdatainput cached
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@46 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
---
.../at/gv/egiz/bku/slcommands/impl/DataObjectHashDataInput.java | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
(limited to 'bkucommon/src/main/java')
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DataObjectHashDataInput.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DataObjectHashDataInput.java
index 71b62911..0386bdd6 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DataObjectHashDataInput.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DataObjectHashDataInput.java
@@ -10,7 +10,9 @@ import at.gv.egiz.stal.HashDataInput;
import java.io.InputStream;
/**
- *
+ * DataObject-backed HashDataInput
+ * If reference caching is enabled,
+ * the hashdata input stream can be obtained repeatedly.
* @author clemens
*/
public class DataObjectHashDataInput implements HashDataInput {
@@ -34,7 +36,7 @@ public class DataObjectHashDataInput implements HashDataInput {
}
/**
- *
+ * may be called repeatedly
* @return the pre-digested input stream if reference caching is enabled, null otherwise
*/
@Override
--
cgit v1.2.3
From 40e57f6c9101ddcc00422d95086d6a485c3ceda2 Mon Sep 17 00:00:00 2001
From: clemenso
Date: Thu, 18 Sep 2008 15:52:02 +0000
Subject: mimetype
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@52 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
---
.../java/at/gv/egiz/bku/slcommands/impl/DataObjectHashDataInput.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'bkucommon/src/main/java')
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DataObjectHashDataInput.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DataObjectHashDataInput.java
index 0386bdd6..1a9b56fb 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DataObjectHashDataInput.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DataObjectHashDataInput.java
@@ -32,7 +32,8 @@ public class DataObjectHashDataInput implements HashDataInput {
@Override
public String getMimeType() {
- return dataObject.getMimeType();
+ String contentType = dataObject.getMimeType();
+ return contentType.split(";")[0].trim();
}
/**
--
cgit v1.2.3
From 9ca314eced8a73f58282684597468f98621ac502 Mon Sep 17 00:00:00 2001
From: wbauer
Date: Fri, 19 Sep 2008 12:17:47 +0000
Subject: git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@53
8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
---
bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrl.java | 3 ++-
.../main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java | 7 +++++--
2 files changed, 7 insertions(+), 3 deletions(-)
(limited to 'bkucommon/src/main/java')
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrl.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrl.java
index a8477ece..d462ac60 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrl.java
@@ -52,7 +52,8 @@ public class DataUrl {
}
public DataUrlConnection openConnection() {
- try {
+ try {
+ log.debug("Opening dataurl connection");
DataUrlConnectionSPI retVal = defaultDataUrlConnection.newInstance();
retVal.init(url);
return retVal;
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java
index 775f4136..6ad0bb78 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java
@@ -91,11 +91,13 @@ public class DataUrlConnectionImpl implements DataUrlConnectionSPI {
String name = headerIt.next();
connection.setRequestProperty(name, requestHttpHeaders.get(name));
}
+ log.trace("Connecting to: "+url);
connection.connect();
if (connection instanceof HttpsURLConnection) {
HttpsURLConnection ssl = (HttpsURLConnection) connection;
X509Certificate[] certs = (X509Certificate[]) ssl.getServerCertificates();
if ((certs != null) && (certs.length >= 1)) {
+ log.trace("Server certificate: "+certs[0]);
serverCertificate = certs[0];
}
}
@@ -142,7 +144,7 @@ public class DataUrlConnectionImpl implements DataUrlConnectionSPI {
formParams.add(slResultPart);
OutputStream os = connection.getOutputStream();
-
+ log.trace("Sending data");
Part[] parts = new Part[formParams.size()];
Part.sendParts(os, formParams.toArray(parts), boundary.getBytes());
os.close();
@@ -152,7 +154,8 @@ public class DataUrlConnectionImpl implements DataUrlConnectionSPI {
is = connection.getInputStream();
} catch (IOException iox) {
log.info(iox);
- }
+ }
+ log.trace("Reading response");
result = new DataUrlResponse(url.toString(), connection.getResponseCode(), is);
Map responseHttpHeaders = new HashMap();
Map> httpHeaders = connection.getHeaderFields();
--
cgit v1.2.3
From 2a0fd44a7999dbcc6ee80fed4e39d3aab66d94ce Mon Sep 17 00:00:00 2001
From: wbauer
Date: Wed, 24 Sep 2008 07:48:54 +0000
Subject: git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@60
8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
---
.../bku/binding/BindingProcessorManagerImpl.java | 529 +++++++++++----------
1 file changed, 273 insertions(+), 256 deletions(-)
(limited to 'bkucommon/src/main/java')
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManagerImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManagerImpl.java
index 22ee0d1d..11f5a160 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManagerImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManagerImpl.java
@@ -1,270 +1,287 @@
/*
-* 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.binding;
-
+ * 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.binding;
+
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import at.gv.egiz.bku.slcommands.SLCommandInvoker;
-import at.gv.egiz.bku.slexceptions.SLRuntimeException;
-import at.gv.egiz.bku.utils.binding.Protocol;
-import at.gv.egiz.stal.STAL;
-import at.gv.egiz.stal.STALFactory;
-
-/**
- * This class maintains all active BindingProcessor Objects. Currently, only
- * HTTPBinding is supported.
- */
-public class BindingProcessorManagerImpl implements BindingProcessorManager {
-
- public final static Protocol[] SUPPORTED_PROTOCOLS = { Protocol.HTTP,
- Protocol.HTTPS };
-
- private static Log log = LogFactory.getLog(BindingProcessorManagerImpl.class);
-
- private RemovalStrategy removalStrategy;
- private STALFactory stalFactory;
- private SLCommandInvoker commandInvokerClass;
- private ExecutorService executorService;
- private Map bindingProcessorMap = Collections
- .synchronizedMap(new HashMap());
-
- /**
- * Container to hold a Future and Bindingprocessor object as map value.
- * @author wbauer
- * @see BindingProcessorManagerImpl#bindingProcessorMap
- */
- static class MapEntityWrapper {
- private Future> future;
- private BindingProcessor bindingProcessor;
-
- public MapEntityWrapper(Future> future, BindingProcessor bindingProcessor) {
- if ((bindingProcessor == null) || (future == null)) {
- throw new NullPointerException("Argument must not be null");
- }
- this.bindingProcessor = bindingProcessor;
- this.future = future;
- }
-
- public Future> getFuture() {
- return future;
- }
-
- public BindingProcessor getBindingProcessor() {
- return bindingProcessor;
- }
-
- public int hashCode() {
- return bindingProcessor.getId().hashCode();
- }
-
- public boolean equals(Object other) {
- if (other instanceof MapEntityWrapper) {
- MapEntityWrapper o = (MapEntityWrapper) other;
- return (o.bindingProcessor.getId().equals(bindingProcessor.getId()));
- } else {
- return false;
- }
- }
- }
-
- /**
- *
- * @param fab
- * must not be null
- * @param ci
- * must not be null (prototype to generate new instances)
- */
- public BindingProcessorManagerImpl(STALFactory fab, SLCommandInvoker ci) {
- if (fab == null) {
- throw new NullPointerException("STALFactory must not be null");
- }
- stalFactory = fab;
- if (ci == null) {
- throw new NullPointerException("SLCommandInvoker must not be null");
- }
- commandInvokerClass = ci;
- executorService = Executors.newCachedThreadPool();
- }
-
- /**
- *
- * @return the STALFactory currently used.
- */
- public STALFactory getStalFactory() {
- return stalFactory;
- }
-
- /**
- * Sets the STALFactory to be used.
- * @param stalFactory
- */
- public void setStalFactory(STALFactory stalFactory) {
- this.stalFactory = stalFactory;
- }
-
- /**
- * Could be used to setup a new executor service during application stratup.
- * @param executorService
- */
- public void setExecutorService(ExecutorService executorService) {
- this.executorService = executorService;
- }
-
- public void setRemovalStrategy(RemovalStrategy aStrategy) {
- removalStrategy = aStrategy;
- }
-
- public RemovalStrategy getRemovlaStrategy() {
- return removalStrategy;
- }
-
- public void shutdown() {
- log.info("Shutting down the BindingProcessorManager");
- executorService.shutdown();
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import at.gv.egiz.bku.slcommands.SLCommandInvoker;
+import at.gv.egiz.bku.slexceptions.SLRuntimeException;
+import at.gv.egiz.bku.utils.binding.Protocol;
+import at.gv.egiz.stal.STAL;
+import at.gv.egiz.stal.STALFactory;
+
+/**
+ * This class maintains all active BindingProcessor Objects. Currently, only
+ * HTTPBinding is supported.
+ */
+public class BindingProcessorManagerImpl implements BindingProcessorManager {
+
+ public final static Protocol[] SUPPORTED_PROTOCOLS = { Protocol.HTTP,
+ Protocol.HTTPS };
+
+ private static Log log = LogFactory.getLog(BindingProcessorManagerImpl.class);
+
+ private RemovalStrategy removalStrategy;
+ private STALFactory stalFactory;
+ private SLCommandInvoker commandInvokerClass;
+ private ExecutorService executorService;
+ private Map bindingProcessorMap = Collections
+ .synchronizedMap(new HashMap());
+
+ /**
+ * Container to hold a Future and Bindingprocessor object as map value.
+ *
+ * @author wbauer
+ * @see BindingProcessorManagerImpl#bindingProcessorMap
+ */
+ static class MapEntityWrapper {
+ private Future> future;
+ private BindingProcessor bindingProcessor;
+
+ public MapEntityWrapper(Future> future, BindingProcessor bindingProcessor) {
+ if ((bindingProcessor == null) || (future == null)) {
+ throw new NullPointerException("Argument must not be null");
+ }
+ this.bindingProcessor = bindingProcessor;
+ this.future = future;
+ }
+
+ public Future> getFuture() {
+ return future;
+ }
+
+ public BindingProcessor getBindingProcessor() {
+ return bindingProcessor;
+ }
+
+ public int hashCode() {
+ return bindingProcessor.getId().hashCode();
+ }
+
+ public boolean equals(Object other) {
+ if (other instanceof MapEntityWrapper) {
+ MapEntityWrapper o = (MapEntityWrapper) other;
+ return (o.bindingProcessor.getId().equals(bindingProcessor.getId()));
+ } else {
+ return false;
+ }
+ }
}
-
+
+ /**
+ *
+ * @param fab
+ * must not be null
+ * @param ci
+ * must not be null (prototype to generate new instances)
+ */
+ public BindingProcessorManagerImpl(STALFactory fab, SLCommandInvoker ci) {
+ if (fab == null) {
+ throw new NullPointerException("STALFactory must not be null");
+ }
+ stalFactory = fab;
+ if (ci == null) {
+ throw new NullPointerException("SLCommandInvoker must not be null");
+ }
+ commandInvokerClass = ci;
+ executorService = Executors.newCachedThreadPool();
+ }
+
+ /**
+ *
+ * @return the STALFactory currently used.
+ */
+ public STALFactory getStalFactory() {
+ return stalFactory;
+ }
+
+ /**
+ * Sets the STALFactory to be used.
+ *
+ * @param stalFactory
+ */
+ public void setStalFactory(STALFactory stalFactory) {
+ this.stalFactory = stalFactory;
+ }
+
+ /**
+ * Could be used to setup a new executor service during application stratup.
+ *
+ * @param executorService
+ */
+ public void setExecutorService(ExecutorService executorService) {
+ this.executorService = executorService;
+ }
+
+ public void setRemovalStrategy(RemovalStrategy aStrategy) {
+ removalStrategy = aStrategy;
+ }
+
+ public RemovalStrategy getRemovlaStrategy() {
+ return removalStrategy;
+ }
+
+ public void shutdown() {
+ log.info("Shutting down the BindingProcessorManager");
+ executorService.shutdown();
+ }
+
public void shutdownNow() {
- log.info("Shutting down the BindingProcessorManager NOW!");
+ log.info("Shutting down the BindingProcessorManager NOW!");
executorService.shutdownNow();
- }
-
- /**
- * Uses the default locale
- */
- public BindingProcessor createBindingProcessor(String srcUrl,
- String aSessionId) throws MalformedURLException {
- return createBindingProcessor(srcUrl, aSessionId, null);
- }
-
- /**
- * FactoryMethod creating a new BindingProcessor object.
- *
- * @param protocol
+ log.debug("Number of binding prcessors currently managed: "
+ + bindingProcessorMap.size());
+ if (log.isDebugEnabled()) {
+ for (Iterator it = bindingProcessorMap.values()
+ .iterator(); it.hasNext();) {
+ MapEntityWrapper entry = it.next();
+ log.debug(entry.getBindingProcessor().getId() + ": isDone: "
+ + entry.getFuture().isDone());
+ log.debug(entry.getBindingProcessor().getId() + ": isCanceled: "
+ + entry.getFuture().isCancelled());
+ }
+ }
+ }
+
+ /**
+ * Uses the default locale
+ */
+ public BindingProcessor createBindingProcessor(String srcUrl,
+ String aSessionId) throws MalformedURLException {
+ return createBindingProcessor(srcUrl, aSessionId, null);
+ }
+
+ /**
+ * FactoryMethod creating a new BindingProcessor object.
+ *
+ * @param protocol
* must not be null
- * @throws MalformedURLException
- */
- public BindingProcessor createBindingProcessor(String srcUrl,
+ * @throws MalformedURLException
+ */
+ public BindingProcessor createBindingProcessor(String srcUrl,
String aSessionId, Locale locale) throws MalformedURLException {
- URL url = new URL(srcUrl);
- String low = url.getProtocol().toLowerCase();
- Protocol proto = null;
- for (int i = 0; i < SUPPORTED_PROTOCOLS.length; i++) {
- if (SUPPORTED_PROTOCOLS[i].toString().equals(low)) {
- proto = SUPPORTED_PROTOCOLS[i];
- break;
- }
- }
- if (proto == null) {
- throw new UnsupportedOperationException();
- }
- BindingProcessor bindingProcessor = new HTTPBindingProcessor(aSessionId,
- commandInvokerClass.newInstance(), url);
+ URL url = new URL(srcUrl);
+ String low = url.getProtocol().toLowerCase();
+ Protocol proto = null;
+ for (int i = 0; i < SUPPORTED_PROTOCOLS.length; i++) {
+ if (SUPPORTED_PROTOCOLS[i].toString().equals(low)) {
+ proto = SUPPORTED_PROTOCOLS[i];
+ break;
+ }
+ }
+ if (proto == null) {
+ throw new UnsupportedOperationException();
+ }
+ BindingProcessor bindingProcessor = new HTTPBindingProcessor(aSessionId,
+ commandInvokerClass.newInstance(), url);
stalFactory.setLocale(locale);
- STAL stal = stalFactory.createSTAL();
- bindingProcessor.init(stal, commandInvokerClass.newInstance());
- if (locale != null) {
- bindingProcessor.setLocale(locale);
- stal.setLocale(locale);
- }
- return bindingProcessor;
- }
-
- /**
- * @return the bindingprocessor object for this id or null if no bindingprocessor was found.
- */
- public BindingProcessor getBindingProcessor(Id aId) {
- if (bindingProcessorMap.get(aId) != null) {
- return bindingProcessorMap.get(aId).getBindingProcessor();
- } else {
- return null;
- }
- }
-
+ STAL stal = stalFactory.createSTAL();
+ bindingProcessor.init(stal, commandInvokerClass.newInstance());
+ if (locale != null) {
+ bindingProcessor.setLocale(locale);
+ stal.setLocale(locale);
+ }
+ return bindingProcessor;
+ }
+
+ /**
+ * @return the bindingprocessor object for this id or null if no
+ * bindingprocessor was found.
+ */
+ public BindingProcessor getBindingProcessor(Id aId) {
+ if (bindingProcessorMap.get(aId) != null) {
+ return bindingProcessorMap.get(aId).getBindingProcessor();
+ } else {
+ return null;
+ }
+ }
+
/**
*
- */
- public void setSTALFactory(STALFactory aStalFactory) {
- if (aStalFactory == null) {
- throw new NullPointerException("Cannot set STALFactory to null");
- }
- stalFactory = aStalFactory;
- }
-
- /**
- * Causes the BindingProcessorManager to manage the provided BindingProcessor
- * @param aBindingProcessor must not be null
- */
- public void process(BindingProcessor aBindingProcessor) {
- if (bindingProcessorMap.containsKey(aBindingProcessor.getId())) {
- log.fatal("Clashing ids, cannot process bindingprocessor with id:"
- + aBindingProcessor.getId());
- throw new SLRuntimeException(
- "Clashing ids, cannot process bindingprocessor with id:"
- + aBindingProcessor.getId());
+ */
+ public void setSTALFactory(STALFactory aStalFactory) {
+ if (aStalFactory == null) {
+ throw new NullPointerException("Cannot set STALFactory to null");
+ }
+ stalFactory = aStalFactory;
+ }
+
+ /**
+ * Causes the BindingProcessorManager to manage the provided BindingProcessor
+ *
+ * @param aBindingProcessor
+ * must not be null
+ */
+ public void process(BindingProcessor aBindingProcessor) {
+ if (bindingProcessorMap.containsKey(aBindingProcessor.getId())) {
+ log.fatal("Clashing ids, cannot process bindingprocessor with id:"
+ + aBindingProcessor.getId());
+ throw new SLRuntimeException(
+ "Clashing ids, cannot process bindingprocessor with id:"
+ + aBindingProcessor.getId());
}
- log.debug("processing bindingprocessor: "+aBindingProcessor.getId());
- Future> f = executorService.submit(aBindingProcessor);
- bindingProcessorMap.put(aBindingProcessor.getId(), new MapEntityWrapper(f,
- aBindingProcessor));
- }
-
- @Override
- public void setSLCommandInvoker(SLCommandInvoker invoker) {
- commandInvokerClass = invoker;
- }
-
- @Override
+ log.debug("processing bindingprocessor: " + aBindingProcessor.getId());
+ Future> f = executorService.submit(aBindingProcessor);
+ bindingProcessorMap.put(aBindingProcessor.getId(), new MapEntityWrapper(f,
+ aBindingProcessor));
+ }
+
+ @Override
+ public void setSLCommandInvoker(SLCommandInvoker invoker) {
+ commandInvokerClass = invoker;
+ }
+
+ @Override
public void removeBindingProcessor(Id sessionId) {
- log.debug("Removing binding processor: "+sessionId);
- MapEntityWrapper wrapper = bindingProcessorMap
- .get(sessionId);
- if (wrapper == null) {
- return;
- }
- Future> f = wrapper.getFuture();
- if (!f.isDone()) {
- f.cancel(true);
- }
- bindingProcessorMap.remove(sessionId);
- }
-
- @Override
- public Set getManagedIds() {
- Set result = new HashSet();
- synchronized (bindingProcessorMap) {
- for (Iterator it = bindingProcessorMap.keySet().iterator(); it
- .hasNext();) {
- result.add(it.next());
- }
- }
- return result;
- }
+ log.debug("Removing binding processor: " + sessionId);
+ MapEntityWrapper wrapper = bindingProcessorMap.get(sessionId);
+ if (wrapper == null) {
+ return;
+ }
+ Future> f = wrapper.getFuture();
+ if (!f.isDone()) {
+ f.cancel(true);
+ }
+ bindingProcessorMap.remove(sessionId);
+ }
+
+ @Override
+ public Set getManagedIds() {
+ Set result = new HashSet();
+ synchronized (bindingProcessorMap) {
+ for (Iterator it = bindingProcessorMap.keySet().iterator(); it
+ .hasNext();) {
+ result.add(it.next());
+ }
+ }
+ return result;
+ }
}
\ No newline at end of file
--
cgit v1.2.3
From 3edfbe631f24d73324bc4dd0d182ca7737c4d5b5 Mon Sep 17 00:00:00 2001
From: mcentner
Date: Wed, 24 Sep 2008 13:56:53 +0000
Subject: Improved SLResult marshalling.
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@66 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
---
.../gv/egiz/bku/binding/HTTPBindingProcessor.java | 40 +--
.../java/at/gv/egiz/bku/slcommands/SLResult.java | 7 +-
.../impl/CreateXMLSignatureResultImpl.java | 73 ++---
.../egiz/bku/slcommands/impl/ErrorResultImpl.java | 21 +-
.../slcommands/impl/InfoboxReadCommandImpl.java | 320 ++++++++++++++++-----
.../slcommands/impl/InfoboxReadResultFileImpl.java | 141 +++++++++
.../bku/slcommands/impl/InfoboxReadResultImpl.java | 190 +++---------
.../slcommands/impl/NullOperationResultImpl.java | 5 +-
.../gv/egiz/bku/slcommands/impl/SLResultImpl.java | 166 ++++++++---
9 files changed, 606 insertions(+), 357 deletions(-)
create mode 100644 bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadResultFileImpl.java
(limited to 'bkucommon/src/main/java')
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java
index 19f22126..8f72c3ee 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java
@@ -35,6 +35,7 @@ import java.util.Locale;
import java.util.Map;
import javax.net.ssl.SSLHandshakeException;
+import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
@@ -108,7 +109,7 @@ public class HTTPBindingProcessor extends AbstractBindingProcessor implements
protected SLTargetContext targetContext = new SLTargetContext();
protected URL srcUrl;
protected State currentState = State.INIT;
- protected Transformer transformer = null;
+ protected Templates templates = null;
protected String resultContentType = null;
protected SLResult slResult = null;
protected int responseCode = 200;
@@ -471,10 +472,10 @@ public class HTTPBindingProcessor extends AbstractBindingProcessor implements
resultContentType = HttpUtil.TXT_XML;
}
}
- transformer = getTransformer(getStyleSheetUrl());
- if (transformer != null) {
+ templates = getTemplates(getStyleSheetUrl());
+ if (templates != null) {
log.debug("Output transformation required");
- resultContentType = transformer.getOutputProperty("media-type");
+ resultContentType = templates.getOutputProperties().getProperty("media-type");
log.debug("Got media type from stylesheet: " + resultContentType);
if (resultContentType == null) {
log.debug("Setting to default text/xml result conent type");
@@ -703,7 +704,7 @@ public class HTTPBindingProcessor extends AbstractBindingProcessor implements
return resultContentType;
}
- protected Transformer getTransformer(String styleSheetURL) {
+ protected Templates getTemplates(String styleSheetURL) {
if (styleSheetURL == null) {
log.debug("Stylesheet URL not set");
return null;
@@ -713,11 +714,10 @@ public class HTTPBindingProcessor extends AbstractBindingProcessor implements
URIResolver resolver = new URIResolverAdapter(URLDereferencer
.getInstance(), urlCtx);
TransformerFactory factory = TransformerFactory.newInstance();
+ factory.setURIResolver(resolver);
StreamData sd = URLDereferencer.getInstance().dereference(styleSheetURL,
urlCtx);
- Transformer t = factory.newTransformer(new StreamSource(sd.getStream()));
- t.setURIResolver(resolver);
- return t;
+ return factory.newTemplates(new StreamSource(sd.getStream()));
} catch (Exception ex) {
log.info("Cannot instantiate transformer", ex);
bindingProcessorError = new SLException(2002);
@@ -726,15 +726,10 @@ public class HTTPBindingProcessor extends AbstractBindingProcessor implements
}
protected void handleBindingProcessorError(OutputStream os, String encoding,
- Transformer transformer) throws IOException {
+ Templates templates) throws IOException {
log.debug("Writing error as result");
ErrorResultImpl error = new ErrorResultImpl(bindingProcessorError);
- try {
- error.writeTo(new StreamResult(new OutputStreamWriter(os, encoding)),
- transformer);
- } catch (TransformerException e) {
- log.fatal("Cannot write error result to stream", e);
- }
+ error.writeTo(new StreamResult(new OutputStreamWriter(os, encoding)), templates);
}
@Override
@@ -745,7 +740,7 @@ public class HTTPBindingProcessor extends AbstractBindingProcessor implements
}
if (bindingProcessorError != null) {
log.debug("Detected error in binding processor, writing error as result");
- handleBindingProcessorError(os, encoding, transformer);
+ handleBindingProcessorError(os, encoding, templates);
return;
} else if (dataUrlResponse != null) {
log.debug("Writing data url response as result");
@@ -754,10 +749,11 @@ public class HTTPBindingProcessor extends AbstractBindingProcessor implements
InputStreamReader isr = new InputStreamReader(
dataUrlResponse.getStream(), charEnc);
OutputStreamWriter osw = new OutputStreamWriter(os, encoding);
- if (transformer == null) {
+ if (templates == null) {
StreamUtil.copyStream(isr, osw);
} else {
try {
+ Transformer transformer = templates.newTransformer();
transformer.transform(new StreamSource(isr), new StreamResult(osw));
} catch (TransformerException e) {
log.fatal("Exception occured during result transformation", e);
@@ -771,18 +767,12 @@ public class HTTPBindingProcessor extends AbstractBindingProcessor implements
} else if (slResult == null) {
// result not yet assigned -> must be a cancel
bindingProcessorError = new SLException(6001);
- handleBindingProcessorError(os, encoding, transformer);
+ handleBindingProcessorError(os, encoding, templates);
return;
} else {
log.debug("Getting result from invoker");
OutputStreamWriter osw = new OutputStreamWriter(os, encoding);
- try {
- slResult.writeTo(new StreamResult(osw), transformer);
- } catch (TransformerException e) {
- log.fatal("Cannot write result to stream", e);
- // bindingProcessorError = new SLException(2008);
- // handleBindingProcessorError(os, encoding, transformer);
- }
+ slResult.writeTo(new StreamResult(osw), templates);
osw.flush();
}
}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLResult.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLResult.java
index 7cf43fda..7989a771 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLResult.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLResult.java
@@ -16,9 +16,8 @@
*/
package at.gv.egiz.bku.slcommands;
-import javax.xml.transform.Result;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
+import javax.xml.transform.Result;
+import javax.xml.transform.Templates;
public interface SLResult {
@@ -40,5 +39,5 @@ public interface SLResult {
* @param result
* @param transformer may be null.
*/
- public void writeTo(Result result, Transformer transformer) throws TransformerException;
+ public void writeTo(Result result, Templates templates);
}
\ No newline at end of file
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 d2d2e678..092a13c4 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
@@ -16,28 +16,24 @@
*/
package at.gv.egiz.bku.slcommands.impl;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.transform.Result;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentFragment;
-import org.w3c.dom.Element;
-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.SLCommandFactory;
-import at.gv.egiz.bku.slexceptions.SLRuntimeException;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+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.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Element;
+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.SLCommandFactory;
+import at.gv.egiz.bku.slexceptions.SLRuntimeException;
/**
* This calls implements the result of the security layer command CreateXMLSignature
.
@@ -104,35 +100,10 @@ public class CreateXMLSignatureResultImpl extends SLResultImpl {
}
}
-
- @Override
- public void writeTo(Result result) {
-
- try {
- writeTo(result, null);
- } catch (TransformerException e) {
- log.error(e);
- }
-
- }
-
- /* (non-Javadoc)
- * @see at.gv.egiz.bku.slcommands.impl.SLResultImpl#writeTo(javax.xml.transform.Result, javax.xml.transform.Transformer)
- */
- @Override
- public void writeTo(Result result, Transformer transformer) throws TransformerException {
-
- if (transformer == null) {
- TransformerFactory transformerFactory = TransformerFactory.newInstance();
- try {
- transformer = transformerFactory.newTransformer();
- } catch (TransformerConfigurationException e) {
- log.error("Failed to create Transformer.", e);
- throw new SLRuntimeException(e);
- }
- }
- transformer.transform(new DOMSource(doc), result);
-
+
+ @Override
+ public void writeTo(Result result, Templates templates) {
+ writeTo(doc, result, templates);
}
}
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 fb624211..176ba001 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
@@ -16,12 +16,9 @@
*/
package at.gv.egiz.bku.slcommands.impl;
-import java.util.Locale;
-
import javax.xml.transform.Result;
+import javax.xml.transform.Templates;
-import at.buergerkarte.namespaces.securitylayer._1.ErrorResponseType;
-import at.buergerkarte.namespaces.securitylayer._1.ObjectFactory;
import at.gv.egiz.bku.slcommands.ErrorResult;
import at.gv.egiz.bku.slexceptions.SLException;
@@ -48,15 +45,9 @@ public class ErrorResultImpl extends SLResultImpl implements ErrorResult {
this.slException = slException;
}
- @Override
- public void writeTo(Result result) {
-
- ObjectFactory factory = new ObjectFactory();
- ErrorResponseType responseType = factory.createErrorResponseType();
- responseType.setErrorCode(slException.getErrorCode());
- responseType.setInfo(slException.getDetailedMsg());
-
- writeTo(factory.createErrorResponse(responseType), result);
-
- }
+ @Override
+ public void writeTo(Result result, Templates templates) {
+ writeErrorTo(slException, result, templates);
+ }
+
}
\ No newline at end of file
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 b6745e1f..4d64ae36 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
@@ -16,55 +16,66 @@
*/
package at.gv.egiz.bku.slcommands.impl;
-import iaik.asn1.CodingException;
-import iaik.asn1.DerCoder;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.security.cert.CertificateException;
-import java.security.cert.CertificateFactory;
-import java.security.cert.X509Certificate;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBException;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.Result;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-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.w3c.dom.Document;
-import org.w3c.dom.Node;
-
-import at.buergerkarte.namespaces.personenbindung._20020506_.CompressedIdentityLinkType;
-import at.buergerkarte.namespaces.securitylayer._1.AnyChildrenType;
-import at.buergerkarte.namespaces.securitylayer._1.InfoboxReadParamsBinaryFileType;
-import at.buergerkarte.namespaces.securitylayer._1.InfoboxReadRequestType;
-import at.gv.egiz.bku.slcommands.InfoboxReadCommand;
-import at.gv.egiz.bku.slcommands.SLCommand;
-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.bku.slexceptions.SLExceptionMessages;
-import at.gv.egiz.bku.slexceptions.SLRuntimeException;
-import at.gv.egiz.idlink.CompressedIdentityLinkFactory;
-import at.gv.egiz.idlink.IdentityLinkTransformer;
-import at.gv.egiz.idlink.ans1.IdentityLink;
-import at.gv.egiz.stal.InfoboxReadRequest;
-import at.gv.egiz.stal.InfoboxReadResponse;
-import at.gv.egiz.stal.STALRequest;
+import iaik.asn1.CodingException;
+import iaik.asn1.DerCoder;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.security.cert.CertificateEncodingException;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Result;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+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.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+import at.buergerkarte.namespaces.personenbindung._20020506_.CompressedIdentityLinkType;
+import at.buergerkarte.namespaces.securitylayer._1.AnyChildrenType;
+import at.buergerkarte.namespaces.securitylayer._1.InfoboxAssocArrayPairType;
+import at.buergerkarte.namespaces.securitylayer._1.InfoboxReadDataAssocArrayType;
+import at.buergerkarte.namespaces.securitylayer._1.InfoboxReadParamsAssocArrayType;
+import at.buergerkarte.namespaces.securitylayer._1.InfoboxReadParamsBinaryFileType;
+import at.buergerkarte.namespaces.securitylayer._1.InfoboxReadRequestType;
+import at.buergerkarte.namespaces.securitylayer._1.ObjectFactory;
+import at.buergerkarte.namespaces.securitylayer._1.InfoboxReadParamsAssocArrayType.ReadKeys;
+import at.buergerkarte.namespaces.securitylayer._1.InfoboxReadParamsAssocArrayType.ReadPairs;
+import at.buergerkarte.namespaces.securitylayer._1.InfoboxReadParamsAssocArrayType.ReadValue;
+import at.gv.egiz.bku.slcommands.InfoboxReadCommand;
+import at.gv.egiz.bku.slcommands.SLCommand;
+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.bku.slexceptions.SLExceptionMessages;
+import at.gv.egiz.bku.slexceptions.SLRuntimeException;
+import at.gv.egiz.idlink.CompressedIdentityLinkFactory;
+import at.gv.egiz.idlink.IdentityLinkTransformer;
+import at.gv.egiz.idlink.ans1.IdentityLink;
+import at.gv.egiz.stal.InfoboxReadRequest;
+import at.gv.egiz.stal.InfoboxReadResponse;
+import at.gv.egiz.stal.STALRequest;
/**
* This class implements the security layer command
@@ -82,23 +93,45 @@ public class InfoboxReadCommandImpl extends SLCommandImplInfoboxIdentifier
*/
protected String infoboxIdentifier;
/**
- * The IdentityLinkDomainIdentifier
value of an IdentyLink infobox.
+ * The IdentityLinkDomainIdentifier
value of an IdentyLink
infobox.
*/
- protected String identityLinkDomainIdentifier;
+ protected String identityLinkDomainIdentifier;
+
+ /**
+ * The list of certificates to be read from an Certificates
infobox.
+ */
+ protected List certificates;
+
+ /**
+ * The result type.
+ */
+ protected int assocArrayResult;
/**
* Is content XML entity?
@@ -125,12 +158,6 @@ public class InfoboxReadCommandImpl extends SLCommandImpl 1) {
+ log.info("UserMakesUnique not supported");
+ // TODO: give more specific error message
+ throw new SLCommandException(4010);
+ }
+ }
+
+ // ReadPairs?
+ if (assocArrayParameters.getReadPairs() != null) {
+ assocArrayResult = ASSOC_ARRAY_READ_PAIRS;
+ ReadPairs readPairs = assocArrayParameters.getReadPairs();
+ if (readPairs.isValuesAreXMLEntities()) {
+ log.info("Got valuesAreXMLEntities but infobox type is binary.");
+ throw new SLCommandException(4010);
+ }
+ certificates = findCertificates(readPairs.getSearchString());
+ if (readPairs.isUserMakesUnique() && certificates.size() > 1) {
+ log.info("UserMakesUnique not supported");
+ // TODO: give more specific error message
+ throw new SLCommandException(4010);
+ }
+ }
+
+ // ReadValue
+ if (assocArrayParameters.getReadValue() != null) {
+ assocArrayResult = ASSOC_ARRAY_READ_VALUE;
+ ReadValue readValue = assocArrayParameters.getReadValue();
+ if (readValue.isValueIsXMLEntity()) {
+ log.info("Got valuesAreXMLEntities but infobox type is binary.");
+ throw new SLCommandException(4010);
+ }
+ String key = readValue.getKey();
+ if (Arrays.asList(INFOXBOX_CERTIFICATES_KEYS).contains(key)) {
+ certificates = Collections.singletonList(key);
+ } else {
+ certificates = Collections.emptyList();
+ }
+ }
+
+ if (assocArrayResult == 0) {
+ log.info("Infobox type is AssocArray but got invalid AssocArrayParameters.");
+ throw new SLCommandException(4010);
+ }
} else {
throw new SLCommandException(4002,
@@ -168,9 +268,15 @@ public class InfoboxReadCommandImpl extends SLCommandImpl findCertificates(String searchString) throws SLCommandException {
+
+ if ("*".equals(searchString) || "**".equals(searchString)) {
+ return Arrays.asList(INFOXBOX_CERTIFICATES_KEYS);
+ }
+
+ if (Pattern.matches(SEARCH_STRING_PATTERN, searchString)) {
+
+// for (int i = 0; i < searchString.length(); i++) {
+// int codePoint = searchString.codePointAt(i);
+//
+// }
+
+ // TODO : build pattern
+ return Collections.emptyList();
+ } else {
+ log.info("Got invalid search string '" + searchString + "'");
+ throw new SLCommandException(4010);
+ }
+
+ }
+
+ private SLResult readCertificates() throws SLCommandException {
+
+ ObjectFactory objectFactory = new ObjectFactory();
+
+ InfoboxReadDataAssocArrayType infoboxReadDataAssocArrayType = objectFactory
+ .createInfoboxReadDataAssocArrayType();
+
+ if (assocArrayResult == ASSOC_ARRAY_READ_KEYS) {
- @Override
- public String getIdentityLinkDomainId() {
- return identityLinkDomainIdentifier;
- }
+ List keys = infoboxReadDataAssocArrayType.getKey();
+ keys.addAll(certificates);
+
+ } else {
+
+ if (certificates != null && !certificates.isEmpty()) {
+
+ List stalRequests = new ArrayList();
+
+ // get certificates
+ InfoboxReadRequest infoboxReadRequest;
+ for (int i = 0; i < certificates.size(); i++) {
+ infoboxReadRequest = new InfoboxReadRequest();
+ infoboxReadRequest.setInfoboxIdentifier(certificates.get(i));
+ stalRequests.add(infoboxReadRequest);
+ }
+
+ requestSTAL(stalRequests);
+
+ List x509Certs = getCertificatesFromResponses();
+
+ for (int i = 0; i < certificates.size(); i++) {
+ InfoboxAssocArrayPairType infoboxAssocArrayPairType = objectFactory.createInfoboxAssocArrayPairType();
+ infoboxAssocArrayPairType.setKey(certificates.get(i));
+ try {
+ infoboxAssocArrayPairType.setBase64Content(x509Certs.get(i).getEncoded());
+ } catch (CertificateEncodingException e) {
+ log.error("Failed to encode certificate.", e);
+ throw new SLCommandException(4000);
+ }
+ infoboxReadDataAssocArrayType.getPair().add(infoboxAssocArrayPairType);
+ }
+
+ }
+
+ }
+
+ return new InfoboxReadResultImpl(infoboxReadDataAssocArrayType);
+
+ }
+
+ @Override
+ public String getIdentityLinkDomainId() {
+ return identityLinkDomainIdentifier;
+ }
}
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
new file mode 100644
index 00000000..6f41b562
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadResultFileImpl.java
@@ -0,0 +1,141 @@
+/*
+* 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;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+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.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+
+import at.buergerkarte.namespaces.securitylayer._1.Base64XMLContentType;
+import at.buergerkarte.namespaces.securitylayer._1.InfoboxReadResponseType;
+import at.buergerkarte.namespaces.securitylayer._1.ObjectFactory;
+import at.buergerkarte.namespaces.securitylayer._1.XMLContentType;
+import at.gv.egiz.bku.slcommands.InfoboxReadResult;
+import at.gv.egiz.bku.slcommands.SLCommand;
+import at.gv.egiz.bku.slcommands.SLCommandFactory;
+import at.gv.egiz.bku.slexceptions.SLRuntimeException;
+
+/**
+ * This class implements the result of the security layer command InfoboxReadRequest
.
+ *
+ * @author mcentner
+ */
+public class InfoboxReadResultFileImpl extends SLResultImpl implements
+ InfoboxReadResult {
+
+ /**
+ * Logging facility.
+ */
+ protected static Log log = LogFactory.getLog(InfoboxReadResultFileImpl.class);
+
+ /**
+ * The XML document containing the infobox content.
+ */
+ Document xmlDocument;
+
+ /**
+ * Creates the response document from the given binaryContent
.
+ *
+ * @param binaryContent the infobox content
+ * @param preserveSpace the value of the preserveSpace
parameter
+ *
+ * @return the created response document
+ */
+ private Document createResponseDocument(byte[] binaryContent, boolean preserveSpace) {
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ Document doc;
+ try {
+ doc = dbf.newDocumentBuilder().newDocument();
+ } catch (ParserConfigurationException e) {
+ // it should always be possible to create a new Document
+ log.error("Failed to create XML document.", e);
+ throw new SLRuntimeException(e);
+ }
+
+ ObjectFactory factory = new ObjectFactory();
+
+ Base64XMLContentType base64XMLContentType = factory.createBase64XMLContentType();
+ if (binaryContent == null) {
+ XMLContentType xmlContentType = factory.createXMLContentType();
+ if (preserveSpace) {
+ xmlContentType.setSpace("preserve");
+ }
+ base64XMLContentType.setXMLContent(xmlContentType);
+ } else {
+ base64XMLContentType.setBase64Content(binaryContent);
+ }
+ InfoboxReadResponseType infoboxReadResponseType = factory.createInfoboxReadResponseType();
+ infoboxReadResponseType.setBinaryFileData(base64XMLContentType);
+
+ JAXBElement infoboxReadResponse = factory.createInfoboxReadResponse(infoboxReadResponseType);
+
+ JAXBContext context = SLCommandFactory.getJaxbContext();
+ try {
+ Marshaller marshaller = context.createMarshaller();
+ marshaller.marshal(infoboxReadResponse, doc);
+ } catch (JAXBException e) {
+ log.error("Failed to marshal 'InfoboxReadResponse' document.", e);
+ throw new SLRuntimeException(e);
+ }
+
+ return doc;
+
+ }
+
+
+ /**
+ * @return an XMLResult for marshalling the infobox to
+ */
+ Result getXmlResult(boolean preserveSpace) {
+
+ xmlDocument = createResponseDocument(null, preserveSpace);
+
+ NodeList nodeList = xmlDocument.getElementsByTagNameNS(SLCommand.NAMESPACE_URI, "XMLContent");
+ return new DOMResult(nodeList.item(0));
+
+ }
+
+ /**
+ * Creates a new result document for this InfoboxReadResult
+ * and sets the given resultBytes
as content.
+ *
+ * @param resultBytes
+ */
+ void setResultBytes(byte[] resultBytes) {
+
+ xmlDocument = createResponseDocument(resultBytes, false);
+
+ }
+
+ @Override
+ public void writeTo(Result result, Templates templates) {
+ writeTo(xmlDocument, result, templates);
+ }
+
+}
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 6f07338f..8904eac6 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
@@ -14,158 +14,38 @@
* 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.JAXBContext;
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.Result;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMResult;
-import javax.xml.transform.dom.DOMSource;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.w3c.dom.Document;
-import org.w3c.dom.NodeList;
-
-import at.buergerkarte.namespaces.securitylayer._1.Base64XMLContentType;
-import at.buergerkarte.namespaces.securitylayer._1.InfoboxReadResponseType;
-import at.buergerkarte.namespaces.securitylayer._1.ObjectFactory;
-import at.buergerkarte.namespaces.securitylayer._1.XMLContentType;
-import at.gv.egiz.bku.slcommands.InfoboxReadResult;
-import at.gv.egiz.bku.slcommands.SLCommand;
-import at.gv.egiz.bku.slcommands.SLCommandFactory;
-import at.gv.egiz.bku.slexceptions.SLRuntimeException;
-
-/**
- * This class implements the result of the security layer command InfoboxReadRequest
.
- *
- * @author mcentner
- */
-public class InfoboxReadResultImpl extends SLResultImpl implements
- InfoboxReadResult {
-
- /**
- * Logging facility.
- */
- protected static Log log = LogFactory.getLog(InfoboxReadResultImpl.class);
-
- /**
- * The XML document containing the infobox content.
- */
- Document xmlDocument;
-
- /**
- * Creates the response document from the given binaryContent
.
- *
- * @param binaryContent the infobox content
- * @param preserveSpace the value of the preserveSpace
parameter
- *
- * @return the created response document
- */
- private Document createResponseDocument(byte[] binaryContent, boolean preserveSpace) {
-
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- Document doc;
- try {
- doc = dbf.newDocumentBuilder().newDocument();
- } catch (ParserConfigurationException e) {
- // it should always be possible to create a new Document
- log.error("Failed to create XML document.", e);
- throw new SLRuntimeException(e);
- }
-
- ObjectFactory factory = new ObjectFactory();
-
- Base64XMLContentType base64XMLContentType = factory.createBase64XMLContentType();
- if (binaryContent == null) {
- XMLContentType xmlContentType = factory.createXMLContentType();
- if (preserveSpace) {
- xmlContentType.setSpace("preserve");
- }
- base64XMLContentType.setXMLContent(xmlContentType);
- } else {
- base64XMLContentType.setBase64Content(binaryContent);
- }
- InfoboxReadResponseType infoboxReadResponseType = factory.createInfoboxReadResponseType();
- infoboxReadResponseType.setBinaryFileData(base64XMLContentType);
-
- JAXBElement infoboxReadResponse = factory.createInfoboxReadResponse(infoboxReadResponseType);
-
- JAXBContext context = SLCommandFactory.getJaxbContext();
- try {
- Marshaller marshaller = context.createMarshaller();
- marshaller.marshal(infoboxReadResponse, doc);
- } catch (JAXBException e) {
- log.error("Failed to marshal 'InfoboxReadResponse' document.", e);
- throw new SLRuntimeException(e);
- }
-
- return doc;
-
- }
-
-
- /**
- * @return an XMLResult for marshalling the infobox to
- */
- Result getXmlResult(boolean preserveSpace) {
-
- xmlDocument = createResponseDocument(null, preserveSpace);
-
- NodeList nodeList = xmlDocument.getElementsByTagNameNS(SLCommand.NAMESPACE_URI, "XMLContent");
- return new DOMResult(nodeList.item(0));
-
- }
-
- /**
- * Creates a new result document for this InfoboxReadResult
- * and sets the given resultBytes
as content.
- *
- * @param resultBytes
- */
- void setResultBytes(byte[] resultBytes) {
-
- xmlDocument = createResponseDocument(resultBytes, false);
-
- }
-
- @Override
- public void writeTo(Result result) {
-
- try {
- writeTo(result, null);
- } catch (TransformerException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
-
- /* (non-Javadoc)
- * @see at.gv.egiz.bku.slcommands.impl.SLResultImpl#writeTo(javax.xml.transform.Result, javax.xml.transform.Transformer)
- */
- @Override
- public void writeTo(Result result, Transformer transformer) throws TransformerException {
-
- if (transformer == null) {
- TransformerFactory transformerFactory = TransformerFactory.newInstance();
- try {
- transformer = transformerFactory.newTransformer();
- } catch (TransformerConfigurationException e) {
- log.error("Failed to create Transformer.", e);
- throw new SLRuntimeException(e);
- }
- }
- transformer.transform(new DOMSource(xmlDocument), result);
-
- }
-
-}
+package at.gv.egiz.bku.slcommands.impl;
+
+import javax.xml.bind.JAXBElement;
+import javax.xml.transform.Result;
+import javax.xml.transform.Templates;
+
+import at.buergerkarte.namespaces.securitylayer._1.InfoboxReadDataAssocArrayType;
+import at.buergerkarte.namespaces.securitylayer._1.InfoboxReadResponseType;
+import at.buergerkarte.namespaces.securitylayer._1.ObjectFactory;
+
+public class InfoboxReadResultImpl extends SLResultImpl {
+
+ /**
+ * The InfoboxReadResponse
+ */
+ protected InfoboxReadResponseType infoboxReadResponse;
+
+ public InfoboxReadResultImpl(InfoboxReadDataAssocArrayType assocArray) {
+
+ ObjectFactory objectFactory = new ObjectFactory();
+ InfoboxReadResponseType infoboxReadResponseType = objectFactory.createInfoboxReadResponseType();
+
+ infoboxReadResponseType.setAssocArrayData(assocArray);
+
+ this.infoboxReadResponse = infoboxReadResponseType;
+ }
+
+ @Override
+ public void writeTo(Result result, Templates templates) {
+ ObjectFactory objectFactory = new ObjectFactory();
+ JAXBElement response = objectFactory.createInfoboxReadResponse(infoboxReadResponse);
+ writeTo(response, result, templates);
+ }
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/NullOperationResultImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/NullOperationResultImpl.java
index ae1f91ce..05986f85 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/NullOperationResultImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/NullOperationResultImpl.java
@@ -18,6 +18,7 @@ package at.gv.egiz.bku.slcommands.impl;
import javax.xml.bind.JAXBElement;
import javax.xml.transform.Result;
+import javax.xml.transform.Templates;
import at.buergerkarte.namespaces.securitylayer._1.NullOperationResponseType;
import at.buergerkarte.namespaces.securitylayer._1.ObjectFactory;
@@ -40,8 +41,8 @@ public class NullOperationResultImpl extends SLResultImpl implements NullOperati
}
@Override
- public void writeTo(Result result) {
- writeTo(RESPONSE, result);
+ public void writeTo(Result result, Templates templates) {
+ writeTo(RESPONSE, result, templates);
}
}
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 a79382b6..57309182 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
@@ -16,24 +16,33 @@
*/
package at.gv.egiz.bku.slcommands.impl;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.transform.Result;
+import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXTransformerFactory;
+import javax.xml.transform.sax.TransformerHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.w3c.dom.Node;
+import at.buergerkarte.namespaces.securitylayer._1.ErrorResponseType;
+import at.buergerkarte.namespaces.securitylayer._1.ObjectFactory;
import at.gv.egiz.bku.slcommands.SLCommandFactory;
import at.gv.egiz.bku.slcommands.SLResult;
+import at.gv.egiz.bku.slexceptions.SLBindingException;
+import at.gv.egiz.bku.slexceptions.SLCommandException;
+import at.gv.egiz.bku.slexceptions.SLException;
+import at.gv.egiz.bku.slexceptions.SLRuntimeException;
/**
* This class serves as an abstract base class for the implementation of a
@@ -72,46 +81,135 @@ public abstract class SLResultImpl implements SLResult {
return resultingMimeType;
}
+ private Marshaller getMarshaller() {
+ try {
+ JAXBContext context = SLCommandFactory.getJaxbContext();
+ Marshaller marshaller = context.createMarshaller();
+ marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+ return marshaller;
+ } catch (JAXBException e) {
+ log.fatal("Failed to marshall error response.", e);
+ throw new SLRuntimeException("Failed to marshall error response.", e);
+ }
+ }
+
+ private TransformerHandler getTransformerHandler(Templates templates, Result result) throws SLException {
+ try {
+ SAXTransformerFactory transformerFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
+ TransformerHandler transformerHandler = transformerFactory.newTransformerHandler(templates);
+ transformerHandler.setResult(result);
+ return transformerHandler;
+ } catch (TransformerFactoryConfigurationError e) {
+ log.error("Failed to create an instance of SAXTransformerFactory.", e);
+ throw new SLBindingException(2000);
+ } catch (IllegalArgumentException e) {
+ log.error("Failed to set result for transformation.", e);
+ throw new SLBindingException(2000);
+ } catch (TransformerConfigurationException e) {
+ log.info("Failed to create an instance of SAXTransformerFactory.", e);
+ throw new SLBindingException(2008);
+ }
+ }
+
+ @Override
+ public void writeTo(Result result) {
+ writeTo(result, null);
+ }
+
+
/**
- * Writes the given response
to the result
.
+ * Writes the given response
to the SAX result
using
+ * the given transform templates
.
*
- * @param response the security layer response element
- * @param result the result to marshal the response to
+ * @param response
+ * @param result
+ * @param templates
*/
- @SuppressWarnings("unchecked")
- public void writeTo(JAXBElement response, Result result) {
+ protected void writeTo(JAXBElement> response, Result result, Templates templates) {
+ TransformerHandler transformerHandler = null;
+ if (templates != null) {
+ try {
+ transformerHandler = getTransformerHandler(templates, result);
+ } catch (SLException e) {
+ writeErrorTo(e, result, templates);
+ }
+ }
+
+ Marshaller marshaller = getMarshaller();
try {
- JAXBContext context = SLCommandFactory.getJaxbContext();
- Marshaller marshaller = context.createMarshaller();
- marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
- marshaller.marshal(response, result);
+ if (transformerHandler != null) {
+ marshaller.marshal(response, transformerHandler);
+ } else {
+ marshaller.marshal(response, result);
+ }
} catch (JAXBException e) {
- // TODO Add throws clause to interface
- log.fatal("Failed to marshall JAXBElement.", e);
- throw new RuntimeException("Failed to marshall JAXBElement.", e);
+ log.info("Failed to marshall " + response.getName() + " result." , e);
+ SLCommandException commandException = new SLCommandException(4000);
+ writeErrorTo(commandException, result, templates);
}
+
+ }
+
+ protected void writeTo(Node node, Result result, Templates templates) {
+ if (templates == null) {
+ try {
+ TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ Transformer transformer = transformerFactory.newTransformer();
+ transformer.transform(new DOMSource(node), result);
+ } catch (TransformerConfigurationException e) {
+ log.error("Failed to create Transformer.", e);
+ writeErrorTo(new SLException(4000), result, null);
+ } catch (TransformerException e) {
+ log.error("Failed to transform result.", e);
+ writeErrorTo(new SLException(4000), result, null);
+ }
+ } else {
+ try {
+ Transformer transformer = templates.newTransformer();
+ transformer.transform(new DOMSource(node), result);
+ } catch (TransformerConfigurationException e) {
+ log.info("Failed to create transformer.", e);
+ writeErrorTo(new SLException(2008), result, templates);
+ } catch (TransformerException e) {
+ log.error("Failed to transform result.", e);
+ writeErrorTo(new SLException(2008), result, templates);
+ }
+ }
+
}
+
+ protected void writeErrorTo(SLException slException, Result result, Templates templates) {
+
+ TransformerHandler transformerHandler = null;
+ if (templates != null) {
+ try {
+ transformerHandler = getTransformerHandler(templates, result);
+ } catch (SLException e) {
+ // write the exception thrown instead of the given one
+ slException = e;
+ }
+ }
- /* (non-Javadoc)
- * @see at.gv.egiz.bku.slcommands.SLResult#writeTo(javax.xml.transform.Result, javax.xml.transform.Transformer)
- */
- @Override
- public void writeTo(Result result, Transformer transformer) throws TransformerException {
- // TODO Auto-generated method stub
- // fixxme: wb added for testing purposes to be completed
- // begin hack
- if (transformer == null) {
- writeTo(result);
- return;
+ ObjectFactory factory = new ObjectFactory();
+ ErrorResponseType responseType = factory.createErrorResponseType();
+ responseType.setErrorCode(slException.getErrorCode());
+ responseType.setInfo(slException.getDetailedMsg());
+ JAXBElement response = factory.createErrorResponse(responseType);
+
+ Marshaller marshaller = getMarshaller();
+ try {
+ if (transformerHandler != null) {
+ marshaller.marshal(response, transformerHandler);
+ } else {
+ marshaller.marshal(response, result);
+ }
+ } catch (JAXBException e) {
+ log.fatal("Failed to marshall error result." , e);
+ throw new SLRuntimeException("Failed to marshall error result.");
}
- // just a quick hack to proceed with testing
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- writeTo(new StreamResult(os));
- ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
- transformer.transform(new StreamSource(is), result);
- //end hack
+
}
}
--
cgit v1.2.3
From e21dd5249d5fa19c5619847922cf8cdea95e3145 Mon Sep 17 00:00:00 2001
From: wbauer
Date: Thu, 25 Sep 2008 07:29:47 +0000
Subject: improved robustness of http binding processor
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@70 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
---
.../src/main/java/at/gv/egiz/bku/binding/BindingProcessor.java | 4 +++-
.../main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java | 9 ++++++++-
.../at/gv/egiz/bku/slcommands/impl/InfoboxReadCommandImpl.java | 8 +++++---
3 files changed, 16 insertions(+), 5 deletions(-)
(limited to 'bkucommon/src/main/java')
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessor.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessor.java
index c386508d..2569bf85 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessor.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessor.java
@@ -71,5 +71,7 @@ public interface BindingProcessor extends Runnable {
* If the locale is not set the default locale will be used.
* @param locale must not be null.
*/
- public void setLocale(Locale locale);
+ public void setLocale(Locale locale);
+
+ public boolean isFinished();
}
\ No newline at end of file
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java
index 8f72c3ee..5e44e82b 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java
@@ -115,6 +115,7 @@ public class HTTPBindingProcessor extends AbstractBindingProcessor implements
protected int responseCode = 200;
protected Map responseHeaders = Collections.EMPTY_MAP;
protected Locale locale = Locale.getDefault();
+ protected boolean finished = false;
/**
*
@@ -246,6 +247,7 @@ public class HTTPBindingProcessor extends AbstractBindingProcessor implements
commandInvoker.setCommand(slCommand);
responseCode = 200;
responseHeaders = Collections.EMPTY_MAP;
+ dataUrlResponse = null;
try {
commandInvoker.invoke(srcContex);
} catch (SLException e) {
@@ -253,7 +255,6 @@ public class HTTPBindingProcessor extends AbstractBindingProcessor implements
bindingProcessorError = e;
currentState = State.TRANSFORM;
}
- dataUrlResponse = null;
if (getDataUrl() != null) {
log.debug("Data Url set to: " + getDataUrl());
currentState = State.DATAURL;
@@ -495,6 +496,7 @@ public class HTTPBindingProcessor extends AbstractBindingProcessor implements
sendSTALQuit();
log.info("Terminating Bindingprocessor; Thread: "
+ Thread.currentThread().getId());
+ finished = true;
}
// -- END Methods that handle the http binding activities as defined in the
@@ -620,6 +622,7 @@ public class HTTPBindingProcessor extends AbstractBindingProcessor implements
currentState = State.FINISHED;
}
log.debug("Terminated http binding processor");
+ finished = true;
}
@Override
@@ -805,4 +808,8 @@ public class HTTPBindingProcessor extends AbstractBindingProcessor implements
this.locale = locale;
}
+ @Override
+ public boolean isFinished() {
+ return finished;
+ }
}
\ No newline at end of file
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 4d64ae36..b6c89e5b 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
@@ -371,12 +371,12 @@ public class InfoboxReadCommandImpl extends SLCommandImpl