Search in sources :

Example 6 with OmException

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

the class TestUserGroup method addUserWithoutGroup.

@Test
public void addUserWithoutGroup() throws Exception {
    String uuid = UUID.randomUUID().toString();
    User u = getUser(uuid);
    u = userDao.update(u, null);
    assertNotNull("User successfully created", u.getId());
    checkEmptyGroup("dao.get()", userDao.get(u.getId()));
    try {
        checkEmptyGroup("dao.login()", userDao.login(u.getAddress().getEmail(), createPass()));
        fail("User with no Group is unable to login");
    } catch (OmException e) {
        assertTrue("Expected Om Exception", "error.nogroup".equals(e.getKey()));
    }
    checkEmptyGroup("dao.getByLogin(user)", userDao.getByLogin(u.getLogin(), u.getType(), u.getDomainId()));
}
Also used : GroupUser(org.apache.openmeetings.db.entity.user.GroupUser) User(org.apache.openmeetings.db.entity.user.User) OmException(org.apache.openmeetings.util.OmException) Test(org.junit.Test)

Example 7 with OmException

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

the class MobileService method loginUser.

public Map<String, Object> loginUser(String login, String password) {
    Map<String, Object> result = getResult();
    try {
        User u = userDao.login(login, password);
        result = login(u, result);
    } catch (OmException e) {
        result.put(PARAM_STATUS, e.getKey());
    } catch (Exception e) {
        log.error("[loginUser]", e);
    }
    return result;
}
Also used : User(org.apache.openmeetings.db.entity.user.User) OAuthUser(org.apache.openmeetings.db.dto.user.OAuthUser) OmException(org.apache.openmeetings.util.OmException) OmException(org.apache.openmeetings.util.OmException)

Example 8 with OmException

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

the class LdapLoginManager method importUsers.

public void importUsers(Long domainId, boolean print) throws OmException {
    try (LdapWorker w = new LdapWorker(domainId)) {
        bindAdmin(w.conn, w.options);
        Dn baseDn = new Dn(w.options.searchBase);
        try (EntryCursor cursor = new EntryCursorImpl(w.conn.search(new SearchRequestImpl().setBase(baseDn).setFilter(w.options.importQuery).setScope(w.options.scope).addAttributes("*").setDerefAliases(w.options.derefMode)))) {
            while (cursor.next()) {
                try {
                    Entry e = cursor.get();
                    User u = userDao.getByLogin(getLogin(w.config, e), Type.ldap, domainId);
                    u = w.getUser(e, u);
                    if (print) {
                        log.info("Going to import user: {}", u);
                    } else {
                        userDao.update(u, null);
                        log.info("User {}, was imported", u);
                    }
                } catch (CursorLdapReferralException cle) {
                    log.warn("Referral LDAP entry found, ignore it");
                }
            }
        }
    } 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);
    }
}
Also used : EntryCursor(org.apache.directory.api.ldap.model.cursor.EntryCursor) EntryCursorImpl(org.apache.directory.ldap.client.api.EntryCursorImpl) Entry(org.apache.directory.api.ldap.model.entry.Entry) User(org.apache.openmeetings.db.entity.user.User) GroupUser(org.apache.openmeetings.db.entity.user.GroupUser) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) CursorLdapReferralException(org.apache.directory.api.ldap.model.cursor.CursorLdapReferralException) 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)

Example 9 with OmException

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

the class AbstractWicketTester method login.

public void login(String login, String password) {
    WebSession s = WebSession.get();
    try {
        if (login != null && password != null) {
            s.signIn(login, password, Type.user, null);
        } else {
            s.signIn(adminUsername, userpass, Type.user, null);
        }
    } catch (OmException e) {
        fail(e.getMessage());
    }
    assertTrue("Web session is not signed in for user: " + (login != null ? login : adminUsername), s.isSignedIn());
}
Also used : WebSession(org.apache.openmeetings.web.app.WebSession) OmException(org.apache.openmeetings.util.OmException)

Example 10 with OmException

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

the class UserWebService method login.

/**
 * @param user - login or email of Openmeetings user with admin or SOAP-rights
 * @param pass - password
 *
 * @return - {@link ServiceResult} with error code or SID and userId
 */
@WebMethod
@GET
@Path("/login")
public ServiceResult login(@WebParam(name = "user") @QueryParam("user") String user, @WebParam(name = "pass") @QueryParam("pass") String pass) {
    try {
        log.debug("Login user");
        User u = userDao.login(user, pass);
        if (u == null) {
            return new ServiceResult("error.bad.credentials", Type.ERROR);
        }
        Sessiondata sd = sessionDao.create(u.getId(), u.getLanguageId());
        log.debug("Login user: {}", u.getId());
        return new ServiceResult(sd.getSessionId(), Type.SUCCESS);
    } catch (OmException oe) {
        return oe.getKey() == null ? UNKNOWN : new ServiceResult(oe.getKey(), Type.ERROR);
    } catch (Exception err) {
        log.error("[login]", err);
        return UNKNOWN;
    }
}
Also used : User(org.apache.openmeetings.db.entity.user.User) ServiceResult(org.apache.openmeetings.db.dto.basic.ServiceResult) Sessiondata(org.apache.openmeetings.db.entity.server.Sessiondata) OmException(org.apache.openmeetings.util.OmException) OmException(org.apache.openmeetings.util.OmException) ServiceException(org.apache.openmeetings.webservice.error.ServiceException) WebMethod(javax.jws.WebMethod) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

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