use of org.usermanagement.exception.RequestValidationException in project open-kilda by telstra.
the class SamlConversionUtil method toUpdateSamlConfigEntity.
/**
* To update saml config entity.
*
* @param samlConfigEntity the saml config entity
* @param roleEntities the role entities
* @param file the metadata file
* @param name the provider name
* @param url the metadata url
* @param entityId the entityId
* @param status the provider status
* @param userCreation the userCreation
* @param attribute the attribute
* @return the requireManagerUpdateStatus
*/
public static boolean toUpdateSamlConfigEntity(SamlConfigEntity samlConfigEntity, Set<RoleEntity> roleEntities, MultipartFile file, String name, String url, String entityId, boolean status, boolean userCreation, String attribute) {
Blob blob = null;
boolean requireManagerUpdate = false;
try {
if (file != null) {
byte[] bytes = file.getBytes();
try {
blob = new SerialBlob(bytes);
} catch (SerialException e) {
LOGGER.error("Error occurred while updating saml provider" + e);
} catch (SQLException e) {
LOGGER.error("Error occurred while updating saml provider" + e);
}
samlConfigEntity.setMetadata(blob);
samlConfigEntity.setType(IConstants.ProviderType.FILE);
requireManagerUpdate = true;
samlConfigEntity.setUrl(null);
} else if (url != null) {
samlConfigEntity.setUrl(url);
samlConfigEntity.setType(IConstants.ProviderType.URL);
requireManagerUpdate = true;
samlConfigEntity.setMetadata(null);
}
samlConfigEntity.setEntityId(entityId);
if (userCreation) {
samlConfigEntity.setUserCreation(true);
if (!samlConfigEntity.getRoles().isEmpty()) {
samlConfigEntity.getRoles().clear();
}
samlConfigEntity.getRoles().addAll(roleEntities);
} else {
samlConfigEntity.setRoles(null);
}
samlConfigEntity.setName(name);
samlConfigEntity.setUserCreation(userCreation);
samlConfigEntity.setAttribute(attribute);
samlConfigEntity.setStatus(status);
} catch (RequestValidationException e) {
throw new RequestValidationException(e.getMessage());
} catch (FileNotFoundException e) {
LOGGER.error("Error occurred while updating saml provider" + e);
} catch (IOException e) {
LOGGER.error("Error occurred while updating saml provider" + e);
}
return requireManagerUpdate;
}
use of org.usermanagement.exception.RequestValidationException in project open-kilda by telstra.
the class RoleService method assignRoleByPermissionId.
/**
* Assign role by permission id.
*
* @param permissionId the permission id
* @param request the request
* @return the permission
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public Permission assignRoleByPermissionId(final Long permissionId, final Permission request) {
PermissionEntity permissionEntity = permissionRepository.findByPermissionId(permissionId);
if (ValidatorUtil.isNull(permissionEntity)) {
LOGGER.warn("Permission with permissionId '" + permissionId + "' not found. Error: " + messageUtil.getAttributeInvalid("permissionId", permissionId + ""));
throw new RequestValidationException(messageUtil.getAttributeInvalid("permissionId", permissionId + ""));
}
permissionEntity.getRoles().clear();
if (request.getRoles() != null) {
for (Role role : request.getRoles()) {
RoleEntity roleEntity = roleRepository.findByRoleId(role.getRoleId());
permissionEntity.getRoles().add(roleEntity);
}
}
permissionRepository.save(permissionEntity);
activityLogger.log(ActivityType.ASSIGN_ROLES_TO_PERMISSION, permissionEntity.getName());
LOGGER.info("Roles assigned with permission successfully (permissionId: " + permissionId + ")");
return RoleConversionUtil.toPermissionByRole(permissionEntity.getRoles(), permissionEntity);
}
use of org.usermanagement.exception.RequestValidationException in project open-kilda by telstra.
the class RoleService method getRoleByName.
/**
* Gets the role by name.
*
* @param role the role
* @return the role by name
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public List<Role> getRoleByName(final Set<String> role) {
List<Role> roles = new ArrayList<Role>();
List<RoleEntity> roleEntities = roleRepository.findByNameIn(role);
if (ValidatorUtil.isNull(roleEntities)) {
LOGGER.warn("Roles with name '" + role + "' not found. Error: " + messageUtil.getAttributeInvalid("role", role + ""));
throw new RequestValidationException(messageUtil.getAttributeInvalid("role", role + ""));
}
for (RoleEntity roleEntity : roleEntities) {
if (Status.ACTIVE.getStatusEntity().getStatus().equalsIgnoreCase(roleEntity.getStatusEntity().getStatus())) {
roles.add(RoleConversionUtil.toRole(roleEntity, true, false));
}
}
return roles;
}
use of org.usermanagement.exception.RequestValidationException 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.exception.RequestValidationException 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);
}
Aggregations