use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class EmailSenderImplTest method prepareUser.
private void prepareUser() {
user = new MotechUser();
user.setLastPasswordChange(DateUtil.now().minusDays(DAYS_TO_CHANGE_PASSWORD - DAYS_FOR_REMINDER));
user.setUserName("FooUsername");
user.setEmail("fooUser@domain.com");
user.setLocale(Locale.ENGLISH);
}
use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class MotechUsersDao method getUsers.
/**
* Returns all MotechUsers that comes from
* {@link LoginMode#REPOSITORY}
*
* @return list that contains users
*/
@Transactional
public List<MotechUser> getUsers() {
List<MotechUser> users = dataService.retrieveAll();
Iterator<MotechUser> iterator = users.iterator();
while (iterator.hasNext()) {
MotechUser user = iterator.next();
if (isNotBlank(user.getOpenId())) {
iterator.remove();
}
}
return users;
}
use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class MotechRoleServiceImpl method updateRole.
@Override
@Transactional
public void updateRole(RoleDto role) {
LOGGER.info("Updating role: {}", role.getRoleName());
MotechRole motechRole = findByRoleName(role.getOriginalRoleName());
motechRole.setRoleName(role.getRoleName());
motechRole.setPermissionNames(role.getPermissionNames());
List<MotechUser> users = motechUsersDao.findByRole(role.getOriginalRoleName());
if (StringUtils.equals(role.getRoleName(), role.getOriginalRoleName())) {
for (MotechUser user : users) {
List<String> roleList = user.getRoles();
roleList.remove(role.getOriginalRoleName());
roleList.add(role.getRoleName());
motechUsersDao.update(user);
}
}
motechRolesDataService.update(motechRole);
userContextsService.refreshAllUsersContextIfActive();
LOGGER.info("Updated role: {}", role.getRoleName());
}
use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class MotechUserServiceImpl method updateUserDetailsWithPassword.
@Override
@Transactional
public void updateUserDetailsWithPassword(UserDto user) {
if (!StringUtils.isEmpty(user.getPassword())) {
validatePassword(user.getPassword());
MotechUser motechUser = motechUsersDao.findByUserName(user.getUserName());
motechUser.setEmail(user.getEmail());
motechUser.setUserStatus(user.getUserStatus());
motechUser.setPassword(passwordEncoder.encode(user.getPassword()));
motechUser.setRoles(user.getRoles());
motechUser.setLocale(user.getLocale());
motechUsersDao.update(motechUser);
userContextsService.refreshUserContextIfActive(motechUser.getUserName());
} else {
throw new IllegalArgumentException("User password cannot be empty. If you wish to omit changing user password, " + "please call method updateUserDetailsWithoutPassword.");
}
}
use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class MotechUserServiceImpl method changeExpiredPassword.
@Override
@Transactional
public MotechUserProfile changeExpiredPassword(String userName, String oldPassword, String newPassword) {
MotechUser motechUser = motechUsersDao.findByUserName(userName);
validatePassword(newPassword);
if (motechUser != null && UserStatus.MUST_CHANGE_PASSWORD.equals(motechUser.getUserStatus()) && passwordEncoder.isPasswordValid(motechUser.getPassword(), oldPassword)) {
// The new password and the old password cannot be the same
if (passwordEncoder.isPasswordValid(motechUser.getPassword(), newPassword)) {
return null;
}
motechUser.setPassword(passwordEncoder.encodePassword(newPassword));
motechUser.setUserStatus(UserStatus.ACTIVE);
motechUsersDao.update(motechUser);
return new MotechUserProfile(motechUser);
} else {
// Wrong password
incrementFailureLoginCount(motechUser);
}
return null;
}
Aggregations