Search in sources :

Example 11 with VXUserPermission

use of org.apache.ranger.view.VXUserPermission in project ranger by apache.

the class XModuleDefService method populateViewBean.

@Override
public VXModuleDef populateViewBean(XXModuleDef xObj) {
    VXModuleDef vModuleDef = super.populateViewBean(xObj);
    Map<Long, XXUser> xXPortalUserIdXXUserMap = xUserService.getXXPortalUserIdXXUserMap();
    Map<Long, XXGroup> xXGroupMap = xGroupService.getXXGroupIdXXGroupMap();
    List<VXUserPermission> vXUserPermissionList = new ArrayList<VXUserPermission>();
    List<VXGroupPermission> vXGroupPermissionList = new ArrayList<VXGroupPermission>();
    List<XXUserPermission> xuserPermissionList = daoManager.getXXUserPermission().findByModuleId(xObj.getId(), false);
    List<XXGroupPermission> xgroupPermissionList = daoManager.getXXGroupPermission().findByModuleId(xObj.getId(), false);
    if (CollectionUtils.isEmpty(xXPortalUserIdXXUserMap)) {
        for (XXUserPermission xUserPerm : xuserPermissionList) {
            VXUserPermission vXUserPerm = xUserPermService.populateViewBean(xUserPerm);
            vXUserPermissionList.add(vXUserPerm);
        }
    } else {
        vXUserPermissionList = xUserPermService.getPopulatedVXUserPermissionList(xuserPermissionList, xXPortalUserIdXXUserMap, vModuleDef);
    }
    if (CollectionUtils.isEmpty(xXGroupMap)) {
        for (XXGroupPermission xGrpPerm : xgroupPermissionList) {
            VXGroupPermission vXGrpPerm = xGrpPermService.populateViewBean(xGrpPerm);
            vXGroupPermissionList.add(vXGrpPerm);
        }
    } else {
        vXGroupPermissionList = xGrpPermService.getPopulatedVXGroupPermissionList(xgroupPermissionList, xXGroupMap, vModuleDef);
    }
    vModuleDef.setUserPermList(vXUserPermissionList);
    vModuleDef.setGroupPermList(vXGroupPermissionList);
    return vModuleDef;
}
Also used : XXUser(org.apache.ranger.entity.XXUser) XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) ArrayList(java.util.ArrayList) XXUserPermission(org.apache.ranger.entity.XXUserPermission) VXUserPermission(org.apache.ranger.view.VXUserPermission) XXGroup(org.apache.ranger.entity.XXGroup) VXGroupPermission(org.apache.ranger.view.VXGroupPermission) VXModuleDef(org.apache.ranger.view.VXModuleDef)

Example 12 with VXUserPermission

use of org.apache.ranger.view.VXUserPermission in project ranger by apache.

the class XUserPermissionService method getPopulatedVXUserPermissionList.

public List<VXUserPermission> getPopulatedVXUserPermissionList(List<XXUserPermission> xuserPermissionList, Map<Long, XXUser> xXPortalUserIdXXUserMap, VXModuleDef vModuleDef) {
    List<VXUserPermission> vXUserPermissionList = new ArrayList<VXUserPermission>();
    XXUser xXUser = null;
    for (XXUserPermission xuserPermission : xuserPermissionList) {
        if (xXPortalUserIdXXUserMap.containsKey(xuserPermission.getUserId())) {
            xXUser = xXPortalUserIdXXUserMap.get(xuserPermission.getUserId());
            VXUserPermission vXUserPerm = new VXUserPermission();
            vXUserPerm.setId(xuserPermission.getId());
            vXUserPerm.setUserId(xXUser.getId());
            vXUserPerm.setModuleId(xuserPermission.getModuleId());
            vXUserPerm.setIsAllowed(xuserPermission.getIsAllowed());
            vXUserPerm.setCreateDate(xuserPermission.getCreateTime());
            vXUserPerm.setUpdateDate(xuserPermission.getUpdateTime());
            vXUserPerm.setModuleName(vModuleDef.getModule());
            vXUserPerm.setLoginId(xXUser.getName());
            vXUserPerm.setUserName(xXUser.getName());
            vXUserPermissionList.add(vXUserPerm);
        }
    }
    return vXUserPermissionList;
}
Also used : XXUser(org.apache.ranger.entity.XXUser) ArrayList(java.util.ArrayList) XXUserPermission(org.apache.ranger.entity.XXUserPermission) VXUserPermission(org.apache.ranger.view.VXUserPermission)

Example 13 with VXUserPermission

use of org.apache.ranger.view.VXUserPermission in project ranger by apache.

the class UserMgr method gjUserToUserProfile.

private void gjUserToUserProfile(XXPortalUser user, VXPortalUser userProfile) {
    UserSessionBase sess = ContextUtil.getCurrentUserSession();
    if (sess == null) {
        return;
    }
    // Admin
    if (sess.isUserAdmin() || sess.isKeyAdmin() || sess.getXXPortalUser().getId().equals(user.getId())) {
        userProfile.setLoginId(user.getLoginId());
        userProfile.setStatus(user.getStatus());
        userProfile.setUserRoleList(new ArrayList<String>());
        String emailAddress = user.getEmailAddress();
        if (emailAddress != null && stringUtil.validateEmail(emailAddress)) {
            userProfile.setEmailAddress(user.getEmailAddress());
        }
        userProfile.setUserSource(sess.getAuthProvider());
        List<XXPortalUserRole> gjUserRoleList = daoManager.getXXPortalUserRole().findByParentId(user.getId());
        for (XXPortalUserRole gjUserRole : gjUserRoleList) {
            userProfile.getUserRoleList().add(gjUserRole.getUserRole());
        }
        userProfile.setId(user.getId());
        List<XXUserPermission> xUserPermissions = daoManager.getXXUserPermission().findByUserPermissionIdAndIsAllowed(userProfile.getId());
        List<XXGroupPermission> xxGroupPermissions = daoManager.getXXGroupPermission().findbyVXPortalUserId(userProfile.getId());
        List<VXGroupPermission> groupPermissions = new ArrayList<VXGroupPermission>();
        List<VXUserPermission> vxUserPermissions = new ArrayList<VXUserPermission>();
        for (XXGroupPermission xxGroupPermission : xxGroupPermissions) {
            VXGroupPermission groupPermission = xGroupPermissionService.populateViewBean(xxGroupPermission);
            groupPermission.setModuleName(daoManager.getXXModuleDef().findByModuleId(groupPermission.getModuleId()).getModule());
            groupPermissions.add(groupPermission);
        }
        for (XXUserPermission xUserPermission : xUserPermissions) {
            VXUserPermission vXUserPermission = xUserPermissionService.populateViewBean(xUserPermission);
            vXUserPermission.setModuleName(daoManager.getXXModuleDef().findByModuleId(vXUserPermission.getModuleId()).getModule());
            vxUserPermissions.add(vXUserPermission);
        }
        userProfile.setGroupPermissions(groupPermissions);
        userProfile.setUserPermList(vxUserPermissions);
        userProfile.setFirstName(user.getFirstName());
        userProfile.setLastName(user.getLastName());
        userProfile.setPublicScreenName(user.getPublicScreenName());
    }
}
Also used : XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) ArrayList(java.util.ArrayList) VXString(org.apache.ranger.view.VXString) XXUserPermission(org.apache.ranger.entity.XXUserPermission) VXUserPermission(org.apache.ranger.view.VXUserPermission) UserSessionBase(org.apache.ranger.common.UserSessionBase) VXGroupPermission(org.apache.ranger.view.VXGroupPermission) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole)

Example 14 with VXUserPermission

use of org.apache.ranger.view.VXUserPermission in project ranger by apache.

the class TestXUserREST method test82createXUserPermission.

@Test
public void test82createXUserPermission() {
    VXUserPermission testvXUserPermission = createVXUserPermission();
    Mockito.doNothing().when(xUserMgr).checkAdminAccess();
    Mockito.when(xUserMgr.createXUserPermission(testvXUserPermission)).thenReturn(testvXUserPermission);
    VXUserPermission retVXUserPermission = xUserRest.createXUserPermission(testvXUserPermission);
    Mockito.verify(xUserMgr).createXUserPermission(testvXUserPermission);
    Mockito.verify(xUserMgr).checkAdminAccess();
    assertNotNull(retVXUserPermission);
    assertEquals(retVXUserPermission.getId(), testvXUserPermission.getId());
    assertEquals(retVXUserPermission.getUserName(), testvXUserPermission.getUserName());
}
Also used : VXUserPermission(org.apache.ranger.view.VXUserPermission) Test(org.junit.Test)

Example 15 with VXUserPermission

use of org.apache.ranger.view.VXUserPermission in project ranger by apache.

the class TestXUserREST method test83getXUserPermission.

@Test
public void test83getXUserPermission() {
    VXUserPermission testVXUserPermission = createVXUserPermission();
    Mockito.when(xUserMgr.getXUserPermission(testVXUserPermission.getId())).thenReturn(testVXUserPermission);
    VXUserPermission retVXUserPermission = xUserRest.getXUserPermission(testVXUserPermission.getId());
    Mockito.verify(xUserMgr).getXUserPermission(id);
    assertNotNull(retVXUserPermission);
    assertEquals(retVXUserPermission.getId(), testVXUserPermission.getId());
    assertEquals(retVXUserPermission.getUserName(), testVXUserPermission.getUserName());
}
Also used : VXUserPermission(org.apache.ranger.view.VXUserPermission) Test(org.junit.Test)

Aggregations

VXUserPermission (org.apache.ranger.view.VXUserPermission)26 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)16 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)14 Date (java.util.Date)12 XXUserPermission (org.apache.ranger.entity.XXUserPermission)12 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)11 XXModuleDef (org.apache.ranger.entity.XXModuleDef)11 XXPortalUser (org.apache.ranger.entity.XXPortalUser)10 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)10 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)9 VXPortalUser (org.apache.ranger.view.VXPortalUser)9 VXString (org.apache.ranger.view.VXString)9 XXGroupPermissionDao (org.apache.ranger.db.XXGroupPermissionDao)6 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)6 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)6 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)5 VXModuleDef (org.apache.ranger.view.VXModuleDef)4 VXStringList (org.apache.ranger.view.VXStringList)4 VXPasswordChange (org.apache.ranger.view.VXPasswordChange)3