aboutsummaryrefslogtreecommitdiff
path: root/id.server/src/at/gv/egovernment/moa/id/auth/parser/InfoboxReadResponseParser.java
diff options
context:
space:
mode:
Diffstat (limited to 'id.server/src/at/gv/egovernment/moa/id/auth/parser/InfoboxReadResponseParser.java')
-rw-r--r--id.server/src/at/gv/egovernment/moa/id/auth/parser/InfoboxReadResponseParser.java122
1 files changed, 81 insertions, 41 deletions
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();
}