Search in sources :

Example 76 with User

use of org.apache.openmeetings.db.entity.user.User in project openmeetings by apache.

the class UserDao method checkEmail.

/**
 * Checks if a mail is already taken by someone else
 *
 * @param email - email to check
 * @param type - user {@link Type} to check
 * @param domainId - domain to check
 * @param id - id of current user to allow self update
 * @return <code>true</code> in case email is allowed
 */
public boolean checkEmail(String email, Type type, Long domainId, Long id) {
    log.debug("checkEmail: email = {}, id = {}", email, id);
    User u = getByEmail(email, type, domainId);
    return u == null || u.getId().equals(id);
}
Also used : User(org.apache.openmeetings.db.entity.user.User)

Example 77 with User

use of org.apache.openmeetings.db.entity.user.User in project openmeetings by apache.

the class UserDao method getAllBackupUsers.

public List<User> getAllBackupUsers() {
    OpenJPAEntityManager oem = OpenJPAPersistence.cast(em);
    boolean qrce = oem.getFetchPlan().getQueryResultCacheEnabled();
    try {
        // update in cache during update
        oem.getFetchPlan().setQueryResultCacheEnabled(false);
        TypedQuery<User> q = oem.createNamedQuery("getAllUsers", User.class);
        @SuppressWarnings("unchecked") OpenJPAQuery<User> kq = OpenJPAPersistence.cast(q);
        kq.getFetchPlan().addFetchGroups("backupexport", "groupUsers");
        return kq.getResultList();
    } finally {
        oem.getFetchPlan().setQueryResultCacheEnabled(qrce);
    }
}
Also used : OpenJPAEntityManager(org.apache.openjpa.persistence.OpenJPAEntityManager) User(org.apache.openmeetings.db.entity.user.User)

Example 78 with User

use of org.apache.openmeetings.db.entity.user.User in project openmeetings by apache.

the class UserDao method get.

private User get(Long id, boolean force) {
    User u = null;
    if (id != null && id.longValue() > 0) {
        OpenJPAEntityManager oem = OpenJPAPersistence.cast(em);
        boolean qrce = oem.getFetchPlan().getQueryResultCacheEnabled();
        try {
            // update in cache during update
            oem.getFetchPlan().setQueryResultCacheEnabled(false);
            TypedQuery<User> q = oem.createNamedQuery("getUserById", User.class).setParameter("id", id);
            @SuppressWarnings("unchecked") OpenJPAQuery<User> kq = OpenJPAPersistence.cast(q);
            kq.getFetchPlan().addFetchGroup("groupUsers");
            if (force) {
                kq.getFetchPlan().addFetchGroup("backupexport");
            }
            List<User> list = kq.getResultList();
            u = list.size() == 1 ? list.get(0) : null;
        } finally {
            oem.getFetchPlan().setQueryResultCacheEnabled(qrce);
        }
    } else {
        log.info("[get]: No user id given");
    }
    return u;
}
Also used : OpenJPAEntityManager(org.apache.openjpa.persistence.OpenJPAEntityManager) User(org.apache.openmeetings.db.entity.user.User)

Example 79 with User

use of org.apache.openmeetings.db.entity.user.User in project openmeetings by apache.

the class UserDao method verifyPassword.

/**
 * Returns true if the password is correct
 *
 * @param userId - id of the user to check
 * @param password - password to check
 * @return <code>true</code> if entered password is correct
 */
public boolean verifyPassword(Long userId, String password) {
    List<String> l = em.createNamedQuery("getPassword", String.class).setParameter(PARAM_USER_ID, userId).getResultList();
    if (l == null || l.size() != 1) {
        return false;
    }
    String hash = l.get(0);
    ICrypt crypt = CryptProvider.get();
    if (crypt.verify(password, hash)) {
        return true;
    }
    if (crypt.fallback(password, hash)) {
        log.warn("Password for user with ID {} crypted with outdated Crypt, updating ...", userId);
        try {
            User u = updatePassword(userId, password, userId);
            log.warn("Password for user {} updated successfully", u);
            return true;
        } catch (NoSuchAlgorithmException e) {
            log.error("Unexpected exception while updating password");
        }
    }
    return false;
}
Also used : ICrypt(org.apache.openmeetings.util.crypt.ICrypt) User(org.apache.openmeetings.db.entity.user.User) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 80 with User

use of org.apache.openmeetings.db.entity.user.User in project openmeetings by apache.

the class UserDao method getRights.

public Set<Right> getRights(Long id) {
    Set<Right> rights = new HashSet<>();
    if (id == null) {
        return rights;
    }
    // For direct access of linked users
    if (id.longValue() < 0) {
        rights.add(Right.Room);
        return rights;
    }
    User u = get(id);
    if (u != null) {
        return u.getRights();
    }
    return rights;
}
Also used : User(org.apache.openmeetings.db.entity.user.User) Right(org.apache.openmeetings.db.entity.user.User.Right) HashSet(java.util.HashSet)

Aggregations

User (org.apache.openmeetings.db.entity.user.User)101 GroupUser (org.apache.openmeetings.db.entity.user.GroupUser)29 Test (org.junit.Test)25 Date (java.util.Date)11 Appointment (org.apache.openmeetings.db.entity.calendar.Appointment)10 ArrayList (java.util.ArrayList)8 ServiceResult (org.apache.openmeetings.db.dto.basic.ServiceResult)8 OmException (org.apache.openmeetings.util.OmException)8 Path (javax.ws.rs.Path)7 MeetingMember (org.apache.openmeetings.db.entity.calendar.MeetingMember)7 Room (org.apache.openmeetings.db.entity.room.Room)7 AbstractJUnitDefaults.getUser (org.apache.openmeetings.AbstractJUnitDefaults.getUser)6 Client (org.apache.openmeetings.db.entity.basic.Client)6 Address (org.apache.openmeetings.db.entity.user.Address)5 Group (org.apache.openmeetings.db.entity.user.Group)5 GroupDao (org.apache.openmeetings.db.dao.user.GroupDao)4 AppointmentDTO (org.apache.openmeetings.db.dto.calendar.AppointmentDTO)4 OAuthUser (org.apache.openmeetings.db.dto.user.OAuthUser)4 Recording (org.apache.openmeetings.db.entity.record.Recording)4 AbstractJUnitDefaults.createUser (org.apache.openmeetings.AbstractJUnitDefaults.createUser)3