Since it's taking a long time, I'll settle with the two accounts approach (one for the administrator to check the user and the one you want to log).
I've been following the excellent blog entry from Niklas that provided all the info I needed.
The final code is:
Code:
private String _managerDn = "CN=manager, CN=users, DC=domain, DC=com";
private String _managerPassword = "managerPassword";
private String _url = "ldap://ldapServer:389";
private String _userBase = "CN=users, DC=domain, DC=com";
DefaultInitialDirContextFactory ctxFactory = new DefaultInitialDirContextFactory(_url);
ctxFactory.setManagerDn( _managerDn );
ctxFactory.setManagerPassword( _managerPassword );
FilterBasedLdapUserSearch userSearch = new FilterBasedLdapUserSearch(_userBase, "(sAMAccountName={0})", ctxFactory);
userSearch.setSearchSubtree( true );
BindAuthenticator bindAuthenticator = new BindAuthenticator(ctxFactory);
bindAuthenticator.setUserSearch( userSearch );
try {
bindAuthenticator.afterPropertiesSet();
bindAuthenticator.authenticate( "userName", "userPassword");
} catch ( Exception e ) {
throw new RuntimeException( e );
}
Best regards and thanks for the help !
Juan Medín