use of org.usermanagement.dao.entity.RoleEntity 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.dao.entity.RoleEntity in project open-kilda by telstra.
the class RoleService method getRolesByPermissionId.
/**
* Gets the roles by permission id.
*
* @param permissionId the permission id
* @return the roles by permission id
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public Permission getRolesByPermissionId(final Long permissionId) {
PermissionEntity permissionEntity = permissionRepository.findByPermissionId(permissionId);
Set<RoleEntity> roleEntityList = roleRepository.findByPermissions_permissionId(permissionId);
return RoleConversionUtil.toPermissionByRole(roleEntityList, permissionEntity);
}
use of org.usermanagement.dao.entity.RoleEntity in project open-kilda by telstra.
the class UserService method updateUser.
/**
* Update user.
*
* @param userInfo the user info
* @param userId the user id
* @return the user info
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public UserInfo updateUser(final UserInfo userInfo, final Long userId) {
UserEntity userEntity = userValidator.validateUpdateUser(userInfo);
StringBuilder activityMessage = new StringBuilder(userEntity.getUsername() + " updated with:\n");
if (userInfo.getRoleIds() != null) {
StringBuilder roles = new StringBuilder();
userEntity.getRoles().clear();
Set<RoleEntity> roleEntities = roleService.getRolesById(userInfo.getRoleIds());
userEntity.getRoles().addAll(roleEntities);
for (RoleEntity role : roleEntities) {
roles = roles.length() > 0 ? roles.append("," + role.getName()) : roles.append(role.getName());
}
activityMessage.append("roles:" + roles.toString() + "\n");
}
UserConversionUtil.toUpateUserEntity(userInfo, userEntity, activityMessage);
userEntity = userRepository.save(userEntity);
activityLogger.log(ActivityType.UPDATE_USER, activityMessage.toString());
LOGGER.info("User updated successfully (id: " + userId + ")");
return UserConversionUtil.toUserInfo(userEntity);
}
use of org.usermanagement.dao.entity.RoleEntity in project open-kilda by telstra.
the class UserService method populateUserInfo.
/**
* Adds user information in session.
*
* @param userInfo the userInfo
* @param username who's information is added in session.
*/
public void populateUserInfo(final UserInfo userInfo, final String username) {
UserEntity user = getUserByUsername(username);
Set<RoleEntity> roleEntities = user.getRoles();
Set<String> roles = new HashSet<String>();
Set<String> permissions = new HashSet<String>();
for (RoleEntity roleEntity : roleEntities) {
roles.add(roleEntity.getName());
userInfo.setRole("ROLE_ADMIN");
if (user.getUserId() != 1) {
Set<PermissionEntity> permissionEntities = roleEntity.getPermissions();
for (PermissionEntity permissionEntity : permissionEntities) {
if (permissionEntity.getStatusEntity().getStatusCode().equalsIgnoreCase(Status.ACTIVE.getCode()) && !permissionEntity.getIsAdminPermission()) {
permissions.add(permissionEntity.getName());
}
}
}
}
if (user.getUserId() == 1) {
List<PermissionEntity> permissionEntities = permissionRepository.findAll();
for (PermissionEntity permissionEntity : permissionEntities) {
permissions.add(permissionEntity.getName());
}
}
userInfo.setUserId(user.getUserId());
userInfo.setUsername(user.getUsername());
userInfo.setName(user.getName());
userInfo.setRoles(roles);
userInfo.setPermissions(permissions);
userInfo.setIs2FaEnabled(user.getIs2FaEnabled());
}
use of org.usermanagement.dao.entity.RoleEntity in project open-kilda by telstra.
the class RoleConversionUtil method toRoleEntity.
/**
* To role entity.
*
* @param role the role
* @param permissionEntitySet the permission entity set
* @return the role entity
*/
public static RoleEntity toRoleEntity(final Role role, final Set<PermissionEntity> permissionEntitySet) {
RoleEntity roleEntity = new RoleEntity();
roleEntity.setName(role.getName());
roleEntity.setPermissions(permissionEntitySet);
roleEntity.setDescription(role.getDescription());
StatusEntity statusEntity = Status.ACTIVE.getStatusEntity();
roleEntity.setStatusEntity(statusEntity);
return roleEntity;
}
Aggregations