use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.
the class TestXUserMgr method test23CreateVXUserGroupInfo.
@Test
public void test23CreateVXUserGroupInfo() {
setup();
VXUserGroupInfo vXUserGroupInfo = new VXUserGroupInfo();
VXUser vXUser = vxUser();
List<VXGroupUser> vXGroupUserList = new ArrayList<VXGroupUser>();
List<VXGroup> vXGroupList = new ArrayList<VXGroup>();
final VXGroup vXGroup1 = vxGroup();
vXGroup1.setName("users");
vXGroup1.setDescription("users -added for unit testing");
vXGroupList.add(vXGroup1);
VXGroupUser vXGroupUser1 = vxGroupUser();
vXGroupUser1.setName("users");
vXGroupUserList.add(vXGroupUser1);
final VXGroup vXGroup2 = vxGroup();
vXGroup2.setName("user1");
vXGroup2.setDescription("user1 -added for unit testing");
vXGroupList.add(vXGroup2);
VXGroupUser vXGroupUser2 = vxGroupUser();
vXGroupUser2.setName("user1");
vXGroupUserList.add(vXGroupUser2);
vXUserGroupInfo.setXuserInfo(vXUser);
vXUserGroupInfo.setXgroupInfo(vXGroupList);
Mockito.when(xUserService.createXUserWithOutLogin(vXUser)).thenReturn(vXUser);
Mockito.when(xGroupService.createXGroupWithOutLogin(vXGroup1)).thenReturn(vXGroup1);
Mockito.when(xGroupService.createXGroupWithOutLogin(vXGroup2)).thenReturn(vXGroup2);
XXPortalUserDao portalUser = Mockito.mock(XXPortalUserDao.class);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(portalUser);
XXPortalUser user = new XXPortalUser();
user.setId(1L);
user.setUserSource(RangerCommonEnums.USER_EXTERNAL);
Mockito.when(portalUser.findByLoginId(vXUser.getName())).thenReturn(user);
XXPortalUserRoleDao userDao = Mockito.mock(XXPortalUserRoleDao.class);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(userDao);
List<String> existingRole = new ArrayList<String>();
existingRole.add(RangerConstants.ROLE_USER);
List<String> reqRoleList = new ArrayList<String>();
reqRoleList.add(RangerConstants.ROLE_SYS_ADMIN);
Mockito.when(userDao.findXPortalUserRolebyXPortalUserId(Mockito.anyLong())).thenReturn(reqRoleList);
VXPortalUser vXPortalUser = userProfile();
Mockito.when(userMgr.getUserProfileByLoginId(Mockito.anyString())).thenReturn(vXPortalUser);
Mockito.when(userMgr.updateRoleForExternalUsers(Mockito.any(), Mockito.any(), (VXPortalUser) Mockito.any())).thenReturn(vXPortalUser);
XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
XXUserPermissionDao xXUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
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(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(sessionMgr.getActiveUserSessionsForPortalUserId(userId)).thenReturn(userSessions);
VXUserGroupInfo vxUserGroupTest = xUserMgr.createXUserGroupFromMap(vXUserGroupInfo);
Assert.assertEquals(userLoginID, vxUserGroupTest.getXuserInfo().getName());
List<VXGroup> result = vxUserGroupTest.getXgroupInfo();
List<VXGroup> expected = new ArrayList<VXGroup>();
expected.add(vXGroup1);
expected.add(vXGroup2);
Assert.assertTrue(result.containsAll(expected));
Mockito.verify(portalUser).findByLoginId(vXUser.getName());
Mockito.verify(userDao).findXPortalUserRolebyXPortalUserId(Mockito.anyLong());
}
use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.
the class TestXUserMgr method test97updateXModuleDefPermission.
@Test
public void test97updateXModuleDefPermission() {
XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
XXModuleDef xModuleDef = xxModuleDef();
VXModuleDef vXModuleDef = vxModuleDef();
Mockito.when(xModuleDefService.updateResource(vXModuleDef)).thenReturn(vXModuleDef);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
Mockito.when(xModuleDefDao.getById(userId)).thenReturn(xModuleDef);
Map<Long, String> xXGroupNameMap = new HashMap<Long, String>();
xXGroupNameMap.put(userId, groupName);
Mockito.when(xGroupService.getXXGroupIdNameMap()).thenReturn(xXGroupNameMap);
Object[] objArr = new Object[] { userId, userId, userLoginID };
Map<Long, Object[]> xXUserMap = new HashMap<Long, Object[]>();
xXUserMap.put(userId, objArr);
Mockito.when(xUserService.getXXPortalUserIdXXUserNameMap()).thenReturn(xXUserMap);
Mockito.when(xModuleDefService.populateViewBean(xModuleDef, xXUserMap, xXGroupNameMap, true)).thenReturn(vXModuleDef);
List<XXGroupPermission> xXGroupPermissions = new ArrayList<XXGroupPermission>();
XXGroupPermission xGroupPermissionObj = xxGroupPermission();
xXGroupPermissions.add(xGroupPermissionObj);
VXGroupPermission vXGroupPermission = vxGroupPermission();
vXGroupPermission.setIsAllowed(0);
List<XXUserPermission> xXUserPermissions = new ArrayList<XXUserPermission>();
XXUserPermission xUserPermissionObj = xxUserPermission();
xXUserPermissions.add(xUserPermissionObj);
VXUserPermission vxUserPermission = vxUserPermission();
vxUserPermission.setIsAllowed(0);
UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
userSessions.add(userSession);
XXGroupUserDao xxGroupUserDao = Mockito.mock(XXGroupUserDao.class);
Mockito.when(daoManager.getXXGroupUser()).thenReturn(xxGroupUserDao);
List<XXGroupUser> grpUsers = new ArrayList<XXGroupUser>();
Mockito.when(xxGroupUserDao.findByGroupId(vXGroupPermission.getGroupId())).thenReturn(grpUsers);
Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(vxUserPermission.getUserId())).thenReturn(userSessions);
Mockito.when(xGroupPermissionService.createResource((VXGroupPermission) Mockito.any())).thenReturn(vXGroupPermission);
Mockito.when(xUserPermissionService.createResource((VXUserPermission) Mockito.any())).thenReturn(vxUserPermission);
VXModuleDef dbMuduleDef = xUserMgr.updateXModuleDefPermission(vXModuleDef);
Assert.assertEquals(dbMuduleDef, vXModuleDef);
Assert.assertNotNull(dbMuduleDef);
Assert.assertEquals(dbMuduleDef, vXModuleDef);
Assert.assertEquals(dbMuduleDef.getId(), vXModuleDef.getId());
Assert.assertEquals(dbMuduleDef.getOwner(), vXModuleDef.getOwner());
Assert.assertEquals(dbMuduleDef.getUpdatedBy(), vXModuleDef.getUpdatedBy());
Assert.assertEquals(dbMuduleDef.getUrl(), vXModuleDef.getUrl());
Assert.assertEquals(dbMuduleDef.getAddedById(), vXModuleDef.getAddedById());
Assert.assertEquals(dbMuduleDef.getCreateDate(), vXModuleDef.getCreateDate());
Assert.assertEquals(dbMuduleDef.getCreateTime(), vXModuleDef.getCreateTime());
Assert.assertEquals(dbMuduleDef.getUserPermList(), vXModuleDef.getUserPermList());
Assert.assertEquals(dbMuduleDef.getGroupPermList(), vXModuleDef.getGroupPermList());
Mockito.verify(xModuleDefService).updateResource(vXModuleDef);
Mockito.verify(daoManager).getXXModuleDef();
Mockito.verify(xModuleDefService).populateViewBean(xModuleDef, xXUserMap, xXGroupNameMap, true);
Mockito.verify(xGroupService).getXXGroupIdNameMap();
Mockito.verify(xUserService).getXXPortalUserIdXXUserNameMap();
}
use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.
the class TestXUserMgr method test113CreateOrUpdateXUsers.
@Test
public void test113CreateOrUpdateXUsers() {
destroySession();
setup();
VXUser vXUser = vxUser();
vXUser.setFirstName("null");
vXUser.setLastName("null");
List<VXUser> vXUserList = new ArrayList<VXUser>();
vXUserList.add(vXUser);
VXUserList users = new VXUserList(vXUserList);
XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
XXGlobalStateDao xxGlobalStateDao = Mockito.mock(XXGlobalStateDao.class);
XXUser xXUser = xxUser(vXUser);
VXPortalUser vXPortalUser = userProfile();
vXPortalUser.setFirstName("null");
vXPortalUser.setLastName("null");
XXPortalUser xXPortalUser = xxPortalUser(vXPortalUser);
xXPortalUser.setUserSource(RangerCommonEnums.USER_EXTERNAL);
List<String> lstRole = new ArrayList<String>();
lstRole.add(RangerConstants.ROLE_SYS_ADMIN);
List<XXModuleDef> xXModuleDefs = new ArrayList<XXModuleDef>();
vXPortalUser.setUserRoleList(lstRole);
Mockito.when(userMgr.getUserProfileByLoginId(vXUser.getName())).thenReturn(vXPortalUser);
Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
Mockito.when(xxUserDao.findByUserName(vXUser.getName())).thenReturn(xXUser);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao);
Mockito.when(daoManager.getXXGlobalState()).thenReturn(xxGlobalStateDao);
Mockito.when(xXModuleDefDao.getAll()).thenReturn(xXModuleDefs);
Mockito.when(xUserService.updateResource(vXUser)).thenReturn(vXUser);
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);
xUserMgr.createOrUpdateXUsers(users);
vXUserList.clear();
vXUser.setUserSource(RangerCommonEnums.USER_APP);
vXUser.setFirstName("testuser");
vXUser.setLastName("testuser");
vXUser.setPassword("TestPassword@123");
vXUserList.add(vXUser);
users = new VXUserList(vXUserList);
vXPortalUser = userProfile();
vXPortalUser.setUserSource(RangerCommonEnums.USER_APP);
vXPortalUser.setFirstName("testuser");
vXPortalUser.setLastName("testuser");
vXPortalUser.setPassword("TestPassword@123");
vXPortalUser.setUserRoleList(lstRole);
Mockito.when(userMgr.getUserProfileByLoginId(vXUser.getName())).thenReturn(vXPortalUser);
Mockito.when(userMgr.updateUserWithPass((VXPortalUser) Mockito.any())).thenReturn(xXPortalUser);
xUserMgr.createOrUpdateXUsers(users);
vXUser.setPassword("*****");
xUserMgr.createOrUpdateXUsers(users);
}
use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.
the class TestXUserMgr method test52createXGroupUserFromMap.
@Test
public void test52createXGroupUserFromMap() {
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);
XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
XXPortalUserRoleDao userRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
XXUser xXUser = xxUser(vxUser);
VXPortalUser userProfile = userProfile();
XXPortalUser xXPortalUser = xxPortalUser(userProfile);
xXPortalUser.setUserSource(RangerCommonEnums.USER_EXTERNAL);
List<String> lstRole = new ArrayList<String>();
lstRole.add(RangerConstants.ROLE_SYS_ADMIN);
List<XXModuleDef> xXModuleDefs = new ArrayList<XXModuleDef>();
Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
Mockito.when(xxUserDao.findByUserName(vxUser.getName())).thenReturn(xXUser);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(userDao.findByLoginId(vxUser.getName())).thenReturn(xXPortalUser);
Mockito.when(xGroupService.createXGroupWithOutLogin(vxGroup)).thenReturn(vxGroup);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(userRoleDao);
Mockito.when(userMgr.mapXXPortalUserToVXPortalUserForDefaultAccount(xXPortalUser)).thenReturn(userProfile);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao);
Mockito.when(xXModuleDefDao.getAll()).thenReturn(xXModuleDefs);
VXGroupUserInfo vxGUInfoObj = xUserMgr.createXGroupUserFromMap(vxGUInfo);
Assert.assertNotNull(vxGUInfoObj);
}
use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.
the class TestXUserMgr method test38setUserRolesByExternalID.
@Test
public void test38setUserRolesByExternalID() {
destroySession();
setup();
VXUser vXUser = vxUser();
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(xUserMgr.getXUser(userId)).thenReturn(vXUser);
Mockito.when(userMgr.getUserProfileByLoginId(vXUser.getName())).thenReturn(null);
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);
Mockito.when(restErrorUtil.createRESTException("User ID doesn't exist.", MessageEnums.INVALID_INPUT_DATA)).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
xUserMgr.setUserRolesByExternalID(userId, vStringRolesList);
}
Aggregations