diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2008-11-19 05:27:58 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2008-11-19 05:27:58 +0000 |
commit | 5f3869c451e46aadc943d00087d6847877dd1c50 (patch) | |
tree | e22baaff1fb9ea42606b7d04af52e032e3bc03bc /java/sca/modules/binding-ws-axis2/src/main | |
parent | 60744a36aae604ac3c4499ed54f1082ab8f5947d (diff) |
Merging the 1.x delta on top of the equinox based modules
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@718858 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/binding-ws-axis2/src/main')
11 files changed, 197 insertions, 132 deletions
diff --git a/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingInvoker.java b/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingInvoker.java index b73725c2e2..cfa2b2678f 100644 --- a/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingInvoker.java +++ b/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingInvoker.java @@ -21,6 +21,7 @@ package org.apache.tuscany.sca.binding.ws.axis2; import java.security.AccessController; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; +import java.util.ArrayList; import java.util.List; import javax.xml.namespace.QName; @@ -39,7 +40,10 @@ import org.apache.axis2.client.Options; import org.apache.axis2.context.MessageContext; import org.apache.axis2.transport.http.HTTPConstants; import org.apache.tuscany.sca.binding.ws.WebServiceBinding; -import org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.basic.Axis2BasicAuthenticationReferenceBindingConfigurator; +import org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.token.Axis2TokenAuthenticationPolicy; +import org.apache.tuscany.sca.binding.ws.axis2.policy.configurator.Axis2BindingBasicAuthenticationConfigurator; +import org.apache.tuscany.sca.binding.ws.axis2.policy.configurator.Axis2BindingHeaderConfigurator; +import org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2HeaderPolicy; import org.apache.tuscany.sca.interfacedef.util.FaultException; import org.apache.tuscany.sca.invocation.DataExchangeSemantics; import org.apache.tuscany.sca.invocation.Invoker; @@ -73,7 +77,10 @@ public class Axis2BindingInvoker implements Invoker, DataExchangeSemantics { private SOAPFactory soapFactory; private List<PolicyHandler> policyHandlerList = null; private WebServiceBinding wsBinding; + private BasicAuthenticationPolicy basicAuthenticationPolicy = null; + private Axis2TokenAuthenticationPolicy axis2TokenAuthenticationPolicy = null; + private List<Axis2HeaderPolicy> axis2HeaderPolicies = new ArrayList<Axis2HeaderPolicy>(); public Axis2BindingInvoker(Axis2ServiceClient serviceClient, QName wsdlOperationName, @@ -95,7 +102,11 @@ public class Axis2BindingInvoker implements Invoker, DataExchangeSemantics { for (Object p : ps.getPolicies()) { if (BasicAuthenticationPolicy.class.isInstance(p)) { basicAuthenticationPolicy = (BasicAuthenticationPolicy)p; - } else { + } else if (Axis2TokenAuthenticationPolicy.class.isInstance(p)) { + axis2TokenAuthenticationPolicy = (Axis2TokenAuthenticationPolicy)p; + } else if (Axis2HeaderPolicy.class.isInstance(p)) { + axis2HeaderPolicies.add((Axis2HeaderPolicy)p); + }else { // etc. check for other types of policy being present } } @@ -137,8 +148,17 @@ public class Axis2BindingInvoker implements Invoker, DataExchangeSemantics { policyHandler.beforeInvoke(msg, requestMC, operationClient); } + // set policy specified headers + for (Axis2HeaderPolicy policy : axis2HeaderPolicies){ + Axis2BindingHeaderConfigurator.setHeader(requestMC, msg, policy.getHeaderName()); + } + if (basicAuthenticationPolicy != null) { - Axis2BasicAuthenticationReferenceBindingConfigurator.setOperationOptions(operationClient, msg, basicAuthenticationPolicy); + Axis2BindingBasicAuthenticationConfigurator.setOperationOptions(operationClient, msg, basicAuthenticationPolicy); + } + + if (axis2TokenAuthenticationPolicy != null) { + Axis2BindingHeaderConfigurator.setHeader(requestMC, msg, axis2TokenAuthenticationPolicy.getTokenName()); } // Allow privileged access to read properties. Requires PropertiesPermission read in @@ -237,6 +257,11 @@ public class Axis2BindingInvoker implements Invoker, DataExchangeSemantics { sh.addChild(epr); requestMC.setFrom(fromEPR); } + + // Set any message headers required by policy + // Get the header from the tuscany message + // If its not already an OM convert it to OM + // add it to the envelope header // if target endpoint was not specified when this invoker was created, // use dynamically specified target endpoint passed in on this call diff --git a/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceClient.java b/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceClient.java index 438e989d85..0d3916019f 100644 --- a/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceClient.java +++ b/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceClient.java @@ -69,12 +69,12 @@ import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; import org.apache.commons.httpclient.params.HttpConnectionManagerParams; import org.apache.tuscany.sca.assembly.AbstractContract; import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.axis2.policy.configuration.Axis2ConfigParamPolicy; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.MessageFactory; import org.apache.tuscany.sca.policy.PolicySet; import org.apache.tuscany.sca.policy.PolicySetAttachPoint; -import org.apache.tuscany.sca.policy.security.ws.Axis2ConfigParamPolicy; import org.apache.tuscany.sca.policy.util.PolicyHandler; import org.apache.tuscany.sca.policy.util.PolicyHandlerTuple; import org.apache.tuscany.sca.policy.util.PolicyHandlerUtils; diff --git a/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java b/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java index 50164d4114..7c7491f331 100644 --- a/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java +++ b/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java @@ -50,6 +50,7 @@ import org.apache.axiom.om.OMFactory; import org.apache.axiom.soap.SOAPHeader; import org.apache.axis2.AxisFault; import org.apache.axis2.Constants; +import org.apache.axis2.Constants.Configuration; import org.apache.axis2.addressing.AddressingConstants; import org.apache.axis2.context.ConfigurationContext; import org.apache.axis2.context.MessageContext; @@ -73,7 +74,12 @@ import org.apache.tuscany.sca.assembly.AbstractContract; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.binding.ws.WebServiceBinding; import org.apache.tuscany.sca.binding.ws.axis2.Axis2ServiceClient.URIResolverImpl; -import org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.basic.Axis2BasicAuthenticationServiceBindingConfigurator; +import org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.token.Axis2TokenAuthenticationPolicy; +import org.apache.tuscany.sca.binding.ws.axis2.policy.configuration.Axis2ConfigParamPolicy; +import org.apache.tuscany.sca.binding.ws.axis2.policy.configurator.Axis2BindingBasicAuthenticationConfigurator; +import org.apache.tuscany.sca.binding.ws.axis2.policy.configurator.Axis2BindingHeaderConfigurator; +import org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2HeaderPolicy; +import org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2SOAPHeaderString; import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl; import org.apache.tuscany.sca.host.http.ServletHost; import org.apache.tuscany.sca.interfacedef.Interface; @@ -85,7 +91,6 @@ import org.apache.tuscany.sca.invocation.MessageFactory; import org.apache.tuscany.sca.policy.PolicySet; import org.apache.tuscany.sca.policy.PolicySetAttachPoint; import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPolicy; -import org.apache.tuscany.sca.policy.security.ws.Axis2ConfigParamPolicy; import org.apache.tuscany.sca.policy.util.PolicyHandler; import org.apache.tuscany.sca.policy.util.PolicyHandlerTuple; import org.apache.tuscany.sca.policy.util.PolicyHandlerUtils; @@ -124,7 +129,10 @@ public class Axis2ServiceProvider { private List<PolicyHandlerTuple> policyHandlerClassnames = null; private List<PolicyHandler> policyHandlerList = new ArrayList<PolicyHandler>(); private Map<String, Port> urlMap = new HashMap<String, Port>(); + private BasicAuthenticationPolicy basicAuthenticationPolicy = null; + private Axis2TokenAuthenticationPolicy axis2TokenAuthenticationPolicy = null; + private List<Axis2HeaderPolicy> axis2HeaderPolicies = new ArrayList<Axis2HeaderPolicy>(); public static final QName QNAME_WSA_ADDRESS = new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.EPR_ADDRESS); @@ -187,7 +195,13 @@ public class Axis2ServiceProvider { } configContext.setContextRoot(servletHost.getContextPath()); - + + // Enable MTOM if the policy intent is specified. + if (AxisPolicyHelper.isIntentRequired(wsBinding, AxisPolicyHelper.MTOM_INTENT)) { + configContext.getAxisConfiguration().getParameter(Configuration.ENABLE_MTOM).setLocked(false); + configContext.getAxisConfiguration().getParameter(Configuration.ENABLE_MTOM).setValue("true"); + } + // Update port addresses with runtime information, and create a // map from endpoint URIs to WSDL ports that eliminates duplicate // ports for the same endpoint. @@ -205,6 +219,10 @@ public class Axis2ServiceProvider { for (Object p : ps.getPolicies()) { if (BasicAuthenticationPolicy.class.isInstance(p)) { basicAuthenticationPolicy = (BasicAuthenticationPolicy)p; + } else if (Axis2TokenAuthenticationPolicy.class.isInstance(p)) { + axis2TokenAuthenticationPolicy = (Axis2TokenAuthenticationPolicy)p; + } else if (Axis2HeaderPolicy.class.isInstance(p)) { + axis2HeaderPolicies.add((Axis2HeaderPolicy)p); } else { // etc. check for other types of policy being present } @@ -295,7 +313,7 @@ public class Axis2ServiceProvider { Axis2ServiceServlet servlet = null; for (String endpointURL : urlMap.keySet()) { - if (endpointURL.startsWith("http://") || endpointURL.startsWith("/")) { + if (endpointURL.startsWith("http://") || endpointURL.startsWith("https://") || endpointURL.startsWith("/")) { if (servlet == null) { servlet = new Axis2ServiceServlet(); servlet.init(configContext); @@ -638,6 +656,11 @@ public class Axis2ServiceProvider { String callbackAddress = null; String callbackID = null; Object conversationID = null; + + // create a message object and set the args as its body + Message msg = messageFactory.createMessage(); + msg.setBody(args); + msg.setOperation(op); //FIXME: can we use the Axis2 addressing support for this? SOAPHeader header = inMC.getEnvelope().getHeader(); @@ -666,12 +689,20 @@ public class Axis2ServiceProvider { } } } + + // get policy specified headers + for (Axis2HeaderPolicy policy : axis2HeaderPolicies){ + //Axis2BindingHeaderConfigurator.getHeader(inMC, msg, policy.getHeaderName()); + } + + if (axis2TokenAuthenticationPolicy != null) { + Axis2SOAPHeaderString tokenHeader = new Axis2SOAPHeaderString(); + Axis2BindingHeaderConfigurator.getHeader(inMC, + msg, + axis2TokenAuthenticationPolicy.getTokenName(), + tokenHeader); + } } - - // create a message object and set the args as its body - Message msg = messageFactory.createMessage(); - msg.setBody(args); - msg.setOperation(op); //fill message with QoS context info fillQoSContext(msg, inMC); @@ -703,7 +734,7 @@ public class Axis2ServiceProvider { } if (basicAuthenticationPolicy != null) { - Axis2BasicAuthenticationServiceBindingConfigurator.parseHTTPHeader(inMC, msg, basicAuthenticationPolicy); + Axis2BindingBasicAuthenticationConfigurator.parseHTTPHeader(inMC, msg, basicAuthenticationPolicy); } // find the runtime wire and invoke it with the message @@ -782,7 +813,7 @@ public class Axis2ServiceProvider { WSSecurityEngineResult securityResult = (WSSecurityEngineResult)wshr.getResults().elementAt(count2); if ( securityResult.get("principal") != null ) { - message.getQoSContext().put(Message.QOS_CTX_SECURITY_PRINCIPAL, securityResult.get("principal")); + message.getHeaders().add(securityResult.get("principal")); } } } diff --git a/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyAxisConfigurator.java b/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyAxisConfigurator.java index 42441f3598..bd154dbc67 100644 --- a/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyAxisConfigurator.java +++ b/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyAxisConfigurator.java @@ -52,7 +52,7 @@ import org.apache.axis2.util.Loader; public class TuscanyAxisConfigurator extends URLBasedAxisConfigurator implements AxisConfigurator { /* these two fields are part of a temporary fix to solve problems that Maven has with including - * rampart-1.3.mar into the classpath and also at the time of Release 1.0 rampart-1.3.mar seems + * rampart-1.4.mar into the classpath and also at the time of Release 1.0 rampart-1.4.mar seems * to pull in a SNAPSHOT version of rampart-project pom. Hence rampart.mar has been excluded * as a Maven dependency and has been packed with this module */ @@ -61,7 +61,7 @@ public class TuscanyAxisConfigurator extends URLBasedAxisConfigurator implements getResource("/org/apache/tuscany/sca/binding/ws/axis2/engine/config/axis2.xml"); private URL axis2_repository = null; private URL rampart_mar_url = - getResource("/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/rampart-1.3.mar"); + getResource("/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/rampart-1.4.mar"); /************** end of fix *************************************************************/ private boolean isRampartRequired; @@ -157,8 +157,8 @@ public class TuscanyAxisConfigurator extends URLBasedAxisConfigurator implements module.setParent(axisConfig); //String moduleFile = fileUrl.substring(0, fileUrl.indexOf(".mar")); if (module.getName() == null) { - module.setName(org.apache.axis2.util.Utils.getModuleName("rampart-1.3")); - module.setVersion(org.apache.axis2.util.Utils.getModuleVersion("rampart-1.3")); + module.setName(org.apache.axis2.util.Utils.getModuleName("rampart-1.4")); + module.setVersion(org.apache.axis2.util.Utils.getModuleVersion("rampart-1.4")); } populateModule(module, rampart_mar_url); module.setFileName(rampart_mar_url); diff --git a/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationServiceBindingConfigurator.java b/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationServiceBindingConfigurator.java deleted file mode 100644 index 6d311faec5..0000000000 --- a/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationServiceBindingConfigurator.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.basic; - -import java.security.Principal; -import java.util.Map; - -import org.apache.axiom.om.util.Base64; -import org.apache.axis2.AxisFault; -import org.apache.axis2.client.OperationClient; -import org.apache.axis2.client.ServiceClient; -import org.apache.axis2.context.ConfigurationContext; -import org.apache.axis2.context.MessageContext; -import org.apache.axis2.description.Parameter; -import org.apache.tuscany.sca.invocation.Message; -import org.apache.tuscany.sca.policy.PolicySet; -import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPolicy; -import org.apache.tuscany.sca.policy.util.PolicyHandler; - -/** - * Deal with basic authentication configuration at the service - * - * @version $Rev$ $Date$ - */ -public class Axis2BasicAuthenticationServiceBindingConfigurator { - - public static void parseHTTPHeader(MessageContext messageContext, Message msg, BasicAuthenticationPolicy policy) { - - Map httpHeaderProperties = (Map)messageContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); - - String basicAuthString = (String)httpHeaderProperties.get("Authorization"); - String decodedBasicAuthString = null; - String username = null; - String password = null; - - if (basicAuthString != null) { - basicAuthString = basicAuthString.trim(); - - if (basicAuthString.startsWith("Basic ")) { - decodedBasicAuthString = new String(Base64.decode(basicAuthString.substring(6))); - } - - int collonIndex = decodedBasicAuthString.indexOf(':'); - - if (collonIndex == -1){ - username = decodedBasicAuthString; - } else { - username = decodedBasicAuthString.substring(0, collonIndex); - password = decodedBasicAuthString.substring(collonIndex + 1); - } - } - - // set the security context. - msg.getQoSContext().put(BasicAuthenticationPolicy.BASIC_AUTHENTICATION_USERNAME, - username); - msg.getQoSContext().put(BasicAuthenticationPolicy.BASIC_AUTHENTICATION_PASSWORD, - password); - - // Set the http headers - // This is just an experiment, looking at the alternatives to extracting - // username and password in the binding. With HTTP headers in the message it - // could be deferred to the interceptor. Asymetric though when compared with the - // reference support. - // how to defined the scheme for message headers? - msg.getHeader().put("httpheaders", httpHeaderProperties); - } - - -} diff --git a/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationReferenceBindingConfigurator.java b/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configurator/Axis2BindingBasicAuthenticationConfigurator.java index 2bc6bff3c7..4c18c89353 100644 --- a/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationReferenceBindingConfigurator.java +++ b/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configurator/Axis2BindingBasicAuthenticationConfigurator.java @@ -17,25 +17,24 @@ * under the License. */ -package org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.basic; +package org.apache.tuscany.sca.binding.ws.axis2.policy.configurator; -import java.security.Principal; import java.util.ArrayList; import java.util.List; +import java.util.Map; -import org.apache.axis2.AxisFault; +import javax.security.auth.Subject; + +import org.apache.axiom.om.util.Base64; import org.apache.axis2.client.OperationClient; -import org.apache.axis2.client.ServiceClient; -import org.apache.axis2.context.ConfigurationContext; import org.apache.axis2.context.MessageContext; -import org.apache.axis2.description.Parameter; import org.apache.axis2.transport.http.HTTPConstants; import org.apache.axis2.transport.http.HttpTransportProperties; import org.apache.axis2.transport.http.HttpTransportProperties.Authenticator; import org.apache.tuscany.sca.invocation.Message; -import org.apache.tuscany.sca.policy.Policy; -import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.SecurityUtil; import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPolicy; +import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPrincipal; import org.osoa.sca.ServiceRuntimeException; /** @@ -43,32 +42,26 @@ import org.osoa.sca.ServiceRuntimeException; * * @version $Rev$ $Date$ */ -public class Axis2BasicAuthenticationReferenceBindingConfigurator { +public class Axis2BindingBasicAuthenticationConfigurator { public static void setOperationOptions(OperationClient operationClient, Message msg, BasicAuthenticationPolicy policy) { - - // get security context - String securityPrincipal = (String)msg.getQoSContext().get(Message.QOS_CTX_SECURITY_PRINCIPAL); String username = null; String password = null; + // get the security context + Subject subject = SecurityUtil.getSubject(msg); + BasicAuthenticationPrincipal principal = SecurityUtil.getPrincipal(subject, + BasicAuthenticationPrincipal.class); + // could use the security principal to look up basic auth credentials - if ( securityPrincipal != null ) { - // look up usename and password based on security principal - } else { - // take the message username and password - username = (String)msg.getQoSContext().get(BasicAuthenticationPolicy.BASIC_AUTHENTICATION_USERNAME); - password = (String)msg.getQoSContext().get(BasicAuthenticationPolicy.BASIC_AUTHENTICATION_PASSWORD); - - if (username == null){ - username = policy.getUserName(); - password = policy.getPassword(); - } + if ( principal != null ) { + username = ((BasicAuthenticationPrincipal)principal).getName(); + password = ((BasicAuthenticationPrincipal)principal).getPassword(); } if (username == null || password == null ){ - throw new ServiceRuntimeException("Basic authenication username or password is null"); + throw new ServiceRuntimeException("Basic authentication username or password is null"); } HttpTransportProperties.Authenticator authenticator = new HttpTransportProperties.Authenticator(); @@ -82,5 +75,37 @@ public class Axis2BasicAuthenticationReferenceBindingConfigurator { operationClient.getOptions().setProperty(HTTPConstants.AUTHENTICATE, authenticator); } - + + public static void parseHTTPHeader(MessageContext messageContext, Message msg, BasicAuthenticationPolicy policy) { + + Map httpHeaderProperties = (Map)messageContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); + + String basicAuthString = (String)httpHeaderProperties.get("Authorization"); + String decodedBasicAuthString = null; + String username = null; + String password = null; + + if (basicAuthString != null) { + basicAuthString = basicAuthString.trim(); + + if (basicAuthString.startsWith("Basic ")) { + decodedBasicAuthString = new String(Base64.decode(basicAuthString.substring(6))); + } + + int collonIndex = decodedBasicAuthString.indexOf(':'); + + if (collonIndex == -1){ + username = decodedBasicAuthString; + } else { + username = decodedBasicAuthString.substring(0, collonIndex); + password = decodedBasicAuthString.substring(collonIndex + 1); + } + } + + // get the security context + Subject subject = SecurityUtil.getSubject(msg); + BasicAuthenticationPrincipal principal = new BasicAuthenticationPrincipal(username, + password); + subject.getPrincipals().add(principal); + } } diff --git a/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configurator/Axis2BindingHeaderConfigurator.java b/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configurator/Axis2BindingHeaderConfigurator.java new file mode 100644 index 0000000000..647f934c02 --- /dev/null +++ b/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configurator/Axis2BindingHeaderConfigurator.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.policy.configurator; + + + +import javax.xml.namespace.QName; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.soap.SOAPEnvelope; +import org.apache.axiom.soap.SOAPHeader; +import org.apache.axis2.context.MessageContext; +import org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2HeaderPolicyUtil; +import org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2SOAPHeader; +import org.apache.tuscany.sca.invocation.Message; + + +/** + * Policy handler to handle PolicySet that contain Axis2ConfigParamPolicy instances + * + * @version $Rev$ $Date$ + */ +public class Axis2BindingHeaderConfigurator { + + + public static void setHeader(MessageContext messageContext, Message msg, QName headerQName) { + + if (headerQName != null){ + SOAPEnvelope envelope = messageContext.getEnvelope(); + OMFactory factory = envelope.getOMFactory(); + SOAPHeader soapHeader = envelope.getHeader(); + + Axis2SOAPHeader header = Axis2HeaderPolicyUtil.getHeader(msg, headerQName) ; + + if (header != null){ + soapHeader.addChild(header.getAsSOAPHeaderBlock(factory)); + } + } + } + + public static void getHeader(MessageContext messageContext, Message msg, QName headerQName, Axis2SOAPHeader header) { + + SOAPEnvelope sev = messageContext.getEnvelope(); + SOAPHeader sh = sev.getHeader(); + OMElement omHeader = sh.getFirstChildWithName(headerQName); + + header.setAsSOAPHeaderBlock(omHeader); + + msg.getHeaders().add(header); + } + +} diff --git a/java/sca/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/definitions.xml b/java/sca/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/definitions.xml index b11059df15..6bff613a7c 100644 --- a/java/sca/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/definitions.xml +++ b/java/sca/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/definitions.xml @@ -25,7 +25,7 @@ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0">
- <sca:bindingType type="sca:binding.ws" mayProvide="SOAP SOAP.1_1 SOAP.1_2" alwaysProvides=""/>
+ <sca:bindingType type="sca:binding.ws" mayProvide="SOAP SOAP.1_1 SOAP.1_2 MTOM" alwaysProvides=""/>
<!-- PolicyIntents defined by the SCA Runtime Extension for WS Binding Axis 2 -->
<sca:intent name="SOAP" constrains="sca:binding.ws">
diff --git a/java/sca/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/axis2.xml b/java/sca/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/axis2.xml index 4d7a34d73d..ea32836f2a 100644 --- a/java/sca/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/axis2.xml +++ b/java/sca/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/axis2.xml @@ -499,5 +499,6 @@ <phase name="RMPhase"/> <phase name="PolicyDetermination"/> <phase name="MessageOut"/> + <phase name="Security"/> </phaseOrder> </axisconfig> diff --git a/java/sca/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/modules.list b/java/sca/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/modules.list index 1641457d28..e6e70dfd4b 100644 --- a/java/sca/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/modules.list +++ b/java/sca/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/modules.list @@ -1 +1 @@ -rampart-1.3.mar
\ No newline at end of file +rampart-1.4.mar
\ No newline at end of file diff --git a/java/sca/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/rampart-1.3.mar b/java/sca/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/rampart-1.3.mar Binary files differdeleted file mode 100644 index af3c45aa93..0000000000 --- a/java/sca/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/rampart-1.3.mar +++ /dev/null |