Search in sources :

Example 31 with XXModuleDefDao

use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.

the class TestXUserMgr method test20DeleteXGroup.

@Test
public void test20DeleteXGroup() {
    setup();
    boolean force = true;
    VXGroup vXGroup = vxGroup();
    XXGroupDao xXGroupDao = Mockito.mock(XXGroupDao.class);
    XXUserDao xXUserDao = Mockito.mock(XXUserDao.class);
    VXUser vxUser = vxUser();
    XXUser xXUser = xxUser(vxUser);
    Mockito.when(daoManager.getXXUser()).thenReturn(xXUserDao);
    Mockito.when(xXUserDao.getById(xXUser.getId())).thenReturn(xXUser);
    XXGroup xXGroup = new XXGroup();
    Mockito.when(daoManager.getXXGroup()).thenReturn(xXGroupDao);
    Mockito.when(xXGroupDao.getById(vXGroup.getId())).thenReturn(xXGroup);
    Mockito.when(xGroupService.populateViewBean(xXGroup)).thenReturn(vXGroup);
    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);
    XXGroupGroupDao xXGroupGroupDao = Mockito.mock(XXGroupGroupDao.class);
    List<XXGroupGroup> xXGroupGroups = new ArrayList<XXGroupGroup>();
    XXGroupGroup xXGroupGroup = xxGroupGroup();
    xXGroupGroups.add(xXGroupGroup);
    Mockito.when(daoManager.getXXGroupGroup()).thenReturn(xXGroupGroupDao);
    Mockito.when(xXGroupGroupDao.findByGroupId(userId)).thenReturn(xXGroupGroups);
    XXGroupPermissionDao xXGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
    Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xXGroupPermissionDao);
    List<XXGroupPermission> xXGroupPermissions = new ArrayList<XXGroupPermission>();
    XXGroupPermission xGroupPermissionObj = xxGroupPermission();
    xXGroupPermissions.add(xGroupPermissionObj);
    Mockito.when(xXGroupPermissionDao.findByGroupId(vXGroup.getId())).thenReturn(xXGroupPermissions);
    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.findByGroupId(userId)).thenReturn(xXPolicyList);
    List<XXResource> xResourceList = new ArrayList<XXResource>();
    XXResource xXResource = new XXResource();
    xXResource.setId(userId);
    xXResource.setName("hadoopdev");
    xXResource.setIsRecursive(AppConstants.BOOL_TRUE);
    xXResource.setResourceStatus(AppConstants.STATUS_ENABLED);
    xResourceList.add(xXResource);
    XXResourceDao xxResourceDao = Mockito.mock(XXResourceDao.class);
    Mockito.when(daoManager.getXXResource()).thenReturn(xxResourceDao);
    Mockito.when(xxResourceDao.getById(Mockito.anyLong())).thenReturn(xXResource);
    RangerPolicy rangerPolicy = rangerPolicy();
    Mockito.when(policyService.getPopulatedViewObject(xXPolicy)).thenReturn(rangerPolicy);
    XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
    XXModuleDef xModuleDef = xxModuleDef();
    Mockito.when(xModuleDefDao.findByModuleId(Mockito.anyLong())).thenReturn(xModuleDef);
    List<XXSecurityZoneRefGroup> zoneSecRefGroup = new ArrayList<XXSecurityZoneRefGroup>();
    XXSecurityZoneRefGroupDao zoneSecRefGroupDao = Mockito.mock(XXSecurityZoneRefGroupDao.class);
    Mockito.when(daoManager.getXXSecurityZoneRefGroup()).thenReturn(zoneSecRefGroupDao);
    Mockito.when(zoneSecRefGroupDao.findByGroupId(userId)).thenReturn(zoneSecRefGroup);
    List<XXRoleRefGroup> roleRefGroup = new ArrayList<XXRoleRefGroup>();
    XXRoleRefGroupDao roleRefGroupDao = Mockito.mock(XXRoleRefGroupDao.class);
    Mockito.when(daoManager.getXXRoleRefGroup()).thenReturn(roleRefGroupDao);
    Mockito.when(roleRefGroupDao.findByGroupId(userId)).thenReturn(roleRefGroup);
    xUserMgr.deleteXGroup(vXGroup.getId(), force);
}
Also used : XXUser(org.apache.ranger.entity.XXUser) XXSecurityZoneRefGroup(org.apache.ranger.entity.XXSecurityZoneRefGroup) VXGroupUserList(org.apache.ranger.view.VXGroupUserList) VXPermMap(org.apache.ranger.view.VXPermMap) XXUserDao(org.apache.ranger.db.XXUserDao) XXGroupPermissionDao(org.apache.ranger.db.XXGroupPermissionDao) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) XXSecurityZoneRefGroupDao(org.apache.ranger.db.XXSecurityZoneRefGroupDao) XXPolicy(org.apache.ranger.entity.XXPolicy) XXRoleRefGroupDao(org.apache.ranger.db.XXRoleRefGroupDao) XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXModuleDef(org.apache.ranger.entity.XXModuleDef) XXRoleRefGroup(org.apache.ranger.entity.XXRoleRefGroup) XXPermMapDao(org.apache.ranger.db.XXPermMapDao) VXAuditMap(org.apache.ranger.view.VXAuditMap) VXPermMapList(org.apache.ranger.view.VXPermMapList) XXGroupGroupDao(org.apache.ranger.db.XXGroupGroupDao) XXResourceDao(org.apache.ranger.db.XXResourceDao) XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) XXResource(org.apache.ranger.entity.XXResource) XXAuditMapDao(org.apache.ranger.db.XXAuditMapDao) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) VXUser(org.apache.ranger.view.VXUser) XXGroup(org.apache.ranger.entity.XXGroup) XXPolicyDao(org.apache.ranger.db.XXPolicyDao) VXGroup(org.apache.ranger.view.VXGroup) XXGroupDao(org.apache.ranger.db.XXGroupDao) XXGroupGroup(org.apache.ranger.entity.XXGroupGroup) Test(org.junit.Test)

Example 32 with XXModuleDefDao

use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.

the class TestXUserMgr method test115UpdateUserRoleAssignments.

@Test
public void test115UpdateUserRoleAssignments() {
    destroySession();
    setup();
    UsersGroupRoleAssignments ugRoleAssignments = new UsersGroupRoleAssignments();
    Set<String> addUsers = new HashSet<String>();
    Set<String> delUsers = new HashSet<String>();
    addUsers.add("testuser");
    addUsers.add("testuser2");
    delUsers.add("testuser2");
    Map<String, String> userMap = new HashMap<String, String>();
    Map<String, String> groupMap = new HashMap<>();
    List<String> allUsers = new ArrayList<>(addUsers);
    userMap.put("testuser", "role1");
    userMap.put("testuser2", "role2");
    groupMap.put("testgroup1", "role1");
    groupMap.put("testgroup2", "role2");
    ugRoleAssignments.setUsers(allUsers);
    ugRoleAssignments.setGroupRoleAssignments(groupMap);
    ugRoleAssignments.setUserRoleAssignments(userMap);
    ugRoleAssignments.setWhiteListUserRoleAssignments(new HashMap<>());
    ugRoleAssignments.setWhiteListGroupRoleAssignments(new HashMap<>());
    VXUser vXUser = vxUser();
    List<VXUser> vXUserList = new ArrayList<VXUser>();
    vXUserList.add(vXUser);
    VXPortalUser vXPortalUser = userProfile();
    XXPortalUser xXPortalUser = xxPortalUser(vXPortalUser);
    xXPortalUser.setUserSource(RangerCommonEnums.USER_EXTERNAL);
    List<String> lstRole = new ArrayList<String>();
    lstRole.add(RangerConstants.ROLE_SYS_ADMIN);
    vXPortalUser.setUserRoleList(lstRole);
    Mockito.when(userMgr.getUserProfileByLoginId(vXUser.getName())).thenReturn(vXPortalUser);
    XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    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);
    Mockito.when(xUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(xUserPermissionsList);
    List<XXModuleDef> xXModuleDefs = xxModuleDefs();
    XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao);
    Mockito.when(daoManager.getXXModuleDef().getAll()).thenReturn(xXModuleDefs);
    xUserMgr.updateUserRoleAssignments(ugRoleAssignments);
    allUsers.clear();
    allUsers.add("UnMappedUser");
    ugRoleAssignments.setUsers(allUsers);
    ugRoleAssignments.setGroupRoleAssignments(groupMap);
    ugRoleAssignments.setUserRoleAssignments(userMap);
    VXUserPermission userPermission = vxUserPermission();
    List<VXUserPermission> userPermList = new ArrayList<VXUserPermission>();
    userPermList.add(userPermission);
    List<XXUserPermission> xUserPermissionsList1 = new ArrayList<XXUserPermission>();
    XXUserPermission xUserPermissionObj1 = xxUserPermission();
    xUserPermissionObj1.setModuleId(userPermission.getModuleId());
    xUserPermissionObj1.setUserId(userPermission.getUserId());
    xUserPermissionsList1.add(xUserPermissionObj1);
    UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
    Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
    userSessions.add(userSession);
    xUserMgr.updateUserRoleAssignments(ugRoleAssignments);
    vXPortalUser.setUserSource(RangerCommonEnums.USER_APP);
    Mockito.when(userMgr.getUserProfileByLoginId(Mockito.anyString())).thenReturn(vXPortalUser);
    xUserMgr.updateUserRoleAssignments(ugRoleAssignments);
}
Also used : HashMap(java.util.HashMap) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) 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) Date(java.util.Date) VXUserPermission(org.apache.ranger.view.VXUserPermission) UserSessionBase(org.apache.ranger.common.UserSessionBase) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXPortalUser(org.apache.ranger.view.VXPortalUser) UsersGroupRoleAssignments(org.apache.ranger.ugsyncutil.model.UsersGroupRoleAssignments) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 33 with XXModuleDefDao

use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.

the class TestXUserMgr method test48searchXGroups.

@Test
public void test48searchXGroups() {
    setupUser();
    VXGroup vXGroup = vxGroup();
    VXGroupList vXGroupListSort = new VXGroupList();
    List<VXGroup> vXGroups = new ArrayList<VXGroup>();
    vXGroups.add(vXGroup);
    vXGroupListSort.setVXGroups(vXGroups);
    String groupName = vXGroup.getName();
    SearchCriteria testSearchCriteria = createsearchCriteria();
    testSearchCriteria.addParam("name", groupName);
    Mockito.when(xGroupService.getGroupByGroupName(groupName)).thenReturn(vXGroup);
    Mockito.when(xGroupService.searchXGroups(testSearchCriteria)).thenReturn(vXGroupListSort);
    VXGroupList vXGroupList = xUserMgr.searchXGroups(testSearchCriteria);
    testSearchCriteria.addParam("isvisible", "true");
    vXGroupList = xUserMgr.searchXGroups(testSearchCriteria);
    Assert.assertNotNull(vXGroupList);
    testSearchCriteria = createsearchCriteria();
    testSearchCriteria.addParam("name", groupName);
    testSearchCriteria.addParam("groupsource", 1L);
    Mockito.when(xGroupService.searchXGroups(testSearchCriteria)).thenReturn(vXGroupListSort);
    vXGroupList = xUserMgr.searchXGroups(testSearchCriteria);
    Assert.assertNotNull(vXGroupList);
    testSearchCriteria = createsearchCriteria();
    testSearchCriteria.addParam("name", groupName);
    testSearchCriteria.addParam("userid", userId);
    VXUser loggedInUser = vxUser();
    List<String> loggedInUserRole = new ArrayList<String>();
    loggedInUserRole.add(RangerConstants.ROLE_USER);
    loggedInUser.setId(8L);
    loggedInUser.setName("testuser");
    loggedInUser.setUserRoleList(loggedInUserRole);
    Mockito.when(xUserService.getXUserByUserName(userLoginID)).thenReturn(loggedInUser);
    Mockito.when(xGroupService.searchXGroups(testSearchCriteria)).thenReturn(vXGroupListSort);
    List<Long> groupIdList = new ArrayList<Long>();
    groupIdList.add(2L);
    XXGroupUserDao mockxxGroupUserDao = Mockito.mock(XXGroupUserDao.class);
    Mockito.when(daoManager.getXXGroupUser()).thenReturn(mockxxGroupUserDao);
    Mockito.when(mockxxGroupUserDao.findGroupIdListByUserId(loggedInUser.getId())).thenReturn(groupIdList);
    XXModuleDefDao modDef = Mockito.mock(XXModuleDefDao.class);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(modDef);
    List<String> lstModule = new ArrayList<String>();
    lstModule.add(RangerConstants.MODULE_USER_GROUPS);
    Mockito.when(modDef.findAccessibleModulesByUserId(Mockito.anyLong(), Mockito.anyLong())).thenReturn(lstModule);
    xUserMgr.searchXGroups(testSearchCriteria);
}
Also used : XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) VXGroupList(org.apache.ranger.view.VXGroupList) ArrayList(java.util.ArrayList) VXLong(org.apache.ranger.view.VXLong) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) VXGroup(org.apache.ranger.view.VXGroup) SearchCriteria(org.apache.ranger.common.SearchCriteria) Test(org.junit.Test)

Example 34 with XXModuleDefDao

use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.

the class TestXUserMgr method test112CreateOrUpdateXUsers.

@Test
public void test112CreateOrUpdateXUsers() {
    destroySession();
    setup();
    List<VXUser> vXUserList = new ArrayList<VXUser>();
    VXUser vXUser = vxUser();
    vXUser.setFirstName("testuser");
    vXUser.setLastName("testuser");
    vXUser.setPassword("TestPassword@123");
    vXUser.setEmailAddress("");
    vXUser.setUserSource(RangerCommonEnums.USER_APP);
    Collection<String> userRoleList = new ArrayList<String>();
    userRoleList.add(RangerConstants.ROLE_USER);
    userRoleList.add(RangerConstants.ROLE_SYS_ADMIN);
    userRoleList.add(RangerConstants.ROLE_KEY_ADMIN);
    userRoleList.add(RangerConstants.ROLE_KEY_ADMIN_AUDITOR);
    userRoleList.add(RangerConstants.ROLE_ADMIN_AUDITOR);
    vXUser.setUserRoleList(userRoleList);
    vXUserList.add(vXUser);
    VXUserList users = new VXUserList(vXUserList);
    VXPortalUser vXPortalUser = userProfile();
    vXPortalUser.setFirstName("testuser");
    vXPortalUser.setLastName("testuser");
    vXPortalUser.setPassword("TestPassword@123");
    XXPortalUser xXPortalUser = xxPortalUser(vXPortalUser);
    List<XXModuleDef> xXModuleDefs = xxModuleDefs();
    List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
    XXUserPermission xUserPermissionObj = xxUserPermission();
    VXUserPermission userPermission = vxUserPermission();
    List<VXUserPermission> userPermList = new ArrayList<VXUserPermission>();
    userPermList.add(userPermission);
    xUserPermissionObj.setModuleId(userPermission.getModuleId());
    xUserPermissionObj.setUserId(userPermission.getUserId());
    xUserPermissionsList.add(xUserPermissionObj);
    UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
    Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
    userSessions.add(userSession);
    XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    XXGlobalStateDao xxGlobalStateDao = Mockito.mock(XXGlobalStateDao.class);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(daoManager.getXXPortalUser().create((XXPortalUser) Mockito.any())).thenReturn(xXPortalUser);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao);
    Mockito.when(xXModuleDefDao.getAll()).thenReturn(xXModuleDefs);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
    Mockito.when(xUserPermissionDao.findByModuleIdAndPortalUserId(null, null)).thenReturn(xUserPermissionObj);
    Mockito.when(xUserPermissionService.createResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
    Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(userId)).thenReturn(userSessions);
    Mockito.when(xUserService.createResource((VXUser) Mockito.any())).thenReturn(vXUser);
    Mockito.when(xUserPermissionService.populateViewBean(xUserPermissionObj)).thenReturn(userPermission);
    Mockito.when(xUserPermissionService.updateResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
    Mockito.when(daoManager.getXXGlobalState()).thenReturn(xxGlobalStateDao);
    xUserMgr.createOrUpdateXUsers(users);
    vXUser.setPassword("*****");
    xUserMgr.createOrUpdateXUsers(users);
}
Also used : XXUserDao(org.apache.ranger.db.XXUserDao) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) ArrayList(java.util.ArrayList) XXGlobalStateDao(org.apache.ranger.db.XXGlobalStateDao) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) XXUserPermission(org.apache.ranger.entity.XXUserPermission) VXUserList(org.apache.ranger.view.VXUserList) VXUserPermission(org.apache.ranger.view.VXUserPermission) UserSessionBase(org.apache.ranger.common.UserSessionBase) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 35 with XXModuleDefDao

use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.

the class TestXUserMgr method test42getUserRolesByExternalID.

@Test
public void test42getUserRolesByExternalID() {
    destroySession();
    setup();
    XXPortalUserRoleDao xPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
    VXUser vXUser = vxUser();
    VXPortalUser userProfile = userProfile();
    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 = xxUserPermission();
    xUserPermissionsList.add(xUserPermissionObj);
    List<XXGroupPermission> xGroupPermissionList = new ArrayList<XXGroupPermission>();
    XXGroupPermission xGroupPermissionObj = xxGroupPermission();
    xGroupPermissionList.add(xGroupPermissionObj);
    List<VXGroupPermission> groupPermList = new ArrayList<VXGroupPermission>();
    VXGroupPermission groupPermission = vxGroupPermission();
    groupPermList.add(groupPermission);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xPortalUserRoleDao);
    Mockito.when(xPortalUserRoleDao.findByUserId(userId)).thenReturn(xPortalUserRoleList);
    Mockito.when(xUserMgr.getXUser(userId)).thenReturn(vXUser);
    Mockito.when(userMgr.getUserProfileByLoginId(vXUser.getName())).thenReturn(userProfile);
    List<String> permissionList = new ArrayList<String>();
    permissionList.add(RangerConstants.MODULE_USER_GROUPS);
    VXUser loggedInUser = vxUser();
    List<String> loggedInUserRole = new ArrayList<String>();
    loggedInUserRole.add(RangerConstants.ROLE_ADMIN);
    loggedInUser.setId(8L);
    loggedInUser.setName("testuser");
    loggedInUser.setUserRoleList(loggedInUserRole);
    Mockito.when(xUserService.getXUserByUserName("admin")).thenReturn(loggedInUser);
    XXModuleDefDao mockxxModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(mockxxModuleDefDao);
    Mockito.when(mockxxModuleDefDao.findAccessibleModulesByUserId(8L, 8L)).thenReturn(permissionList);
    VXStringList vXStringList = xUserMgr.getUserRolesByExternalID(userId);
    Assert.assertNotNull(vXStringList);
    Mockito.when(restErrorUtil.createRESTException("Please provide a valid ID", MessageEnums.INVALID_INPUT_DATA)).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    Mockito.when(xUserService.readResourceWithOutLogin((Long) Mockito.any())).thenReturn(null);
    xUserMgr.getUserRolesByExternalID(userId);
}
Also used : XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) VXStringList(org.apache.ranger.view.VXStringList) WebApplicationException(javax.ws.rs.WebApplicationException) 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) VXString(org.apache.ranger.view.VXString) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) VXGroupPermission(org.apache.ranger.view.VXGroupPermission) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) Test(org.junit.Test)

Aggregations

XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)42 Test (org.junit.Test)42 ArrayList (java.util.ArrayList)37 VXString (org.apache.ranger.view.VXString)33 XXUserPermission (org.apache.ranger.entity.XXUserPermission)27 XXModuleDef (org.apache.ranger.entity.XXModuleDef)26 VXPortalUser (org.apache.ranger.view.VXPortalUser)26 VXUser (org.apache.ranger.view.VXUser)26 VXUserPermission (org.apache.ranger.view.VXUserPermission)22 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)21 XXPortalUser (org.apache.ranger.entity.XXPortalUser)20 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)18 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)18 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)16 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)15 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)15 Date (java.util.Date)14 UserSessionBase (org.apache.ranger.common.UserSessionBase)14 HashSet (java.util.HashSet)12 XXGroupPermissionDao (org.apache.ranger.db.XXGroupPermissionDao)12