use of org.usermanagement.dao.entity.UserEntity in project open-kilda by telstra.
the class UserService method resetPassword.
/**
* Reset password.
*
* @param userId the user id
* @param adminFlag the admin flag
* @return the user info
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public UserInfo resetPassword(final long userId, final boolean adminFlag) {
UserInfo userinfo = new UserInfo();
userinfo.setUserId(userId);
UserEntity userEntity = userRepository.findByUserId(userId);
if (ValidatorUtil.isNull(userEntity)) {
LOGGER.warn("User Entity not found for user(id: " + userId + ")");
throw new RequestValidationException(messageUtil.getAttributeInvalid("user_id", userId + ""));
}
String randomPassword = ValidatorUtil.randomAlphaNumeric(16);
userEntity = UserConversionUtil.toResetPwdUserEntity(userEntity, randomPassword);
if (adminFlag) {
userEntity.setIs2FaConfigured(false);
userEntity.setTwoFaKey(null);
}
userEntity = userRepository.save(userEntity);
if (adminFlag) {
activityLogger.log(ActivityType.ADMIN_RESET_PASSWORD, userEntity.getUsername());
} else {
activityLogger.log(ActivityType.RESET_PASSWORD, userEntity.getUsername());
}
LOGGER.info("Password reset successfully for user(userId: " + userId + ").");
try {
if (!adminFlag) {
Map<String, Object> context = new HashMap<>();
context.put("name", userEntity.getName());
context.put("password", randomPassword);
mailService.send(userEntity.getEmail(), mailUtils.getSubjectResetPassword(), TemplateService.Template.RESET_ACCOUNT_PASSWORD, context);
LOGGER.info("Reset password mail sent successfully for user(userId: " + userId + ").");
}
} catch (Exception e) {
LOGGER.warn("Reset password mail failed for username: " + userEntity.getUsername());
}
userinfo.setPassword(randomPassword);
return userinfo;
}
use of org.usermanagement.dao.entity.UserEntity in project open-kilda by telstra.
the class UserService method assignUserByRoleId.
/**
* Assign user by role id.
*
* @param roleId the role id
* @param role the role
* @return the role
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public Role assignUserByRoleId(final Long roleId, final Role role) {
RoleEntity roleEntity = roleRepository.findByRoleId(roleId);
if (ValidatorUtil.isNull(roleEntity)) {
LOGGER.warn("Role with role id '" + roleId + "' not found. Error: " + messageUtil.getAttributeInvalid("role_id", roleId + ""));
throw new RequestValidationException(messageUtil.getAttributeInvalid("role_id", roleId + ""));
}
roleEntity.getUsers().clear();
if (role.getUserInfo() != null) {
for (UserInfo user : role.getUserInfo()) {
UserEntity userEntity = userRepository.findByUserId(user.getUserId());
roleEntity.getUsers().add(userEntity);
}
}
roleEntity = roleRepository.save(roleEntity);
activityLogger.log(ActivityType.ASSIGN_USERS_BY_ROLE, roleEntity.getName());
LOGGER.info("Users assigned with role successfully (role id: " + roleId + ")");
return RoleConversionUtil.toRole(roleEntity, false, true);
}
use of org.usermanagement.dao.entity.UserEntity in project open-kilda by telstra.
the class UserService method updateUser2FaKey.
/**
* Update user 2 FA key.
*
* @param userName the user name
* @param secretKey the secret key
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public void updateUser2FaKey(final String userName, final String secretKey) {
UserEntity userEntity = userRepository.findByUsernameIgnoreCase(userName);
userEntity.setTwoFaKey(secretKey);
userRepository.save(userEntity);
LOGGER.info("User 2FA updated successfully (username: " + userName + ")");
}
use of org.usermanagement.dao.entity.UserEntity in project open-kilda by telstra.
the class UserService method reset2fa.
/**
* Reset 2 fa.
*
* @param userId the user id
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public void reset2fa(final long userId) {
UserEntity userEntity = userRepository.findByUserId(userId);
if (ValidatorUtil.isNull(userEntity)) {
LOGGER.warn("User Entity not found for user(user_id: " + userId + ")");
throw new RequestValidationException(messageUtil.getAttributeInvalid("user_id", userId + ""));
}
userEntity.setIs2FaConfigured(false);
userEntity.setTwoFaKey(null);
userEntity = userRepository.save(userEntity);
activityLogger.log(ActivityType.RESET_2FA, userEntity.getUsername());
LOGGER.info("2FA reset successfully for user(user_id: " + userId + ").");
try {
if (!userEntity.getIs2FaConfigured()) {
Map<String, Object> context = new HashMap<>();
context.put("name", userEntity.getName());
mailService.send(userEntity.getEmail(), mailUtils.getSubjectReset2fa(), TemplateService.Template.RESET_2FA, context);
LOGGER.info("Reset 2FA mail sent successfully for user(user_id: " + userId + ").");
}
} catch (Exception e) {
LOGGER.warn("Reset 2FA mail failed for user: " + userId);
}
}
use of org.usermanagement.dao.entity.UserEntity in project open-kilda by telstra.
the class UserService method unlockUserAccount.
/**
* Unlock user account.
*
* @param userId the user id
*/
public void unlockUserAccount(Long userId) {
UserEntity userEntity = userValidator.validateUserId(userId);
userEntity.setStatusEntity(Status.ACTIVE.getStatusEntity());
userEntity.setFailedLoginCount(null);
userEntity.setUnlockTime(null);
userEntity.setLoginTime(new Timestamp(System.currentTimeMillis()));
userRepository.save(userEntity);
}
Aggregations