Search in sources :

Example 36 with MotechUser

use of org.motechproject.security.domain.MotechUser in project motech by motech.

the class MotechUsersDao method getOpenIdUsers.

/**
 * Returns all MotechUsers that comes from
 * {@link LoginMode#OPEN_ID}
 *
 * @return list that contains users
 */
@Transactional
public List<MotechUser> getOpenIdUsers() {
    List<MotechUser> users = dataService.retrieveAll();
    Iterator<MotechUser> iterator = users.iterator();
    while (iterator.hasNext()) {
        MotechUser user = iterator.next();
        if (isBlank(user.getOpenId())) {
            iterator.remove();
        }
    }
    return users;
}
Also used : MotechUser(org.motechproject.security.domain.MotechUser) Transactional(org.springframework.transaction.annotation.Transactional)

Example 37 with MotechUser

use of org.motechproject.security.domain.MotechUser in project motech by motech.

the class MotechRoleServiceImpl method deleteRole.

@Override
@Transactional
public void deleteRole(RoleDto role) {
    LOGGER.info("Deleting role: {}", role.getRoleName());
    MotechRole motechRole = findByRoleName(role.getRoleName());
    if (motechRole.isDeletable()) {
        List<MotechUser> users = motechUsersDao.findByRole(role.getRoleName());
        if (!users.isEmpty()) {
            throw new RoleHasUserException("Role cannot be deleted because a user has the role.");
        }
        motechRolesDataService.delete(motechRole);
        userContextsService.refreshAllUsersContextIfActive();
        LOGGER.info("Deleted role: {}", role);
    } else {
        LOGGER.warn("The role {} cant be deleted", role.getRoleName());
    }
}
Also used : MotechUser(org.motechproject.security.domain.MotechUser) RoleHasUserException(org.motechproject.security.exception.RoleHasUserException) MotechRole(org.motechproject.security.domain.MotechRole) Transactional(org.springframework.transaction.annotation.Transactional)

Example 38 with MotechUser

use of org.motechproject.security.domain.MotechUser in project motech by motech.

the class MotechUserServiceImpl method sendLoginInformation.

@Override
@Transactional
public void sendLoginInformation(String userName) throws UserNotFoundException, NonAdminUserException {
    String token;
    MotechUser user = motechUsersDao.findByUserName(userName);
    if (settingsFacade.getPlatformSettings().getLoginMode().isRepository()) {
        token = passwordRecoveryService.passwordRecoveryRequest(user.getEmail(), false);
    } else {
        token = passwordRecoveryService.oneTimeTokenOpenId(user.getEmail(), false);
    }
    emailSender.sendLoginInfo(user, token);
}
Also used : MotechUser(org.motechproject.security.domain.MotechUser) Transactional(org.springframework.transaction.annotation.Transactional)

Example 39 with MotechUser

use of org.motechproject.security.domain.MotechUser in project motech by motech.

the class MotechUserServiceImpl method deleteUser.

@Override
@Transactional
public void deleteUser(UserDto user) {
    LOGGER.info("Deleting user: {}", user.getUserName());
    MotechUser motechUser = motechUsersDao.findByUserName(user.getUserName());
    motechUsersDao.remove(motechUser);
    userContextsService.logoutUser(user.getUserName());
    LOGGER.info("Deleted user: {}", user.getUserName());
}
Also used : MotechUser(org.motechproject.security.domain.MotechUser) Transactional(org.springframework.transaction.annotation.Transactional)

Example 40 with MotechUser

use of org.motechproject.security.domain.MotechUser in project motech by motech.

the class MotechUserServiceImpl method changePassword.

@Override
@Transactional
public MotechUserProfile changePassword(String userName, String oldPassword, String newPassword) {
    MotechUser motechUser = motechUsersDao.findByUserName(userName);
    validatePassword(newPassword);
    if (motechUser != null && passwordEncoder.isPasswordValid(motechUser.getPassword(), oldPassword)) {
        motechUser.setPassword(passwordEncoder.encodePassword(newPassword));
        motechUsersDao.update(motechUser);
        return new MotechUserProfile(motechUser);
    }
    return null;
}
Also used : MotechUser(org.motechproject.security.domain.MotechUser) MotechUserProfile(org.motechproject.security.domain.MotechUserProfile) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

MotechUser (org.motechproject.security.domain.MotechUser)61 Test (org.junit.Test)27 Transactional (org.springframework.transaction.annotation.Transactional)24 MotechUserProfile (org.motechproject.security.domain.MotechUserProfile)8 ArrayList (java.util.ArrayList)6 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)6 DateTime (org.joda.time.DateTime)4 PasswordRecovery (org.motechproject.security.domain.PasswordRecovery)4 Authentication (org.springframework.security.core.Authentication)4 User (org.springframework.security.core.userdetails.User)4 HttpSession (javax.servlet.http.HttpSession)3 MotechRole (org.motechproject.security.domain.MotechRole)3 RoleDto (org.motechproject.security.model.RoleDto)3 ConfigAttribute (org.springframework.security.access.ConfigAttribute)3 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)3 AuthenticationException (org.springframework.security.core.AuthenticationException)3 UserNotFoundException (org.motechproject.security.exception.UserNotFoundException)2 UserDto (org.motechproject.security.model.UserDto)2 SecurityConfig (org.springframework.security.access.SecurityConfig)2 AbstractAuthenticationToken (org.springframework.security.authentication.AbstractAuthenticationToken)2