use of org.apache.ranger.view.VXPortalUser 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);
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestXUserMgr method test49createServiceConfigUser.
@Test
public void test49createServiceConfigUser() {
XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
VXUser vxUser = vxUser();
XXUser xXUser = xxUser(vxUser);
VXPortalUser userProfile = userProfile();
Collection<String> userRoleList = getRoleList();
VXUserPermission vXUserPermission = vxUserPermission();
XXUserPermission xUserPermissionObj = xxUserPermission();
xUserPermissionObj.setModuleId(vXUserPermission.getModuleId());
xUserPermissionObj.setUserId(vXUserPermission.getUserId());
Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
Mockito.when(xxUserDao.findByUserName(vxUser.getName())).thenReturn(xXUser);
Mockito.when(xUserService.populateViewBean(xXUser)).thenReturn(vxUser);
VXUser serviceConfigUser = xUserMgr.createServiceConfigUser(vxUser.getName());
Assert.assertNotNull(serviceConfigUser);
Assert.assertEquals(xXUser.getName(), serviceConfigUser.getName());
Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
Mockito.when(xxUserDao.findByUserName(vxUser.getName())).thenReturn(null, xXUser);
Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
userSessions.add(userSession);
userProfile.setUserRoleList(userRoleList);
List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
XXUserPermission xUserPermissionObj2 = new XXUserPermission();
xUserPermissionObj2.setAddedByUserId(userId);
xUserPermissionObj2.setCreateTime(new Date());
xUserPermissionObj2.setId(userId);
xUserPermissionObj2.setIsAllowed(1);
xUserPermissionObj2.setModuleId(1L);
xUserPermissionObj2.setUpdatedByUserId(userId);
xUserPermissionObj2.setUpdateTime(new Date());
xUserPermissionObj2.setUserId(userId);
xUserPermissionsList.add(xUserPermissionObj2);
serviceConfigUser = xUserMgr.createServiceConfigUser(vxUser.getName());
Assert.assertNotNull(serviceConfigUser);
Assert.assertEquals(xXUser.getName(), serviceConfigUser.getName());
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestXUserMgr method test127DeleteXUser.
@Test
public void test127DeleteXUser() {
destroySession();
setup();
boolean force = true;
VXUser vXUser = vxUser();
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);
VXPermMapList vXPermMapList = new VXPermMapList();
VXPermMap vXPermMap1 = getVXPermMap();
List<VXPermMap> vXPermMaps = new ArrayList<VXPermMap>();
vXPermMaps.add(vXPermMap1);
vXPermMapList.setVXPermMaps(vXPermMaps);
VXAuditMapList vXAuditMapList = new VXAuditMapList();
List<VXAuditMap> vXAuditMaps = new ArrayList<VXAuditMap>();
VXAuditMap vXAuditMap = getVXAuditMap();
vXAuditMaps.add(vXAuditMap);
vXAuditMapList.setVXAuditMaps(vXAuditMaps);
VXPortalUser vXPortalUser = userProfile();
XXPortalUser xXPortalUser = xxPortalUser(vXPortalUser);
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);
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
XXPortalUserRole.setId(userId);
XXPortalUserRole.setUserId(userId);
XXPortalUserRole.setUserRole("ROLE_USER");
List<XXAuthSession> xXAuthSessions = new ArrayList<XXAuthSession>();
XXAuthSession xXAuthSession = new XXAuthSession();
xXAuthSession.setId(userId);
xXAuthSession.setLoginId(vXPortalUser.getLoginId());
xXAuthSessions.add(xXAuthSession);
List<XXUserPermission> xXUserPermissions = new ArrayList<XXUserPermission>();
xXUserPermissions.add(xxUserPermission());
List<XXPortalUserRole> xXPortalUserRoles = new ArrayList<XXPortalUserRole>();
xXPortalUserRoles.add(XXPortalUserRole);
List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
XXPolicy xXPolicy = getXXPolicy();
xXPolicyList.add(xXPolicy);
List<XXSecurityZoneRefUser> zoneSecRefUser = new ArrayList<XXSecurityZoneRefUser>();
XXSecurityZoneRefUserDao zoneSecRefUserDao = Mockito.mock(XXSecurityZoneRefUserDao.class);
Mockito.when(daoManager.getXXSecurityZoneRefUser()).thenReturn(zoneSecRefUserDao);
Mockito.when(zoneSecRefUserDao.findByUserId(userId)).thenReturn(zoneSecRefUser);
List<XXRoleRefUser> roleRefUser = new ArrayList<XXRoleRefUser>();
XXRoleRefUser xRoleRefUser = new XXRoleRefUser();
xRoleRefUser.setRoleId(userId);
xRoleRefUser.setUserId(userId);
xRoleRefUser.setUserName(vXUser.getName().trim());
xRoleRefUser.setUserType(0);
roleRefUser.add(xRoleRefUser);
XXRoleRefUserDao roleRefUserDao = Mockito.mock(XXRoleRefUserDao.class);
Mockito.when(daoManager.getXXRoleRefUser()).thenReturn(roleRefUserDao);
Mockito.when(roleRefUserDao.findByUserId(userId)).thenReturn(roleRefUser);
XXRole xRole = new XXRole();
xRole.setId(userId);
xRole.setName("Role1");
XXRoleDao roleDao = Mockito.mock(XXRoleDao.class);
Mockito.when(daoManager.getXXRole()).thenReturn(roleDao);
Mockito.when(roleDao.getById(xRoleRefUser.getRoleId())).thenReturn(xRole);
VXResponse vXResponse = new VXResponse();
vXResponse.setStatusCode(HttpServletResponse.SC_BAD_REQUEST);
vXResponse.setMsgDesc("Can Not Delete User '" + vXUser.getName().trim() + "' as its present in " + RangerConstants.ROLE_FIELD);
Mockito.when(restErrorUtil.generateRESTException((VXResponse) Mockito.any())).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
xUserMgr.deleteXUser(vXUser.getId(), force);
force = false;
xUserMgr.deleteXUser(vXUser.getId(), force);
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class PatchAssignSecurityZonePersmissionToAdmin_J10026 method assignPermissions.
private int assignPermissions(List<XXPortalUser> xXPortalUsers) {
HashMap<String, Long> moduleNameId = xUserMgr.getAllModuleNameAndIdMap();
int countUserPermissionUpdated = 0;
if (!CollectionUtils.isEmpty(xXPortalUsers)) {
for (XXPortalUser xPortalUser : xXPortalUsers) {
try {
if (xPortalUser != null) {
VXPortalUser vPortalUser = xPortalUserService.populateViewBean(xPortalUser);
if (vPortalUser != null) {
vPortalUser.setUserRoleList(daoManager.getXXPortalUserRole().findXPortalUserRolebyXPortalUserId(vPortalUser.getId()));
xUserMgr.createOrUpdateUserPermisson(vPortalUser, moduleNameId.get(RangerConstants.MODULE_SECURITY_ZONE), false);
countUserPermissionUpdated += 1;
logger.info("Security Zone Permission assigned/updated to Admin Role, UserId [" + xPortalUser.getId() + "]");
}
}
} catch (Exception ex) {
logger.error("Error while assigning security zone permission for admin users", ex);
System.exit(1);
}
}
}
return countUserPermissionUpdated;
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class XPortalUserServiceBase method searchXPortalUsers.
/**
* @param searchCriteria
* @return
*/
public VXPortalUserList searchXPortalUsers(SearchCriteria searchCriteria) {
VXPortalUserList returnList = new VXPortalUserList();
List<VXPortalUser> xPortalUserList = new ArrayList<VXPortalUser>();
List<T> resultList = searchResources(searchCriteria, searchFields, sortFields, returnList);
// Iterate over the result list and create the return list
for (T gjXPortalUser : resultList) {
VXPortalUser vXPortalUser = populateViewBean(gjXPortalUser);
xPortalUserList.add(vXPortalUser);
}
returnList.setVXPortalUsers(xPortalUserList);
return returnList;
}
Aggregations