Search in sources :

Example 56 with User

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

the class LocalUserManager method changePassword.

@Override
@Transactional(readOnly = false, propagation = REQUIRED)
public OperationResult changePassword(String username, String oldPassword, String newPassword) throws UserPersistenceException {
    if (verifyPassword(username, oldPassword)) {
        User user = userDao.loadByUserName(username, true);
        String encodedNewPassword = checkAndEncodePassword(newPassword);
        user.setPassword(encodedNewPassword);
        userDao.update(user);
        updateCache(user);
        return new OperationResult();
    } else {
        return new OperationResult(false, "WRONG_PASSWORD", "Wrong password specified");
    }
}
Also used : User(org.openforis.collect.model.User) Transactional(org.springframework.transaction.annotation.Transactional)

Example 57 with User

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

the class LocalUserManager method loadAllAvailableUsers.

@Override
public List<User> loadAllAvailableUsers(User availableTo) {
    if (availableTo.getRoles().contains(UserRole.ADMIN)) {
        return loadAll();
    } else {
        Set<User> users = new TreeSet<User>();
        List<UserGroup> userGroups = groupManager.findByUser(availableTo);
        for (UserGroup userGroup : userGroups) {
            List<UserInGroup> groupUsers = groupManager.findUsersInGroup(userGroup);
            for (UserInGroup userInGroup : groupUsers) {
                Integer userId = userInGroup.getUserId();
                User user = loadById(userId);
                users.add(user);
            }
        }
        // sorted by username by default (see User.compareTo)
        return new ArrayList<User>(users);
    }
}
Also used : User(org.openforis.collect.model.User) UserInGroup(org.openforis.collect.model.UserInGroup) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) UserGroup(org.openforis.collect.model.UserGroup)

Example 58 with User

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

the class LocalUserManager method loadById.

@Override
public User loadById(Integer id) {
    User user = userById.get(id);
    if (user == null) {
        user = userDao.loadById(id);
        updateCache(user);
    }
    return user;
}
Also used : User(org.openforis.collect.model.User)

Example 59 with User

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

the class LocalUserManager method loadByUserName.

private User loadByUserName(String userName, Boolean enabled) {
    User user = userByName.get(userName);
    if (user == null) {
        user = userDao.loadByUserName(userName, null);
        updateCache(user);
    }
    if (user != null && (enabled == null || enabled.equals(user.getEnabled()))) {
        return user;
    } else {
        return null;
    }
}
Also used : User(org.openforis.collect.model.User)

Example 60 with User

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

the class DataRestoreController method restoreDataRemotely.

@RequestMapping(value = "/surveys/{surveyName}/data/restoreremotely.json", method = POST)
@ResponseBody
public RemoteDataRestoreResponse restoreDataRemotely(UploadItem uploadItem, @PathVariable String surveyName, @RequestParam String restoreKey) {
    RemoteDataRestoreResponse response = new RemoteDataRestoreResponse();
    String allowedRestoreKey = configurationManager.getConfiguration().get(ConfigurationItem.ALLOWED_RESTORE_KEY);
    if (StringUtils.isBlank(allowedRestoreKey) || allowedRestoreKey.equals(restoreKey)) {
        try {
            User user = userManager.loadAdminUser();
            boolean newSurvey = surveyManager.get(surveyName) == null;
            DataRestoreJob job = startRestoreJob(uploadItem.getFileData().getInputStream(), newSurvey, surveyName, user, true, false, OverwriteStrategy.OVERWRITE_OLDER);
            response.setJobId(job.getId().toString());
        } catch (Exception e) {
            response.setErrorStatus();
            response.setErrorMessage(e.getMessage());
        }
    } else {
        response.setErrorStatus();
        response.setErrorMessage("Restore not allowed: invalid restore key");
    }
    return response;
}
Also used : User(org.openforis.collect.model.User) DataRestoreJob(org.openforis.collect.io.data.DataRestoreJob) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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