Author: fmeschbe Date: Tue Aug 24 07:41:11 2010 New Revision: 988415 URL: http://svn.apache.org/viewvc?rev=988415&view=rev Log: SLING-1688 Add built-in HTTP Basic authentication handler to Web Console Authenticator page if not disabled
Modified: sling/trunk/bundles/auth/core/src/main/java/org/apache/sling/auth/core/impl/AuthenticatorWebConsolePlugin.java sling/trunk/bundles/auth/core/src/main/java/org/apache/sling/auth/core/impl/HttpBasicAuthenticationHandler.java sling/trunk/bundles/auth/core/src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java Modified: sling/trunk/bundles/auth/core/src/main/java/org/apache/sling/auth/core/impl/AuthenticatorWebConsolePlugin.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/auth/core/src/main/java/org/apache/sling/auth/core/impl/AuthenticatorWebConsolePlugin.java?rev=988415&r1=988414&r2=988415&view=diff ============================================================================== --- sling/trunk/bundles/auth/core/src/main/java/org/apache/sling/auth/core/impl/AuthenticatorWebConsolePlugin.java (original) +++ sling/trunk/bundles/auth/core/src/main/java/org/apache/sling/auth/core/impl/AuthenticatorWebConsolePlugin.java Tue Aug 24 07:41:11 2010 @@ -21,6 +21,7 @@ package org.apache.sling.auth.core.impl; import java.io.IOException; import java.io.PrintWriter; import java.util.List; +import java.util.Map; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; @@ -80,12 +81,13 @@ public class AuthenticatorWebConsolePlug pw.println("<th class='content' colspan='2'>Handler</td>"); pw.println("</tr>"); - final List<AbstractAuthenticationHandlerHolder> holderList = slingAuthenticator.getAuthenticationHandler(); - for (AbstractAuthenticationHandlerHolder handler : holderList) { + final Map<String, String> handlerMap = slingAuthenticator.getAuthenticationHandler(); + for (Map.Entry<String, String> handler : handlerMap.entrySet()) { pw.println("<tr class='content'>"); - pw.println("<td class='content'>" + handler.fullPath + "</td>"); - pw.println("<td class='content' colspan='2'>" + handler.getProvider() + "</td>"); + pw.println("<td class='content'>" + handler.getKey() + "</td>"); + pw.println("<td class='content' colspan='2'>" + handler.getValue() + + "</td>"); pw.println("</tr>"); } Modified: sling/trunk/bundles/auth/core/src/main/java/org/apache/sling/auth/core/impl/HttpBasicAuthenticationHandler.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/auth/core/src/main/java/org/apache/sling/auth/core/impl/HttpBasicAuthenticationHandler.java?rev=988415&r1=988414&r2=988415&view=diff ============================================================================== --- sling/trunk/bundles/auth/core/src/main/java/org/apache/sling/auth/core/impl/HttpBasicAuthenticationHandler.java (original) +++ sling/trunk/bundles/auth/core/src/main/java/org/apache/sling/auth/core/impl/HttpBasicAuthenticationHandler.java Tue Aug 24 07:41:11 2010 @@ -248,6 +248,12 @@ class HttpBasicAuthenticationHandler ext return false; } + @Override + public String toString() { + return "HTTP Basic Authentication Handler (" + + (fullSupport ? "enabled" : "preemptive") + ")"; + } + // ---------- internal ----------------------------------------------------- /** Modified: sling/trunk/bundles/auth/core/src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/auth/core/src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java?rev=988415&r1=988414&r2=988415&view=diff ============================================================================== --- sling/trunk/bundles/auth/core/src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java (original) +++ sling/trunk/bundles/auth/core/src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java Tue Aug 24 07:41:11 2010 @@ -22,6 +22,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.Hashtable; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -298,13 +299,7 @@ public class SlingAuthenticator implemen final String http = OsgiUtil.toString(properties.get(PAR_HTTP_AUTH), HTTP_AUTH_PREEMPTIVE); if (HTTP_AUTH_DISABLED.equals(http)) { - httpBasicHandler = new HttpBasicAuthenticationHandler(realm, false) { - @Override - public AuthenticationInfo extractCredentials( - HttpServletRequest request, HttpServletResponse response) { - return null; - } - }; + httpBasicHandler = null; } else { httpBasicHandler = new HttpBasicAuthenticationHandler(realm, HTTP_AUTH_ENABLED.equals(http)); @@ -469,7 +464,7 @@ public class SlingAuthenticator implemen } // fall back to HTTP Basic handler (if not done already) - if (!done) { + if (!done && httpBasicHandler != null) { done = httpBasicHandler.requestCredentials(request, response); } @@ -520,7 +515,10 @@ public class SlingAuthenticator implemen } } } - httpBasicHandler.dropCredentials(request, response); + + if (httpBasicHandler != null) { + httpBasicHandler.dropCredentials(request, response); + } redirectAfterLogout(request, response); } @@ -542,8 +540,19 @@ public class SlingAuthenticator implemen // ---------- WebConsolePlugin support - List<AbstractAuthenticationHandlerHolder> getAuthenticationHandler() { - return authHandlerCache.getHolders(); + /** + * Returns the list of registered authentication handlers as a map + */ + Map<String, String> getAuthenticationHandler() { + List<AbstractAuthenticationHandlerHolder> registeredHolders = authHandlerCache.getHolders(); + LinkedHashMap<String, String> handlerMap = new LinkedHashMap<String, String>(); + for (AbstractAuthenticationHandlerHolder holder : registeredHolders) { + handlerMap.put(holder.fullPath, holder.getProvider()); + } + if (httpBasicHandler != null) { + handlerMap.put("/", httpBasicHandler.toString()); + } + return handlerMap; } List<AuthenticationRequirementHolder> getAuthenticationRequirements() { @@ -590,14 +599,16 @@ public class SlingAuthenticator implemen } // check whether the HTTP Basic handler can extract the header - final AuthenticationInfo authInfo = httpBasicHandler.extractCredentials( - request, response); - if (authInfo != null) { - // post process the AuthenticationInfo object - postProcess(authInfo, request, response); - - authInfo.put(AUTH_INFO_PROP_FEEDBACK_HANDLER, httpBasicHandler); - return authInfo; + if (httpBasicHandler != null) { + final AuthenticationInfo authInfo = httpBasicHandler.extractCredentials( + request, response); + if (authInfo != null) { + // post process the AuthenticationInfo object + postProcess(authInfo, request, response); + + authInfo.put(AUTH_INFO_PROP_FEEDBACK_HANDLER, httpBasicHandler); + return authInfo; + } } // no handler found for the request ....