diff options
Diffstat (limited to 'java/sca/modules')
6 files changed, 14 insertions, 334 deletions
diff --git a/java/sca/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java b/java/sca/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java index 12f1143e3a..80881f7859 100644 --- a/java/sca/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java +++ b/java/sca/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java @@ -24,25 +24,18 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.URLDecoder; import java.text.ParseException; -import java.util.List; import javax.servlet.ServletException; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.xml.namespace.QName; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.binding.http.HTTPCacheContext; -import org.apache.tuscany.sca.binding.http.util.HTTPHeadersParser; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.invocation.MessageFactory; -import org.apache.tuscany.sca.policy.Intent; -import org.apache.tuscany.sca.policy.PolicySet; -import org.apache.tuscany.sca.policy.PolicySetAttachPoint; -import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPolicy; /** * Servlet responsible for dispatching HTTP requests to the @@ -53,13 +46,8 @@ import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPol public class HTTPBindingListenerServlet extends HttpServlet { private static final long serialVersionUID = 2865466417329430610L; - private static final QName AUTEHTICATION_INTENT = new QName("http://www.osoa.org/xmlns/sca/1.0","authentication"); - transient private Binding binding; - transient private boolean requiresAuthentication = false; - transient private BasicAuthenticationPolicy basicAuthenticationPolicy = null; - private MessageFactory messageFactory; private Invoker getInvoker; private Invoker conditionalGetInvoker; @@ -76,42 +64,11 @@ public class HTTPBindingListenerServlet extends HttpServlet { public HTTPBindingListenerServlet(Binding binding, MessageFactory messageFactory) { this.binding = binding; this.messageFactory = messageFactory; - - - // find out which policies are active - if (binding instanceof PolicySetAttachPoint) { - List<Intent> intents = ((PolicySetAttachPoint)binding).getRequiredIntents(); - for(Intent intent : intents) { - if(intent.getName().equals(AUTEHTICATION_INTENT)) { - requiresAuthentication = true; - } - } - - - List<PolicySet> policySets = ((PolicySetAttachPoint)binding).getApplicablePolicySets(); - for (PolicySet ps : policySets) { - for (Object p : ps.getPolicies()) { - if (BasicAuthenticationPolicy.class.isInstance(p)) { - basicAuthenticationPolicy = (BasicAuthenticationPolicy)p; - } else { - // etc. check for other types of policy being present - } - } - } - } } @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - - if(requiresAuthentication) { - if(! hasAuthorization(request, response)) { - response.setHeader("WWW-Authenticate", "BASIC realm=\"Tuscany\""); - response.sendError(HttpServletResponse.SC_UNAUTHORIZED); - } - } - super.service(request, response); } @@ -129,9 +86,6 @@ public class HTTPBindingListenerServlet extends HttpServlet { // Invoke the get operation on the service implementation Message requestMessage = messageFactory.createMessage(); - //store http headers to message - requestMessage.getHeaders().addAll(HTTPHeadersParser.getHeaders(request)); - String id = path.substring(1); Message responseMessage = null; @@ -496,21 +450,4 @@ public class HTTPBindingListenerServlet extends HttpServlet { public void setConditionalDeleteInvoker(Invoker conditionalDeleteInvoker) { this.conditionalDeleteInvoker = conditionalDeleteInvoker; } - - - /** - * Utility Methods related to Policy - */ - - - private boolean hasAuthorization(HttpServletRequest request, ServletResponse response) { - boolean result = false; - if(request.getHeader("Authorization") != null) { - result = true; - } - - return result; - } - - } diff --git a/java/sca/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingProviderFactory.java b/java/sca/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingProviderFactory.java index 768636d478..32596fde33 100644 --- a/java/sca/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingProviderFactory.java +++ b/java/sca/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingProviderFactory.java @@ -19,18 +19,17 @@ package org.apache.tuscany.sca.binding.http.provider; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.binding.http.HTTPBinding; -import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.host.http.ServletHost; import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; import org.apache.tuscany.sca.invocation.MessageFactory; import org.apache.tuscany.sca.provider.BindingProviderFactory; import org.apache.tuscany.sca.provider.ReferenceBindingProvider; import org.apache.tuscany.sca.provider.ServiceBindingProvider; -import org.apache.tuscany.sca.runtime.RuntimeComponent; -import org.apache.tuscany.sca.runtime.RuntimeComponentReference; -import org.apache.tuscany.sca.runtime.RuntimeComponentService; /** @@ -47,16 +46,16 @@ public class HTTPBindingProviderFactory implements BindingProviderFactory<HTTPBi this.extensionPoints = extensionPoints; ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class); this.servletHost = servletHosts.getServletHosts().get(0); - ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); messageFactory = modelFactories.getFactory(MessageFactory.class); } - public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, RuntimeComponentReference reference, HTTPBinding binding) { + public ReferenceBindingProvider createReferenceBindingProvider(EndpointReference endpointReference) { return null; } - public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, RuntimeComponentService service, HTTPBinding binding) { - return new HTTPServiceBindingProvider(component, service, binding, extensionPoints, messageFactory, servletHost); + public ServiceBindingProvider createServiceBindingProvider(Endpoint endpoint) { + return new HTTPServiceBindingProvider(endpoint, extensionPoints, messageFactory, servletHost); } public Class<HTTPBinding> getModelType() { diff --git a/java/sca/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPRRBListenerServlet.java b/java/sca/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPRRBListenerServlet.java deleted file mode 100644 index 605e2c6211..0000000000 --- a/java/sca/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPRRBListenerServlet.java +++ /dev/null @@ -1,102 +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.http.provider; - -import java.io.BufferedReader; -import java.io.CharArrayWriter; -import java.io.IOException; -import java.io.InputStreamReader; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.binding.http.HTTPBindingContext; -import org.apache.tuscany.sca.invocation.Invoker; -import org.apache.tuscany.sca.invocation.Message; -import org.apache.tuscany.sca.invocation.MessageFactory; - -public class HTTPRRBListenerServlet extends HttpServlet { - - private static final long serialVersionUID = 6688524143716091739L; - - transient private Binding binding; - transient private Invoker bindingInvoker; - transient private MessageFactory messageFactory; - - /** - * Constructs a new HTTPServiceListenerServlet. - */ - public HTTPRRBListenerServlet(Binding binding, Invoker bindingInvoker, MessageFactory messageFactory) { - this.binding = binding; - this.bindingInvoker = bindingInvoker; - this.messageFactory = messageFactory; - } - - public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - - // Decode using the charset in the request if it exists otherwise - // use UTF-8 as this is what all browser implementations use. - // The JSON-RPC-Java JavaScript client is ASCII clean so it - // although here we can correctly handle data from other clients - // that do not escape non ASCII data - String charset = request.getCharacterEncoding(); - if (charset == null) { - charset = "UTF-8"; - } - BufferedReader in = new BufferedReader(new InputStreamReader(request.getInputStream(), charset)); - - // Read the request - CharArrayWriter data = new CharArrayWriter(); - char[] buf = new char[4096]; - int ret; - while ((ret = in.read(buf, 0, 4096)) != -1) { - data.write(buf, 0, ret); - } - - HTTPBindingContext bindingContext = new HTTPBindingContext(); - bindingContext.setHttpRequest(request); - bindingContext.setHttpResponse(response); - - // Dispatch the service interaction to the service invoker - Message requestMessage = messageFactory.createMessage(); - requestMessage.setBindingContext(bindingContext); - requestMessage.setBody(new Object[]{data}); - - Message responseMessage = bindingInvoker.invoke(requestMessage); - - // return response to client - if (responseMessage.isFault()) { - // Turn a fault into an exception - //throw new ServletException((Throwable)responseMessage.getBody()); - Throwable e = (Throwable)responseMessage.getBody(); - response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); - } else { - byte[] bout; - bout = responseMessage.<Object>getBody().toString().getBytes("UTF-8"); - response.getOutputStream().write(bout); - response.getOutputStream().flush(); - response.getOutputStream().close(); - } - } - -} diff --git a/java/sca/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java b/java/sca/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java index 3a3428268c..0cfec663c3 100644 --- a/java/sca/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java +++ b/java/sca/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java @@ -19,14 +19,11 @@ package org.apache.tuscany.sca.binding.http.provider; -import java.util.List; - import javax.servlet.Servlet; -import javax.xml.namespace.QName; +import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.binding.http.HTTPBinding; import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.host.http.SecurityContext; import org.apache.tuscany.sca.host.http.ServletHost; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.Operation; @@ -34,11 +31,6 @@ import org.apache.tuscany.sca.invocation.InvocationChain; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.MessageFactory; import org.apache.tuscany.sca.invocation.Phase; -import org.apache.tuscany.sca.policy.Intent; -import org.apache.tuscany.sca.policy.PolicySet; -import org.apache.tuscany.sca.policy.PolicySetAttachPoint; -import org.apache.tuscany.sca.policy.authentication.AuthenticationConfigurationPolicy; -import org.apache.tuscany.sca.policy.confidentiality.ConfidentialityPolicy; import org.apache.tuscany.sca.provider.OperationSelectorProvider; import org.apache.tuscany.sca.provider.OperationSelectorProviderFactory; import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; @@ -55,11 +47,9 @@ import org.apache.tuscany.sca.runtime.RuntimeWire; * @version $Rev$ $Date$ */ public class HTTPServiceBindingProvider implements ServiceBindingProviderRRB { - private static final QName AUTEHTICATION_INTENT = new QName("http://www.osoa.org/xmlns/sca/1.0","authentication"); - private static final QName CONFIDENTIALITY_INTENT = new QName("http://www.osoa.org/xmlns/sca/1.0","confidentiality"); - private ExtensionPointRegistry extensionPoints; + private Endpoint endpoint; private RuntimeComponent component; private RuntimeComponentService service; private InterfaceContract serviceContract; @@ -73,12 +63,12 @@ public class HTTPServiceBindingProvider implements ServiceBindingProviderRRB { private String servletMapping; private HTTPBindingListenerServlet bindingListenerServlet; - public HTTPServiceBindingProvider(RuntimeComponent component, - RuntimeComponentService service, - HTTPBinding binding, + public HTTPServiceBindingProvider(Endpoint endpoint, ExtensionPointRegistry extensionPoints, MessageFactory messageFactory, ServletHost servletHost) { + + this.endpoint = endpoint; this.component = component; this.service = service; @@ -169,11 +159,7 @@ public class HTTPServiceBindingProvider implements ServiceBindingProviderRRB { Invoker serviceInvoker = invocationChain.getHeadInvoker(); servlet = new HTTPServiceListenerServlet(binding, serviceInvoker, messageFactory); break; - } else if (binding.getOperationSelector() != null || binding.getRequestWireFormat() != null) { - Invoker bindingInvoker = wire.getBindingInvocationChain().getHeadInvoker(); - servlet = new HTTPRRBListenerServlet(binding, bindingInvoker, messageFactory); - break; - } + } } if (servlet == null) { throw new IllegalStateException("No get or service method found on the service"); @@ -189,46 +175,7 @@ public class HTTPServiceBindingProvider implements ServiceBindingProviderRRB { servletMapping += "*"; } - - SecurityContext securityContext = new SecurityContext(); - boolean isConfidentialityRequired = false; - boolean isAuthenticationRequired = false; - - - // find out which policies are active - if (binding instanceof PolicySetAttachPoint) { - List<Intent> intents = ((PolicySetAttachPoint)binding).getRequiredIntents(); - for(Intent intent : intents) { - if (intent.getName().equals(AUTEHTICATION_INTENT)) { - isAuthenticationRequired = true; - } else if (intent.getName().equals(CONFIDENTIALITY_INTENT)) { - isConfidentialityRequired = true; - } - } - - List<PolicySet> policySets = ((PolicySetAttachPoint)binding).getApplicablePolicySets(); - for (PolicySet ps : policySets) { - for (Object p : ps.getPolicies()) { - if (ConfidentialityPolicy.class.isInstance(p) && isConfidentialityRequired) { - //Handle enabling and configuring SSL - ConfidentialityPolicy confidentialityPolicy = (ConfidentialityPolicy)p; - - securityContext.setSSLEnabled(true); - securityContext.setSSLProperties(confidentialityPolicy.toProperties()); - } else if(AuthenticationConfigurationPolicy.class.isInstance(p) && isAuthenticationRequired) { - // Handle authentication and user configuration - AuthenticationConfigurationPolicy authenticationConfiguration = (AuthenticationConfigurationPolicy)p; - - securityContext.setAuthenticationEnabled(true); - securityContext.getUsers().clear(); - securityContext.getUsers().addAll(authenticationConfiguration.getUsers()); - } - } - } - } - - - servletHost.addServletMapping(servletMapping, servlet, securityContext); + servletHost.addServletMapping(servletMapping, servlet); } public void stop() { diff --git a/java/sca/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceListenerServlet.java b/java/sca/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceListenerServlet.java index 493255655d..f752dce3e1 100644 --- a/java/sca/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceListenerServlet.java +++ b/java/sca/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceListenerServlet.java @@ -20,25 +20,18 @@ package org.apache.tuscany.sca.binding.http.provider; import java.io.IOException; -import java.util.List; import javax.servlet.Servlet; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.xml.namespace.QName; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.invocation.MessageFactory; -import org.apache.tuscany.sca.policy.Intent; -import org.apache.tuscany.sca.policy.PolicySet; -import org.apache.tuscany.sca.policy.PolicySetAttachPoint; -import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPolicy; /** * Servlet responsible for dispatching HTTP service requests to the @@ -47,16 +40,11 @@ import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPol * @version $Rev$ $Date$ */ public class HTTPServiceListenerServlet implements Servlet { - private static final QName AUTEHTICATION_INTENT = new QName("http://www.osoa.org/xmlns/sca/1.0","authentication"); - transient private Binding binding; transient private ServletConfig config; transient private MessageFactory messageFactory; transient private Invoker serviceInvoker; - transient private boolean requiresAuthentication = false; - transient private BasicAuthenticationPolicy basicAuthenticationPolicy = null; - /** * Constructs a new HTTPServiceListenerServlet. */ @@ -64,28 +52,6 @@ public class HTTPServiceListenerServlet implements Servlet { this.binding = binding; this.serviceInvoker = serviceInvoker; this.messageFactory = messageFactory; - - // find out which policies are active - if (binding instanceof PolicySetAttachPoint) { - List<Intent> intents = ((PolicySetAttachPoint)binding).getRequiredIntents(); - for(Intent intent : intents) { - if(intent.getName().equals(AUTEHTICATION_INTENT)) { - requiresAuthentication = true; - } - } - - - List<PolicySet> policySets = ((PolicySetAttachPoint)binding).getApplicablePolicySets(); - for (PolicySet ps : policySets) { - for (Object p : ps.getPolicies()) { - if (BasicAuthenticationPolicy.class.isInstance(p)) { - basicAuthenticationPolicy = (BasicAuthenticationPolicy)p; - } else { - // etc. check for other types of policy being present - } - } - } - } } public ServletConfig getServletConfig() { @@ -105,13 +71,6 @@ public class HTTPServiceListenerServlet implements Servlet { } public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { - - if(requiresAuthentication) { - if(! hasAuthenticationHeader((HttpServletRequest)request, (HttpServletResponse)response)) { - ((HttpServletResponse)response).sendError(HttpServletResponse.SC_UNAUTHORIZED); - } - } - // Dispatch the service interaction to the service invoker Message requestMessage = messageFactory.createMessage(); requestMessage.setBody(new Object[]{request, response}); @@ -123,14 +82,4 @@ public class HTTPServiceListenerServlet implements Servlet { ((HttpServletResponse)response).sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); } } - - - private boolean hasAuthenticationHeader(HttpServletRequest request, ServletResponse response) { - boolean result = false; - if(request.getHeader("Authorization") != null) { - result = true; - } - - return result; - } } diff --git a/java/sca/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/util/HTTPHeadersParser.java b/java/sca/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/util/HTTPHeadersParser.java deleted file mode 100644 index 1fe4600e31..0000000000 --- a/java/sca/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/util/HTTPHeadersParser.java +++ /dev/null @@ -1,50 +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.http.util; - -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.List; - -import javax.servlet.http.HttpServletRequest; - -import org.apache.tuscany.sca.binding.http.HTTPHeader; - -public class HTTPHeadersParser { - - /** - * Parse http request headers to a map - * - * @param request - * @return - */ - public static List<HTTPHeader> getHeaders(HttpServletRequest request) { - List<HTTPHeader> headers = new ArrayList<HTTPHeader>(); - - Enumeration<?> headerNames = request.getHeaderNames(); - while (headerNames.hasMoreElements()) { - String headerName = (String) headerNames.nextElement(); - Object headerValue = request.getHeader(headerName); - HTTPHeader header = new HTTPHeader(headerName, headerValue); - headers.add(header); - } - return headers; - } -} |