]> source.dussan.org Git - gitblit.git/commitdiff
Warn on LDAP synchronization if the uid attribute is null/undefined 41/41/1
authorJames Moger <james.moger@gitblit.com>
Tue, 8 Apr 2014 04:21:40 +0000 (00:21 -0400)
committerJames Moger <james.moger@gitblit.com>
Tue, 8 Apr 2014 04:21:40 +0000 (00:21 -0400)
releases.moxie
src/main/java/com/gitblit/auth/LdapAuthProvider.java

index 34e64887478cb96c68cb3021f0edb8ef8e513f85..e9a92c22009e8355b169f7040b2e97424798d10a 100644 (file)
@@ -16,6 +16,7 @@ r22: {
     - Ensure the Lucene ticket index is updated on repository deletion.
     changes:
     - Specify the --dailyLogFile option for the Ubuntu and CentOS service scripts (issue-348)
+    - Improve logging for missing LDAP uid attribute when synchronizing (issue-394)
     - The ticket close-on-push commit message regular expression is now configurable by a setting (issue-404)
     - Redirect to summary page on edit repository (issue-405)
     - Option to allow LDAP users to directly authenticate without performing LDAP searches (pr-162)
index 83f2466988916f7f8a4efc5c35710e7a55ecb353..a4d7bb0536f40a5df9baeb021973302a70007631 100644 (file)
@@ -119,8 +119,12 @@ public class LdapAuthProvider extends UsernamePasswordAuthenticationProvider {
                                                final Map<String, UserModel> ldapUsers = new HashMap<String, UserModel>();
 
                                                for (SearchResultEntry loggingInUser : result.getSearchEntries()) {
-
-                                                       final String username = loggingInUser.getAttribute(uidAttribute).getValue();
+                                                       Attribute uid = loggingInUser.getAttribute(uidAttribute);
+                                                       if (uid == null) {
+                                                               logger.error("Can not synchronize with LDAP, missing \"{}\" attribute", uidAttribute);
+                                                               continue;
+                                                       }
+                                                       final String username = uid.getValue();
                                                        logger.debug("LDAP synchronizing: " + username);
 
                                                        UserModel user = userManager.getUserModel(username);
@@ -295,13 +299,13 @@ public class LdapAuthProvider extends UsernamePasswordAuthenticationProvider {
                if (ldapConnection != null) {
                        try {
                                boolean alreadyAuthenticated = false;
-                               
+
                                String bindPattern = settings.getString(Keys.realm.ldap.bindpattern, "");
                                if (!StringUtils.isEmpty(bindPattern)) {
                                        try {
                                                String bindUser = StringUtils.replace(bindPattern, "${username}", escapeLDAPSearchFilter(simpleUsername));
                                                ldapConnection.bind(bindUser, new String(password));
-                                               
+
                                                alreadyAuthenticated = true;
                                        } catch (LDAPException e) {
                                                return null;