if (ldapConfig.getUserDnPattern() == null && ldapConfig.getUserFilter() == null) {
error("Neither user dn pattern or user filter specified");
return;
}
LDAPSecurityProvider provider = new LDAPSecurityProvider(getSecurityManager());
LDAPAuthenticationProvider authProvider = (LDAPAuthenticationProvider) provider
.createAuthenticationProvider(ldapConfig);
Authentication authentication = authProvider
.authenticate(new UsernamePasswordAuthenticationToken(
username, password));
if(authentication == null || !authentication.isAuthenticated()) {
throw new AuthenticationException("Cannot authenticate " + username);
}
provider.destroy(null);
info(new StringResourceModel(LDAPAuthProviderPanel.class.getSimpleName() +
".connectionSuccessful", null).getObject());
} catch (Exception e) {
error(e);
LOGGER.log(Level.WARNING, e.getMessage(), e);