use of org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser in project jackrabbit-oak by apache.
the class LdapIdentityProvider method authenticate.
@Override
public ExternalUser authenticate(@Nonnull Credentials credentials) throws ExternalIdentityException, LoginException {
if (!(credentials instanceof SimpleCredentials)) {
log.debug("LDAP IDP can only authenticate SimpleCredentials.");
return null;
}
final SimpleCredentials creds = (SimpleCredentials) credentials;
final ExternalUser user = getUser(creds.getUserID());
if (user != null) {
// see http://tools.ietf.org/html/rfc4513#section-5.1.1 for details.
if (creds.getPassword().length == 0) {
throw new LoginException("Refusing to authenticate against LDAP server: Empty passwords not allowed.");
}
// authenticate
LdapConnection connection = null;
try {
DebugTimer timer = new DebugTimer();
if (userPool == null) {
connection = userConnectionFactory.makeObject();
} else {
connection = userPool.getConnection();
}
timer.mark("connect");
connection.bind(user.getExternalId().getId(), new String(creds.getPassword()));
timer.mark("bind");
if (log.isDebugEnabled()) {
log.debug("authenticate({}) {}", user.getId(), timer.getString());
}
} catch (LdapAuthenticationException e) {
throw new LoginException("Unable to authenticate against LDAP server: " + e.getMessage());
} catch (Exception e) {
throw new ExternalIdentityException("Error while binding user credentials", e);
} finally {
if (connection != null) {
try {
if (userPool == null) {
userConnectionFactory.destroyObject(connection);
} else {
userPool.releaseConnection(connection);
}
} catch (Exception e) {
// ignore
}
}
}
}
return user;
}
use of org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser in project jackrabbit-oak by apache.
the class LdapProviderTest method testAuthenticateValidateFalseTrue.
@Test
public void testAuthenticateValidateFalseTrue() throws Exception {
providerConfig.getAdminPoolConfig().setMaxActive(2).setLookupOnValidate(false);
providerConfig.getUserPoolConfig().setMaxActive(2).setLookupOnValidate(true);
idp.close();
idp = new LdapIdentityProvider(providerConfig);
SimpleCredentials creds = new SimpleCredentials(TEST_USER1_UID, "pass".toCharArray());
for (int i = 0; i < 8; i++) {
ExternalUser user = idp.authenticate(creds);
assertNotNull("User 1 must authenticate", user);
assertEquals("User Ref", TEST_USER1_DN, user.getExternalId().getId());
}
}
use of org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser in project jackrabbit-oak by apache.
the class LdapProviderTest method testResolvePrincipalNameUser.
@Test
public void testResolvePrincipalNameUser() throws ExternalIdentityException {
ExternalUser user = idp.getUser(TEST_USER5_UID);
assertNotNull(user);
assertEquals(user.getPrincipalName(), idp.fromExternalIdentityRef(user.getExternalId()));
}
use of org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser in project jackrabbit-oak by apache.
the class LdapProviderTest method testGetUserByUserId.
@Test
public void testGetUserByUserId() throws Exception {
ExternalUser user = idp.getUser(TEST_USER1_UID);
assertNotNull("User 1 must exist", user);
assertEquals("User Ref", TEST_USER1_DN, user.getExternalId().getId());
}
use of org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser in project jackrabbit-oak by apache.
the class LdapProviderTest method testAuthenticateValidateTrueFalse.
@Test
public void testAuthenticateValidateTrueFalse() throws Exception {
providerConfig.getAdminPoolConfig().setMaxActive(2).setLookupOnValidate(true);
providerConfig.getUserPoolConfig().setMaxActive(2).setLookupOnValidate(false);
idp.close();
idp = new LdapIdentityProvider(providerConfig);
SimpleCredentials creds = new SimpleCredentials(TEST_USER1_UID, "pass".toCharArray());
for (int i = 0; i < 8; i++) {
ExternalUser user = idp.authenticate(creds);
assertNotNull("User 1 must authenticate (i=" + i + ")", user);
assertEquals("User Ref", TEST_USER1_DN, user.getExternalId().getId());
}
}
Aggregations