Search in sources :

Example 31 with XXModuleDef

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

the class TestXUserMgr method test51assignPermissionToUser.

@Test
public void test51assignPermissionToUser() {
    XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    XXUserPermissionDao xXUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
    VXPortalUser vXPortalUser = userProfile();
    Collection<String> userRoleList = new ArrayList<String>();
    userRoleList.add("ROLE_USER");
    vXPortalUser.setUserRoleList(userRoleList);
    VXUser vxUser = vxUser();
    XXUser xXUser = xxUser(vxUser);
    List<XXModuleDef> xXModuleDefs = xxModuleDefs();
    VXUserPermission userPermission = vxUserPermission();
    List<VXUserPermission> userPermList = new ArrayList<VXUserPermission>();
    userPermList.add(userPermission);
    List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
    XXUserPermission xUserPermissionObj = xxUserPermission();
    xUserPermissionObj.setModuleId(userPermission.getModuleId());
    xUserPermissionObj.setUserId(userPermission.getUserId());
    xUserPermissionsList.add(xUserPermissionObj);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao);
    Mockito.when(xXModuleDefDao.getAll()).thenReturn(xXModuleDefs);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xXUserPermissionDao);
    Mockito.when(xXUserPermissionDao.findByModuleIdAndPortalUserId(vXPortalUser.getId(), xXModuleDefs.get(0).getId())).thenReturn(xUserPermissionObj);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(xxUserDao.findByPortalUserId(vXPortalUser.getId())).thenReturn(xXUser);
    UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
    Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
    userSessions.add(userSession);
    Mockito.when(xUserPermissionService.createResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
    Mockito.when(xUserPermissionService.populateViewBean(xUserPermissionObj)).thenReturn(userPermission);
    Mockito.when(xUserPermissionService.updateResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
    Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(userId)).thenReturn(userSessions);
    xUserMgr.assignPermissionToUser(vXPortalUser, true);
    userRoleList.clear();
    userRoleList.add("ROLE_SYS_ADMIN");
    vXPortalUser.setUserRoleList(userRoleList);
    xUserMgr.assignPermissionToUser(vXPortalUser, true);
    userRoleList.clear();
    userRoleList.add("ROLE_KEY_ADMIN");
    vXPortalUser.setUserRoleList(userRoleList);
    xUserMgr.assignPermissionToUser(vXPortalUser, true);
    userRoleList.clear();
    userRoleList.add("ROLE_KEY_ADMIN_AUDITOR");
    vXPortalUser.setUserRoleList(userRoleList);
    xUserMgr.assignPermissionToUser(vXPortalUser, true);
    userRoleList.clear();
    userRoleList.add("ROLE_ADMIN_AUDITOR");
    vXPortalUser.setUserRoleList(userRoleList);
    xUserMgr.assignPermissionToUser(vXPortalUser, true);
    Assert.assertNotNull(xXModuleDefs);
}
Also used : XXUser(org.apache.ranger.entity.XXUser) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) XXUserDao(org.apache.ranger.db.XXUserDao) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) XXUserPermission(org.apache.ranger.entity.XXUserPermission) VXUserPermission(org.apache.ranger.view.VXUserPermission) UserSessionBase(org.apache.ranger.common.UserSessionBase) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXPortalUser(org.apache.ranger.view.VXPortalUser) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 32 with XXModuleDef

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

the class PatchTagModulePermission_J10005 method assignPermissionOnTagModuleToAdminUsers.

public void assignPermissionOnTagModuleToAdminUsers() {
    int countUserPermissionUpdated = 0;
    XXModuleDef xModDef = daoManager.getXXModuleDef().findByModuleName(RangerConstants.MODULE_TAG_BASED_POLICIES);
    if (xModDef == null) {
        return;
    }
    List<XXPortalUser> allAdminUsers = daoManager.getXXPortalUser().findByRole(RangerConstants.ROLE_SYS_ADMIN);
    if (!CollectionUtils.isEmpty(allAdminUsers)) {
        for (XXPortalUser xPortalUser : allAdminUsers) {
            VXPortalUser vPortalUser = xPortalUserService.populateViewBean(xPortalUser);
            if (vPortalUser != null) {
                vPortalUser.setUserRoleList(daoManager.getXXPortalUserRole().findXPortalUserRolebyXPortalUserId(vPortalUser.getId()));
                xUserMgr.createOrUpdateUserPermisson(vPortalUser, xModDef.getId(), false);
                countUserPermissionUpdated += 1;
                logger.info("Added '" + xModDef.getModule() + "' permission to user '" + xPortalUser.getLoginId() + "'");
            }
        }
    }
    logger.info(countUserPermissionUpdated + " permissions were assigned");
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXPortalUser(org.apache.ranger.view.VXPortalUser)

Example 33 with XXModuleDef

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

the class XUserPermissionService method populateViewBean.

@Override
public VXUserPermission populateViewBean(XXUserPermission xObj) {
    VXUserPermission vObj = super.populateViewBean(xObj);
    XXPortalUser xPortalUser = daoManager.getXXPortalUser().getById(xObj.getUserId());
    if (xPortalUser != null) {
        vObj.setUserName(xPortalUser.getLoginId());
    }
    XXModuleDef xModuleDef = daoManager.getXXModuleDef().getById(xObj.getModuleId());
    if (xModuleDef != null) {
        vObj.setModuleName(xModuleDef.getModule());
    }
    return vObj;
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXUserPermission(org.apache.ranger.view.VXUserPermission)

Example 34 with XXModuleDef

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

the class TestXUserMgr method test05UpdateXUser.

@Test
public void test05UpdateXUser() {
    setup();
    XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    Collection<String> existingRoleList = new ArrayList<String>();
    existingRoleList.add(RangerConstants.ROLE_USER);
    Collection<String> reqRoleList = new ArrayList<String>();
    reqRoleList.add(RangerConstants.ROLE_SYS_ADMIN);
    Collection<Long> groupIdList = new ArrayList<Long>();
    groupIdList.add(userId);
    VXUser vxUser = vxUser();
    vxUser.setUserRoleList(reqRoleList);
    vxUser.setUserSource(RangerCommonEnums.USER_EXTERNAL);
    vxUser.setGroupIdList(groupIdList);
    vxUser.setFirstName("user12");
    vxUser.setLastName("test12");
    Mockito.when(xUserService.updateResource(vxUser)).thenReturn(vxUser);
    XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    VXPortalUser vXPortalUser = userProfile();
    vXPortalUser.setUserRoleList(existingRoleList);
    Mockito.when(userMgr.getUserProfileByLoginId(vxUser.getName())).thenReturn(vXPortalUser);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
    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<XXModuleDef> xXModuleDefs = xxModuleDefs();
    Mockito.when(xUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(xUserPermissionsList);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
    Mockito.when(xModuleDefDao.getAll()).thenReturn(xXModuleDefs);
    XXUser xXUser = xxUser(vxUser);
    XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(xxUserDao.findByPortalUserId(vXPortalUser.getId())).thenReturn(xXUser);
    VXGroupUserList vxGroupUserList = vxGroupUserList();
    Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
    UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
    Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
    userSessions.add(userSession);
    VXUserPermission vXUserPermission = vxUserPermission();
    Mockito.when(xUserPermissionService.createResource((VXUserPermission) Mockito.any())).thenReturn(vXUserPermission);
    Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(userId)).thenReturn(userSessions);
    VXUser dbvxUser = xUserMgr.updateXUser(vxUser);
    Assert.assertNotNull(dbvxUser);
    Assert.assertEquals(dbvxUser.getId(), vxUser.getId());
    Assert.assertEquals(dbvxUser.getDescription(), vxUser.getDescription());
    Assert.assertEquals(dbvxUser.getName(), vxUser.getName());
    Mockito.verify(xUserService).updateResource(vxUser);
    groupIdList.clear();
    groupIdList.add(9L);
    vxUser.setGroupIdList(groupIdList);
    List<XXTrxLog> trxLogList = new ArrayList<XXTrxLog>();
    Mockito.when(xGroupUserService.getTransactionLog((VXGroupUser) Mockito.any(), Mockito.anyString())).thenReturn(trxLogList);
    VXGroup vXGroup = vxGroup();
    Mockito.when(xGroupService.readResource(Mockito.anyLong())).thenReturn(vXGroup);
    VXGroupUser vXGroupUser = vxGroupUser();
    Mockito.when(xGroupUserService.createResource((VXGroupUser) Mockito.any())).thenReturn(vXGroupUser);
    dbvxUser = xUserMgr.updateXUser(vxUser);
    Assert.assertNotNull(dbvxUser);
}
Also used : XXUser(org.apache.ranger.entity.XXUser) VXGroupUserList(org.apache.ranger.view.VXGroupUserList) XXUserDao(org.apache.ranger.db.XXUserDao) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) VXUserPermission(org.apache.ranger.view.VXUserPermission) UserSessionBase(org.apache.ranger.common.UserSessionBase) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXPortalUser(org.apache.ranger.view.VXPortalUser) HashSet(java.util.HashSet) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) VXGroupUser(org.apache.ranger.view.VXGroupUser) XXTrxLog(org.apache.ranger.entity.XXTrxLog) VXUser(org.apache.ranger.view.VXUser) XXUserPermission(org.apache.ranger.entity.XXUserPermission) Date(java.util.Date) VXLong(org.apache.ranger.view.VXLong) VXGroup(org.apache.ranger.view.VXGroup) Test(org.junit.Test)

Example 35 with XXModuleDef

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

the class TestXUserMgr method test21DeleteXUser.

@Test
public void test21DeleteXUser() {
    setup();
    boolean force = true;
    VXUser vXUser = vxUser();
    XXUser xXUser = new XXUser();
    XXUserDao xXUserDao = Mockito.mock(XXUserDao.class);
    Mockito.when(daoManager.getXXUser()).thenReturn(xXUserDao);
    Mockito.when(xXUserDao.getById(vXUser.getId())).thenReturn(xXUser);
    Mockito.when(xUserService.populateViewBean(xXUser)).thenReturn(vXUser);
    VXGroupUserList vxGroupUserList = vxGroupUserList();
    XXGroupUserDao xGroupUserDao = Mockito.mock(XXGroupUserDao.class);
    Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
    Mockito.when(daoManager.getXXGroupUser()).thenReturn(xGroupUserDao);
    VXPermMapList vXPermMapList = new VXPermMapList();
    VXPermMap vXPermMap1 = getVXPermMap();
    List<VXPermMap> vXPermMaps = new ArrayList<VXPermMap>();
    vXPermMaps.add(vXPermMap1);
    vXPermMapList.setVXPermMaps(vXPermMaps);
    XXPermMapDao xXPermMapDao = Mockito.mock(XXPermMapDao.class);
    Mockito.when(xPermMapService.searchXPermMaps((SearchCriteria) Mockito.any())).thenReturn(vXPermMapList);
    Mockito.when(daoManager.getXXPermMap()).thenReturn(xXPermMapDao);
    VXAuditMapList vXAuditMapList = new VXAuditMapList();
    List<VXAuditMap> vXAuditMaps = new ArrayList<VXAuditMap>();
    VXAuditMap vXAuditMap = getVXAuditMap();
    vXAuditMaps.add(vXAuditMap);
    vXAuditMapList.setVXAuditMaps(vXAuditMaps);
    XXAuditMapDao xXAuditMapDao = Mockito.mock(XXAuditMapDao.class);
    Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(vXAuditMapList);
    Mockito.when(daoManager.getXXAuditMap()).thenReturn(xXAuditMapDao);
    VXPortalUser vXPortalUser = userProfile();
    XXPortalUser xXPortalUser = xxPortalUser(vXPortalUser);
    XXPortalUserDao xXPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xXPortalUserDao);
    Mockito.when(xXPortalUserDao.findByLoginId(vXUser.getName().trim())).thenReturn(xXPortalUser);
    Mockito.when(xPortalUserService.populateViewBean(xXPortalUser)).thenReturn(vXPortalUser);
    XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
    XXPortalUserRole.setId(userId);
    XXPortalUserRole.setUserId(userId);
    XXPortalUserRole.setUserRole("ROLE_USER");
    XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
    XXModuleDef xModuleDef = xxModuleDef();
    Mockito.when(xModuleDefDao.findByModuleId(Mockito.anyLong())).thenReturn(xModuleDef);
    XXAuthSessionDao xXAuthSessionDao = Mockito.mock(XXAuthSessionDao.class);
    XXUserPermissionDao xXUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    XXPortalUserRoleDao xXPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
    Mockito.when(daoManager.getXXAuthSession()).thenReturn(xXAuthSessionDao);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xXUserPermissionDao);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xXPortalUserRoleDao);
    List<XXAuthSession> xXAuthSessions = new ArrayList<XXAuthSession>();
    XXAuthSession xXAuthSession = new XXAuthSession();
    xXAuthSession.setId(userId);
    xXAuthSession.setLoginId(vXPortalUser.getLoginId());
    xXAuthSessions.add(xXAuthSession);
    List<XXUserPermission> xXUserPermissions = new ArrayList<XXUserPermission>();
    xXUserPermissions.add(xxUserPermission());
    List<XXPortalUserRole> xXPortalUserRoles = new ArrayList<XXPortalUserRole>();
    xXPortalUserRoles.add(XXPortalUserRole);
    Mockito.when(xXAuthSessionDao.getAuthSessionByUserId(vXPortalUser.getId())).thenReturn(xXAuthSessions);
    Mockito.when(xXUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(xXUserPermissions);
    Mockito.when(xXPortalUserRoleDao.findByUserId(vXPortalUser.getId())).thenReturn(xXPortalUserRoles);
    XXPolicyDao xXPolicyDao = Mockito.mock(XXPolicyDao.class);
    List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
    XXPolicy xXPolicy = getXXPolicy();
    xXPolicyList.add(xXPolicy);
    Mockito.when(daoManager.getXXPolicy()).thenReturn(xXPolicyDao);
    Mockito.when(xXPolicyDao.findByUserId(vXUser.getId())).thenReturn(xXPolicyList);
    RangerPolicy rangerPolicy = rangerPolicy();
    Mockito.when(policyService.getPopulatedViewObject(xXPolicy)).thenReturn(rangerPolicy);
    List<XXSecurityZoneRefUser> zoneSecRefUser = new ArrayList<XXSecurityZoneRefUser>();
    XXSecurityZoneRefUserDao zoneSecRefUserDao = Mockito.mock(XXSecurityZoneRefUserDao.class);
    Mockito.when(daoManager.getXXSecurityZoneRefUser()).thenReturn(zoneSecRefUserDao);
    Mockito.when(zoneSecRefUserDao.findByUserId(userId)).thenReturn(zoneSecRefUser);
    List<XXRoleRefUser> roleRefUser = new ArrayList<XXRoleRefUser>();
    XXRoleRefUserDao roleRefUserDao = Mockito.mock(XXRoleRefUserDao.class);
    Mockito.when(daoManager.getXXRoleRefUser()).thenReturn(roleRefUserDao);
    Mockito.when(roleRefUserDao.findByUserId(userId)).thenReturn(roleRefUser);
    xUserMgr.deleteXUser(vXUser.getId(), force);
    force = false;
    xUserMgr.deleteXUser(vXUser.getId(), force);
}
Also used : XXRoleRefUser(org.apache.ranger.entity.XXRoleRefUser) XXUser(org.apache.ranger.entity.XXUser) VXGroupUserList(org.apache.ranger.view.VXGroupUserList) VXPermMap(org.apache.ranger.view.VXPermMap) XXUserDao(org.apache.ranger.db.XXUserDao) ArrayList(java.util.ArrayList) XXSecurityZoneRefUser(org.apache.ranger.entity.XXSecurityZoneRefUser) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) XXPolicy(org.apache.ranger.entity.XXPolicy) XXAuthSessionDao(org.apache.ranger.db.XXAuthSessionDao) XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) XXModuleDef(org.apache.ranger.entity.XXModuleDef) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXPermMapDao(org.apache.ranger.db.XXPermMapDao) VXAuditMap(org.apache.ranger.view.VXAuditMap) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) VXPermMapList(org.apache.ranger.view.VXPermMapList) XXRoleRefUserDao(org.apache.ranger.db.XXRoleRefUserDao) XXAuditMapDao(org.apache.ranger.db.XXAuditMapDao) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) VXUser(org.apache.ranger.view.VXUser) XXAuthSession(org.apache.ranger.entity.XXAuthSession) XXUserPermission(org.apache.ranger.entity.XXUserPermission) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXSecurityZoneRefUserDao(org.apache.ranger.db.XXSecurityZoneRefUserDao) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) XXPolicyDao(org.apache.ranger.db.XXPolicyDao) Test(org.junit.Test)

Aggregations

XXModuleDef (org.apache.ranger.entity.XXModuleDef)41 ArrayList (java.util.ArrayList)34 Test (org.junit.Test)31 XXUserPermission (org.apache.ranger.entity.XXUserPermission)29 VXPortalUser (org.apache.ranger.view.VXPortalUser)28 VXUserPermission (org.apache.ranger.view.VXUserPermission)28 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)26 VXString (org.apache.ranger.view.VXString)26 XXPortalUser (org.apache.ranger.entity.XXPortalUser)25 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)23 Date (java.util.Date)19 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)19 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)18 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)18 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)16 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)16 VXUser (org.apache.ranger.view.VXUser)15 XXUserDao (org.apache.ranger.db.XXUserDao)14 HashSet (java.util.HashSet)13 UserSessionBase (org.apache.ranger.common.UserSessionBase)13