[jboss-svn-commits] JBL Code SVN: r29447 - labs/jbossesb/workspace/dbevenius/saml_support/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Sep 24 02:42:57 EDT 2009
Author: beve
Date: 2009-09-24 02:42:57 -0400 (Thu, 24 Sep 2009)
New Revision: 29447
Added:
labs/jbossesb/workspace/dbevenius/saml_support/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPSamlHandlerUtil.java
Modified:
labs/jbossesb/workspace/dbevenius/saml_support/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPSamlHandler.java
Log:
Refactored a little.
Modified: labs/jbossesb/workspace/dbevenius/saml_support/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPSamlHandler.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/saml_support/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPSamlHandler.java 2009-09-23 17:36:34 UTC (rev 29446)
+++ labs/jbossesb/workspace/dbevenius/saml_support/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPSamlHandler.java 2009-09-24 06:42:57 UTC (rev 29447)
@@ -24,11 +24,7 @@
import java.util.Set;
import javax.xml.namespace.QName;
-import javax.xml.soap.SOAPElement;
-import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
-import javax.xml.soap.SOAPFactory;
-import javax.xml.soap.SOAPHeader;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPHandler;
@@ -36,6 +32,7 @@
import org.jboss.soa.esb.services.security.auth.login.SamlContext;
import org.jboss.soa.esb.services.security.auth.login.SamlPrincipal;
+import org.w3c.dom.Element;
/**
* SOAPSamlHandler is a SOAP Protocol Handler that will add a security header to
@@ -49,8 +46,6 @@
public final static String WSSE_NS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
QName securityQName = new QName(SOAPSamlHandler.WSSE_NS, "Security");
- private static final SOAPFactory SOAP_FACTORY = createSOAPFactory();
-
public boolean handleMessage(final SOAPMessageContext soapContext)
{
final Boolean outBound = (Boolean) soapContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
@@ -59,19 +54,11 @@
try
{
- final SOAPEnvelope envelope = soapContext.getMessage().getSOAPPart().getEnvelope();
- SOAPHeader header = envelope.getHeader();
- if (header == null)
- {
- header = envelope.addHeader();
- }
-
- final SOAPElement securityElement = header.addChildElement("Security", "wsse", WSSE_NS);
final SamlPrincipal samlPrincipal = SamlContext.getContext();
if (samlPrincipal != null)
{
- // Add the assertion elemetn ignoring the result.
- securityElement.addChildElement(SOAP_FACTORY.createElement(samlPrincipal.getAssertionElement()));
+ final Element assertionElement = samlPrincipal.getAssertionElement();
+ SOAPSamlHandlerUtil.addAssertion(soapContext, securityQName, assertionElement);
}
}
catch (final SOAPException e)
@@ -100,16 +87,4 @@
return false;
}
- private static SOAPFactory createSOAPFactory()
- {
- try
- {
- return SOAPFactory.newInstance();
- }
- catch (final SOAPException e)
- {
- throw new IllegalStateException(e.getMessage(), e);
- }
- }
-
}
Added: labs/jbossesb/workspace/dbevenius/saml_support/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPSamlHandlerUtil.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/saml_support/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPSamlHandlerUtil.java (rev 0)
+++ labs/jbossesb/workspace/dbevenius/saml_support/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPSamlHandlerUtil.java 2009-09-24 06:42:57 UTC (rev 29447)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2009, Red Hat Middleware
+ * LLC, and individual contributors by the @authors tag. See the copyright.txt
+ * in the distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.actions.soap;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFactory;
+import javax.xml.soap.SOAPHeader;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+
+import org.jboss.internal.soa.esb.assertion.AssertArgument;
+import org.w3c.dom.Element;
+
+/**
+ * Util methods for handling SAML related tasks for SOAP Protocol Handlers.
+ *
+ * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
+ *
+ */
+public class SOAPSamlHandlerUtil
+{
+ private static final SOAPFactory SOAP_FACTORY = createSOAPFactory();
+
+ private SOAPSamlHandlerUtil()
+ {
+ }
+
+ public static SOAPElement addAssertion(final SOAPMessageContext soapContext, final QName securityHeader, final Element assertion) throws SOAPException
+ {
+ AssertArgument.isNotNull(soapContext, "soapContext");
+ AssertArgument.isNotNull(assertion, "assertion");
+
+ final SOAPEnvelope envelope = soapContext.getMessage().getSOAPPart().getEnvelope();
+ SOAPHeader header = envelope.getHeader();
+ if (header == null)
+ {
+ header = envelope.addHeader();
+ }
+ final SOAPElement securityElement = header.addChildElement(securityHeader);
+ // Add the assertion element.
+ return securityElement.addChildElement(SOAP_FACTORY.createElement(assertion));
+ }
+
+ private static SOAPFactory createSOAPFactory()
+ {
+ try
+ {
+ return SOAPFactory.newInstance();
+ }
+ catch (final SOAPException e)
+ {
+ throw new IllegalStateException(e.getMessage(), e);
+ }
+ }
+
+}
More information about the jboss-svn-commits
mailing list