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.
+ * <p>
+ * 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;
+ }
}