use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.
the class TestXUserMgr method test77updateUserRolesPermissions.
@Test
public void test77updateUserRolesPermissions() {
setup();
List<String> existingRoleList = new ArrayList<String>();
existingRoleList.add(RangerConstants.ROLE_USER);
List<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("null");
vxUser.setLastName("null");
vxUser.setPassword("*****");
VXPortalUser oldUserProfile = userProfile();
oldUserProfile.setUserSource(RangerCommonEnums.USER_APP);
oldUserProfile.setPassword(vxUser.getPassword());
oldUserProfile.setUserRoleList(existingRoleList);
VXPortalUser vXPortalUser = userProfile();
vXPortalUser.setUserRoleList(reqRoleList);
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);
UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
userSessions.add(userSession);
XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
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);
XXUser xXUser = xxUser(vxUser);
List<XXModuleDef> xXModuleDefs = xxModuleDefs();
VXUserPermission userPermission = vxUserPermission();
List<VXUserPermission> userPermList = new ArrayList<VXUserPermission>();
userPermList.add(userPermission);
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);
Mockito.when(xXUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(xUserPermissionsList);
Mockito.when(xUserPermissionService.createResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(userId)).thenReturn(userSessions);
xUserMgr.updateUserRolesPermissions(oldUserProfile, reqRoleList);
}
use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.
the class TestXUserMgr method test96updateXModuleDefPermission.
@Test
public void test96updateXModuleDefPermission() {
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);
List<VXGroupPermission> vXGroupPermissions = new ArrayList<VXGroupPermission>();
VXGroupPermission vXGroupPermission = vxGroupPermission();
vXGroupPermission.setIsAllowed(0);
vXGroupPermissions.add(vXGroupPermission);
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);
Map<Long, VXGroupPermission> groupPermMapOld = new HashMap<Long, VXGroupPermission>();
groupPermMapOld.put(vXGroupPermission.getGroupId(), vXGroupPermission);
Mockito.when(xGroupPermissionService.convertVListToVMap((List<VXGroupPermission>) Mockito.any())).thenReturn(groupPermMapOld);
Mockito.when(xGroupPermissionService.updateResource(vXGroupPermission)).thenReturn(vXGroupPermission);
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);
List<VXUserPermission> userPermListOld = new ArrayList<VXUserPermission>();
userPermListOld.add(vxUserPermission);
Map<Long, VXUserPermission> userPermMapOld = new HashMap<Long, VXUserPermission>();
userPermMapOld.put(vxUserPermission.getUserId(), vxUserPermission);
Mockito.when(xUserPermissionService.convertVListToVMap((List<VXUserPermission>) Mockito.any())).thenReturn(userPermMapOld);
Mockito.when(xUserPermissionService.updateResource(vxUserPermission)).thenReturn(vxUserPermission);
Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(vxUserPermission.getUserId())).thenReturn(userSessions);
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).populateViewBean(xModuleDef, xXUserMap, xXGroupNameMap, true);
Mockito.verify(xModuleDefService).updateResource(vXModuleDef);
Mockito.verify(daoManager).getXXModuleDef();
}
use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.
the class TestXUserMgr method test37setUserRolesByExternalID.
@Test
public void test37setUserRolesByExternalID() {
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.setUserRolesByExternalID(userId, vStringRolesList);
Assert.assertNotNull(vXStringList);
}
use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.
the class TestXUserMgr method test43getUserRolesByExternalID.
@Test
public void test43getUserRolesByExternalID() {
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("User ID doesn't exist.", MessageEnums.INVALID_INPUT_DATA)).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
Mockito.when(userMgr.getUserProfileByLoginId((String) Mockito.anyString())).thenReturn(null);
xUserMgr.getUserRolesByExternalID(userId);
}
use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.
the class TestXUserMgr method test111CreateOrUpdateXUsers.
@Test
public void test111CreateOrUpdateXUsers() {
destroySession();
setup();
List<VXUser> vXUserList = new ArrayList<VXUser>();
VXUser vXUser = vxUser();
VXUser vXUser1 = vxUser();
vXUser.setFirstName("null");
vXUser.setLastName("null");
vXUser.setEmailAddress("");
vXUser1.setName("null");
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);
vXUser1.setUserRoleList(userRoleList);
vXUserList.add(vXUser);
vXUserList.add(vXUser1);
VXUserList users = new VXUserList(vXUserList);
XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.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 = xxModuleDefs();
vXPortalUser.setUserRoleList(lstRole);
Mockito.when(userMgr.getUserProfileByLoginId(vXUser.getName())).thenReturn(null);
Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
Mockito.when(xxUserDao.findByUserName(vXUser.getName())).thenReturn(xXUser);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao);
Mockito.when(daoManager.getXXGlobalState()).thenReturn(xxGlobalStateDao);
Mockito.when(xXModuleDefDao.getAll()).thenReturn(xXModuleDefs);
Mockito.when(userMgr.mapVXPortalUserToXXPortalUser((VXPortalUser) Mockito.any())).thenReturn(xXPortalUser);
XXPortalUserDao xXPortalUserDao = Mockito.mock(XXPortalUserDao.class);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(xXPortalUserDao);
Mockito.when(daoManager.getXXPortalUser().create((XXPortalUser) Mockito.any())).thenReturn(xXPortalUser);
XXUser xUser = xxUser(vXUser);
Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
Mockito.when(daoManager.getXXUser().findByUserName(vXUser.getName())).thenReturn(xUser);
Mockito.when(xUserService.populateViewBean(xUser)).thenReturn(vXUser);
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);
XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
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);
xUserMgr.createOrUpdateXUsers(users);
Mockito.when(xUserPermissionDao.findByModuleIdAndPortalUserId(null, null)).thenReturn(xUserPermissionObj);
Mockito.when(xUserPermissionService.populateViewBean(xUserPermissionObj)).thenReturn(userPermission);
Mockito.when(xUserPermissionService.updateResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
xUserMgr.createOrUpdateXUsers(users);
}
Aggregations