Captured generic exceptions.

FEA: ItEr74S09LdapAuhentication
This commit is contained in:
Ignacio Diaz Teijido 2011-06-07 09:33:50 +02:00 committed by Manuel Rego Casasnovas
parent a2fb6d324e
commit 36eaa4014c
2 changed files with 6 additions and 43 deletions

View file

@ -41,8 +41,6 @@ import org.navalplanner.business.common.entities.LDAPConfiguration;
import org.navalplanner.business.common.entities.ProgressType;
import org.navalplanner.business.common.exceptions.ValidationException;
import org.navalplanner.web.common.components.bandboxsearch.BandboxSearch;
import org.springframework.ldap.CommunicationException;
import org.springframework.ldap.UncategorizedLdapException;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.DefaultDirObjectFactory;
@ -253,12 +251,8 @@ public class ConfigurationController extends GenericForwardComposer {
.getLdapUserId(), "test").toString(), "test");
messages.showMessage(Level.INFO,
_("LDAP connection was successful"));
} catch (UncategorizedLdapException ule) {
LOG.info(ule);
messages.showMessage(Level.ERROR,
_("Cannot connect to LDAP server"));
} catch (CommunicationException ce) {
LOG.info(ce);
} catch (Exception e) {
LOG.info(e);
messages.showMessage(Level.ERROR,
_("Cannot connect to LDAP server"));
}

View file

@ -27,9 +27,6 @@ import org.navalplanner.business.users.daos.IUserDAO;
import org.navalplanner.business.users.entities.User;
import org.navalplanner.business.users.entities.UserRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.CommunicationException;
import org.springframework.ldap.ServiceUnavailableException;
import org.springframework.ldap.UncategorizedLdapException;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.filter.EqualsFilter;
@ -227,44 +224,16 @@ public class LDAPCustomAuthenticationProvider extends
throw new BadCredentialsException(
"User is not in LDAP.");
}
} catch (CommunicationException ce) {
// This exception captures when LDAP is not reachable.
} catch (Exception e) {
// This exception captures when LDAP authentication is not
// possible
// We must in this case try to authenticate against DB.
// LDAP is not enabled we must check if the LDAP user is in
// DB
if (authenticateInDatabase(authentication, username, user)) {
// user credentials are ok
return getUserDetailsService().loadUserByUsername(
username);
} else {
throw new BadCredentialsException(
"Authenticating LDAP user against LDAP. Maybe LDAP is out of service. "
+ "Credentials are not the same as in database.");
}
} catch (UncategorizedLdapException ule) {
// This exception captures when LDAP URL is malformed
// this should never occur, but we check it to try
// database authentication.
if (authenticateInDatabase(authentication, username, user)) {
// user credentials are ok
return getUserDetailsService().loadUserByUsername(
username);
} else {
throw new BadCredentialsException(
"LDAP url is malformed. Trying to authenticate against DB. "
+ "Credentials are not the same as in database");
}
} catch (ServiceUnavailableException sua) {
// This exception captures when LDAP is not available
// We try database authentication.
if (authenticateInDatabase(authentication, username, user)) {
// user credentials are ok
return getUserDetailsService().loadUserByUsername(
username);
} else {
throw new BadCredentialsException(
"LDAP is out of service. Trying to authenticate against DB. "
+ "Credentials are not the same as in database");
throw new BadCredentialsException(e.getMessage());
}
}
} else {