Skip to content

(ticket-537) user bindUser for group detection #925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/distrib/data/gitblit.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,13 @@ realm.ldap.username = cn=Directory Manager
# SINCE 1.0.0
realm.ldap.password = password

# After sucessfull user ldap authentication
# when true the group query will be executed with as the new user
# when false the group query will be executed under the realm.ldap.username
#
# SINCE 1.6.3
realm.ldap.groupQueryWithUser = false

# Bind pattern for Authentication.
# Allow to directly authenticate an user without LDAP Searches.
#
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/com/gitblit/auth/LdapAuthProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ public UserModel authenticate(String username, char[] password) {
if (result != null && result.getEntryCount() == 1) {
SearchResultEntry loggingInUser = result.getSearchEntries().get(0);
String loggingInUserDN = loggingInUser.getDN();

if (alreadyAuthenticated || isAuthenticated(ldapConnection, loggingInUserDN, new String(password))) {
logger.debug("LDAP authenticated: " + username);

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

private void getTeamsFromLdap(LDAPConnection ldapConnection, String simpleUsername, SearchResultEntry loggingInUser, UserModel user) {
String loggingInUserDN = loggingInUser.getDN();

// Clear the users team memberships - we're going to get them from LDAP
user.teams.clear();

Expand Down Expand Up @@ -533,13 +531,22 @@ private SearchResult doSearch(LDAPConnection ldapConnection, String base, boolea
}

private boolean isAuthenticated(LDAPConnection ldapConnection, String userDn, String password) {
LDAPConnection authldapConnection = getLdapConnection();
try {
// Binding will stop any LDAP-Injection Attacks since the searched-for user needs to bind to that DN
ldapConnection.bind(userDn, password);
if (settings.getBoolean(Keys.realm.ldap.groupQueryWithUser, false)
&& !StringUtils.isEmpty(settings.getString(Keys.realm.ldap.username, "")) ) {
// bind authConnection to user
authldapConnection.bind(userDn, password);
} else {
// Binding will stop any LDAP-Injection Attacks since the searched-for user needs to bind to that DN
ldapConnection.bind(userDn, password);
}
return true;
} catch (LDAPException e) {
logger.error("Error authenticating user", e);
return false;
} finally {
authldapConnection.close();
}
}

Expand Down