org.springframework.ldap.AuthenticationException Java Examples

The following examples show how to use org.springframework.ldap.AuthenticationException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LdapTemplateAuthenticationITest.java    From spring-ldap with Apache License 2.0 5 votes vote down vote up
@Test(expected = AuthenticationException.class)
@Category(NoAdTest.class)
public void testAuthenticateWithLdapQueryAndInvalidPassword() {
    AndFilter filter = new AndFilter();
    filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
    tested.authenticate(query()
            .where("objectclass").is("person")
            .and("uid").is("some.person3"),
            "invalidpassword");
}
 
Example #2
Source File: LdapTemplateAuthenticationITest.java    From spring-ldap with Apache License 2.0 5 votes vote down vote up
@Test(expected = AuthenticationException.class)
@Category(NoAdTest.class)
public void testAuthenticateWithLdapQueryAndMapperAndInvalidPassword() {
    DirContextOperations ctx = tested.authenticate(query()
            .where("objectclass").is("person")
            .and("uid").is("some.person3"),
            "invalidpassword",
            new LookupAttemptingCallback());
}
 
Example #3
Source File: LdapTemplateAuthenticationITest.java    From spring-ldap with Apache License 2.0 5 votes vote down vote up
@Test
   @Category(NoAdTest.class)
public void testAuthenticateWithInvalidPasswordAndCollectedException() {
	AndFilter filter = new AndFilter();
	filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
	final CollectingAuthenticationErrorCallback errorCallback = new CollectingAuthenticationErrorCallback();
	assertThat(tested.authenticate("", filter.toString(), "invalidpassword", errorCallback)).isFalse();
	final Exception error = errorCallback.getError();
	assertThat(error).as("collected error should not be null").isNotNull();
	assertThat(error instanceof AuthenticationException).as("expected org.springframework.ldap.AuthenticationException").isTrue();
	assertThat(error.getCause() instanceof javax.naming.AuthenticationException).as("expected javax.naming.AuthenticationException").isTrue();
}
 
Example #4
Source File: LdapTemplate.java    From spring-ldap with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public <T> T authenticate(LdapQuery query, String password, AuthenticatedLdapEntryContextMapper<T> mapper) {
    SearchControls searchControls = searchControlsForQuery(query, RETURN_OBJ_FLAG);
    ReturningAuthenticatedLdapEntryContext<T> mapperCallback =
            new ReturningAuthenticatedLdapEntryContext<T>(mapper);
    CollectingAuthenticationErrorCallback errorCallback =
            new CollectingAuthenticationErrorCallback();

    AuthenticationStatus authenticationStatus = authenticate(query.base(),
            query.filter().encode(),
            password,
            searchControls,
            mapperCallback,
            errorCallback);

    if(errorCallback.hasError()) {
        Exception error = errorCallback.getError();

        if (error instanceof NamingException) {
            throw (NamingException) error;
        } else {
            throw new UncategorizedLdapException(error);
        }
    } else if(AuthenticationStatus.EMPTYRESULT == authenticationStatus) {
    	throw new EmptyResultDataAccessException(1);
    } else if(!authenticationStatus.isSuccess()) {
        throw new AuthenticationException();
    }

    return mapperCallback.collectedObject;
}
 
Example #5
Source File: LdapClientLiveTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test(expected = AuthenticationException.class)
public void givenLdapClient_whenIncorrectCredentials_thenFailedLogin() {
    ldapClient.authenticate(USER3, USER2_PWD);
}