Return-Path: Delivered-To: apmail-incubator-sling-commits-archive@minotaur.apache.org Received: (qmail 50133 invoked from network); 17 Apr 2009 13:57:32 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 17 Apr 2009 13:57:32 -0000 Received: (qmail 98416 invoked by uid 500); 17 Apr 2009 13:57:32 -0000 Delivered-To: apmail-incubator-sling-commits-archive@incubator.apache.org Received: (qmail 98362 invoked by uid 500); 17 Apr 2009 13:57:32 -0000 Mailing-List: contact sling-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sling-dev@incubator.apache.org Delivered-To: mailing list sling-commits@incubator.apache.org Received: (qmail 98353 invoked by uid 99); 17 Apr 2009 13:57:31 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Apr 2009 13:57:31 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED 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; Fri, 17 Apr 2009 13:57:31 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id EC9882388B6B; Fri, 17 Apr 2009 13:57:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r766012 - /incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/auth/SlingAuthenticator.java Date: Fri, 17 Apr 2009 13:57:09 -0000 To: sling-commits@incubator.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090417135710.EC9882388B6B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: cziegeler Date: Fri Apr 17 13:57:08 2009 New Revision: 766012 URL: http://svn.apache.org/viewvc?rev=766012&view=rev Log: SLING-868 : Prevent NPE if no authentication handlers can be found. Modified: incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/auth/SlingAuthenticator.java Modified: incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/auth/SlingAuthenticator.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/auth/SlingAuthenticator.java?rev=766012&r1=766011&r2=766012&view=diff ============================================================================== --- incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/auth/SlingAuthenticator.java (original) +++ incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/auth/SlingAuthenticator.java Fri Apr 17 13:57:08 2009 @@ -334,30 +334,32 @@ private static Map> EMPTY_PROTOCOL_MAP = new HashMap>(); private static AuthenticationHandlerInfo[] EMPTY_INFO = new AuthenticationHandlerInfo[0]; - + private AuthenticationHandlerInfo[] findApplicableAuthenticationHandlers(HttpServletRequest request) { Map> byProtocolMap = getAuthenticationHandlers(); - + Map byHostMap = byProtocolMap.get(request.getScheme()); - if(byHostMap == null) { + if (byHostMap == null) { byHostMap = byProtocolMap.get(""); } - - String hostname = request.getServerName() + + + String hostname = request.getServerName() + (request.getServerPort() != 80 && request.getServerPort() != 443 ? ":" + request.getServerPort() : ""); - - AuthenticationHandlerInfo[] infos = byHostMap.get(hostname); - if(infos == null) { - infos = byHostMap.get(""); - } - - if(infos != null) { - return infos; + + AuthenticationHandlerInfo[] infos = null; + if ( byHostMap != null ) { + infos = byHostMap.get(hostname); + if (infos == null) { + infos = byHostMap.get(""); + } + if (infos != null) { + return infos; + } } - + return EMPTY_INFO; } - + private Map> getAuthenticationHandlers() { if (authHandlerCache == null || authHandlerTrackerCount < authHandlerTracker.getTrackingCount()) { @@ -365,31 +367,31 @@ if ( services == null || services.length == 0 ) { this.authHandlerCache = EMPTY_PROTOCOL_MAP; } else { - final Map>> byProtocolMap = new HashMap>>(); + final Map>> byProtocolMap = new HashMap>>(); int regPathCount = 0; - + for (int i = 0; i < services.length; i++) { final String paths[] = OsgiUtil.toStringArray(services[i].getProperty(AuthenticationHandler.PATH_PROPERTY)); - + if ( paths != null && paths.length > 0 ) { final AuthenticationHandler handler = (AuthenticationHandler) authHandlerTracker.getService(services[i]); - + for(int m = 0; m < paths.length; m++) { if ( paths[m] != null && paths[m].length() > 0 ) { String path = paths[m]; String host = ""; String protocol = ""; - + if(path.startsWith("http://") || path.startsWith("https://")) { int idxProtocolEnd = path.indexOf("://"); protocol = path.substring(0,idxProtocolEnd); path = path.substring(idxProtocolEnd + 1); } - + if (path.startsWith("//")) { int idxHostEnd = path.indexOf("/",2); idxHostEnd = idxHostEnd == -1 ? path.length() : idxHostEnd; - + if(path.length() > 2) { host = path.substring(2,idxHostEnd); if(idxHostEnd < path.length()) { @@ -400,22 +402,22 @@ } else { path="/"; } - } - + } + AuthenticationHandlerInfo newInfo = new AuthenticationHandlerInfo(path, host, protocol, handler); - + Map> byHostMap = byProtocolMap.get(protocol); if(byHostMap == null) { byHostMap = new HashMap>(); byProtocolMap.put(protocol, byHostMap); } - + List byPathList = byHostMap.get(host); if(byPathList == null) { byPathList = new ArrayList(); byHostMap.put(host, byPathList); } - + byPathList.add(newInfo); regPathCount++; } @@ -426,24 +428,24 @@ authHandlerCache = EMPTY_PROTOCOL_MAP; } else { authHandlerCache = new HashMap>(); - + for(Map.Entry>> protocolEntry : byProtocolMap.entrySet()) { Map> hostMap = protocolEntry.getValue(); - + Map finalHostMap = authHandlerCache.get(protocolEntry.getKey()); if(finalHostMap == null) { finalHostMap = new HashMap(); authHandlerCache.put(protocolEntry.getKey(), finalHostMap); } - + for(Map.Entry> hostEntry : hostMap.entrySet()) { List pathList = hostEntry.getValue(); - + Collections.sort(pathList, AuthenticationHandlerInfoComparator.SINGLETON); - - final AuthenticationHandlerInfo[] authInfos = + + final AuthenticationHandlerInfo[] authInfos = pathList.toArray(new AuthenticationHandlerInfo[pathList.size()]); - + finalHostMap.put(hostEntry.getKey(), authInfos); } } @@ -464,7 +466,7 @@ if (pathInfo == null || pathInfo.length() == 0) { pathInfo = "/"; } - + AuthenticationHandlerInfo[] local = findApplicableAuthenticationHandlers(request); for (int i = 0; i < local.length; i++) { if ( pathInfo.startsWith(local[i].path) ) { @@ -475,7 +477,7 @@ } } } - + // no handler found for the request .... log.debug("getCredentials: no handler could extract credentials"); return null;