You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2019/09/16 13:31:05 UTC

[sling-org-apache-sling-auth-core] branch master updated: SLING-8711 : NPE when auth failed event is sent

This is an automated email from the ASF dual-hosted git repository.

cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-auth-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 4e16a9c  SLING-8711 : NPE when auth failed event is sent
4e16a9c is described below

commit 4e16a9cfa6e7279fbd6469342dc9e79c2c1fd384
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Mon Sep 16 15:30:05 2019 +0200

    SLING-8711 : NPE when auth failed event is sent
---
 .../sling/auth/core/impl/SlingAuthenticator.java   | 36 ++++++++++++----------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java b/src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java
index 89f124c..12d1b34 100644
--- a/src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java
+++ b/src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java
@@ -489,7 +489,7 @@ public class SlingAuthenticator implements Authenticator,
             postProcess(authInfo, request, response);
         } catch (LoginException e) {
         	postLoginFailedEvent(request, authInfo, e);
-        	
+
             handleLoginFailure(request, response, authInfo, e);
             return false;
         }
@@ -945,21 +945,21 @@ public class SlingAuthenticator implements Authenticator,
         if (path == null || holderPath == null) {
             return false;
         }
-        
+
         if (("/").equals(holderPath)) {
             return true;
         }
-        
+
         int holderPathLength = holderPath.length();
-        
+
         if (path.length() < holderPathLength) {
             return false;
         }
-        
+
         if (path.equals(holderPath)) {
             return true;
         }
-        
+
         if (path.startsWith(holderPath)) {
             if (path.charAt(holderPathLength) == '/' || path.charAt(holderPathLength) == '.') {
                 return true;
@@ -967,8 +967,8 @@ public class SlingAuthenticator implements Authenticator,
         }
         return false;
     }
-    
-    
+
+
     /**
      * Returns credentials to use for anonymous resource access. If an anonymous
      * user is configued, this returns an {@link AuthenticationInfo} instance
@@ -1094,10 +1094,10 @@ public class SlingAuthenticator implements Authenticator,
             	code = AuthenticationHandler.FAILURE_REASON_CODES.INVALID_LOGIN;
             }
         }
-        
+
         return code;
     }
-    
+
     /**
      * Tries to request credentials from the client. The following mechanisms
      * are implemented by this method:
@@ -1538,10 +1538,14 @@ public class SlingAuthenticator implements Authenticator,
         //if reason_code is null, it is problem some non-login related failure, so don't send the event
         if (reason_code != null) {
         	final Dictionary<String, Object> properties = new Hashtable<String, Object>();
-            properties.put(SlingConstants.PROPERTY_USERID, authInfo.getUser());
-            properties.put(AuthenticationInfo.AUTH_TYPE, authInfo.getAuthType());
+            if (authInfo.getUser() != null) {
+                properties.put(SlingConstants.PROPERTY_USERID, authInfo.getUser());
+            }
+            if (authInfo.getAuthType() != null) {
+                properties.put(AuthenticationInfo.AUTH_TYPE, authInfo.getAuthType());
+            }
            	properties.put("reason_code", reason_code.name());
-            
+
             EventAdmin localEA = this.eventAdmin;
             if (localEA != null) {
                 localEA.postEvent(new Event(AuthConstants.TOPIC_LOGIN_FAILED, properties));
@@ -1615,11 +1619,11 @@ public class SlingAuthenticator implements Authenticator,
         if (value == null || value.length() == 0) {
             return value;
         }
-        
+
         if (value.startsWith("\"") && value.endsWith("\"")) {
             value = value.substring(1, value.length()-1);
         }
-        
+
         StringBuilder builder = new StringBuilder();
         String [] values = value.split("\\\\");
         for (String v:values) {
@@ -1627,7 +1631,7 @@ public class SlingAuthenticator implements Authenticator,
                 builder.append(URLDecoder.decode(v, "UTF-8"));
             } catch (UnsupportedEncodingException e) {
                 builder.append(v);
-            } 
+            }
         }
         return builder.toString();
     }