use of org.usermanagement.exception.RequestValidationException in project open-kilda by telstra.
the class RoleService method createRole.
/**
* Creates the role.
*
* @param role the role
* @return the role
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public Role createRole(final Role role) {
roleValidator.validateRole(role);
Set<PermissionEntity> permissionEntities = new HashSet<>();
List<PermissionEntity> permissionEntityList = permissionRepository.findAll();
for (Long permissionId : role.getPermissionId()) {
PermissionEntity permissionEntity = permissionEntityList.parallelStream().filter((entity) -> entity.getPermissionId().equals(permissionId)).findFirst().orElse(null);
if (!ValidatorUtil.isNull(permissionEntity)) {
permissionEntities.add(permissionEntity);
} else {
LOGGER.warn("Permission with id '" + permissionId + "' not found.");
throw new RequestValidationException(messageUtil.getAttributeNotFound("permission"));
}
}
RoleEntity roleEntity = RoleConversionUtil.toRoleEntity(role, permissionEntities);
roleRepository.save(roleEntity);
activityLogger.log(ActivityType.CREATE_ROLE, role.getName());
LOGGER.info("Role with name '" + roleEntity.getName() + "' created successfully.");
return RoleConversionUtil.toRole(roleEntity, true, false);
}
use of org.usermanagement.exception.RequestValidationException in project open-kilda by telstra.
the class UserService method deleteUserById.
/**
* Delete user by id.
*
* @param userId the user id
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public void deleteUserById(final Long userId) {
UserEntity userEntity = userRepository.findByUserId(userId);
if (ValidatorUtil.isNull(userEntity)) {
LOGGER.warn("User with user id '" + userId + "' not found. Error: " + messageUtil.getAttributeInvalid("user_id", userId + ""));
throw new RequestValidationException(messageUtil.getAttributeInvalid("user_id", userId + ""));
}
userRepository.delete(userEntity);
activityLogger.log(ActivityType.DELETE_USER, userEntity.getUsername());
LOGGER.info("User deleted successfully (userId: " + userId + ")");
}
use of org.usermanagement.exception.RequestValidationException in project open-kilda by telstra.
the class UserService method updateLoginDetail.
/**
* Update login detail.
*
* @param userName the user name
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public void updateLoginDetail(final String userName) {
UserEntity userEntity = userRepository.findByUsernameIgnoreCase(userName);
if (ValidatorUtil.isNull(userEntity)) {
LOGGER.warn("User with username '" + userName + "' not found. Error: " + messageUtil.getAttributeInvalid("username", userName + ""));
throw new RequestValidationException(messageUtil.getAttributeInvalid("username", userName + ""));
}
userEntity.setLoginTime(Calendar.getInstance().getTime());
userEntity.setFailedLoginCount(null);
userEntity.setUnlockTime(null);
if (userEntity.getIs2FaEnabled()) {
userEntity.setIs2FaConfigured(true);
}
userRepository.save(userEntity);
LOGGER.info("User last login updated successfully (username: " + userName + ")");
}
use of org.usermanagement.exception.RequestValidationException in project open-kilda by telstra.
the class PermissionService method updatePermission.
/**
* Update permission.
*
* @param permissionId the permission id
* @param permission the permission
* @return the permission
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public Permission updatePermission(final Long permissionId, final Permission permission) {
permissionValidator.validateUpdatePermission(permission, permissionId);
PermissionEntity permissionEntity = permissionRepository.findByPermissionId(permissionId);
if (ValidatorUtil.isNull(permissionEntity)) {
LOGGER.warn("Permission with permissionId '" + permissionId + "' not found. Error: " + messageUtil.getAttributeInvalid("permission_id", permissionId + ""));
throw new RequestValidationException(messageUtil.getAttributeInvalid("permission_id", permissionId + ""));
}
permissionEntity = PermissionConversionUtil.toUpatePermissionEntity(permission, permissionEntity);
permissionRepository.save(permissionEntity);
activityLogger.log(ActivityType.UPDATE_PERMISSION, permissionEntity.getName());
LOGGER.info("Permission(permissionId: " + permissionId + ") updated successfully.");
return PermissionConversionUtil.toPermission(permissionEntity, null);
}
use of org.usermanagement.exception.RequestValidationException in project open-kilda by telstra.
the class UserValidator method validateChangePassword.
/**
* Validate change password.
*
* @param userInfo the user info
*/
public void validateChangePassword(final UserInfo userInfo) {
String regexOne = "^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[^\\w\\s]).{8,15}$";
String regexTwo = "[%,&,+,\\,\\s,\"]";
if (ValidatorUtil.isNull(userInfo.getNewPassword())) {
LOGGER.warn("Validation fail for change user password request (id: " + userInfo.getUserId() + "). Error: " + messageUtil.getAttributeNotNull("password"));
throw new RequestValidationException(messageUtil.getAttributeNotNull("password"));
}
Matcher matcherOne = Pattern.compile(regexOne).matcher(userInfo.getNewPassword());
if (!matcherOne.matches()) {
LOGGER.warn("Validation fail for change user password request (id: " + userInfo.getUserId() + "). Error: " + messageUtil.getAttributePasswordMustContain());
throw new RequestValidationException(messageUtil.getAttributePasswordMustContain());
}
Matcher matcherTwo = Pattern.compile(regexTwo).matcher(userInfo.getNewPassword());
if (matcherTwo.find()) {
LOGGER.warn("Validation fail for change user password request (id: " + userInfo.getUserId() + "). Error: " + messageUtil.getAttributePasswordMustNotContain());
throw new RequestValidationException(messageUtil.getAttributePasswordMustNotContain());
}
if (userInfo.getNewPassword().equals(userInfo.getPassword())) {
LOGGER.warn("New password not valid (id: " + userInfo.getUserId() + "). Error: " + messageUtil.getAttributePasswordShouldNotSame());
throw new RequestValidationException(messageUtil.getAttributePasswordShouldNotSame());
}
if (userInfo.getNewPassword().equals(userInfo.getPassword())) {
LOGGER.warn("New password not valid (id: " + userInfo.getUserId() + "). Error: " + messageUtil.getAttributePasswordLength("8", "15"));
throw new RequestValidationException(messageUtil.getAttributePasswordLength("8", "15"));
}
}
Aggregations