aboutsummaryrefslogtreecommitdiff
path: root/id.server
diff options
context:
space:
mode:
authorharald.bratko <harald.bratko@d688527b-c9ab-4aba-bd8d-4036d912da1d>2005-09-02 16:01:29 +0000
committerharald.bratko <harald.bratko@d688527b-c9ab-4aba-bd8d-4036d912da1d>2005-09-02 16:01:29 +0000
commit235241ec5f18ad26c013b091887ce5f651462553 (patch)
tree3d9b8d297770c4a8e449497bf7f4a999b987d79a /id.server
parent8d5ba9260dcf2ed438056ca237a073b8b7719a5b (diff)
downloadmoa-id-spss-235241ec5f18ad26c013b091887ce5f651462553.tar.gz
moa-id-spss-235241ec5f18ad26c013b091887ce5f651462553.tar.bz2
moa-id-spss-235241ec5f18ad26c013b091887ce5f651462553.zip
Redesigned because response has been parsed twice.
git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/trunk@490 d688527b-c9ab-4aba-bd8d-4036d912da1d
Diffstat (limited to 'id.server')
-rw-r--r--id.server/src/at/gv/egovernment/moa/id/auth/parser/CreateXMLSignatureResponseParser.java88
-rw-r--r--id.server/src/at/gv/egovernment/moa/id/auth/parser/ErrorResponseParser.java92
-rw-r--r--id.server/src/at/gv/egovernment/moa/id/auth/parser/IdentityLinkAssertionParser.java13
-rw-r--r--id.server/src/at/gv/egovernment/moa/id/auth/parser/InfoboxReadResponseParser.java122
4 files changed, 178 insertions, 137 deletions
diff --git a/id.server/src/at/gv/egovernment/moa/id/auth/parser/CreateXMLSignatureResponseParser.java b/id.server/src/at/gv/egovernment/moa/id/auth/parser/CreateXMLSignatureResponseParser.java
index cae470cc4..4264ca2cb 100644
--- a/id.server/src/at/gv/egovernment/moa/id/auth/parser/CreateXMLSignatureResponseParser.java
+++ b/id.server/src/at/gv/egovernment/moa/id/auth/parser/CreateXMLSignatureResponseParser.java
@@ -45,26 +45,22 @@ public class CreateXMLSignatureResponseParser {
private static final String SAML_ATTRIBUTE_VALUE_XPATH = SAML + "AttributeValue";
- /** This is the root element of the XML-Document provided by the Security Layer Card */
- private Element sigResponse;
+ /** This is the root element of the CreateXMLsignatureResponse */
+ private Element sigResponse_;
/**
- * Constructor for CreateXMLSignatureResponseParser.
- * A DOM-representation of the incoming String will be created
- * @param xmlResponse <code>&lt;InfoboxReadResponse&gt;</code> as String
+ * Parses and validates the document given as string and extracts the
+ * root element.
+ *
+ * @param xmlResponse <code>&lt;CreateXMLSignatureResponse&gt;</code> as String
+ *
* @throws AuthenticationException if any authentication error occurs
* @throws ParseException if an element cannot be parsed
*/
public CreateXMLSignatureResponseParser(String xmlResponse) throws AuthenticationException, ParseException {
- ErrorResponseParser erp = new ErrorResponseParser(xmlResponse);
- if (erp.getErrorCode() != null) {
- throw new AuthenticationException("auth.08", new Object[] { erp.getErrorCode(), erp.getErrorInfo()});
- }
-
try {
-
InputStream s = new ByteArrayInputStream(xmlResponse.getBytes("UTF-8"));
- sigResponse = DOMUtils.parseXmlValidating(s);
+ init(s);
}
catch (Throwable t) {
throw new ParseException("parser.01", new Object[] { t.toString()}, t);
@@ -72,27 +68,16 @@ public class CreateXMLSignatureResponseParser {
}
/**
- * Constructor for CreateXMLSignatureResponseParser.
- * A DOM-representation of the incoming Inputstream will be created
- * @param xmlResponse <code>&lt;InfoboxReadResponse&gt;</code> as InputStream
- * @throws AuthenticationException if any Authentication error occurs
+ * Parses and validates the document given as stream and extracts the
+ * root element.
+ *
+ * @param xmlResponse <code>&lt;CreateXMLSignatureResponse&gt;</code> as String
+ *
+ * @throws AuthenticationException if any authentication error occurs
* @throws ParseException if an element cannot be parsed
*/
public CreateXMLSignatureResponseParser(InputStream is) throws AuthenticationException, ParseException {
-
- ErrorResponseParser erp = new ErrorResponseParser(is);
- if (erp.getErrorCode() != null) {
- throw new AuthenticationException("auth.08", new Object[] { erp.getErrorCode(), erp.getErrorInfo()});
- }
-
- try {
-
- sigResponse = DOMUtils.parseXmlValidating(is);
-
- }
- catch (Throwable t) {
- throw new ParseException("parser.01", new Object[] { t.toString()}, t);
- }
+ init(is);
}
/**
@@ -101,13 +86,40 @@ public class CreateXMLSignatureResponseParser {
* @param xmlResponse <code>&lt;InfoboxReadResponse&gt;</code> as InputStream
*/
public CreateXMLSignatureResponseParser(Element xmlResponse) {
- sigResponse = xmlResponse;
-
+ sigResponse_ = xmlResponse;
+ }
+
+ /**
+ * Initializes the parser.
+ * Parses and validates the document given as stream and extracts the
+ * root element.
+ *
+ * @param is The CreateXMLSignatureResponse as stream.
+ * @throws AuthenticationException if an authentication error occurs.
+ * @throws ParseException If an error occurs on parsing the the document.
+ */
+ private void init(InputStream is) throws AuthenticationException, ParseException {
+ try {
+
+ Element responseElem = DOMUtils.parseXmlValidating(is);
+
+ if ("CreateXMLSignatureResponse".equals(responseElem.getLocalName())) {
+ sigResponse_ = responseElem;
+ } else {
+ ErrorResponseParser erp = new ErrorResponseParser(responseElem);
+ throw new AuthenticationException("auth.08", new Object[] { erp.getErrorCode(), erp.getErrorInfo()});
+ }
+
+ } catch (Throwable t) {
+ throw new ParseException("parser.01", new Object[] { t.toString()}, t);
+ }
}
/**
- * Parses the identity link from <code>&lt;InfoboxReadResponse&gt;</code>
- * @return Identity link
+ * Unmarshalls the <@link sigResponse> to an
+ * <code>&lt;CreateXMLSignatureResponse&gt;</code> object.
+ *
+ * @return a <code>&lt;CreateXMLSignatureResponse&gt;</code> object
* @throws ParseException
*/
@@ -115,10 +127,10 @@ public class CreateXMLSignatureResponseParser {
CreateXMLSignatureResponse cResp;
try {
cResp = new CreateXMLSignatureResponse();
- String slPrefix = XPathUtils.getSlPrefix(sigResponse);
- cResp.setSamlNameIdentifier(XPathUtils.getElementValue(sigResponse, "/" + slPrefix + SAML_SUBJECT_NAME_IDENTIFIER_XPATH, null));
- cResp.setSamlAssertion((Element) XPathUtils.selectSingleNode(sigResponse, "/" + slPrefix + SAML_ASSERTION_XPATH));
- NodeIterator attrIter = XPathUtils.selectNodeIterator(sigResponse, "/" + slPrefix + SAML_ATTRIBUTE_XPATH);
+ String slPrefix = XPathUtils.getSlPrefix(sigResponse_);
+ cResp.setSamlNameIdentifier(XPathUtils.getElementValue(sigResponse_, "/" + slPrefix + SAML_SUBJECT_NAME_IDENTIFIER_XPATH, null));
+ cResp.setSamlAssertion((Element) XPathUtils.selectSingleNode(sigResponse_, "/" + slPrefix + SAML_ASSERTION_XPATH));
+ NodeIterator attrIter = XPathUtils.selectNodeIterator(sigResponse_, "/" + slPrefix + SAML_ATTRIBUTE_XPATH);
Element samlAttr;
List samlAttributes = new ArrayList();
while ((samlAttr = (Element) attrIter.nextNode()) != null) {
diff --git a/id.server/src/at/gv/egovernment/moa/id/auth/parser/ErrorResponseParser.java b/id.server/src/at/gv/egovernment/moa/id/auth/parser/ErrorResponseParser.java
index 7084faf1f..8edeec8ae 100644
--- a/id.server/src/at/gv/egovernment/moa/id/auth/parser/ErrorResponseParser.java
+++ b/id.server/src/at/gv/egovernment/moa/id/auth/parser/ErrorResponseParser.java
@@ -1,89 +1,71 @@
package at.gv.egovernment.moa.id.auth.parser;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
+import java.util.List;
import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
import at.gv.egovernment.moa.id.ParseException;
import at.gv.egovernment.moa.util.DOMUtils;
-import at.gv.egovernment.moa.util.XPathUtils;
/**
- * Parses an <code>&lt;InfoboxReadResponse&gt;</code>.
+ * Parses an <code>&lt;ErrorResponse&gt;</code>.
*
* @author Stefan Knirsch
* @version $Id$
*/
public class ErrorResponseParser {
-
- /** This is the root element of the XML-Document provided by the Security Layer Card */
- private Element errorElement;
-
+
/**
- * Constructor for InfoboxReadResponseParser.
- * A DOM-representation of the incoming String will be created
- * @param xmlResponse <code>&lt;InfoboxReadResponse&gt;</code> as String
- * @throws ParseException on any error
+ * The error code included in this error response.
+ * <code>1000</code> is used as default value, if some problems occur on
+ * evaluating the error response.
*/
- public ErrorResponseParser(String xmlResponse) throws ParseException {
- try {
- InputStream s = new ByteArrayInputStream(xmlResponse.getBytes("UTF-8"));
- errorElement = DOMUtils.parseXmlValidating(s);
- }
- catch (Throwable t) {
- throw new ParseException("parser.01", new Object[] { t.toString()}, t);
- }
- }
+ private String errorCode_ = "1000";
+
+ /**
+ * The error info included in this error response.
+ * <code>&lt;Unklassifizierter Fehler.&gt;</code> is used as default value,
+ * if some problems occur on evaluating the error response.
+ */
+ private String errorInfo_ = "Unklassifizierter Fehler.";
+
/**
- * Constructor for InfoboxReadResponseParser.
- * A DOM-representation of the incoming Inputstream will be created
- * @param xmlResponse <code>&lt;InfoboxReadResponse&gt;</code> as InputStream
- * @throws ParseException on any error
+ * This Constructor extracts the error code and error info included in this
+ * error response.
+ *
+ * @param errorElement The error element. This is the root element of
+ * the error response.
*/
- public ErrorResponseParser(InputStream xmlResponse) throws ParseException {
- try {
- errorElement = DOMUtils.parseXmlValidating(xmlResponse);
- }
- catch (Throwable t) {
- throw new ParseException("parser.01", new Object[] { t.toString() }, t);
+ public ErrorResponseParser(Element errorElement) throws ParseException {
+ if (errorElement != null) {
+ String namespace = errorElement.getNamespaceURI();
+ NodeList nl = errorElement.getElementsByTagNameNS(namespace, "ErrorCode");
+ if (nl.getLength() == 1) {
+ errorCode_ = ((Element)nl.item(0)).getFirstChild().getNodeValue();
+ }
+ nl = errorElement.getElementsByTagNameNS(namespace, "Info");
+ if (nl.getLength() == 1) {
+ errorInfo_ = ((Element)nl.item(0)).getFirstChild().getNodeValue();
+ }
}
}
/**
- * Method getErrorCode. returns the error code
- * @return String
+ * Returns the error code included in this error response.
*/
public String getErrorCode() {
-
- String slPrefix = XPathUtils.getSlPrefix(errorElement);
- StringBuffer sb = new StringBuffer("/");
- sb.append(slPrefix);
- sb.append(":ErrorResponse/");
- sb.append(slPrefix);
- sb.append(":ErrorCode");
- String errorCodeXPath = sb.toString();
- return XPathUtils.getElementValue(errorElement,errorCodeXPath,null);
-
+ return errorCode_ ;
}
/**
- * Method getErrorInfo: returns the information about the error
- * @return String
+ * Returns the information included in this error response.
+ * @return
*/
public String getErrorInfo() {
-
- String slPrefix = XPathUtils.getSlPrefix(errorElement);
- StringBuffer sb = new StringBuffer("/");
- sb.append(slPrefix);
- sb.append(":ErrorResponse/");
- sb.append(slPrefix);
- sb.append(":Info");
- String errorInfoXPath = sb.toString();
- return XPathUtils.getElementValue(errorElement,errorInfoXPath,null);
-
+ return errorInfo_ ;
}
diff --git a/id.server/src/at/gv/egovernment/moa/id/auth/parser/IdentityLinkAssertionParser.java b/id.server/src/at/gv/egovernment/moa/id/auth/parser/IdentityLinkAssertionParser.java
index 2df33725a..9ed6909b3 100644
--- a/id.server/src/at/gv/egovernment/moa/id/auth/parser/IdentityLinkAssertionParser.java
+++ b/id.server/src/at/gv/egovernment/moa/id/auth/parser/IdentityLinkAssertionParser.java
@@ -34,8 +34,6 @@ public class IdentityLinkAssertionParser {
/** Xpath prefix for reaching PersonData Namespaces */
private static final String PDATA = Constants.PD_PREFIX + ":";
- /** Xpath prefix for reaching SecurityLayer 1.0 Namespaces */
- private static final String SL10 = Constants.SL10_PREFIX + ":";
/** Xpath prefix for reaching SAML Namespaces */
private static final String SAML = Constants.SAML_PREFIX + ":";
/** Xpath prefix for reaching XML-DSIG Namespaces */
@@ -43,7 +41,7 @@ public class IdentityLinkAssertionParser {
/** Xpath prefix for reaching ECDS Namespaces */
private static final String ECDSA = Constants.ECDSA_PREFIX + ":";
/** Xpath expression to the root element */
- private static final String ROOT = "/" + SAML + "Assertion/";
+ private static final String ROOT = "";
/** Xpath expression to the SAMLSubjectConfirmationData element */
private static final String SAML_SUBJECT_CONFIRMATION_DATA_XPATH =
ROOT
@@ -178,6 +176,15 @@ public class IdentityLinkAssertionParser {
throw new ParseException("parser.01", new Object[] { t.toString()}, t);
}
}
+
+ /**
+ * Sets the <@link assertionElem>.
+ * @param xmlAssertion the assertion element
+ * @throws ParseException on any parsing error
+ */
+ public IdentityLinkAssertionParser(Element xmlAssertion) throws ParseException {
+ assertionElem = xmlAssertion;
+ }
/**
* Constructor for <code>IdentityLinkAssertionParser</code>.
diff --git a/id.server/src/at/gv/egovernment/moa/id/auth/parser/InfoboxReadResponseParser.java b/id.server/src/at/gv/egovernment/moa/id/auth/parser/InfoboxReadResponseParser.java
index ffb80aadd..0cedda28d 100644
--- a/id.server/src/at/gv/egovernment/moa/id/auth/parser/InfoboxReadResponseParser.java
+++ b/id.server/src/at/gv/egovernment/moa/id/auth/parser/InfoboxReadResponseParser.java
@@ -19,75 +19,104 @@ import at.gv.egovernment.moa.util.XPathUtils;
*/
public class InfoboxReadResponseParser {
-// //
-// // XPath namespace prefix shortcuts
-// //
-// /** Xpath prefix for reaching SecurityLayer 1.0 Namespaces */
-// private static final String SL10 = Constants.SL10_PREFIX + ":";
-// /** Xpath prefix for reaching SAML Namespaces */
-// private static final String SAML = Constants.SAML_PREFIX + ":";
-// /** Xpath expression to the root element */
-// private static final String ROOT = "/" + SL10 + "InfoboxReadResponse/";
-// /** Xpath expression to the SAML:Assertion element */
-// private static final String SAML_ASSERTION_XPATH = ROOT + SL10 + "BinaryFileData/" + SL10 + "XMLContent/" + SAML + "Assertion";
/** This is the root element of the XML-Document provided by the Security Layer Card*/
- private Element infoBoxElem;
+ private Element infoBoxElem_;
/**
- * Constructor for InfoboxReadResponseParser.
- * A DOM-representation of the incoming String will be created
+ * Parses and validates the document given as string and extracts the
+ * root element.
+ *
* @param xmlResponse <code>&lt;InfoboxReadResponse&gt;</code> as String
* @throws ParseException on any parsing error
*/
public InfoboxReadResponseParser(String xmlResponse) throws ParseException, AuthenticationException {
-
- ErrorResponseParser erp = new ErrorResponseParser(xmlResponse);
- if (erp.getErrorCode() != null) {
- throw new AuthenticationException("auth.08", new Object[] { erp.getErrorCode(), erp.getErrorInfo()});
- }
-
+
try {
-
InputStream s = new ByteArrayInputStream(xmlResponse.getBytes("UTF-8"));
- infoBoxElem = DOMUtils.parseXmlValidating(s);
+ init(s);
}
catch (Throwable t) {
- throw new ParseException("parser.01", new Object[] { t.toString()}, t);
+ throw new ParseException("parser.01", new Object[] { t.toString()}, t);
}
}
/**
- * Constructor for InfoboxReadResponseParser.
- * A DOM-representation of the incoming Inputstream will be created
+ * Parses and validates the document given as stream and extracts the
+ * root element.
+ *
* @param xmlResponse <code>&lt;InfoboxReadResponse&gt;</code> as InputStream
* @throws ParseException on any parsing error
*/
public InfoboxReadResponseParser(InputStream is) throws ParseException, AuthenticationException {
+ init(is);
+ }
- ErrorResponseParser erp = new ErrorResponseParser(is);
- if (erp.getErrorCode() != null) {
- throw new AuthenticationException("auth.08", new Object[] { erp.getErrorCode(), erp.getErrorInfo()});
- }
-
+ /**
+ * Initializes the parser.
+ * Parses and validates the document given as stream and extracts the
+ * root element.
+ *
+ * @param is The InfoBoxReadResponse as stream.
+ * @throws AuthenticationException if an authentication error occurs.
+ * @throws ParseException If an error occurs on parsing the the document.
+ */
+ private void init(InputStream is) throws AuthenticationException, ParseException {
try {
-
- infoBoxElem = DOMUtils.parseXmlValidating(is);
- }
- catch (Throwable t) {
+
+ Element responseElem = DOMUtils.parseXmlValidating(is);
+
+ if ("InfoboxReadResponse".equals(responseElem.getLocalName())) {
+ infoBoxElem_ = responseElem;
+ } else {
+ ErrorResponseParser erp = new ErrorResponseParser(responseElem);
+ throw new AuthenticationException("auth.08", new Object[] { erp.getErrorCode(), erp.getErrorInfo()});
+ }
+
+ } catch (Throwable t) {
throw new ParseException("parser.01", new Object[] { t.toString()}, t);
}
}
+
+
+ /**
+ * Parses the embedded <code>&lt;saml:Assertion&gt;</code> element from <code>&lt;InfoboxReadResponse&gt;</code>
+ * @return <code>&lt;saml:Assertion&gt;</code> as String
+ * @throws ParseException on any parsing error
+ */
+// public String parseSAMLAssertion() throws ParseException {
+// try {
+//
+// String slPrefix = XPathUtils.getSlPrefix(infoBoxElem_);
+// StringBuffer sb = new StringBuffer("/");
+// sb.append(slPrefix);
+// sb.append(":InfoboxReadResponse/");
+// sb.append(slPrefix);
+// sb.append(":BinaryFileData/");
+// sb.append(slPrefix);
+// sb.append(":XMLContent/");
+// sb.append(Constants.SAML_PREFIX);
+// sb.append(":Assertion");
+// String samlAssertionXPath = sb.toString();
+// Element samlAssertion = (Element) XPathUtils.selectSingleNode(infoBoxElem_, samlAssertionXPath);
+// return DOMUtils.serializeNode(samlAssertion);
+//
+// }
+// catch (Throwable t) {
+// throw new ParseException("parser.01", new Object[] { t.toString()}, t);
+// }
+// }
+
/**
* Parses the embedded <code>&lt;saml:Assertion&gt;</code> element from <code>&lt;InfoboxReadResponse&gt;</code>
* @return <code>&lt;saml:Assertion&gt;</code> as String
* @throws ParseException on any parsing error
*/
- public String parseSAMLAssertion() throws ParseException {
+ public Element parseSAMLAssertion() throws ParseException {
try {
- String slPrefix = XPathUtils.getSlPrefix(infoBoxElem);
+ String slPrefix = XPathUtils.getSlPrefix(infoBoxElem_);
StringBuffer sb = new StringBuffer("/");
sb.append(slPrefix);
sb.append(":InfoboxReadResponse/");
@@ -98,8 +127,8 @@ public class InfoboxReadResponseParser {
sb.append(Constants.SAML_PREFIX);
sb.append(":Assertion");
String samlAssertionXPath = sb.toString();
- Element samlAssertion = (Element) XPathUtils.selectSingleNode(infoBoxElem, samlAssertionXPath);
- return DOMUtils.serializeNode(samlAssertion);
+ Element samlAssertion = (Element) XPathUtils.selectSingleNode(infoBoxElem_, samlAssertionXPath);
+ return samlAssertion;
}
catch (Throwable t) {
@@ -113,9 +142,20 @@ public class InfoboxReadResponseParser {
* @throws ParseException on any parsing error
*/
- public IdentityLink parseIdentityLink() throws ParseException {
- String samlAssertionString = parseSAMLAssertion();
- IdentityLinkAssertionParser ilParser = new IdentityLinkAssertionParser(samlAssertionString);
+// public IdentityLink parseIdentityLink() throws ParseException {
+// String samlAssertionString = parseSAMLAssertion();
+// IdentityLinkAssertionParser ilParser = new IdentityLinkAssertionParser(samlAssertionString);
+// return ilParser.parseIdentityLink();
+// }
+
+ /**
+ * Parses the identity link from the <code>&lt;saml:Assertion&gt;</code>
+ * @return Identity link
+ * @throws ParseException on any parsing error
+ */
+ public IdentityLink parseIdentityLink() throws ParseException {
+ Element samlAssertion = parseSAMLAssertion();
+ IdentityLinkAssertionParser ilParser = new IdentityLinkAssertionParser(samlAssertion);
return ilParser.parseIdentityLink();
}