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());
}
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);
}
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);
}
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);
}
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);
}
Aggregations