Search in sources :

Example 1 with IAuthentication

use of org.jbei.ice.lib.account.authentication.IAuthentication 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;
    AccountPreferences accountPreferences = accountPreferencesDAO.getAccountPreferences(account);
    if (accountPreferences == null) {
        accountPreferences = new AccountPreferences();
        accountPreferences.setAccount(account);
        accountPreferencesDAO.create(accountPreferences);
    }
    // add to public groups
    List<Group> groups = groupDAO.getGroupsBy(GroupType.PUBLIC, true);
    try {
        if (groups != null) {
            for (Group group : groups) {
                if (!account.getGroups().contains(group)) {
                    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) AccountPreferences(org.jbei.ice.storage.model.AccountPreferences)

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 AccountPreferences (org.jbei.ice.storage.model.AccountPreferences)1 Group (org.jbei.ice.storage.model.Group)1