Search in sources :

Example 86 with VXPortalUser

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

the class TestXUserMgr method test28DeleteXUser.

@Test
public void test28DeleteXUser() {
    setup();
    boolean force = true;
    VXUser vXUser = vxUser();
    // XXUser
    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);
    // VXGroupUser
    VXGroupUserList vxGroupUserList = new VXGroupUserList();
    XXGroupUserDao xGroupUserDao = Mockito.mock(XXGroupUserDao.class);
    VXGroupUser vxGroupUser = new VXGroupUser();
    vxGroupUser.setId(userId);
    vxGroupUser.setName("group user test");
    vxGroupUser.setOwner("Admin");
    vxGroupUser.setUserId(vXUser.getId());
    vxGroupUser.setUpdatedBy("User");
    Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
    Mockito.when(daoManager.getXXGroupUser()).thenReturn(xGroupUserDao);
    // VXPermMap
    VXPermMapList vXPermMapList = new VXPermMapList();
    XXPermMapDao xXPermMapDao = Mockito.mock(XXPermMapDao.class);
    Mockito.when(xPermMapService.searchXPermMaps((SearchCriteria) Mockito.any())).thenReturn(vXPermMapList);
    Mockito.when(daoManager.getXXPermMap()).thenReturn(xXPermMapDao);
    // VXAuditMap
    VXAuditMapList vXAuditMapList = new VXAuditMapList();
    XXAuditMapDao xXAuditMapDao = Mockito.mock(XXAuditMapDao.class);
    Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(vXAuditMapList);
    Mockito.when(daoManager.getXXAuditMap()).thenReturn(xXAuditMapDao);
    // XXPortalUser
    VXPortalUser vXPortalUser = userProfile();
    XXPortalUser xXPortalUser = new XXPortalUser();
    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);
    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>();
    List<XXUserPermission> xXUserPermissions = new ArrayList<XXUserPermission>();
    List<XXPortalUserRole> xXPortalUserRoles = new ArrayList<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);
    // update XXPolicyItemUserPerm
    XXPolicyDao xXPolicyDao = Mockito.mock(XXPolicyDao.class);
    List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
    Mockito.when(daoManager.getXXPolicy()).thenReturn(xXPolicyDao);
    Mockito.when(xXPolicyDao.findByUserId(vXUser.getId())).thenReturn(xXPolicyList);
    xUserMgr.deleteXUser(vXUser.getId(), force);
    Mockito.verify(xGroupUserService).searchXGroupUsers((SearchCriteria) Mockito.any());
}
Also used : XXUser(org.apache.ranger.entity.XXUser) VXGroupUserList(org.apache.ranger.view.VXGroupUserList) XXUserDao(org.apache.ranger.db.XXUserDao) ArrayList(java.util.ArrayList) XXPolicy(org.apache.ranger.entity.XXPolicy) XXAuthSessionDao(org.apache.ranger.db.XXAuthSessionDao) XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) XXPermMapDao(org.apache.ranger.db.XXPermMapDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) VXPermMapList(org.apache.ranger.view.VXPermMapList) XXAuditMapDao(org.apache.ranger.db.XXAuditMapDao) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) VXGroupUser(org.apache.ranger.view.VXGroupUser) 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) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) XXPolicyDao(org.apache.ranger.db.XXPolicyDao) Test(org.junit.Test)

Example 87 with VXPortalUser

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

the class TestXUserMgr method test12UpdateXUser.

@Test
public void test12UpdateXUser() {
    setup();
    VXUser vxUser = vxUser();
    vxUser.setUserSource(RangerCommonEnums.USER_APP);
    vxUser.setName("name");
    Mockito.when(xUserService.updateResource(vxUser)).thenReturn(vxUser);
    VXPortalUser vXPortalUser = new VXPortalUser();
    Mockito.when(userMgr.getUserProfileByLoginId(vxUser.getName())).thenReturn(vXPortalUser);
    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);
}
Also used : VXPortalUser(org.apache.ranger.view.VXPortalUser) VXUser(org.apache.ranger.view.VXUser) Test(org.junit.Test)

Example 88 with VXPortalUser

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

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

the class TestXUserMgr method test109AssignPermissionToUser.

@Test
public void test109AssignPermissionToUser() {
    destroySession();
    setup();
    VXPortalUser vXPortalUser = userProfile();
    List<XXModuleDef> xXModuleDefs = xxModuleDefs();
    XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao);
    Mockito.when(daoManager.getXXModuleDef().getAll()).thenReturn(xXModuleDefs);
    VXUserPermission userPermission = vxUserPermission();
    List<VXUserPermission> userPermList = new ArrayList<VXUserPermission>();
    userPermList.add(userPermission);
    List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
    XXUserPermission xUserPermission = xxUserPermission();
    xUserPermission.setModuleId(userPermission.getModuleId());
    xUserPermission.setUserId(userPermission.getUserId());
    xUserPermissionsList.add(xUserPermission);
    XXUserPermissionDao xXUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xXUserPermissionDao);
    Mockito.when(xXUserPermissionDao.findByModuleIdAndPortalUserId(vXPortalUser.getId(), xXModuleDefs.get(0).getId())).thenReturn(xUserPermission);
    VXUser vxUser = vxUser();
    XXUser xXUser = xxUser(vxUser);
    XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(xxUserDao.findByPortalUserId(vXPortalUser.getId())).thenReturn(xXUser);
    Mockito.when(xUserPermissionService.populateViewBean(xUserPermission)).thenReturn(userPermission);
    Mockito.when(xUserPermissionService.createResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
    Mockito.when(xUserPermissionService.updateResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
    UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
    Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
    userSessions.add(userSession);
    Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(userId)).thenReturn(userSessions);
    Collection<String> existingRoleList = new ArrayList<String>();
    existingRoleList.add(RangerConstants.ROLE_SYS_ADMIN);
    vXPortalUser.setUserRoleList(existingRoleList);
    xUserMgr.assignPermissionToUser(vXPortalUser, true);
    existingRoleList.clear();
    existingRoleList.add(RangerConstants.ROLE_KEY_ADMIN);
    vXPortalUser.setUserRoleList(existingRoleList);
    xUserMgr.assignPermissionToUser(vXPortalUser, true);
    existingRoleList.clear();
    existingRoleList.add(RangerConstants.ROLE_KEY_ADMIN_AUDITOR);
    vXPortalUser.setUserRoleList(existingRoleList);
    xUserMgr.assignPermissionToUser(vXPortalUser, true);
    existingRoleList.clear();
    existingRoleList.add(RangerConstants.ROLE_ADMIN_AUDITOR);
    vXPortalUser.setUserRoleList(existingRoleList);
    xUserMgr.assignPermissionToUser(vXPortalUser, true);
}
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) XXUserPermission(org.apache.ranger.entity.XXUserPermission) VXUser(org.apache.ranger.view.VXUser) 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 90 with VXPortalUser

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

the class TestXUserMgr method test01CreateXUser.

@Test
public void test01CreateXUser() {
    setup();
    VXUser vxUser = vxUser();
    vxUser.setFirstName("user12");
    vxUser.setLastName("test12");
    Collection<Long> groupIdList = new ArrayList<Long>();
    groupIdList.add(userId);
    vxUser.setGroupIdList(groupIdList);
    VXGroup vxGroup = vxGroup();
    vxGroup.setName("user12Grp");
    VXGroupUser vXGroupUser = new VXGroupUser();
    vXGroupUser.setParentGroupId(userId);
    vXGroupUser.setUserId(userId);
    vXGroupUser.setName(vxGroup.getName());
    Mockito.when(xGroupService.readResource(userId)).thenReturn(vxGroup);
    Mockito.when(xGroupUserService.createResource((VXGroupUser) Mockito.any())).thenReturn(vXGroupUser);
    ArrayList<String> userRoleListVXPortaUser = getRoleList();
    VXPortalUser vXPortalUser = new VXPortalUser();
    vXPortalUser.setUserRoleList(userRoleListVXPortaUser);
    Mockito.when(xUserService.createResource(vxUser)).thenReturn(vxUser);
    XXModuleDefDao value = Mockito.mock(XXModuleDefDao.class);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(value);
    Mockito.when(userMgr.createDefaultAccountUser((VXPortalUser) Mockito.any())).thenReturn(vXPortalUser);
    Mockito.when(stringUtil.validateEmail("test@test.com")).thenReturn(true);
    VXUser dbUser = xUserMgr.createXUser(vxUser);
    Assert.assertNotNull(dbUser);
    userId = dbUser.getId();
    Assert.assertEquals(userId, dbUser.getId());
    Assert.assertEquals(dbUser.getDescription(), vxUser.getDescription());
    Assert.assertEquals(dbUser.getName(), vxUser.getName());
    Assert.assertEquals(dbUser.getUserRoleList(), vxUser.getUserRoleList());
    Assert.assertEquals(dbUser.getGroupNameList(), vxUser.getGroupNameList());
    Mockito.verify(xUserService).createResource(vxUser);
    Mockito.when(xUserService.readResourceWithOutLogin(userId)).thenReturn(vxUser);
    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);
    VXUser dbvxUser = xUserMgr.getXUser(userId);
    Mockito.verify(userMgr).createDefaultAccountUser((VXPortalUser) Mockito.any());
    Assert.assertNotNull(dbvxUser);
    Assert.assertEquals(userId, dbvxUser.getId());
    Assert.assertEquals(dbvxUser.getDescription(), vxUser.getDescription());
    Assert.assertEquals(dbvxUser.getName(), vxUser.getName());
    Assert.assertEquals(dbvxUser.getUserRoleList(), vxUser.getUserRoleList());
    Assert.assertEquals(dbvxUser.getGroupIdList(), vxUser.getGroupIdList());
    Assert.assertEquals(dbvxUser.getGroupNameList(), vxUser.getGroupNameList());
    Mockito.verify(xUserService).readResourceWithOutLogin(userId);
}
Also used : VXLong(org.apache.ranger.view.VXLong) ArrayList(java.util.ArrayList) VXGroupUser(org.apache.ranger.view.VXGroupUser) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) 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