Author: mmoyses
Date: 2010-10-25 08:56:33 -0400 (Mon, 25 Oct 2010)
New Revision: 507
Modified:
trust/trunk/jbossws/src/main/java/org/picketlink/trust/jbossws/handler/SAML2Handler.java
Log:
fixing the way username is retrieved from assertion
Modified:
trust/trunk/jbossws/src/main/java/org/picketlink/trust/jbossws/handler/SAML2Handler.java
===================================================================
---
trust/trunk/jbossws/src/main/java/org/picketlink/trust/jbossws/handler/SAML2Handler.java 2010-10-23
01:23:08 UTC (rev 506)
+++
trust/trunk/jbossws/src/main/java/org/picketlink/trust/jbossws/handler/SAML2Handler.java 2010-10-25
12:56:33 UTC (rev 507)
@@ -41,6 +41,8 @@
import org.picketlink.trust.jbossws.Util;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
/**
* A SAMLv2 WS handler.
@@ -91,7 +93,7 @@
}
Element subject = Util.findElement(assertion, new
QName(SAML2Constants.SAML2_ASSERTION_URI, "Subject"));
Element nameID = Util.findElement(subject, new
QName(SAML2Constants.SAML2_ASSERTION_URI, "NameID"));
- String username = nameID.getTextContent();
+ String username = getUsername(nameID);
// set SecurityContext
Subject s = new Subject();
SecurityContext sc = SecurityActions.createSecurityContext(new
PicketLinkPrincipal(username), credential, s);
@@ -152,5 +154,20 @@
Util.addNamespace(element, Constants.XML_ENCRYPTION_PREFIX,
Constants.XML_SIGNATURE_NS);
return element;
}
+
+ private String getUsername(final Element nameID) {
+ String username = nameID.getNodeValue();
+ if (username == null) {
+ final NodeList childNodes = nameID.getChildNodes();
+ final int size = childNodes.getLength();
+ for (int i = 0; i < size; i++) {
+ final Node childNode = childNodes.item(i);
+ if (childNode.getNodeType() == Node.TEXT_NODE) {
+ username = childNode.getNodeValue();
+ }
+ }
+ }
+ return username;
+ }
}
Show replies by date