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

LDAP: Authenticated Searches without a manager password #162

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/main/distrib/data/gitblit.properties
Expand Up @@ -1516,6 +1516,15 @@ realm.ldap.username = cn=Directory Manager
# SINCE 1.0.0
realm.ldap.password = password

# Bind pattern for Authentication.
#
# Allow to authenticate an user without LDAP Searches.
#
# e.g. CN=${username},OU=Users,OU=UserControl,OU=MyOrganization,DC=MyDomain
#
realm.ldap.bindpattern =


# Delegate team membership control to LDAP.
#
# If true, team user memberships will be specified by LDAP groups. This will
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/com/gitblit/auth/LdapAuthProvider.java
Expand Up @@ -294,6 +294,20 @@ public UserModel authenticate(String username, char[] password) {
LDAPConnection ldapConnection = getLdapConnection();
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}", simpleUsername);
ldapConnection.bind(bindUser, new String(password));

alreadyAuthenticated = true;
} catch (LDAPException e) {
return null;
}
}

// Find the logging in user's DN
String accountBase = settings.getString(Keys.realm.ldap.accountBase, "");
String accountPattern = settings.getString(Keys.realm.ldap.accountPattern, "(&(objectClass=person)(sAMAccountName=${username}))");
Expand All @@ -304,7 +318,7 @@ public UserModel authenticate(String username, char[] password) {
SearchResultEntry loggingInUser = result.getSearchEntries().get(0);
String loggingInUserDN = loggingInUser.getDN();

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

UserModel user = null;
Expand Down