use of org.jbei.ice.lib.account.authentication.AuthenticationException in project ice by JBEI.
the class AccountController method authenticate.
/**
* Authenticate a user in the database.
* <p>
* Using the {@link org.jbei.ice.lib.account.authentication.IAuthentication} specified in the
* settings file, authenticate the user, and return the sessionData
*
* @param login
* @param password
* @param ip IP Address of the user.
* @return the account identifier (email) on a successful login, otherwise {@code null}
*/
protected Account authenticate(final String login, final String password, final String ip) {
final IAuthentication authentication = new LocalAuthentication();
String email;
try {
email = authentication.authenticates(login.trim(), password);
if (email == null) {
loginFailureCooldown();
return null;
}
} catch (final AuthenticationException e2) {
loginFailureCooldown();
return null;
}
Account account = dao.getByEmail(email);
if (account == null)
return null;
// add to public groups
List<Group> groups = groupDAO.getGroupsBy(GroupType.PUBLIC, true);
try {
if (groups != null) {
for (Group group : groups) {
account.getGroups().add(group);
}
dao.update(account);
}
} catch (Exception e) {
Logger.error(e);
}
account.setIp(ip);
account.setLastLoginTime(Calendar.getInstance().getTime());
account = save(account);
UserSessions.createNewSessionForUser(account.getEmail());
return account;
}
Aggregations