LdapAuthenticationFilter extends OncePerRequestFilter { boolean authenticate(final LDAPConnection ldap, final String userDN, final String password) throws LDAPException { final BindResult bindResult = ldap.bind(userDN, password); if (bindResult.getResultCode().equals(ResultCode.SUCCESS)) { LOG.debug("Login successful: " + userDN); return true; } else { LOG.warn("Access denied: " + userDN); return false; } } LdapAuthenticationFilter(final LdapProperties ldapProperties, final LdapConnectionFactory ldapConnectionFactory);   }
@Test public void shouldAuthenticateUser() throws LDAPException { final boolean authenticated = testee.authenticate(someLdapConnectionReturning(SUCCESS), "user", "password"); assertThat(authenticated).isEqualTo(true); }
@Test public void shouldNotAuthenticateUser() throws LDAPException { final boolean authenticated = testee.authenticate(someLdapConnectionReturning(AUTHORIZATION_DENIED), "user", "password"); assertThat(authenticated).isEqualTo(false); }