Skip to content
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

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

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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