Search in sources :

Example 96 with VXPortalUser

use of org.apache.ranger.view.VXPortalUser 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 97 with VXPortalUser

use of org.apache.ranger.view.VXPortalUser 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)

Example 98 with VXPortalUser

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

the class TestXUserMgr method test03CreateXUser_WithBlankName.

@Test
public void test03CreateXUser_WithBlankName() {
    destroySession();
    setup();
    VXUser vxUser = vxUser();
    ArrayList<String> userRoleListVXPortaUser = getRoleList();
    VXPortalUser vXPortalUser = new VXPortalUser();
    vXPortalUser.setUserRoleList(userRoleListVXPortaUser);
    vxUser.setName("");
    Mockito.when(restErrorUtil.createRESTException("Please provide a valid username.", MessageEnums.INVALID_INPUT_DATA)).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    xUserMgr.createXUser(vxUser);
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) VXPortalUser(org.apache.ranger.view.VXPortalUser) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) Test(org.junit.Test)

Example 99 with VXPortalUser

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

the class TestXUserMgr method test53getXGroupUserFromMap.

@Test
public void test53getXGroupUserFromMap() {
    setup();
    VXGroup vxGroup = vxGroup();
    VXUser vxUser = vxUser();
    List<VXUser> vXUserList = new ArrayList<VXUser>();
    vXUserList.add(vxUser);
    VXGroupUserInfo vxGUInfo = new VXGroupUserInfo();
    vxGUInfo.setXgroupInfo(vxGroup);
    vxGUInfo.setXuserInfo(vXUserList);
    XXGroupDao xxGroupDao = Mockito.mock(XXGroupDao.class);
    XXGroup xxGroup = new XXGroup();
    xxGroup.setId(vxGroup.getId());
    xxGroup.setName(vxGroup.getName());
    xxGroup.setDescription(vxGroup.getDescription());
    xxGroup.setIsVisible(vxGroup.getIsVisible());
    VXPortalUser userProfile = userProfile();
    XXPortalUser xXPortalUser = xxPortalUser(userProfile);
    xXPortalUser.setUserSource(RangerCommonEnums.USER_EXTERNAL);
    VXGroupUserList vxGroupUserList = new VXGroupUserList();
    List<VXGroupUser> vXGroupUsers = new ArrayList<VXGroupUser>();
    VXGroupUser vxGroupUser = vxGroupUser();
    vXGroupUsers.add(vxGroupUser);
    vxGroupUserList.setVXGroupUsers(vXGroupUsers);
    List<String> lstRole = new ArrayList<String>();
    lstRole.add(RangerConstants.ROLE_USER);
    Mockito.when(daoManager.getXXGroup()).thenReturn(xxGroupDao);
    SearchCriteria searchCriteria = createsearchCriteria();
    searchCriteria.addParam("xGroupId", xxGroup.getId());
    Mockito.when(xxGroupDao.findByGroupName("")).thenReturn(null);
    VXGroupUserInfo vxGUInfoObjNull = xUserMgr.getXGroupUserFromMap("");
    Assert.assertNull(vxGUInfoObjNull.getXgroupInfo());
    Mockito.when(xxGroupDao.findByGroupName(Mockito.anyString())).thenReturn(xxGroup);
    Mockito.when(xGroupService.populateViewBean(xxGroup)).thenReturn(vxGroup);
    Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
    XXUser xXUser = xxUser(vxUser);
    XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(xxUserDao.getById(userId)).thenReturn(xXUser);
    XXPortalUserDao xXPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xXPortalUserDao);
    Mockito.when(xXPortalUserDao.findByLoginId(xXUser.getName().trim())).thenReturn(xXPortalUser);
    XXPortalUserRoleDao xXPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xXPortalUserRoleDao);
    vxGUInfoObjNull = xUserMgr.getXGroupUserFromMap(xxGroup.getName());
}
Also used : XXUser(org.apache.ranger.entity.XXUser) VXGroupUserList(org.apache.ranger.view.VXGroupUserList) XXUserDao(org.apache.ranger.db.XXUserDao) ArrayList(java.util.ArrayList) VXGroupUser(org.apache.ranger.view.VXGroupUser) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) SearchCriteria(org.apache.ranger.common.SearchCriteria) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) XXGroup(org.apache.ranger.entity.XXGroup) VXGroupUserInfo(org.apache.ranger.view.VXGroupUserInfo) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXGroup(org.apache.ranger.view.VXGroup) XXGroupDao(org.apache.ranger.db.XXGroupDao) Test(org.junit.Test)

Example 100 with VXPortalUser

use of org.apache.ranger.view.VXPortalUser 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)

Aggregations

VXPortalUser (org.apache.ranger.view.VXPortalUser)129 Test (org.junit.Test)110 XXPortalUser (org.apache.ranger.entity.XXPortalUser)86 VXString (org.apache.ranger.view.VXString)80 ArrayList (java.util.ArrayList)74 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)61 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)49 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)47 XXUserPermission (org.apache.ranger.entity.XXUserPermission)47 VXUser (org.apache.ranger.view.VXUser)33 Date (java.util.Date)29 WebApplicationException (javax.ws.rs.WebApplicationException)29 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)29 XXModuleDef (org.apache.ranger.entity.XXModuleDef)28 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)26 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)26 VXUserPermission (org.apache.ranger.view.VXUserPermission)24 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)21 XXUserDao (org.apache.ranger.db.XXUserDao)20 XXUser (org.apache.ranger.entity.XXUser)19