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");
}
}
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);
}
}
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;
}
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;
}
}
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;
}
Aggregations