Search in sources :

Example 1 with OmException

use of org.apache.openmeetings.util.OmException in project openmeetings by apache.

the class UserDao method login.

/**
 * login logic
 *
 * @param userOrEmail - login or email of the user being tested
 * @param userpass - password of the user being tested
 * @return User object in case of successful login
 * @throws OmException in case of any issue
 */
public User login(String userOrEmail, String userpass) throws OmException {
    List<User> users = em.createNamedQuery("getUserByLoginOrEmail", User.class).setParameter("userOrEmail", userOrEmail).setParameter("type", Type.user).getResultList();
    log.debug("login:: {} users were found", users.size());
    if (users.isEmpty()) {
        log.debug("No users was found: {}", userOrEmail);
        return null;
    }
    User u = users.get(0);
    if (!verifyPassword(u.getId(), userpass)) {
        log.debug("Password does not match: {}", u);
        return null;
    }
    // Check if activated
    if (!AuthLevelUtil.hasLoginLevel(u.getRights())) {
        log.debug("Not activated: {}", u);
        throw new OmException("error.notactivated");
    }
    log.debug("loginUser " + u.getGroupUsers());
    if (u.getGroupUsers().isEmpty()) {
        log.debug("No Group assigned: {}", u);
        throw new OmException("error.nogroup");
    }
    u.setLastlogin(new Date());
    return update(u, u.getId());
}
Also used : User(org.apache.openmeetings.db.entity.user.User) OmException(org.apache.openmeetings.util.OmException) Date(java.util.Date)

Example 2 with OmException

use of org.apache.openmeetings.util.OmException in project openmeetings by apache.

the class WebSession method isSignedIn.

@Override
public boolean isSignedIn() {
    if (userId == null) {
        IAuthenticationStrategy strategy = getAuthenticationStrategy();
        // get username and password from persistence store
        String[] data = strategy.load();
        if (data != null && data.length > 3 && data[2] != null) {
            Long domainId = null;
            try {
                domainId = Long.valueOf(data[3]);
            } catch (Exception e) {
            // no-op
            }
            // try to sign in the user
            try {
                if (!signIn(data[0], data[1], Type.valueOf(data[2]), domainId)) {
                    // the loaded credentials are wrong. erase them.
                    strategy.remove();
                }
            } catch (OmException e) {
            // no-op, bad credentials
            }
        }
    }
    return userId != null && userId.longValue() > 0;
}
Also used : IAuthenticationStrategy(org.apache.wicket.authentication.IAuthenticationStrategy) OmException(org.apache.openmeetings.util.OmException) OmException(org.apache.openmeetings.util.OmException)

Example 3 with OmException

use of org.apache.openmeetings.util.OmException in project openmeetings by apache.

the class WebSession method signIn.

public boolean signIn(String login, String password, Type type, Long domainId) throws OmException {
    User u;
    switch(type) {
        case ldap:
            u = ldapManager.login(login, password, domainId);
            break;
        case user:
            /* we will allow login against internal DB in case user 'guess' LDAP password */
            u = userDao.login(login, password);
            break;
        case oauth:
            // we did all the checks at this stage, just set the user
            u = userDao.getByLogin(login, Type.oauth, domainId);
            break;
        default:
            throw new OmException("error.unknown");
    }
    if (u == null) {
        return false;
    }
    signIn(u);
    return true;
}
Also used : User(org.apache.openmeetings.db.entity.user.User) GroupUser(org.apache.openmeetings.db.entity.user.GroupUser) OmException(org.apache.openmeetings.util.OmException)

Example 4 with OmException

use of org.apache.openmeetings.util.OmException in project openmeetings by apache.

the class SignInDialog method onSubmit.

@Override
protected void onSubmit(AjaxRequestTarget target) {
    if (domain.getAddDomainToUserName()) {
        login = login + "@" + domain.getDomain();
    }
    OmAuthenticationStrategy strategy = getAuthenticationStrategy();
    WebSession ws = WebSession.get();
    Type type = domain.getId() > 0 ? Type.ldap : Type.user;
    boolean signIn = false;
    try {
        signIn = ws.signIn(login, password, type, domain.getId());
    } catch (OmException e) {
        error(getString(e.getKey()));
        target.add(feedback);
    }
    if (signIn) {
        setResponsePage(Application.get().getHomePage());
        if (rememberMe) {
            strategy.save(login, password, type, domain.getId());
        } else {
            strategy.remove();
        }
    } else {
        if (!hasErrorMessage()) {
            error(getString("error.bad.credentials"));
            target.add(feedback);
        }
        // add random timeout
        try {
            Thread.sleep(6 + (long) (10 * Math.random() * 1000));
        } catch (InterruptedException e) {
            log.error("Unexpected exception while sleeping", e);
        }
        strategy.remove();
        shake(target);
    }
}
Also used : Type(org.apache.openmeetings.db.entity.user.User.Type) WebSession(org.apache.openmeetings.web.app.WebSession) OmException(org.apache.openmeetings.util.OmException) OmAuthenticationStrategy(org.apache.openmeetings.web.app.OmAuthenticationStrategy)

Example 5 with OmException

use of org.apache.openmeetings.util.OmException in project openmeetings by apache.

the class LdapLoginManager method login.

/**
 * Ldap Login
 *
 * Connection Data is retrieved from ConfigurationFile
 *
 * @param _login - user login
 * @param passwd - user password
 * @param domainId - user domain id
 * @return - {@link User} with this credentials or <code>null</code>
 * @throws OmException - in case of any error
 */
public User login(String _login, String passwd, Long domainId) throws OmException {
    log.debug("LdapLoginmanager.doLdapLogin");
    if (!userDao.validLogin(_login)) {
        log.error("Invalid login provided");
        return null;
    }
    User u = null;
    try (LdapWorker w = new LdapWorker(domainId)) {
        String login = w.options.useLowerCase ? _login.toLowerCase() : _login;
        boolean authenticated = true;
        Dn userDn = null;
        Entry entry = null;
        switch(w.options.type) {
            case SEARCHANDBIND:
                {
                    bindAdmin(w.conn, w.options);
                    Dn baseDn = new Dn(w.options.searchBase);
                    String searchQ = String.format(w.options.searchQuery, login);
                    try (EntryCursor cursor = new EntryCursorImpl(w.conn.search(new SearchRequestImpl().setBase(baseDn).setFilter(searchQ).setScope(w.options.scope).addAttributes("*").setDerefAliases(w.options.derefMode)))) {
                        while (cursor.next()) {
                            try {
                                Entry e = cursor.get();
                                if (userDn != null) {
                                    log.error("more than 1 user found in LDAP");
                                    throw UNKNOWN;
                                }
                                userDn = e.getDn();
                                if (w.options.useAdminForAttrs) {
                                    entry = e;
                                }
                            } catch (CursorLdapReferralException cle) {
                                log.warn("Referral LDAP entry found, ignore it");
                            }
                        }
                    }
                    if (userDn == null) {
                        log.error("NONE users found in LDAP");
                        throw BAD_CREDENTIALS;
                    }
                    w.conn.bind(userDn, passwd);
                }
                break;
            case SIMPLEBIND:
                userDn = new Dn(String.format(w.options.userDn, login));
                w.conn.bind(userDn, passwd);
                break;
            case NONE:
            default:
                authenticated = false;
                break;
        }
        u = authenticated ? userDao.getByLogin(login, Type.ldap, domainId) : userDao.login(login, passwd);
        log.debug("getByLogin:: authenticated ? {}, login = '{}', domain = {}, user = {}", authenticated, login, domainId, u);
        if (u == null && Provisionning.AUTOCREATE != w.options.prov) {
            log.error("User not found in OM DB and Provisionning.AUTOCREATE was not set");
            throw BAD_CREDENTIALS;
        }
        if (authenticated && entry == null) {
            if (w.options.useAdminForAttrs) {
                bindAdmin(w.conn, w.options);
            }
            entry = w.conn.lookup(userDn);
        }
        switch(w.options.prov) {
            case AUTOUPDATE:
            case AUTOCREATE:
                u = w.getUser(entry, u);
                if (w.options.syncPasswd) {
                    u.updatePassword(cfgDao, passwd);
                }
                u = userDao.update(u, null);
                break;
            case NONE:
            default:
                break;
        }
    } catch (LdapAuthenticationException ae) {
        log.error("Not authenticated.", ae);
        throw BAD_CREDENTIALS;
    } catch (OmException e) {
        throw e;
    } catch (Exception e) {
        log.error("Unexpected exception.", e);
        throw new OmException(e);
    }
    return u;
}
Also used : EntryCursor(org.apache.directory.api.ldap.model.cursor.EntryCursor) EntryCursorImpl(org.apache.directory.ldap.client.api.EntryCursorImpl) User(org.apache.openmeetings.db.entity.user.User) GroupUser(org.apache.openmeetings.db.entity.user.GroupUser) SearchRequestImpl(org.apache.directory.api.ldap.model.message.SearchRequestImpl) Dn(org.apache.directory.api.ldap.model.name.Dn) OmException(org.apache.openmeetings.util.OmException) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) CursorLdapReferralException(org.apache.directory.api.ldap.model.cursor.CursorLdapReferralException) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) OmException(org.apache.openmeetings.util.OmException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) IOException(java.io.IOException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Entry(org.apache.directory.api.ldap.model.entry.Entry) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) CursorLdapReferralException(org.apache.directory.api.ldap.model.cursor.CursorLdapReferralException)

Aggregations

OmException (org.apache.openmeetings.util.OmException)10 User (org.apache.openmeetings.db.entity.user.User)7 GroupUser (org.apache.openmeetings.db.entity.user.GroupUser)4 IOException (java.io.IOException)2 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)2 CursorLdapReferralException (org.apache.directory.api.ldap.model.cursor.CursorLdapReferralException)2 EntryCursor (org.apache.directory.api.ldap.model.cursor.EntryCursor)2 Entry (org.apache.directory.api.ldap.model.entry.Entry)2 LdapAuthenticationException (org.apache.directory.api.ldap.model.exception.LdapAuthenticationException)2 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)2 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)2 SearchRequestImpl (org.apache.directory.api.ldap.model.message.SearchRequestImpl)2 Dn (org.apache.directory.api.ldap.model.name.Dn)2 EntryCursorImpl (org.apache.directory.ldap.client.api.EntryCursorImpl)2 WebSession (org.apache.openmeetings.web.app.WebSession)2 Date (java.util.Date)1 WebMethod (javax.jws.WebMethod)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 ServiceResult (org.apache.openmeetings.db.dto.basic.ServiceResult)1