You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2008/04/15 14:35:21 UTC
svn commit: r648224 - in
/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2:
description/ util/
Author: dims
Date: Tue Apr 15 05:35:18 2008
New Revision: 648224
URL: http://svn.apache.org/viewvc?rev=648224&view=rev
Log:
Fix for AXIS2-3455 - ?wsdl2 does not show engaged security policies
Modified:
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisBinding.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisBindingMessage.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisBindingOperation.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisEndpoint.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2WSDL20.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/AxisPolicyLocator.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/WSDLSerializationUtil.java
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisBinding.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisBinding.java?rev=648224&r1=648223&r2=648224&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisBinding.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisBinding.java Tue Apr 15 05:35:18 2008
@@ -224,6 +224,8 @@
nameSpaceMap, serviceName));
}
WSDLSerializationUtil.addWSDLDocumentationElement(this, bindingElement, omFactory, wsdl);
+ WSDLSerializationUtil.addPoliciesAsExtensibleElement(this,
+ bindingElement);
return bindingElement;
}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisBindingMessage.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisBindingMessage.java?rev=648224&r1=648223&r2=648224&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisBindingMessage.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisBindingMessage.java Tue Apr 15 05:35:18 2008
@@ -209,6 +209,8 @@
}
WSDLSerializationUtil.addWSDLDocumentationElement(this,
bindingMessageElement, omFactory, wsdl);
+ WSDLSerializationUtil.addPoliciesAsExtensibleElement(this,
+ bindingMessageElement);
return bindingMessageElement;
}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisBindingOperation.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisBindingOperation.java?rev=648224&r1=648223&r2=648224&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisBindingOperation.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisBindingOperation.java Tue Apr 15 05:35:18 2008
@@ -228,7 +228,7 @@
WSDL2Constants.ATTRIBUTE_QUERY_PARAMETER_SEPERATOR, whttp,
property));
}
-
+
// Add the input element
AxisBindingMessage inMessage = (AxisBindingMessage) this
.getChild(WSDLConstants.WSDL_MESSAGE_DIRECTION_IN);
@@ -258,6 +258,8 @@
}
WSDLSerializationUtil.addWSDLDocumentationElement(this,
bindingOpElement, omFactory, wsdl);
+ WSDLSerializationUtil.addPoliciesAsExtensibleElement(this,
+ bindingOpElement);
return bindingOpElement;
}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisEndpoint.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisEndpoint.java?rev=648224&r1=648223&r2=648224&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisEndpoint.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisEndpoint.java Tue Apr 15 05:35:18 2008
@@ -156,6 +156,8 @@
}
WSDLSerializationUtil.addWSDLDocumentationElement(this,
endpointElement, omFactory, wsdl);
+ WSDLSerializationUtil.addPoliciesAsExtensibleElement(this,
+ endpointElement);
return endpointElement;
}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2WSDL20.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2WSDL20.java?rev=648224&r1=648223&r2=648224&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2WSDL20.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2WSDL20.java Tue Apr 15 05:35:18 2008
@@ -31,10 +31,17 @@
import org.apache.axis2.addressing.AddressingConstants;
import org.apache.axis2.addressing.AddressingHelper;
import org.apache.axis2.description.java2wsdl.Java2WSDLConstants;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.util.ExternalPolicySerializer;
import org.apache.axis2.util.JavaUtils;
+import org.apache.axis2.util.PolicyLocator;
+import org.apache.axis2.util.PolicyUtil;
import org.apache.axis2.util.WSDLSerializationUtil;
import org.apache.axis2.util.XMLUtils;
import org.apache.axis2.wsdl.WSDLConstants;
+import org.apache.neethi.Policy;
+import org.apache.neethi.PolicyComponent;
+import org.apache.neethi.PolicyReference;
import org.apache.ws.commons.schema.XmlSchema;
import org.apache.ws.commons.schema.XmlSchemaComplexType;
import org.apache.ws.commons.schema.XmlSchemaElement;
@@ -45,15 +52,19 @@
import org.apache.ws.commons.schema.XmlSchemaType;
import javax.xml.namespace.QName;
+import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLStreamException;
import java.io.ByteArrayInputStream;
import java.io.StringWriter;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -64,6 +75,9 @@
private String[] eprs = null;
private OMNamespace wsaw;
+ private HashMap policiesInDescription = new HashMap();
+ private ExternalPolicySerializer filter = null;
+
public AxisService2WSDL20(AxisService service) {
this.axisService = service;
this.serviceName = service.getName();
@@ -84,6 +98,16 @@
Map nameSpacesMap = axisService.getNamespaceMap();
OMFactory omFactory = OMAbstractFactory.getOMFactory();
OMNamespace wsdl;
+
+ //
+ filter = new ExternalPolicySerializer();
+ AxisConfiguration axisConfiguration = axisService
+ .getAxisConfiguration();
+ if (axisConfiguration != null) {
+ filter.setAssertionsToFilter(axisConfiguration
+ .getLocalPolicyAssertions());
+ }
+ //
if (nameSpacesMap != null && nameSpacesMap.containsValue(WSDL2Constants.WSDL_NAMESPACE)) {
wsdl = omFactory
@@ -275,18 +299,20 @@
}
if (!endpointAlreadyAdded) {
+// addPolicyAsExtensibleElement(axisEndpoint, endpointElement);
serviceElement.addChild(endpointElement);
}
}
Iterator iter = bindings.iterator();
while (iter.hasNext()) {
AxisBinding binding = (AxisBinding) iter.next();
+ OMElement bindingElement = binding.toWSDL20(wsdl, tns, wsoap, whttp,
+ interfaceName,
+ axisService.getNamespaceMap(),
+ AddressingHelper.getAddressingRequirementParemeterValue(axisService),
+ serviceName,wsaw);
descriptionElement
- .addChild(binding.toWSDL20(wsdl, tns, wsoap, whttp,
- interfaceName,
- axisService.getNamespaceMap(),
- AddressingHelper.getAddressingRequirementParemeterValue(axisService),
- serviceName,wsaw));
+ .addChild(bindingElement);
}
descriptionElement.addChild(serviceElement);
@@ -313,6 +339,9 @@
disableSOAP12, eprs,
serviceName));
}
+
+ ArrayList policies = new ArrayList(policiesInDescription.values());
+ addPoliciesToDescriptionElement(policies, descriptionElement);
return descriptionElement;
}
@@ -326,14 +355,19 @@
* @param fac The active OMFactory
* @param interfaceName The name of the interface
* @return The generated interface element
+ * @throws FactoryConfigurationError
+ * @throws XMLStreamException
*/
private OMElement getInterfaceElement(OMNamespace wsdl, OMNamespace tns, OMNamespace wsdlx,
OMNamespace wrpc, OMFactory fac, String interfaceName)
- throws URISyntaxException, AxisFault {
+ throws URISyntaxException, AxisFault, XMLStreamException, FactoryConfigurationError {
OMElement interfaceElement = fac.createOMElement(WSDL2Constants.INTERFACE_LOCAL_NAME, wsdl);
interfaceElement.addAttribute(fac.createOMAttribute(WSDL2Constants.ATTRIBUTE_NAME, null,
interfaceName));
+
+ addPolicyAsExtensibleElement(axisService, interfaceElement);
+
Iterator iterator = axisService.getOperations();
ArrayList interfaceOperations = new ArrayList();
ArrayList interfaceFaults = new ArrayList();
@@ -402,13 +436,15 @@
* @param tns the target namespace
* @param wsdlx the WSDL extentions namespace (WSDL 2.0)
* @return the generated <operation> element
+ * @throws FactoryConfigurationError
+ * @throws XMLStreamException
*/
public OMElement generateInterfaceOperationElement(AxisOperation axisOperation,
OMNamespace wsdl,
OMNamespace tns,
OMNamespace wsdlx,
OMNamespace wrpc) throws
- URISyntaxException, AxisFault {
+ URISyntaxException, AxisFault, XMLStreamException, FactoryConfigurationError {
OMFactory omFactory = OMAbstractFactory.getOMFactory();
OMElement axisOperationElement =
omFactory.createOMElement(WSDL2Constants.OPERATION_LOCAL_NAME, wsdl);
@@ -418,6 +454,8 @@
null,
axisOperation
.getName().getLocalPart()));
+ addPolicyAsExtensibleElement(axisOperation, axisOperationElement);
+
URI[] opStyle = (URI[]) axisOperation.getParameterValue(WSDL2Constants.OPERATION_STYLE);
if (opStyle == null) {
opStyle = checkStyle(axisOperation);
@@ -699,4 +737,78 @@
}
return in + out + inOut;
}
+
+ private void addPolicyAsExtensibleElement(AxisDescription axisDescription,
+ OMElement descriptionElement) throws XMLStreamException,
+ FactoryConfigurationError, AxisFault {
+ PolicySubject policySubject = axisDescription.getPolicySubject();
+ Collection attachPolicyComponents = policySubject
+ .getAttachedPolicyComponents();
+
+ for (Iterator iterator = attachPolicyComponents.iterator(); iterator
+ .hasNext();) {
+ Object policyElement = iterator.next();
+
+ if (policyElement instanceof Policy) {
+ PolicyReference policyReference = PolicyUtil
+ .createPolicyReference((Policy) policyElement);
+ OMElement policyRefElement = PolicyUtil
+ .getPolicyComponentAsOMElement(
+ (PolicyComponent) policyReference, filter);
+
+ OMNode firstChildElem = descriptionElement.getFirstElement();
+ if (firstChildElem == null) {
+ descriptionElement.addChild(policyRefElement);
+ } else {
+ firstChildElem.insertSiblingBefore(policyRefElement);
+ }
+ String key = ((PolicyReference) policyReference).getURI();
+ if (key.startsWith("#")) {
+ key = key.substring(key.indexOf("#") + 1);
+ }
+ policiesInDescription.put(key, (Policy) policyElement);
+
+ } else if (policyElement instanceof PolicyReference) {
+ OMElement child = PolicyUtil
+ .getPolicyComponentAsOMElement((PolicyComponent) policyElement);
+ OMElement firstChildElem = descriptionElement.getFirstElement();
+
+ if (firstChildElem == null) {
+ descriptionElement.addChild(child);
+ } else {
+ firstChildElem.insertSiblingBefore(child);
+ }
+
+ String key = ((PolicyReference) policyElement).getURI();
+ if (key.startsWith("#")) {
+ key = key.substring(key.indexOf("#") + 1);
+ }
+
+ PolicyLocator locator = new PolicyLocator(axisService);
+ Policy p = locator.lookup(key);
+
+ if (p == null) {
+ throw new AxisFault("Policy not found for uri : " + key);
+ }
+ policiesInDescription.put(key, p);
+ }
+ }
+ }
+
+ private void addPoliciesToDescriptionElement(List policies,
+ OMElement descriptionElement) throws XMLStreamException,
+ FactoryConfigurationError {
+
+ for (int i = 0; i < policies.size(); i++) {
+ Policy policy = (Policy) policies.get(i);
+ OMElement policyElement = PolicyUtil.getPolicyComponentAsOMElement(
+ policy, filter);
+ OMNode firstChild = descriptionElement.getFirstOMChild();
+ if (firstChild != null) {
+ firstChild.insertSiblingBefore(policyElement);
+ } else {
+ descriptionElement.addChild(policyElement);
+ }
+ }
+ }
}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/AxisPolicyLocator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/AxisPolicyLocator.java?rev=648224&r1=648223&r2=648224&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/AxisPolicyLocator.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/AxisPolicyLocator.java Tue Apr 15 05:35:18 2008
@@ -29,8 +29,10 @@
import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.AxisServiceGroup;
import org.apache.axis2.description.PolicyInclude;
+import org.apache.axis2.description.PolicySubject;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.neethi.Policy;
+import org.apache.neethi.PolicyComponent;
import org.apache.neethi.PolicyRegistry;
public class AxisPolicyLocator implements PolicyRegistry {
@@ -58,13 +60,28 @@
return null;
}
- PolicyInclude policyInclude = subject.getPolicyInclude();
- PolicyRegistry policyRegistry = policyInclude.getPolicyRegistry();
- Policy policy = policyRegistry.lookup(key);
+ Policy policy = null;
- if (policy != null) {
- return policy;
- }
+ PolicySubject policySubject = subject.getPolicySubject();
+ PolicyComponent attachedPolicyComponent = policySubject
+ .getAttachedPolicyComponent(key);
+
+ if (attachedPolicyComponent != null
+ && attachedPolicyComponent instanceof Policy) {
+ policy = (Policy) attachedPolicyComponent;
+ if (policy != null) {
+ return policy;
+ }
+ }
+
+
+ if (subject instanceof AxisService) {
+ policy = ((AxisService) subject).lookupPolicy(key);
+ if (policy != null) {
+ return policy;
+ }
+ }
+
short type = getType(subject);
@@ -121,6 +138,10 @@
return ((AxisBinding) thisLevel).getAxisEndpoint();
case AXIS_ENDPOINT:
return ((AxisEndpoint) thisLevel).getAxisService();
+ case AXIS_MESSAGE:
+ return ((AxisMessage) thisLevel).getAxisOperation();
+ case AXIS_OPERATION:
+ return ((AxisOperation) thisLevel).getAxisService();
case AXIS_SERVICE:
return ((AxisService) thisLevel).getAxisServiceGroup();
case AXIS_SERVICE_GROUP:
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/WSDLSerializationUtil.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/WSDLSerializationUtil.java?rev=648224&r1=648223&r2=648224&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/WSDLSerializationUtil.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/WSDLSerializationUtil.java Tue Apr 15 05:35:18 2008
@@ -29,15 +29,26 @@
import org.apache.axis2.description.AxisMessage;
import org.apache.axis2.description.AxisOperation;
import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.PolicySubject;
import org.apache.axis2.description.WSDL2Constants;
import org.apache.axis2.description.java2wsdl.Java2WSDLConstants;
+import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.namespace.Constants;
import org.apache.axis2.wsdl.HTTPHeaderMessage;
import org.apache.axis2.wsdl.SOAPHeaderMessage;
import org.apache.axis2.wsdl.SOAPModuleMessage;
+import org.apache.neethi.Policy;
+import org.apache.neethi.PolicyComponent;
+import org.apache.neethi.PolicyReference;
+
+import sun.security.krb5.internal.crypto.Des;
import javax.xml.namespace.QName;
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLStreamException;
+
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -484,4 +495,73 @@
omElement.addChild(documentation);
}
}
+
+ public static void addPoliciesAsExtensibleElement(
+ AxisDescription description, OMElement descriptionElement) {
+ PolicySubject policySubject = description.getPolicySubject();
+ Collection attachPolicyComponents = policySubject
+ .getAttachedPolicyComponents();
+ ArrayList policies = new ArrayList();
+
+ for (Iterator iterator = attachPolicyComponents.iterator(); iterator
+ .hasNext();) {
+ Object policyElement = iterator.next();
+
+ if (policyElement instanceof Policy) {
+ policies.add(policyElement);
+
+ } else if (policyElement instanceof PolicyReference) {
+ String key = ((PolicyReference) policyElement).getURI();
+
+ if (key.startsWith("#")) {
+ key = key.substring(key.indexOf("#") + 1);
+ }
+ AxisService service = getAxisService(description);
+ PolicyLocator locator = new PolicyLocator(service);
+ Policy p = locator.lookup(key);
+
+ if (p == null) {
+ throw new RuntimeException("Policy not found for uri : "
+ + key);
+ }
+ policies.add(p);
+ }
+ }
+
+ ExternalPolicySerializer filter = null;
+ if (!policies.isEmpty()) {
+ filter = new ExternalPolicySerializer();
+ AxisConfiguration axisConfiguration = description
+ .getAxisConfiguration();
+ if (axisConfiguration != null) {
+ filter.setAssertionsToFilter(axisConfiguration
+ .getLocalPolicyAssertions());
+ }
+ }
+
+ for (Iterator iterator = policies.iterator(); iterator.hasNext();) {
+ Policy policy = (Policy) iterator.next();
+ OMElement policyElement;
+ try {
+ policyElement = PolicyUtil.getPolicyComponentAsOMElement(
+ policy, filter);
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ OMNode firstChild = descriptionElement.getFirstOMChild();
+ if (firstChild != null) {
+ firstChild.insertSiblingBefore(policyElement);
+ } else {
+ descriptionElement.addChild(policyElement);
+ }
+ }
+ }
+
+ private static AxisService getAxisService(AxisDescription description) {
+ if (description == null || description instanceof AxisService) {
+ return (AxisService) description;
+ } else {
+ return getAxisService(description);
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org