Search in sources :

Example 51 with User

use of org.openforis.collect.model.User in project collect by openforis.

the class PasswordChangeValidator method validateOldPassword.

private void validateOldPassword(Errors errors) {
    if (validateRequiredField(errors, OLD_PASSWORD_FIELD)) {
        String oldPassword = (String) errors.getFieldValue(OLD_PASSWORD_FIELD);
        User loggedUser = sessionManager.getLoggedUser();
        if (!userManager.verifyPassword(loggedUser.getUsername(), oldPassword)) {
            errors.rejectValue(OLD_PASSWORD_FIELD, WRONG_PASSWORD_SPECIFIED_MESSAGE_KEY);
        }
    }
}
Also used : User(org.openforis.collect.model.User)

Example 52 with User

use of org.openforis.collect.model.User in project collect by openforis.

the class RecordLockManager method checkIsLocked.

public synchronized boolean checkIsLocked(int recordId, User user, String sessionId) throws RecordUnlockedException {
    RecordLock lock = getLock(recordId);
    String lockUserName = null;
    if (lock != null) {
        String lockSessionId = lock.getSessionId();
        int lockRecordId = lock.getRecordId();
        User lUser = lock.getUser();
        if (recordId == lockRecordId && (lUser == user || lUser.getId().equals(user.getId())) && lockSessionId.equals(sessionId)) {
            lock.keepAlive();
            return true;
        } else {
            User lockUser = lock.getUser();
            lockUserName = lockUser.getUsername();
        }
    }
    throw new RecordUnlockedException(lockUserName);
}
Also used : User(org.openforis.collect.model.User) RecordLock(org.openforis.collect.model.RecordLock) RecordUnlockedException(org.openforis.collect.persistence.RecordUnlockedException)

Example 53 with User

use of org.openforis.collect.model.User in project collect by openforis.

the class RecordLockManager method isForceUnlockAllowed.

private boolean isForceUnlockAllowed(User user, RecordLock lock) {
    boolean isAdmin = user.hasRole(UserRole.ADMIN);
    Integer userId = user.getId();
    User lockUser = lock.getUser();
    return isAdmin || userId.equals(lockUser.getId());
}
Also used : User(org.openforis.collect.model.User)

Example 54 with User

use of org.openforis.collect.model.User in project collect by openforis.

the class LocalUserManager method isDefaultAdminPasswordSet.

public Boolean isDefaultAdminPasswordSet() {
    User adminUser = loadAdminUser();
    String encodedDefaultPassword = encodePassword(ADMIN_DEFAULT_PASSWORD);
    return encodedDefaultPassword.equals(adminUser.getPassword());
}
Also used : User(org.openforis.collect.model.User)

Example 55 with User

use of org.openforis.collect.model.User in project collect by openforis.

the class LocalUserManager method deleteById.

@Override
@Transactional(readOnly = false, propagation = REQUIRED)
public void deleteById(Integer id) throws CannotDeleteUserException {
    if (recordDao.hasAssociatedRecords(id)) {
        throw new CannotDeleteUserException();
    }
    User user = userDao.loadById(id);
    groupManager.deleteAllUserRelations(user);
    userDao.delete(id);
    User cachedUser = userById.get(id);
    if (cachedUser != null) {
        userById.remove(id);
        userByName.remove(cachedUser.getUsername());
    }
}
Also used : User(org.openforis.collect.model.User) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

User (org.openforis.collect.model.User)71 CollectRecord (org.openforis.collect.model.CollectRecord)19 CollectSurvey (org.openforis.collect.model.CollectSurvey)19 SessionState (org.openforis.collect.web.session.SessionState)16 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)12 Transactional (org.springframework.transaction.annotation.Transactional)11 RecordFilter (org.openforis.collect.model.RecordFilter)10 Test (org.junit.Test)8 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)6 RecordUpdater (org.openforis.collect.model.RecordUpdater)6 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)5 Date (java.util.Date)4 UserGroup (org.openforis.collect.model.UserGroup)4 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)4 Secured (org.springframework.security.access.annotation.Secured)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 RecordStep (org.openforis.collect.event.RecordStep)3 Step (org.openforis.collect.model.CollectRecord.Step)3