Search in sources :

Example 1 with AuthenticationException

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;
}
Also used : Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) AuthenticationException(org.jbei.ice.lib.account.authentication.AuthenticationException) LocalAuthentication(org.jbei.ice.lib.account.authentication.LocalAuthentication) IAuthentication(org.jbei.ice.lib.account.authentication.IAuthentication) AuthenticationException(org.jbei.ice.lib.account.authentication.AuthenticationException) PermissionException(org.jbei.ice.lib.access.PermissionException)

Aggregations

PermissionException (org.jbei.ice.lib.access.PermissionException)1 AuthenticationException (org.jbei.ice.lib.account.authentication.AuthenticationException)1 IAuthentication (org.jbei.ice.lib.account.authentication.IAuthentication)1 LocalAuthentication (org.jbei.ice.lib.account.authentication.LocalAuthentication)1 Account (org.jbei.ice.storage.model.Account)1 Group (org.jbei.ice.storage.model.Group)1