Skip to content

Commit f04f891

Browse files
committed
gitblit-org#247 allow enable/disable of ldap bind switch via config
new config key : "realm.ldap.groupQueryWithUser"
1 parent 5e0491c commit f04f891

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/main/distrib/data/gitblit.properties

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,13 @@ realm.ldap.username = cn=Directory Manager
16241624
# SINCE 1.0.0
16251625
realm.ldap.password = password
16261626

1627+
# After sucessfull user ldap authentication
1628+
# when true the group query will be executed with as the new user
1629+
# when false the group query will be executed under the realm.ldap.username
1630+
#
1631+
# SINCE 1.6.3
1632+
realm.ldap.groupQueryWithUser = false
1633+
16271634
# Bind pattern for Authentication.
16281635
# Allow to directly authenticate an user without LDAP Searches.
16291636
#

src/main/java/com/gitblit/auth/LdapAuthProvider.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ public UserModel authenticate(String username, char[] password) {
321321
if (result != null && result.getEntryCount() == 1) {
322322
SearchResultEntry loggingInUser = result.getSearchEntries().get(0);
323323
String loggingInUserDN = loggingInUser.getDN();
324-
325324
if (alreadyAuthenticated || isAuthenticated(ldapConnection, loggingInUserDN, new String(password))) {
326325
logger.debug("LDAP authenticated: " + username);
327326

@@ -438,7 +437,6 @@ private void setUserAttributes(UserModel user, SearchResultEntry userEntry) {
438437

439438
private void getTeamsFromLdap(LDAPConnection ldapConnection, String simpleUsername, SearchResultEntry loggingInUser, UserModel user) {
440439
String loggingInUserDN = loggingInUser.getDN();
441-
442440
// Clear the users team memberships - we're going to get them from LDAP
443441
user.teams.clear();
444442

@@ -533,13 +531,22 @@ private SearchResult doSearch(LDAPConnection ldapConnection, String base, boolea
533531
}
534532

535533
private boolean isAuthenticated(LDAPConnection ldapConnection, String userDn, String password) {
534+
LDAPConnection authldapConnection = getLdapConnection();
536535
try {
537-
// Binding will stop any LDAP-Injection Attacks since the searched-for user needs to bind to that DN
538-
ldapConnection.bind(userDn, password);
536+
if (settings.getBoolean(Keys.realm.ldap.groupQueryWithUser, false)
537+
&& !StringUtils.isEmpty(settings.getString(Keys.realm.ldap.username, "")) ) {
538+
// bind authConnection to user
539+
authldapConnection.bind(userDn, password);
540+
} else {
541+
// Binding will stop any LDAP-Injection Attacks since the searched-for user needs to bind to that DN
542+
ldapConnection.bind(userDn, password);
543+
}
539544
return true;
540545
} catch (LDAPException e) {
541546
logger.error("Error authenticating user", e);
542547
return false;
548+
} finally {
549+
authldapConnection.close();
543550
}
544551
}
545552

0 commit comments

Comments
 (0)