use of org.apache.ranger.db.XXUserPermissionDao 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.db.XXUserPermissionDao 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);
}
use of org.apache.ranger.db.XXUserPermissionDao 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);
}
use of org.apache.ranger.db.XXUserPermissionDao 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.db.XXUserPermissionDao 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);
}
Aggregations