Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 4C9AA200B68 for ; Fri, 19 Aug 2016 16:21:52 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 4B0CB160A8E; Fri, 19 Aug 2016 14:21:52 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 5165D160A79 for ; Fri, 19 Aug 2016 16:21:50 +0200 (CEST) Received: (qmail 96126 invoked by uid 500); 19 Aug 2016 14:21:49 -0000 Mailing-List: contact commits-help@chemistry.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@chemistry.apache.org Delivered-To: mailing list commits@chemistry.apache.org Received: (qmail 96114 invoked by uid 99); 19 Aug 2016 14:21:49 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Aug 2016 14:21:49 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id CEC4218027E for ; Fri, 19 Aug 2016 14:21:48 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.584 X-Spam-Level: * X-Spam-Status: No, score=1.584 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, KAM_MANYCOMMENTS=1.2, RP_MATCHES_RCVD=-1.426, T_FILL_THIS_FORM_SHORT=0.01] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id HPMTea79NdRh for ; Fri, 19 Aug 2016 14:21:39 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 965B05F5A4 for ; Fri, 19 Aug 2016 14:21:39 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id E44ADE0054 for ; Fri, 19 Aug 2016 14:21:38 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 071283A0319 for ; Fri, 19 Aug 2016 14:21:37 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1756919 - in /chemistry/opencmis/trunk/chemistry-opencmis-server: chemistry-opencmis-server-archetype/src/main/resources/archetype-resources/ chemistry-opencmis-server-archetype/src/main/resources/archetype-resources/src/main/java/ chemist... Date: Fri, 19 Aug 2016 14:21:37 -0000 To: commits@chemistry.apache.org From: fmui@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20160819142138.071283A0319@svn01-us-west.apache.org> archived-at: Fri, 19 Aug 2016 14:21:52 -0000 Author: fmui Date: Fri Aug 19 14:21:37 2016 New Revision: 1756919 URL: http://svn.apache.org/viewvc?rev=1756919&view=rev Log: added more code and comment around authentication Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/AbstractCallContextInterceptor.java chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/CallContextHandlerInterceptor.java chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AttributeCallContextHandler.java chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/UserPrincipalCallContextHandler.java Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-archetype/src/main/resources/archetype-resources/pom.xml chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-archetype/src/main/resources/archetype-resources/src/main/java/__projectPrefix__CmisServiceFactory.java chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings-war/src/main/webapp/WEB-INF/web-async.xml chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings-war/src/main/webapp/WEB-INF/web.xml chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/CmisWebServicesServlet.java chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/UsernameTokenInterceptor.java chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractCmisHttpServlet.java chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/BasicAuthCallContextHandler.java Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-archetype/src/main/resources/archetype-resources/pom.xml URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-archetype/src/main/resources/archetype-resources/pom.xml?rev=1756919&r1=1756918&r2=1756919&view=diff ============================================================================== --- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-archetype/src/main/resources/archetype-resources/pom.xml (original) +++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-archetype/src/main/resources/archetype-resources/pom.xml Fri Aug 19 14:21:37 2016 @@ -18,19 +18,9 @@ - true - maven-compiler-plugin - 3.0 - - 1.6 - 1.6 - UTF-8 - - - org.apache.maven.plugins maven-war-plugin - 2.3 + 2.4 Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-archetype/src/main/resources/archetype-resources/src/main/java/__projectPrefix__CmisServiceFactory.java URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-archetype/src/main/resources/archetype-resources/src/main/java/__projectPrefix__CmisServiceFactory.java?rev=1756919&r1=1756918&r2=1756919&view=diff ============================================================================== --- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-archetype/src/main/resources/archetype-resources/src/main/java/__projectPrefix__CmisServiceFactory.java (original) +++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-archetype/src/main/resources/archetype-resources/src/main/java/__projectPrefix__CmisServiceFactory.java Fri Aug 19 14:21:37 2016 @@ -41,7 +41,9 @@ public class ${projectPrefix}CmisService @Override public CmisService getService(CallContext context) { - // authentication can go here + // get the user name and password that the CallContextHandler has determined + // - if the user is null, this is either an anonymous request or the CallContextHandler configuration is wrong + // - the password may be null depending on the authentication method String user = context.getUsername(); String password = context.getPassword(); Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings-war/src/main/webapp/WEB-INF/web-async.xml URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings-war/src/main/webapp/WEB-INF/web-async.xml?rev=1756919&r1=1756918&r2=1756919&view=diff ============================================================================== --- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings-war/src/main/webapp/WEB-INF/web-async.xml (original) +++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings-war/src/main/webapp/WEB-INF/web-async.xml Fri Aug 19 14:21:37 2016 @@ -20,7 +20,7 @@ - + OpenCMIS Server @@ -31,64 +31,97 @@ org.apache.chemistry.opencmis.server.impl.CmisRepositoryContextListener - + + + + + 1 true - + cmisws11 org.apache.chemistry.opencmis.server.async.impl.webservices.AsyncCmisWebServicesServlet + CMIS version of this endpoint cmisVersion 1.1 + 1 true @@ -190,11 +240,21 @@ callContextHandler org.apache.chemistry.opencmis.server.shared.BasicAuthCallContextHandler + + + CMIS version of this endpoint cmisVersion 1.0 + 2 true @@ -205,26 +265,45 @@ callContextHandler org.apache.chemistry.opencmis.server.shared.BasicAuthCallContextHandler + + + CMIS version of this endpoint cmisVersion 1.1 + 2 true - + cmisbrowser org.apache.chemistry.opencmis.server.async.impl.browser.AsyncCmisBrowserBindingServlet callContextHandler org.apache.chemistry.opencmis.server.impl.browser.token.TokenCallContextHandler + + + + 2 true - + cmisendpoints org.apache.chemistry.opencmis.server.impl.endpoints.SimpleCmisEndpointsDocumentServlet @@ -249,7 +328,7 @@ cmisatom10 /atom/* - + cmisatom11 /atom11/* Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings-war/src/main/webapp/WEB-INF/web.xml URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings-war/src/main/webapp/WEB-INF/web.xml?rev=1756919&r1=1756918&r2=1756919&view=diff ============================================================================== --- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings-war/src/main/webapp/WEB-INF/web.xml (original) +++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings-war/src/main/webapp/WEB-INF/web.xml Fri Aug 19 14:21:37 2016 @@ -31,64 +31,97 @@ org.apache.chemistry.opencmis.server.impl.CmisRepositoryContextListener - + + + + + 1 - + cmisws11 org.apache.chemistry.opencmis.server.impl.webservices.CmisWebServicesServlet + CMIS version of this endpoint cmisVersion 1.1 + 1 @@ -186,13 +236,24 @@ cmisatom10 org.apache.chemistry.opencmis.server.impl.atompub.CmisAtomPubServlet + Call Context Handler implementation callContextHandler org.apache.chemistry.opencmis.server.shared.BasicAuthCallContextHandler + + + CMIS version of this endpoint cmisVersion 1.0 + 2 @@ -200,26 +261,47 @@ cmisatom11 org.apache.chemistry.opencmis.server.impl.atompub.CmisAtomPubServlet + Call Context Handler implementation callContextHandler org.apache.chemistry.opencmis.server.shared.BasicAuthCallContextHandler + + + CMIS version of this endpoint cmisVersion 1.1 + 2 - + cmisbrowser org.apache.chemistry.opencmis.server.impl.browser.CmisBrowserBindingServlet + Call Context Handler implementation callContextHandler org.apache.chemistry.opencmis.server.impl.browser.token.TokenCallContextHandler + + + 2 - + cmisendpoints org.apache.chemistry.opencmis.server.impl.endpoints.SimpleCmisEndpointsDocumentServlet @@ -244,7 +326,7 @@ cmisatom10 /atom/* - + cmisatom11 /atom11/* @@ -254,7 +336,7 @@ cmisbrowser /browser/* - + cmisendpoints /cmis-endpoints.json Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/AbstractCallContextInterceptor.java URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/AbstractCallContextInterceptor.java?rev=1756919&view=auto ============================================================================== --- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/AbstractCallContextInterceptor.java (added) +++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/AbstractCallContextInterceptor.java Fri Aug 19 14:21:37 2016 @@ -0,0 +1,115 @@ +/* + * 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.chemistry.opencmis.server.impl.webservices; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.chemistry.opencmis.commons.server.CallContext; +import org.apache.cxf.binding.soap.SoapMessage; +import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor; +import org.apache.cxf.phase.Phase; + +/** + * Base class for all interceptors that add data to the call context. + */ +public abstract class AbstractCallContextInterceptor extends AbstractSoapInterceptor { + + public AbstractCallContextInterceptor() { + super(Phase.PRE_INVOKE); + } + + /** + * Returns the current call context map. + * + * @return the call context map or {@code null} if there isn't one + */ + @SuppressWarnings("unchecked") + protected Map getCurrentCallContextMap(SoapMessage message) { + Object callContextMapObject = message.getExchange().getInMessage().get(AbstractService.CALL_CONTEXT_MAP); + + if (callContextMapObject instanceof Map) { + return (Map) callContextMapObject; + } + + return null; + } + + /** + * Sets a new call context map. + */ + protected void setCallContextMap(SoapMessage message, Map callContextMap) { + message.getExchange().getInMessage().put(AbstractService.CALL_CONTEXT_MAP, callContextMap); + } + + /** + * Returns the current user. + */ + protected String getCurrentUser(SoapMessage message) { + Map callContextMap = getCurrentCallContextMap(message); + if (callContextMap != null) { + return callContextMap.get(CallContext.USERNAME); + } + + return null; + } + + /** + * Adds data to the current call context map. + */ + protected void addToCurrentCallContextMap(SoapMessage message, Map callContextMapAdditions) { + Map callContextMap = getCurrentCallContextMap(message); + if (callContextMap == null) { + callContextMap = new HashMap(); + } + + callContextMap.putAll(callContextMapAdditions); + + setCallContextMap(message, callContextMap); + } + + /** + * Adds a user and a password to the current call context map. + */ + protected void setUserAndPassword(SoapMessage message, String user, String password) { + Map callContextMap = getCurrentCallContextMap(message); + if (callContextMap == null) { + callContextMap = new HashMap(); + } + + callContextMap.put(CallContext.USERNAME, user); + callContextMap.put(CallContext.PASSWORD, password); + + setCallContextMap(message, callContextMap); + } + + /** + * Adds just a user to the current call context map. + */ + protected void setUser(SoapMessage message, String user) { + Map callContextMap = getCurrentCallContextMap(message); + if (callContextMap == null) { + callContextMap = new HashMap(); + } + + callContextMap.put(CallContext.USERNAME, user); + + setCallContextMap(message, callContextMap); + } +} Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/CallContextHandlerInterceptor.java URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/CallContextHandlerInterceptor.java?rev=1756919&view=auto ============================================================================== --- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/CallContextHandlerInterceptor.java (added) +++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/CallContextHandlerInterceptor.java Fri Aug 19 14:21:37 2016 @@ -0,0 +1,59 @@ +/* + * 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.chemistry.opencmis.server.impl.webservices; + +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.chemistry.opencmis.server.shared.CallContextHandler; +import org.apache.cxf.binding.soap.SoapMessage; +import org.apache.cxf.transport.http.AbstractHTTPDestination; + +/** + * Adds data form a {@link CallContextHandler} if one is configured. + */ +public class CallContextHandlerInterceptor extends AbstractCallContextInterceptor { + + private final CallContextHandler callContextHandler; + + public CallContextHandlerInterceptor(CallContextHandler callContextHandler) { + super(); + this.callContextHandler = callContextHandler; + } + + @Override + public void handleMessage(SoapMessage message) { + if (callContextHandler == null) { + return; + } + + HttpServletRequest request = (HttpServletRequest) message.get(AbstractHTTPDestination.HTTP_REQUEST); + if (request == null) { + return; + } + + Map callContextMap = callContextHandler.getCallContextMap(request); + if (callContextMap == null || callContextMap.isEmpty()) { + return; + } + + addToCurrentCallContextMap(message, callContextMap); + } +} Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/CmisWebServicesServlet.java URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/CmisWebServicesServlet.java?rev=1756919&r1=1756918&r2=1756919&view=diff ============================================================================== --- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/CmisWebServicesServlet.java (original) +++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/CmisWebServicesServlet.java Fri Aug 19 14:21:37 2016 @@ -39,6 +39,8 @@ import org.apache.chemistry.opencmis.com import org.apache.chemistry.opencmis.commons.impl.UrlBuilder; import org.apache.chemistry.opencmis.commons.server.CmisServiceFactory; import org.apache.chemistry.opencmis.server.impl.CmisRepositoryContextListener; +import org.apache.chemistry.opencmis.server.shared.AbstractCmisHttpServlet; +import org.apache.chemistry.opencmis.server.shared.CallContextHandler; import org.apache.chemistry.opencmis.server.shared.CsrfManager; import org.apache.chemistry.opencmis.server.shared.Dispatcher; import org.apache.commons.lang3.StringEscapeUtils; @@ -74,6 +76,7 @@ public class CmisWebServicesServlet exte private Map docs; + private CallContextHandler callContextHandler; private CsrfManager csrfManager; @Override @@ -93,6 +96,9 @@ public class CmisWebServicesServlet exte cmisVersion = CmisVersion.CMIS_1_0; } + // initialize the call context handler + callContextHandler = AbstractCmisHttpServlet.loadCallContextHandler(config); + // set up WSDL and XSD documents docs = new HashMap(); @@ -108,6 +114,16 @@ public class CmisWebServicesServlet exte super.init(config); } + /** + * Returns the {@code CallContextHandler}. + * + * @return the {@code CallContextHandler} or {@code null} if it is not + * configured + */ + protected CallContextHandler getCallContextHandler() { + return callContextHandler; + } + private String readFile(ServletConfig config, String path) throws ServletException { InputStream stream = config.getServletContext().getResourceAsStream(path); if (stream == null) { @@ -176,10 +192,10 @@ public class CmisWebServicesServlet exte String respDoc = doc; respDoc = BASE_PATTERN.matcher(respDoc).replaceAll(baseUrl.toString()); - respDoc = CORE_PATTERN.matcher(respDoc) - .replaceAll((new UrlBuilder(baseUrl)).addPath("cmis").addParameter("core").toString()); - respDoc = MSG_PATTERN.matcher(respDoc) - .replaceAll((new UrlBuilder(baseUrl)).addPath("cmis").addParameter("msg").toString()); + respDoc = CORE_PATTERN.matcher(respDoc).replaceAll( + (new UrlBuilder(baseUrl)).addPath("cmis").addParameter("core").toString()); + respDoc = MSG_PATTERN.matcher(respDoc).replaceAll( + (new UrlBuilder(baseUrl)).addPath("cmis").addParameter("msg").toString()); PrintWriter pw = response.getWriter(); pw.print(respDoc); @@ -192,12 +208,14 @@ public class CmisWebServicesServlet exte response.setContentType("text/html"); response.setCharacterEncoding(IOUtils.UTF8); - String urlEscaped = StringEscapeUtils - .escapeHtml4((new UrlBuilder(baseUrl)).addPath("cmis").addParameter("wsdl").toString()); + String urlEscaped = StringEscapeUtils.escapeHtml4((new UrlBuilder(baseUrl)).addPath("cmis") + .addParameter("wsdl").toString()); PrintWriter pw = response.getWriter(); - pw.print("Apache Chemistry OpenCMIS - CMIS " + cmisVersion.value() + " Web Services" + pw.print("Apache Chemistry OpenCMIS - CMIS " + + cmisVersion.value() + + " Web Services" + ""); @@ -309,6 +327,7 @@ public class CmisWebServicesServlet exte */ protected void configureInterceptors(Bus bus) { bus.getInInterceptors().add(new SoapActionRemoveInterceptor()); + bus.getInInterceptors().add(new CallContextHandlerInterceptor(getCallContextHandler())); bus.getInInterceptors().add(new UsernameTokenInterceptor()); } Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/UsernameTokenInterceptor.java URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/UsernameTokenInterceptor.java?rev=1756919&r1=1756918&r2=1756919&view=diff ============================================================================== --- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/UsernameTokenInterceptor.java (original) +++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/UsernameTokenInterceptor.java Fri Aug 19 14:21:37 2016 @@ -18,17 +18,11 @@ */ package org.apache.chemistry.opencmis.server.impl.webservices; -import java.util.HashMap; -import java.util.Map; - import javax.xml.namespace.QName; import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException; -import org.apache.chemistry.opencmis.commons.server.CallContext; import org.apache.cxf.binding.soap.SoapMessage; -import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor; import org.apache.cxf.headers.Header; -import org.apache.cxf.phase.Phase; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -39,10 +33,10 @@ import org.w3c.dom.NodeList; * This class emulates the behavior of the OpenCMIS server framework 0.13.0 and * earlier. */ -public class UsernameTokenInterceptor extends AbstractSoapInterceptor { +public class UsernameTokenInterceptor extends AbstractCallContextInterceptor { public UsernameTokenInterceptor() { - super(Phase.PRE_INVOKE); + super(); } protected static final String WSSE_NS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"; @@ -54,29 +48,28 @@ public class UsernameTokenInterceptor ex @Override public void handleMessage(SoapMessage message) { - Header securityHeader = message.getHeader(WSSE_SECURITY); - if (securityHeader != null) { - if (!(securityHeader.getObject() instanceof Node)) { - throw new CmisRuntimeException("Cannot read Security header."); - } + // don't extract a user, if there is already one + if (getCurrentUser(message) == null) { + Header securityHeader = message.getHeader(WSSE_SECURITY); + if (securityHeader != null) { + if (!(securityHeader.getObject() instanceof Node)) { + throw new CmisRuntimeException("Cannot read Security header."); + } + + Node usernameTokenNode = getUsernameTokenNode((Node) securityHeader.getObject()); + if (usernameTokenNode == null) { + return; + } + + String username = getUsername(usernameTokenNode); + if (username == null) { + return; + } - Node usernameTokenNode = getUsernameTokenNode((Node) securityHeader.getObject()); - if (usernameTokenNode == null) { - return; - } + String password = getPassword(usernameTokenNode); - String username = getUsername(usernameTokenNode); - if (username == null) { - return; + setUserAndPassword(message, username, password); } - - String password = getPasswordText(usernameTokenNode); - - Map callContextMap = new HashMap(); - callContextMap.put(CallContext.USERNAME, username); - callContextMap.put(CallContext.PASSWORD, password); - - message.getExchange().getInMessage().put(AbstractService.CALL_CONTEXT_MAP, callContextMap); } } @@ -94,7 +87,7 @@ public class UsernameTokenInterceptor ex return null; } - protected String getPasswordText(Node usernameTokenNode) { + protected String getPassword(Node usernameTokenNode) { Node node = findElement(usernameTokenNode, WSSE_NS, WSSE_PASSWORD); if (node != null) { Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractCmisHttpServlet.java URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractCmisHttpServlet.java?rev=1756919&r1=1756918&r2=1756919&view=diff ============================================================================== --- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractCmisHttpServlet.java (original) +++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractCmisHttpServlet.java Fri Aug 19 14:21:37 2016 @@ -55,16 +55,7 @@ public abstract class AbstractCmisHttpSe super.init(config); // initialize the call context handler - callContextHandler = null; - String callContextHandlerClass = config.getInitParameter(PARAM_CALL_CONTEXT_HANDLER); - if (callContextHandlerClass != null) { - try { - callContextHandler = (CallContextHandler) ClassLoaderUtil.loadClass(callContextHandlerClass) - .newInstance(); - } catch (Exception e) { - throw new ServletException("Could not load call context handler: " + e, e); - } - } + callContextHandler = loadCallContextHandler(config); // get service factory factory = CmisRepositoryContextListener.getServiceFactory(config.getServletContext()); @@ -78,6 +69,23 @@ public abstract class AbstractCmisHttpSe } /** + * Loads a {@code CallContextHandler} if it is configured in for this + * servlet. + */ + public static CallContextHandler loadCallContextHandler(ServletConfig config) throws ServletException { + String callContextHandlerClass = config.getInitParameter(PARAM_CALL_CONTEXT_HANDLER); + if (callContextHandlerClass != null) { + try { + return (CallContextHandler) ClassLoaderUtil.loadClass(callContextHandlerClass).newInstance(); + } catch (Exception e) { + throw new ServletException("Could not load call context handler: " + e, e); + } + } + + return null; + } + + /** * Sets the binding. */ protected void setBinding(String binding) { Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AttributeCallContextHandler.java URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AttributeCallContextHandler.java?rev=1756919&view=auto ============================================================================== --- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AttributeCallContextHandler.java (added) +++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AttributeCallContextHandler.java Fri Aug 19 14:21:37 2016 @@ -0,0 +1,67 @@ +/* + * 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.chemistry.opencmis.server.shared; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.chemistry.opencmis.commons.server.CallContext; + +/** + * Call Context handler that takes the user from a request attribute. + * + * If the current user is determined in a filter, the filter can set the + * following attribute to pass down the user name to OpenCMIS with this + * CallContextHandler. + * + *
+ * {@code
+ *  request.setAttribute(AttributeCallContextHandler.USERNAME_ATTRIBUTE, user);
+ * }
+ * 
+ */ +public class AttributeCallContextHandler implements CallContextHandler, Serializable { + + private static final long serialVersionUID = 1L; + + public static final String USERNAME_ATTRIBUTE = "org.apache.chemistry.opencmis.server.username"; + + /** + * Constructor. + */ + public AttributeCallContextHandler() { + } + + @Override + public Map getCallContextMap(HttpServletRequest request) { + assert request != null; + + Map result = null; + + if (request.getAttribute(USERNAME_ATTRIBUTE) != null) { + result = new HashMap(); + result.put(CallContext.USERNAME, request.getAttribute(USERNAME_ATTRIBUTE).toString()); + } + + return result; + } +} Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/BasicAuthCallContextHandler.java URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/BasicAuthCallContextHandler.java?rev=1756919&r1=1756918&r2=1756919&view=diff ============================================================================== --- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/BasicAuthCallContextHandler.java (original) +++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/BasicAuthCallContextHandler.java Fri Aug 19 14:21:37 2016 @@ -31,6 +31,14 @@ import org.apache.chemistry.opencmis.com /** * Call Context handler that handles basic authentication. + * + * This handler assumes that the user credentials have either already checked + * (for example by a Servlet filter) or will be checked later in the CMIS + * implementation. + * + * Checking the credentials before the request reaches the CMIS implementation + * is the preferred option because it prevents malicious clients early from + * flooding the server with useless data. */ public class BasicAuthCallContextHandler implements CallContextHandler, Serializable { Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/UserPrincipalCallContextHandler.java URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/UserPrincipalCallContextHandler.java?rev=1756919&view=auto ============================================================================== --- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/UserPrincipalCallContextHandler.java (added) +++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/UserPrincipalCallContextHandler.java Fri Aug 19 14:21:37 2016 @@ -0,0 +1,55 @@ +/* + * 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.chemistry.opencmis.server.shared; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.chemistry.opencmis.commons.server.CallContext; + +/** + * Call Context handler that handles UserPrincipals. + */ +public class UserPrincipalCallContextHandler implements CallContextHandler, Serializable { + + private static final long serialVersionUID = 1L; + + /** + * Constructor. + */ + public UserPrincipalCallContextHandler() { + } + + @Override + public Map getCallContextMap(HttpServletRequest request) { + assert request != null; + + Map result = null; + + if (request.getUserPrincipal() != null) { + result = new HashMap(); + result.put(CallContext.USERNAME, request.getUserPrincipal().getName()); + } + + return result; + } +}