use of com.unboundid.ldap.sdk.BindResult in project spring-boot by spring-projects.
the class EmbeddedLdapAutoConfigurationTests method testSetCredentials.
@Test
public void testSetCredentials() throws LDAPException {
load("spring.ldap.embedded.base-dn:dc=spring,dc=org", "spring.ldap.embedded.credential.username:uid=root", "spring.ldap.embedded.credential.password:boot");
InMemoryDirectoryServer server = this.context.getBean(InMemoryDirectoryServer.class);
BindResult result = server.bind("uid=root", "boot");
assertThat(result).isNotNull();
}
use of com.unboundid.ldap.sdk.BindResult in project gitblit by gitblit.
the class LdapConnection method bind.
/**
* Bind using the given credentials, by filling in the username in the given {@code bindPattern} to
* create the DN.
* @return A bind result, or null if binding failed.
*/
public BindResult bind(String bindPattern, String simpleUsername, String password) {
BindResult result = null;
try {
String bindUser = StringUtils.replace(bindPattern, "${username}", escapeLDAPSearchFilter(simpleUsername));
SimpleBindRequest request = new SimpleBindRequest(bindUser, password);
result = conn.bind(request);
userBindRequest = request;
currentBindRequest = userBindRequest;
} catch (LDAPException e) {
logger.error("Error authenticating to LDAP with user account to search the directory.");
logger.error(" Please check your settings for realm.ldap.bindpattern.");
logger.debug(" Received exception when binding to LDAP", e);
return null;
}
return result;
}
use of com.unboundid.ldap.sdk.BindResult in project gitblit by gitblit.
the class LdapAuthProvider method authenticate.
@Override
public UserModel authenticate(String username, char[] password) {
String simpleUsername = getSimpleUsername(username);
LdapConnection ldapConnection = new LdapConnection(settings);
if (ldapConnection.connect()) {
// Try to bind either to the "manager" account,
// or directly to the DN of the user logging in, if realm.ldap.bindpattern is configured.
String passwd = new String(password);
BindResult bindResult = null;
String bindPattern = settings.getString(Keys.realm.ldap.bindpattern, "");
if (!StringUtils.isEmpty(bindPattern)) {
bindResult = ldapConnection.bind(bindPattern, simpleUsername, passwd);
} else {
bindResult = ldapConnection.bind();
}
if (bindResult == null) {
ldapConnection.close();
return null;
}
try {
// Find the logging in user's DN
SearchResult result = ldapConnection.searchUser(simpleUsername);
if (result != null && result.getEntryCount() == 1) {
SearchResultEntry loggingInUser = result.getSearchEntries().get(0);
String loggingInUserDN = loggingInUser.getDN();
if (ldapConnection.isAuthenticated(loggingInUserDN, passwd)) {
logger.debug("LDAP authenticated: " + username);
UserModel user = null;
synchronized (this) {
user = userManager.getUserModel(simpleUsername);
if (user == null) {
// create user object for new authenticated user
user = new UserModel(simpleUsername);
}
// create a user cookie
setCookie(user);
if (!supportsTeamMembershipChanges()) {
getTeamsFromLdap(ldapConnection, simpleUsername, loggingInUser, user);
}
// Get User Attributes
setUserAttributes(user, loggingInUser);
// Push the ldap looked up values to backing file
updateUser(user);
if (!supportsTeamMembershipChanges()) {
for (TeamModel userTeam : user.teams) {
// Is this an administrative team?
setAdminAttribute(userTeam);
updateTeam(userTeam);
}
}
}
return user;
}
}
} finally {
ldapConnection.close();
}
}
return null;
}
use of com.unboundid.ldap.sdk.BindResult in project gitblit by gitblit.
the class LdapConnectionTest method testBindAsAdmin.
@Test
public void testBindAsAdmin() {
// This test tests for anonymous bind, so run only in authentication mode DS_MANAGER.
assumeTrue(authMode == AuthMode.DS_MANAGER);
LdapConnection conn = new LdapConnection(settings);
try {
assertTrue(conn.connect());
BindResult br = conn.bind();
assertNotNull(br);
assertEquals(ResultCode.SUCCESS, br.getResultCode());
assertEquals(settings.getString(Keys.realm.ldap.username, "UNSET"), authMode.getBindTracker().getLastSuccessfulBindDN(br.getMessageID()));
} finally {
conn.close();
}
}
use of com.unboundid.ldap.sdk.BindResult in project gitblit by gitblit.
the class LdapConnectionTest method testBindAnonymous.
@Test
public void testBindAnonymous() {
// This test tests for anonymous bind, so run only in authentication mode ANONYMOUS.
assumeTrue(authMode == AuthMode.ANONYMOUS);
LdapConnection conn = new LdapConnection(settings);
try {
assertTrue(conn.connect());
BindResult br = conn.bind();
assertNotNull(br);
assertEquals(ResultCode.SUCCESS, br.getResultCode());
assertEquals("", authMode.getBindTracker().getLastSuccessfulBindDN(br.getMessageID()));
} finally {
conn.close();
}
}
Aggregations