use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestXUserMgr method test102getKeyAdminUserDetailsWithUserHavingUSER_ROLE.
@Test
public void test102getKeyAdminUserDetailsWithUserHavingUSER_ROLE() {
destroySession();
RangerSecurityContext context = new RangerSecurityContext();
context.setUserSession(new UserSessionBase());
RangerContextHolder.setSecurityContext(context);
UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
currentUserSession.setUserAdmin(false);
XXPortalUser xXPortalUser = new XXPortalUser();
xXPortalUser.setLoginId(userLoginID);
xXPortalUser.setId(userId);
currentUserSession.setXXPortalUser(xXPortalUser);
VXUser loggedInUser = vxUser();
List<String> loggedInUserRole = new ArrayList<String>();
loggedInUserRole.add(RangerConstants.ROLE_USER);
loggedInUser.setId(8L);
loggedInUser.setName("testuser");
loggedInUser.setUserRoleList(loggedInUserRole);
VXUser vxUser = vxUser();
List<String> userRole = new ArrayList<String>();
userRole.add(RangerConstants.ROLE_KEY_ADMIN);
vxUser.setId(5L);
vxUser.setName("test3");
vxUser.setUserRoleList(userRole);
vxUser.setUserSource(RangerCommonEnums.USER_UNIX);
Mockito.when(xUserService.readResourceWithOutLogin(5L)).thenReturn(vxUser);
Mockito.when(xUserService.getXUserByUserName("testuser")).thenReturn(loggedInUser);
Mockito.when(restErrorUtil.create403RESTException("Logged-In user is not allowed to access requested user data.")).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
xUserMgr.getXUser(5L);
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestXUserMgr method test107RoleUserWillFetchOnlyHisOwnGroupDetails.
@Test
public void test107RoleUserWillFetchOnlyHisOwnGroupDetails() {
destroySession();
RangerSecurityContext context = new RangerSecurityContext();
context.setUserSession(new UserSessionBase());
RangerContextHolder.setSecurityContext(context);
UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
currentUserSession.setUserAdmin(false);
XXPortalUser xXPortalUser = new XXPortalUser();
xXPortalUser.setLoginId(userLoginID);
xXPortalUser.setId(userId);
currentUserSession.setXXPortalUser(xXPortalUser);
List<String> permissionList = new ArrayList<String>();
permissionList.add(RangerConstants.MODULE_USER_GROUPS);
List<Long> groupIdList = new ArrayList<Long>();
groupIdList.add(5L);
VXGroup expectedVXGroup = new VXGroup();
expectedVXGroup.setId(5L);
expectedVXGroup.setName("testGroup");
VXUser loggedInUser = vxUser();
List<String> loggedInUserRole = new ArrayList<String>();
loggedInUserRole.add(RangerConstants.ROLE_USER);
loggedInUser.setId(8L);
loggedInUser.setName("testuser");
loggedInUser.setUserRoleList(loggedInUserRole);
loggedInUser.setGroupIdList(groupIdList);
VXUser vxUser = vxUser();
List<String> userRole = new ArrayList<String>();
userRole.add(RangerConstants.ROLE_USER);
vxUser.setId(8L);
vxUser.setName("test3");
vxUser.setUserRoleList(userRole);
vxUser.setUserSource(RangerCommonEnums.USER_UNIX);
Mockito.when(xGroupService.readResourceWithOutLogin(5L)).thenReturn(expectedVXGroup);
VXGroup rcvVXGroup = xUserMgr.getXGroup(5L);
Assert.assertNotNull(rcvVXGroup);
Assert.assertEquals(expectedVXGroup.getId(), rcvVXGroup.getId());
Assert.assertEquals(expectedVXGroup.getName(), rcvVXGroup.getName());
}
use of org.apache.ranger.entity.XXPortalUser 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.entity.XXPortalUser in project ranger by apache.
the class PatchAssignSecurityZonePersmissionToAdmin_J10026 method assignSecurityZonePermissionToExistingAdminUsers.
private void assignSecurityZonePermissionToExistingAdminUsers() {
int countUserPermissionUpdated = 0;
Long userCount = daoManager.getXXPortalUser().getAllCount();
List<XXPortalUser> xXPortalUsers = null;
Long patchModeMaxLimit = Long.valueOf(500L);
try {
if (userCount != null && userCount > 0) {
List<String> loginIdList = readUserNamesFromFile(usersListFileName);
if (!CollectionUtils.isEmpty(loginIdList)) {
xXPortalUsers = new ArrayList<XXPortalUser>();
XXPortalUser xXPortalUser = null;
for (String loginId : loginIdList) {
try {
xXPortalUser = daoManager.getXXPortalUser().findByLoginId(loginId);
if (xXPortalUser != null) {
xXPortalUsers.add(xXPortalUser);
} else {
logger.info("User " + loginId + " doesn't exist!");
}
} catch (Exception ex) {
}
}
countUserPermissionUpdated = assignPermissions(xXPortalUsers);
logger.info("Security Zone Permissions assigned to " + countUserPermissionUpdated + " of total " + loginIdList.size());
} else {
xXPortalUsers = daoManager.getXXPortalUser().findByRole(RangerConstants.ROLE_SYS_ADMIN);
if (!CollectionUtils.isEmpty(xXPortalUsers)) {
countUserPermissionUpdated = assignPermissions(xXPortalUsers);
logger.info("Security Zone Permissions assigned to users having role:" + RangerConstants.ROLE_SYS_ADMIN + ". Processed:" + countUserPermissionUpdated + " of total " + xXPortalUsers.size());
}
xXPortalUsers = daoManager.getXXPortalUser().findByRole(RangerConstants.ROLE_ADMIN_AUDITOR);
if (!CollectionUtils.isEmpty(xXPortalUsers)) {
countUserPermissionUpdated = assignPermissions(xXPortalUsers);
logger.info("Security Zone Permissions assigned to users having role:" + RangerConstants.ROLE_ADMIN_AUDITOR + ". Processed:" + countUserPermissionUpdated + " of total " + xXPortalUsers.size());
}
// if total no. of users are more than 500 then process ADMIN and KEY_ADMIN users only to avoid timeout
if (userCount.compareTo(Long.valueOf(patchModeMaxLimit)) < 0 || grantAllUsers) {
xXPortalUsers = daoManager.getXXPortalUser().findByRole(RangerConstants.ROLE_USER);
if (!CollectionUtils.isEmpty(xXPortalUsers)) {
countUserPermissionUpdated = assignPermissions(xXPortalUsers);
logger.info("Security Zone Permissions assigned to " + countUserPermissionUpdated + " of total " + xXPortalUsers.size());
}
logger.info("Please execute this patch separately with argument 'ALL' to assign permission to remaining users ");
System.out.println("Please execute this patch separately with argument 'ALL' to assign module permissions to remaining users!!");
}
}
}
} catch (Exception ex) {
}
}
use of org.apache.ranger.entity.XXPortalUser 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;
}
Aggregations