Return-Path: Delivered-To: apmail-sling-commits-archive@www.apache.org Received: (qmail 34896 invoked from network); 11 Nov 2009 13:35:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 11 Nov 2009 13:35:05 -0000 Received: (qmail 89396 invoked by uid 500); 11 Nov 2009 13:35:05 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 89340 invoked by uid 500); 11 Nov 2009 13:35:05 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 89331 invoked by uid 99); 11 Nov 2009 13:35:05 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Nov 2009 13:35:05 +0000 X-ASF-Spam-Status: No, hits=-3.0 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Nov 2009 13:35:03 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C26392388996; Wed, 11 Nov 2009 13:34:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r834878 - in /sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/auth: LogoutServlet.java SlingAuthenticator.java Date: Wed, 11 Nov 2009 13:34:42 -0000 To: commits@sling.apache.org From: fmeschbe@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091111133442.C26392388996@eris.apache.org> Author: fmeschbe Date: Wed Nov 11 13:34:42 2009 New Revision: 834878 URL: http://svn.apache.org/viewvc?rev=834878&view=rev Log: SLING-1182 Provide the path to be used to select the authentication handler as a request attribute better supporting logout servlets/scripts Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/auth/LogoutServlet.java sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/auth/SlingAuthenticator.java Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/auth/LogoutServlet.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/auth/LogoutServlet.java?rev=834878&r1=834877&r2=834878&view=diff ============================================================================== --- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/auth/LogoutServlet.java (original) +++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/auth/LogoutServlet.java Wed Nov 11 13:34:42 2009 @@ -58,9 +58,13 @@ protected void service(SlingHttpServletRequest request, SlingHttpServletResponse response) { - Authenticator authenticator = this.authenticator; + final Authenticator authenticator = this.authenticator; if (authenticator != null) { try { + final String resourcePath = request.getParameter("resource"); + request.setAttribute(Authenticator.LOGIN_RESOURCE, + (resourcePath != null) ? resourcePath : "/"); + authenticator.logout(request, response); return; } catch (IllegalStateException ise) { Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/auth/SlingAuthenticator.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/auth/SlingAuthenticator.java?rev=834878&r1=834877&r2=834878&view=diff ============================================================================== --- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/auth/SlingAuthenticator.java (original) +++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/auth/SlingAuthenticator.java Wed Nov 11 13:34:42 2009 @@ -254,15 +254,8 @@ } // select path used for authentication handler selection - final Object loginPathO = request.getAttribute(Authenticator.LOGIN_RESOURCE); - String path = (loginPathO instanceof String) - ? (String) loginPathO - : request.getPathInfo(); - if (path == null || path.length() == 0) { - path = "/"; - } - - AuthenticationHandlerHolder[] handlerInfos = findApplicableAuthenticationHandlers(request); + final AuthenticationHandlerHolder[] handlerInfos = findApplicableAuthenticationHandlers(request); + final String path = getHandlerSelectionPath(request); boolean done = false; for (int i = 0; !done && i < handlerInfos.length; i++) { if ( path.startsWith(handlerInfos[i].path) ) { @@ -304,9 +297,10 @@ throw new IllegalStateException("Response already committed"); } - AuthenticationHandlerHolder[] handlerInfos = findApplicableAuthenticationHandlers(request); + final AuthenticationHandlerHolder[] handlerInfos = findApplicableAuthenticationHandlers(request); + final String path = getHandlerSelectionPath(request); for (int i = 0; i < handlerInfos.length; i++) { - if (request.getPathInfo().startsWith(handlerInfos[i].path)) { + if (path.startsWith(handlerInfos[i].path)) { log.debug("logout: dropping authentication using handler: {}", handlerInfos[i]); @@ -694,4 +688,28 @@ // return the session return session; } + + /** + * Returns the path to be used to select the authentication handler to login + * or logout with. + *

+ * This method uses the {@link Authenticator#LOGIN_RESOURCE} request + * attribute. If this attribute is not set (or is not a string), the request + * path info is used. If this is not set either, or is the empty string, "/" + * is returned. + * + * @param request The request providing the request attribute or path info. + * @return The path as set by the request attribute or the path info or "/" + * if neither is set. + */ + private String getHandlerSelectionPath(HttpServletRequest request) { + final Object loginPathO = request.getAttribute(Authenticator.LOGIN_RESOURCE); + String path = (loginPathO instanceof String) + ? (String) loginPathO + : request.getPathInfo(); + if (path == null || path.length() == 0) { + path = "/"; + } + return path; + } }