Author: veithen
Date: Thu Sep 4 21:26:26 2014
New Revision: 1622565
URL: http://svn.apache.org/r1622565
Log:
AXIS2-5659: Applied Detelin Yordanov's patch to improve
WS-AddressingAndIdentity support (with minor formatting changes).
Modified:
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/addressing/AddressingConstants.java
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/addressing/AddressingHelper.java
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/context/MessageContext.java
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/AxisService2WSDL11.java
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java
Modified:
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/addressing/AddressingConstants.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/addressing/AddressingConstants.java?rev=1622565&r1=1622564&r2=1622565&view=diff
==============================================================================
---
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/addressing/AddressingConstants.java
(original)
+++
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/addressing/AddressingConstants.java
Thu Sep 4 21:26:26 2014
@@ -116,6 +116,12 @@ public interface AddressingConstants {
static final String REFERENCE_PARAMETER_PARAMETER = "referenceParameters";
/**
+ * Used to attach any <wsid:Identity> OMElement found in an EPR
embedded in a WSDL to an
+ * AxisEndpoint object.
+ */
+ static final String ADDRESSING_IDENTITY_PARAMETER = "addressingIdentity";
+
+ /**
* This parameter is used to decide whether the reference parameters in an
inbound request
* message are to be processed or not.
*/
@@ -145,6 +151,8 @@ public interface AddressingConstants {
static final String IDENTITY_KEY_INFO = "KeyInfo";
static final String IDENTITY_X509_DATA = "X509Data";
static final String IDENTITY_X509_CERT = "X509Certificate";
+ static final String IDENTITY_SPN = "Spn";
+ static final String IDENTITY_UPN = "Upn";
static final String IDENTITY_PARAMETER = "WSAddressingAndIdentity";
@@ -152,6 +160,8 @@ public interface AddressingConstants {
static final QName QNAME_IDENTITY_KEY_INFO = new
QName(XML_SIG_NS,IDENTITY_KEY_INFO,XML_SIG_PREFIX);
static final QName QNAME_IDENTITY_X509_DATA = new
QName(XML_SIG_NS,IDENTITY_X509_DATA,XML_SIG_PREFIX);
static final QName QNAME_IDENTITY_X509_CERT = new
QName(XML_SIG_NS,IDENTITY_X509_CERT,XML_SIG_PREFIX);
+ static final QName QNAME_IDENTITY_SPN = new QName(ADDRESSING_IDENTITY_NS,
IDENTITY_SPN, ADDRESSING_IDENTITY_PREFIX);
+ static final QName QNAME_IDENTITY_UPN = new QName(ADDRESSING_IDENTITY_NS,
IDENTITY_UPN, ADDRESSING_IDENTITY_PREFIX);
interface Final {
Modified:
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/addressing/AddressingHelper.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/addressing/AddressingHelper.java?rev=1622565&r1=1622564&r2=1622565&view=diff
==============================================================================
---
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/addressing/AddressingHelper.java
(original)
+++
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/addressing/AddressingHelper.java
Thu Sep 4 21:26:26 2014
@@ -19,10 +19,14 @@
package org.apache.axis2.addressing;
+import org.apache.axiom.om.OMElement;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.deployment.DeploymentConstants;
+import org.apache.axis2.description.AxisBinding;
import org.apache.axis2.description.AxisDescription;
+import org.apache.axis2.description.AxisEndpoint;
import org.apache.axis2.description.AxisOperation;
import org.apache.axis2.description.Parameter;
import org.apache.axis2.util.LoggingControl;
@@ -328,5 +332,52 @@ public class AddressingHelper {
}
}
}
- }
+ }
+
+ /**
+ * @param endpoint
+ * The endpoint to check for a
+ * {@link AddressingConstants#ADDRESSING_IDENTITY_PARAMETER}.
Must not be
+ * <code>null</code>
+ * @return The Addressing identity OMElement ({@link
AddressingConstants#QNAME_IDENTITY}) if
+ * such is configured on the specified <code>endpoint</code> or
its <code>binding</code>
+ * , or <code>null</code> if not available. This will normally be
available if the
+ * service was created from a WSDL which contains a WS-Addressing
endpoint reference
+ * with an <wsid:Identity> extension either on the port or
corresponding binding.
+ */
+ public static OMElement getAddressingIdentityParameterValue(AxisEndpoint
endpoint) {
+ OMElement identityElement = (OMElement)
endpoint.getParameterValue(AddressingConstants.ADDRESSING_IDENTITY_PARAMETER);
+
+ //unwrap identity element if wrapped in a parameter element
+ //NB: in revision 1371373 wrapping of parameter value when parsing
parameters from services.xml has been removed
+ if (identityElement != null &&
identityElement.getLocalName().equals(DeploymentConstants.TAG_PARAMETER)) {
+ identityElement = identityElement.getFirstElement();
+ }
+
+ if (identityElement != null) {
+ if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled()) {
+ log.debug(String.format("getAddressingIdentityParameterValue:
%s parameter from AxisEndpoint '%s': %s",
AddressingConstants.ADDRESSING_IDENTITY_PARAMETER,
+ endpoint.getName(), identityElement.toString()));
+ }
+
+ return identityElement;
+ }
+
+ AxisBinding binding = endpoint.getBinding();
+ if (binding != null) {
+ identityElement = (OMElement)
binding.getParameterValue(AddressingConstants.ADDRESSING_IDENTITY_PARAMETER);
+ }
+
+ //unwrap identity element if wrapped in a parameter element
+ if (identityElement != null &&
identityElement.getLocalName().equals(DeploymentConstants.TAG_PARAMETER)) {
+ identityElement = identityElement.getFirstElement();
+ }
+
+ if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled()) {
+ log.debug(String.format("getAddressingIdentityParameterValue: %s
parameter from AxisBinding '%s': %s",
AddressingConstants.ADDRESSING_IDENTITY_PARAMETER,
+ binding.getName(), identityElement == null ? "N/A" :
identityElement.toString()));
+ }
+
+ return identityElement;
+ }
}
Modified:
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/context/MessageContext.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/context/MessageContext.java?rev=1622565&r1=1622564&r2=1622565&view=diff
==============================================================================
---
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/context/MessageContext.java
(original)
+++
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/context/MessageContext.java
Thu Sep 4 21:26:26 2014
@@ -52,6 +52,7 @@ import org.apache.axis2.description.Modu
import org.apache.axis2.description.Parameter;
import org.apache.axis2.description.TransportInDescription;
import org.apache.axis2.description.TransportOutDescription;
+import org.apache.axis2.description.WSDL2Constants;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.engine.AxisError;
import org.apache.axis2.engine.Handler;
@@ -4320,4 +4321,49 @@ public class MessageContext extends Abst
public void setFailureReason(Exception failureReason) {
this.failureReason = failureReason;
}
+
+ /**
+ * @return Identifies and returns the service endpoint for this message
context. The method will
+ * use the following steps to identify the endpoint:
+ * <ul>
+ * <li>If a non-null {@link AxisEndpoint} instance is set under the
+ * {@link WSDL2Constants#ENDPOINT_LOCAL_NAME ENDPOINT_LOCAL_NAME}
message context
+ * property, return it</li>
+ * <li>If a non-null {@link #getAxisService() axisService}
instance is set and it
+ * specifies {@link AxisService#isClientSide() clientSide=true},
retrieve the endpoint
+ * which matches its {@link AxisService#getEndpointName()
enpointName}</li>
+ * <li>else, return <code>null</code></li>
+ * </ul>
+ */
+ public AxisEndpoint findEndpoint() {
+ AxisEndpoint endpoint = (AxisEndpoint)
getProperty(WSDL2Constants.ENDPOINT_LOCAL_NAME);
+
+ final String methodName = "findEnpoint()";
+ if (endpoint != null) {
+ if (log.isDebugEnabled()) {
+ log.debug(String.format("%s:%s - identified endpoint from
property '%s': %s", getLogIDString(), methodName,
WSDL2Constants.ENDPOINT_LOCAL_NAME, endpoint.getName()));
+ }
+
+ return endpoint;
+ }
+
+ if (axisService == null) {
+ if (log.isWarnEnabled()) {
+ log.warn(String.format("%s:%s - no service set, cannot
identify endpoint", getLogIDString(), methodName));
+ }
+
+ return null;
+ }
+
+ if (!axisService.isClientSide()) {
+ if (log.isWarnEnabled()) {
+ log.warn(String.format("%s:%s - no '%s' property set and
serverSide=true, cannot uniquely identify endpoint for service: ",
getLogIDString(), methodName, WSDL2Constants.ENDPOINT_LOCAL_NAME,
axisService.getName()));
+ }
+ return null;
+ }
+
+ //on client-side, the default endpoint name is the one the AxisService
was created with
+ String endpointName = axisService.getEndpointName();
+ return axisService.getEndpoint(endpointName);
+ }
}
Modified:
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/AxisService2WSDL11.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/AxisService2WSDL11.java?rev=1622565&r1=1622564&r2=1622565&view=diff
==============================================================================
---
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/AxisService2WSDL11.java
(original)
+++
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/AxisService2WSDL11.java
Thu Sep 4 21:26:26 2014
@@ -676,7 +676,7 @@ public class AxisService2WSDL11 implemen
WSDLSerializationUtil.addExtensionElement(fac, port,
SOAP_ADDRESS, LOCATION,
(endpointURL == null) ? ""
:
endpointURL, soap);
- generateEPRElement(fac, port,
endpointURL);
+ generateEPRElement(axisEndpoint, fac,
port, endpointURL);
addPolicyAsExtElement(axisEndpoint,
port);
service.addChild(modifyPort(port));
if (isAlreadyAdded(axisBinding,
definition)) {
@@ -726,7 +726,7 @@ public class AxisService2WSDL11 implemen
WSDLSerializationUtil.addExtensionElement(fac, port,
SOAP_ADDRESS, LOCATION,
(endpointURL == null) ? ""
:
endpointURL, soap12);
- generateEPRElement(fac, port,
endpointURL);
+ generateEPRElement(axisEndpoint, fac,
port, endpointURL);
addPolicyAsExtElement(axisEndpoint,
port);
service.addChild(modifyPort(port));
if (isAlreadyAdded(axisBinding,
definition)) {
@@ -1351,27 +1351,61 @@ public class AxisService2WSDL11 implemen
}
}
- /**
- * Generate the Identity element according to the
WS-AddressingAndIdentity if the
- * AddressingConstants.IDENTITY_PARAMETER parameter is set.
- * http://schemas.xmlsoap.org/ws/2006/02/addressingidentity/
- */
-
- private void generateIdentityElement(OMFactory fac,OMElement epr,
Parameter wsaIdParam) {
-
- // Create the Identity element
- OMElement identity =
fac.createOMElement(AddressingConstants.QNAME_IDENTITY);
- OMElement keyInfo =
fac.createOMElement(AddressingConstants.QNAME_IDENTITY_KEY_INFO);
- OMElement x509Data =
fac.createOMElement(AddressingConstants.QNAME_IDENTITY_X509_DATA);
- OMElement x509cert =
fac.createOMElement(AddressingConstants.QNAME_IDENTITY_X509_CERT);
- x509cert.setText((String)wsaIdParam.getValue());
-
- x509Data.addChild(x509cert);
- keyInfo.addChild(x509Data);
- identity.addChild(keyInfo);
-
- epr.addChild(identity);
-
+ /**
+ * Generate a <wsid:Identity> element according to the <a
+ *
href="http://www.oasis-open.org/committees/download.php/29516/ws-addressingandidentity.doc"
+ * >WS-AddressingAndIdentity specification</a> and add it as a child of
the given
+ * <code>epr</code> <wsa:EndpointReference> element.
+ * <p>
+ * If none of the <code>identityParameter</code> and
<code>x509CertIdentityParameter</code>
+ * configures a valid value, this method will skip creating and adding an
identity element.
+ * </p>
+ *
+ * @param fac
+ * A factory to use for creating OMElements.
+ * @param epr
+ * The endpoint reference element to add the generated identity
element to. Must not
+ * be <code>null</code>.
+ * @param identity
+ * An optional <wsid:Identity> OMElement to clone and
use, instead of
+ * generating a new one.
+ * @param x509CertIdentityParameter
+ * An optional parameter that may contain a
<ds:X509Certificate> String literal
+ * value to set as key info in the created identity element.
+ */
+ private void generateIdentityElement(OMFactory fac, OMElement epr,
OMElement identity, Parameter x509CertIdentityParameter) {
+ if (identity != null) {
+ identity = identity.cloneOMElement();
+ epr.addChild(identity);
+ }
+
+ if (x509CertIdentityParameter != null &&
x509CertIdentityParameter.getValue() != null) {
+ if (identity == null) {
+ identity =
fac.createOMElement(AddressingConstants.QNAME_IDENTITY);
+ epr.addChild(identity);
+ }
+
+ OMElement keyInfo =
identity.getFirstChildWithName(AddressingConstants.QNAME_IDENTITY_KEY_INFO);
+ if (keyInfo == null) {
+ keyInfo =
fac.createOMElement(AddressingConstants.QNAME_IDENTITY_KEY_INFO);
+ identity.addChild(keyInfo);
+ }
+
+ OMElement x509Data =
keyInfo.getFirstChildWithName(AddressingConstants.QNAME_IDENTITY_X509_DATA);
+ if (x509Data == null) {
+ x509Data =
fac.createOMElement(AddressingConstants.QNAME_IDENTITY_X509_DATA);
+ keyInfo.addChild(x509Data);
+ }
+
+ OMElement x509cert =
x509Data.getFirstChildWithName(AddressingConstants.QNAME_IDENTITY_X509_CERT);
+ if (x509cert == null) {
+ x509cert =
fac.createOMElement(AddressingConstants.QNAME_IDENTITY_X509_CERT);
+ x509Data.addChild(x509cert);
+ }
+
+ String x509CertValue = (String)
x509CertIdentityParameter.getValue();
+ x509cert.setText(x509CertValue);
+ }
}
@@ -1384,12 +1418,15 @@ public class AxisService2WSDL11 implemen
* </wsa:EndpointReference>
*
*/
- private void generateEPRElement(OMFactory fac, OMElement port, String
endpointURL){
+ private void generateEPRElement(AxisEndpoint endpoint, OMFactory fac,
OMElement port, String endpointURL){
+ //an optional String parameter that contains x509 certificate
information
+ Parameter x509CertIdentityParameter =
axisService.getParameter(AddressingConstants.IDENTITY_PARAMETER);
- Parameter parameter =
axisService.getParameter(AddressingConstants.IDENTITY_PARAMETER);
-
- // If the parameter is not set, return
- if (parameter == null || parameter.getValue() == null) {
+ //an optional OMElement parameter that represents an
<wsid:Identity> element
+ OMElement identityElement =
AddressingHelper.getAddressingIdentityParameterValue(endpoint);
+
+ if ((x509CertIdentityParameter == null ||
x509CertIdentityParameter.getValue() == null) && identityElement == null) {
+ //none of these is configured, for backward compatibility do
not generate anything and return
return;
}
@@ -1401,7 +1438,7 @@ public class AxisService2WSDL11 implemen
wsaEpr.addChild(address);
// This will generate the identity element if the service parameter
is set
- generateIdentityElement(fac, wsaEpr, parameter);
+ generateIdentityElement(fac, wsaEpr, identityElement,
x509CertIdentityParameter);
port.addChild(wsaEpr);
Modified:
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java?rev=1622565&r1=1622564&r2=1622565&view=diff
==============================================================================
---
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java
(original)
+++
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java
Thu Sep 4 21:26:26 2014
@@ -564,6 +564,12 @@ public class WSDL11ToAxisServiceBuilder
if(referenceParameters != null){
axisEndpoint.addParameter(AddressingConstants.REFERENCE_PARAMETER_PARAMETER,
new ArrayList(referenceParameters.values()));
}
+ for (OMElement extensibleElement :
epr.getExtensibleElements()) {
+ if
(AddressingConstants.QNAME_IDENTITY.equals(extensibleElement.getQName())) {
+
axisEndpoint.addParameter(AddressingConstants.ADDRESSING_IDENTITY_PARAMETER,
extensibleElement.cloneOMElement());
+ break;
+ }
+ }
} catch (Exception e) {
if(log.isDebugEnabled()){
log.debug("Exception encountered
processing embedded wsa:EndpointReference", e);