use of org.usermanagement.model.Permission in project open-kilda by telstra.
the class RequestInterceptor method availablePermissions.
private Set<String> availablePermissions(final UserInfo userInfo) {
Set<String> availablePermissions = new HashSet<>();
UserEntity userEntity = userRepository.findByUserId(userInfo.getUserId());
if (userInfo.getUserId() != 1 && userEntity != null && Status.ACTIVE.getStatusEntity().equals(userEntity.getStatusEntity())) {
Set<String> roles = userInfo.getRoles();
if (roles != null && roles.size() > 0) {
List<Role> roleList = roleService.getRoleByName(roles);
for (Role role : roleList) {
if (Status.ACTIVE.getStatusEntity().getStatus().equalsIgnoreCase(role.getStatus()) && role.getPermissions() != null) {
for (Permission permission : role.getPermissions()) {
if (Status.ACTIVE.getStatusEntity().getStatus().equalsIgnoreCase(permission.getStatus())) {
availablePermissions.add(permission.getName());
}
}
}
}
}
} else {
List<Permission> permissions = permissionService.getAllPermission(userInfo.getUserId());
for (Permission permission : permissions) {
availablePermissions.add(permission.getName());
}
}
userInfo.setPermissions(availablePermissions);
return availablePermissions;
}
use of org.usermanagement.model.Permission in project open-kilda by telstra.
the class PermissionConversionUtil method toPermission.
/**
* To permission.
*
* @param permissionEntity the permission entity
* @param roleEntities the role entities
* @return the permission
*/
public static Permission toPermission(final PermissionEntity permissionEntity, final Set<RoleEntity> roleEntities) {
Permission permission = new Permission();
permission.setName(permissionEntity.getName());
permission.setPermissionId(permissionEntity.getPermissionId());
permission.setIsEditable(permissionEntity.getIsEditable());
permission.setIsAdminPermission(permissionEntity.getIsAdminPermission());
permission.setStatus(permissionEntity.getStatusEntity().getStatus());
permission.setDescription(permissionEntity.getDescription());
if (!ValidatorUtil.isNull(roleEntities)) {
List<Role> roles = new ArrayList<>();
for (RoleEntity entity : roleEntities) {
Role role = new Role();
role.setRoleId(entity.getRoleId());
role.setName(entity.getName());
roles.add(role);
}
permission.setRoles(roles);
}
return permission;
}
use of org.usermanagement.model.Permission in project open-kilda by telstra.
the class RoleConversionUtil method toPermissionByRole.
/**
* To permission by role.
*
* @param roleEntityList the role entity list
* @param permissionEntity the permission entity
* @return the permission
*/
public static Permission toPermissionByRole(final Set<RoleEntity> roleEntityList, final PermissionEntity permissionEntity) {
Permission permission = new Permission();
permission.setName(permissionEntity.getName());
permission.setDescription(permissionEntity.getDescription());
permission.setPermissionId(permissionEntity.getPermissionId());
List<Role> role = new ArrayList<>();
for (RoleEntity roleEntity : roleEntityList) {
Role roles = new Role();
roles.setRoleId(roleEntity.getRoleId());
roles.setName(roleEntity.getName());
role.add(roles);
}
permission.setRoles(role);
return permission;
}
use of org.usermanagement.model.Permission in project open-kilda by telstra.
the class RoleConversionUtil method toRole.
/**
* To role.
*
* @param roleEntity the role entity
* @param withPermissions the with permissions
* @param withUsers the with users
* @return the role
*/
public static Role toRole(final RoleEntity roleEntity, final boolean withPermissions, final boolean withUsers) {
Role role = new Role();
role.setName(roleEntity.getName());
role.setRoleId(roleEntity.getRoleId());
role.setStatus(roleEntity.getStatusEntity().getStatus());
role.setDescription(roleEntity.getDescription());
if (withPermissions) {
List<Permission> permissionList = new ArrayList<Permission>();
if (!ValidatorUtil.isNull(roleEntity.getPermissions())) {
for (PermissionEntity permissionEntity : roleEntity.getPermissions()) {
permissionList.add(PermissionConversionUtil.toPermission(permissionEntity, null));
}
role.setPermissions(permissionList);
}
}
if (withUsers) {
List<UserInfo> userInfoList = new ArrayList<>();
for (UserEntity userEntity : roleEntity.getUsers()) {
if (userEntity.getUserId() != 1) {
UserInfo userInfo = new UserInfo();
userInfo.setUserId(userEntity.getUserId());
userInfo.setName(userEntity.getName());
userInfoList.add(userInfo);
}
}
role.setUserInfo(userInfoList);
}
return role;
}
Aggregations