Search in sources :

Example 11 with XXUserPermission

use of org.apache.ranger.entity.XXUserPermission in project ranger by apache.

the class TestXUserMgr method test38deleteXUserPermission.

@Test
public void test38deleteXUserPermission() {
    Mockito.when(xUserPermissionService.deleteResource(1L)).thenReturn(true);
    XXUserPermission xUserPerm = Mockito.mock(XXUserPermission.class);
    XXUserPermissionDao xUserPermDao = Mockito.mock(XXUserPermissionDao.class);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermDao);
    Mockito.when(daoManager.getXXUserPermission().getById(1L)).thenReturn(xUserPerm);
    xUserMgr.deleteXUserPermission(1L, true);
    Mockito.verify(xUserPermissionService).deleteResource(1L);
}
Also used : XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) XXUserPermission(org.apache.ranger.entity.XXUserPermission) Test(org.junit.Test)

Example 12 with XXUserPermission

use of org.apache.ranger.entity.XXUserPermission in project ranger by apache.

the class TestUserMgr method test33setUserRoles.

@Test
public void test33setUserRoles() {
    setup();
    XXPortalUserRoleDao xPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    XXGroupPermissionDao xGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
    XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    VXPortalUser userProfile = userProfile();
    XXPortalUser user = new XXPortalUser();
    user.setEmailAddress(userProfile.getEmailAddress());
    user.setFirstName(userProfile.getFirstName());
    user.setLastName(userProfile.getLastName());
    user.setLoginId(userProfile.getLoginId());
    user.setPassword(userProfile.getPassword());
    user.setUserSource(userProfile.getUserSource());
    user.setPublicScreenName(userProfile.getPublicScreenName());
    user.setId(userProfile.getId());
    List<VXString> vStringRolesList = new ArrayList<VXString>();
    VXString vXStringObj = new VXString();
    vXStringObj.setValue("ROLE_USER");
    vStringRolesList.add(vXStringObj);
    List<XXPortalUserRole> xPortalUserRoleList = new ArrayList<XXPortalUserRole>();
    XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
    XXPortalUserRole.setId(userId);
    XXPortalUserRole.setUserId(userId);
    XXPortalUserRole.setUserRole("ROLE_USER");
    xPortalUserRoleList.add(XXPortalUserRole);
    List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
    XXUserPermission xUserPermissionObj = new XXUserPermission();
    xUserPermissionObj.setAddedByUserId(userId);
    xUserPermissionObj.setCreateTime(new Date());
    xUserPermissionObj.setId(userId);
    xUserPermissionObj.setIsAllowed(1);
    xUserPermissionObj.setModuleId(1L);
    xUserPermissionObj.setUpdatedByUserId(userId);
    xUserPermissionObj.setUpdateTime(new Date());
    xUserPermissionObj.setUserId(userId);
    xUserPermissionsList.add(xUserPermissionObj);
    List<XXGroupPermission> xGroupPermissionList = new ArrayList<XXGroupPermission>();
    XXGroupPermission xGroupPermissionObj = new XXGroupPermission();
    xGroupPermissionObj.setAddedByUserId(userId);
    xGroupPermissionObj.setCreateTime(new Date());
    xGroupPermissionObj.setId(userId);
    xGroupPermissionObj.setIsAllowed(1);
    xGroupPermissionObj.setModuleId(1L);
    xGroupPermissionObj.setUpdatedByUserId(userId);
    xGroupPermissionObj.setUpdateTime(new Date());
    xGroupPermissionObj.setGroupId(userId);
    xGroupPermissionList.add(xGroupPermissionObj);
    List<VXGroupPermission> groupPermList = new ArrayList<VXGroupPermission>();
    VXGroupPermission groupPermission = new VXGroupPermission();
    groupPermission.setId(1L);
    groupPermission.setIsAllowed(1);
    groupPermission.setModuleId(1L);
    groupPermission.setGroupId(userId);
    groupPermission.setGroupName("xyz");
    groupPermission.setOwner("admin");
    groupPermList.add(groupPermission);
    XXModuleDef xModuleDef = new XXModuleDef();
    xModuleDef.setUpdatedByUserId(userId);
    xModuleDef.setAddedByUserId(userId);
    xModuleDef.setCreateTime(new Date());
    xModuleDef.setId(userId);
    xModuleDef.setModule("Policy manager");
    xModuleDef.setUpdateTime(new Date());
    xModuleDef.setUrl("/policy manager");
    VXUserPermission userPermission = new VXUserPermission();
    userPermission.setId(1L);
    userPermission.setIsAllowed(1);
    userPermission.setModuleId(1L);
    userPermission.setUserId(userId);
    userPermission.setUserName("xyz");
    userPermission.setOwner("admin");
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xPortalUserRoleDao);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(userDao.getById(userId)).thenReturn(user);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
    Mockito.when(xUserPermissionDao.findByUserPermissionIdAndIsAllowed(userProfile.getId())).thenReturn(xUserPermissionsList);
    Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xGroupPermissionDao);
    Mockito.when(xGroupPermissionDao.findbyVXPortalUserId(userProfile.getId())).thenReturn(xGroupPermissionList);
    Mockito.when(xGroupPermissionService.populateViewBean(xGroupPermissionObj)).thenReturn(groupPermission);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
    Mockito.when(xModuleDefDao.findByModuleId(Mockito.anyLong())).thenReturn(xModuleDef);
    Mockito.when(xUserPermissionService.populateViewBean(xUserPermissionObj)).thenReturn(userPermission);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
    Mockito.when(xModuleDefDao.findByModuleId(Mockito.anyLong())).thenReturn(xModuleDef);
    Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
    userMgr.checkAccess(userId);
    userMgr.setUserRoles(userId, vStringRolesList);
    Mockito.verify(daoManager).getXXUserPermission();
    Mockito.verify(daoManager).getXXGroupPermission();
    Mockito.verify(xGroupPermissionService).populateViewBean(xGroupPermissionObj);
    Mockito.verify(xUserPermissionService).populateViewBean(xUserPermissionObj);
}
Also used : XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) XXGroupPermissionDao(org.apache.ranger.db.XXGroupPermissionDao) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) XXUserPermission(org.apache.ranger.entity.XXUserPermission) Date(java.util.Date) VXUserPermission(org.apache.ranger.view.VXUserPermission) VXString(org.apache.ranger.view.VXString) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXGroupPermission(org.apache.ranger.view.VXGroupPermission) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) Test(org.junit.Test)

Example 13 with XXUserPermission

use of org.apache.ranger.entity.XXUserPermission in project ranger by apache.

the class TestUserMgr method test31getUserProfile.

@Test
public void test31getUserProfile() {
    setup();
    XXPortalUserDao xPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    XXPortalUser xPortalUser = Mockito.mock(XXPortalUser.class);
    XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    XXGroupPermissionDao xGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
    XXPortalUserRoleDao xPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
    List<XXPortalUserRole> xPortalUserRoleList = new ArrayList<XXPortalUserRole>();
    XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
    XXPortalUserRole.setId(userId);
    XXPortalUserRole.setUserRole("ROLE_USER");
    xPortalUserRoleList.add(XXPortalUserRole);
    List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
    XXUserPermission xUserPermissionObj = new XXUserPermission();
    xUserPermissionObj.setAddedByUserId(userId);
    xUserPermissionObj.setCreateTime(new Date());
    xUserPermissionObj.setId(userId);
    xUserPermissionObj.setIsAllowed(1);
    xUserPermissionObj.setModuleId(1L);
    xUserPermissionObj.setUpdatedByUserId(userId);
    xUserPermissionObj.setUpdateTime(new Date());
    xUserPermissionObj.setUserId(userId);
    xUserPermissionsList.add(xUserPermissionObj);
    List<XXGroupPermission> xGroupPermissionList = new ArrayList<XXGroupPermission>();
    XXGroupPermission xGroupPermissionObj = new XXGroupPermission();
    xGroupPermissionObj.setAddedByUserId(userId);
    xGroupPermissionObj.setCreateTime(new Date());
    xGroupPermissionObj.setId(userId);
    xGroupPermissionObj.setIsAllowed(1);
    xGroupPermissionObj.setModuleId(1L);
    xGroupPermissionObj.setUpdatedByUserId(userId);
    xGroupPermissionObj.setUpdateTime(new Date());
    xGroupPermissionObj.setGroupId(userId);
    xGroupPermissionList.add(xGroupPermissionObj);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xPortalUserDao);
    Mockito.when(xPortalUserDao.getById(userId)).thenReturn(xPortalUser);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xPortalUserRoleDao);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
    Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xGroupPermissionDao);
    VXPortalUser dbVXPortalUser = userMgr.getUserProfile(userId);
    Assert.assertNotNull(dbVXPortalUser);
    Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(daoManager).getXXUserPermission();
    Mockito.verify(daoManager).getXXUserPermission();
    Mockito.verify(daoManager).getXXGroupPermission();
}
Also used : XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) XXGroupPermissionDao(org.apache.ranger.db.XXGroupPermissionDao) ArrayList(java.util.ArrayList) XXUserPermission(org.apache.ranger.entity.XXUserPermission) Date(java.util.Date) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) Test(org.junit.Test)

Example 14 with XXUserPermission

use of org.apache.ranger.entity.XXUserPermission in project ranger by apache.

the class TestUserMgr method test21CreateUser.

@Test
public void test21CreateUser() {
    setup();
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    XXPortalUserRoleDao roleDao = Mockito.mock(XXPortalUserRoleDao.class);
    XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    XXGroupPermissionDao xGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
    XXPortalUser user = new XXPortalUser();
    VXPortalUser userProfile = userProfile();
    XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
    XXPortalUserRole.setId(userId);
    XXPortalUserRole.setUserRole("ROLE_USER");
    List<XXPortalUserRole> list = new ArrayList<XXPortalUserRole>();
    list.add(XXPortalUserRole);
    List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
    XXUserPermission xUserPermissionObj = new XXUserPermission();
    xUserPermissionObj.setAddedByUserId(userId);
    xUserPermissionObj.setCreateTime(new Date());
    xUserPermissionObj.setId(userId);
    xUserPermissionObj.setIsAllowed(1);
    xUserPermissionObj.setModuleId(1L);
    xUserPermissionObj.setUpdatedByUserId(userId);
    xUserPermissionObj.setUpdateTime(new Date());
    xUserPermissionObj.setUserId(userId);
    xUserPermissionsList.add(xUserPermissionObj);
    List<XXGroupPermission> xGroupPermissionList = new ArrayList<XXGroupPermission>();
    XXGroupPermission xGroupPermissionObj = new XXGroupPermission();
    xGroupPermissionObj.setAddedByUserId(userId);
    xGroupPermissionObj.setCreateTime(new Date());
    xGroupPermissionObj.setId(userId);
    xGroupPermissionObj.setIsAllowed(1);
    xGroupPermissionObj.setModuleId(1L);
    xGroupPermissionObj.setUpdatedByUserId(userId);
    xGroupPermissionObj.setUpdateTime(new Date());
    xGroupPermissionObj.setGroupId(userId);
    xGroupPermissionList.add(xGroupPermissionObj);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(userDao.create((XXPortalUser) Mockito.any())).thenReturn(user);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
    Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xGroupPermissionDao);
    Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
    VXPortalUser dbVXPortalUser = userMgr.createUser(userProfile);
    Assert.assertNotNull(dbVXPortalUser);
    Assert.assertEquals(user.getId(), dbVXPortalUser.getId());
    Assert.assertEquals(user.getFirstName(), dbVXPortalUser.getFirstName());
    Assert.assertEquals(user.getFirstName(), dbVXPortalUser.getFirstName());
    Assert.assertEquals(user.getLastName(), dbVXPortalUser.getLastName());
    Assert.assertEquals(user.getLoginId(), dbVXPortalUser.getLoginId());
    Assert.assertEquals(user.getEmailAddress(), dbVXPortalUser.getEmailAddress());
    Assert.assertEquals(user.getPassword(), dbVXPortalUser.getPassword());
    Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(daoManager).getXXUserPermission();
    Mockito.verify(daoManager).getXXGroupPermission();
}
Also used : XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) XXGroupPermissionDao(org.apache.ranger.db.XXGroupPermissionDao) ArrayList(java.util.ArrayList) XXUserPermission(org.apache.ranger.entity.XXUserPermission) Date(java.util.Date) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) Test(org.junit.Test)

Example 15 with XXUserPermission

use of org.apache.ranger.entity.XXUserPermission 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)

Aggregations

XXUserPermission (org.apache.ranger.entity.XXUserPermission)23 ArrayList (java.util.ArrayList)18 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)14 XXPortalUser (org.apache.ranger.entity.XXPortalUser)14 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)14 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)13 Test (org.junit.Test)13 VXPortalUser (org.apache.ranger.view.VXPortalUser)12 VXUserPermission (org.apache.ranger.view.VXUserPermission)12 Date (java.util.Date)11 XXModuleDef (org.apache.ranger.entity.XXModuleDef)11 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)11 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)10 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)9 VXString (org.apache.ranger.view.VXString)9 XXGroupPermissionDao (org.apache.ranger.db.XXGroupPermissionDao)7 XXUser (org.apache.ranger.entity.XXUser)6 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)5 VXStringList (org.apache.ranger.view.VXStringList)4 UserSessionBase (org.apache.ranger.common.UserSessionBase)3