Search in sources :

Example 1 with Permission

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;
}
Also used : Role(org.usermanagement.model.Role) Permission(org.usermanagement.model.Permission) UserEntity(org.usermanagement.dao.entity.UserEntity) HashSet(java.util.HashSet)

Example 2 with Permission

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;
}
Also used : Role(org.usermanagement.model.Role) RoleEntity(org.usermanagement.dao.entity.RoleEntity) Permission(org.usermanagement.model.Permission) ArrayList(java.util.ArrayList)

Example 3 with 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;
}
Also used : Role(org.usermanagement.model.Role) RoleEntity(org.usermanagement.dao.entity.RoleEntity) Permission(org.usermanagement.model.Permission) ArrayList(java.util.ArrayList)

Example 4 with 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;
}
Also used : Role(org.usermanagement.model.Role) Permission(org.usermanagement.model.Permission) ArrayList(java.util.ArrayList) UserInfo(org.usermanagement.model.UserInfo) PermissionEntity(org.usermanagement.dao.entity.PermissionEntity) UserEntity(org.usermanagement.dao.entity.UserEntity)

Aggregations

Permission (org.usermanagement.model.Permission)4 Role (org.usermanagement.model.Role)4 ArrayList (java.util.ArrayList)3 RoleEntity (org.usermanagement.dao.entity.RoleEntity)2 UserEntity (org.usermanagement.dao.entity.UserEntity)2 HashSet (java.util.HashSet)1 PermissionEntity (org.usermanagement.dao.entity.PermissionEntity)1 UserInfo (org.usermanagement.model.UserInfo)1