cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject [2/2] git commit: [CXF-5664] - Support wsp:URI + JAXB Elements when parsing Participants
Date Wed, 16 Apr 2014 16:02:13 GMT
[CXF-5664] - Support wsp:URI + JAXB Elements when parsing Participants


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/62282751
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/62282751
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/62282751

Branch: refs/heads/2.7.x-fixes
Commit: 622827512ef56fc2a2d9d36d0598bca37749096b
Parents: d76659f
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Wed Apr 16 16:57:12 2014 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Wed Apr 16 16:58:35 2014 +0100

----------------------------------------------------------------------
 .../provider/DefaultConditionsProvider.java     | 56 ++++++++++++++------
 1 file changed, 40 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/62282751/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/provider/DefaultConditionsProvider.java
----------------------------------------------------------------------
diff --git a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/provider/DefaultConditionsProvider.java
b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/provider/DefaultConditionsProvider.java
index b044869..a899af9 100644
--- a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/provider/DefaultConditionsProvider.java
+++ b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/provider/DefaultConditionsProvider.java
@@ -26,13 +26,16 @@ import java.util.Date;
 import java.util.List;
 import java.util.logging.Logger;
 
-import org.w3c.dom.Element;
+import javax.xml.bind.JAXBElement;
+import javax.xml.namespace.QName;
 
+import org.w3c.dom.Element;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.sts.STSConstants;
 import org.apache.cxf.sts.request.Lifetime;
 import org.apache.cxf.sts.request.Participants;
+import org.apache.cxf.ws.addressing.EndpointReferenceType;
 import org.apache.cxf.ws.security.sts.provider.STSException;
 import org.apache.ws.security.saml.ext.bean.AudienceRestrictionBean;
 import org.apache.ws.security.saml.ext.bean.ConditionsBean;
@@ -257,9 +260,8 @@ public class DefaultConditionsProvider implements ConditionsProvider {
             
             if (participants.getParticipants() != null) {
                 for (Object participant : participants.getParticipants()) {
-                    if (participant instanceof Element) {
-                        String address = 
-                            extractAddressFromParticipantsEPR((Element)participant);
+                    if (participant != null) {
+                        String address = extractAddressFromParticipantsEPR(participant);
                         if (address != null) {
                             AudienceRestrictionBean audienceRestriction = new AudienceRestrictionBean();
                             audienceRestriction.setAudienceURIs(Collections.singletonList(address));
@@ -274,21 +276,43 @@ public class DefaultConditionsProvider implements ConditionsProvider
{
     }
     
     /**
-     * Extract an address from a Particpants EPR DOM element
+     * Extract an address from a Participants EPR DOM element
      */
-    protected static String extractAddressFromParticipantsEPR(Element participants) {
-        if (participants != null && STSConstants.WSA_NS_05.equals(participants.getNamespaceURI())
-                && "EndpointReference".equals(participants.getLocalName())) {
-            LOG.fine("Found EndpointReference element");
-            Element address = 
-                DOMUtils.getFirstChildWithName(
-                        participants, STSConstants.WSA_NS_05, "Address");
-            if (address != null) {
-                LOG.fine("Found address element");
-                return address.getTextContent();
+    protected String extractAddressFromParticipantsEPR(Object participants) {
+        if (participants instanceof Element) {
+            String localName = ((Element)participants).getLocalName();
+            String namespace = ((Element)participants).getNamespaceURI();
+            
+            if (STSConstants.WSA_NS_05.equals(namespace) && "EndpointReference".equals(localName))
{
+                LOG.fine("Found EndpointReference element");
+                Element address = 
+                    DOMUtils.getFirstChildWithName((Element)participants, 
+                            STSConstants.WSA_NS_05, "Address");
+                if (address != null) {
+                    LOG.fine("Found address element");
+                    return address.getTextContent();
+                }
+            } else if ((STSConstants.WSP_NS.equals(namespace) || STSConstants.WSP_NS_04.equals(namespace))
+                && "URI".equals(localName)) {
+                return ((Element)participants).getTextContent();
+            }
+            LOG.fine("Participants element does not exist or could not be parsed");
+            return null;
+        } else if (participants instanceof JAXBElement<?>) {
+            JAXBElement<?> jaxbElement = (JAXBElement<?>) participants;
+            QName participantsName = jaxbElement.getName();
+            if (STSConstants.WSA_NS_05.equals(participantsName.getNamespaceURI()) 
+                && "EndpointReference".equals(participantsName.getLocalPart())) {
+                LOG.fine("Found EndpointReference element");
+                EndpointReferenceType endpointReference = (EndpointReferenceType)jaxbElement.getValue();
+                if (endpointReference.getAddress() != null) {
+                    LOG.fine("Found address element");
+                    return endpointReference.getAddress().getValue();
+                }
             }
+            LOG.fine("Participants element does not exist or could not be parsed");
         }
-        LOG.fine("Participants element does not exist or could not be parsed");
+        
         return null;
     }
 


Mime
View raw message