Search in sources :

Example 86 with XXPortalUser

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);
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) RangerSecurityContext(org.apache.ranger.security.context.RangerSecurityContext) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) UserSessionBase(org.apache.ranger.common.UserSessionBase) Test(org.junit.Test)

Example 87 with XXPortalUser

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());
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) RangerSecurityContext(org.apache.ranger.security.context.RangerSecurityContext) ArrayList(java.util.ArrayList) VXLong(org.apache.ranger.view.VXLong) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) VXGroup(org.apache.ranger.view.VXGroup) UserSessionBase(org.apache.ranger.common.UserSessionBase) Test(org.junit.Test)

Example 88 with XXPortalUser

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);
}
Also used : XXRoleRefUser(org.apache.ranger.entity.XXRoleRefUser) XXUser(org.apache.ranger.entity.XXUser) VXPermMap(org.apache.ranger.view.VXPermMap) WebApplicationException(javax.ws.rs.WebApplicationException) XXUserDao(org.apache.ranger.db.XXUserDao) ArrayList(java.util.ArrayList) XXSecurityZoneRefUser(org.apache.ranger.entity.XXSecurityZoneRefUser) XXPolicy(org.apache.ranger.entity.XXPolicy) VXAuditMap(org.apache.ranger.view.VXAuditMap) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) VXPermMapList(org.apache.ranger.view.VXPermMapList) VXResponse(org.apache.ranger.view.VXResponse) XXRoleRefUserDao(org.apache.ranger.db.XXRoleRefUserDao) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) XXRoleDao(org.apache.ranger.db.XXRoleDao) VXUser(org.apache.ranger.view.VXUser) XXAuthSession(org.apache.ranger.entity.XXAuthSession) XXUserPermission(org.apache.ranger.entity.XXUserPermission) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXSecurityZoneRefUserDao(org.apache.ranger.db.XXSecurityZoneRefUserDao) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) XXRole(org.apache.ranger.entity.XXRole) Test(org.junit.Test)

Example 89 with XXPortalUser

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) {
    }
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) IOException(java.io.IOException)

Example 90 with XXPortalUser

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;
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) VXPortalUser(org.apache.ranger.view.VXPortalUser) IOException(java.io.IOException)

Aggregations

XXPortalUser (org.apache.ranger.entity.XXPortalUser)192 Test (org.junit.Test)113 ArrayList (java.util.ArrayList)93 VXPortalUser (org.apache.ranger.view.VXPortalUser)86 VXString (org.apache.ranger.view.VXString)82 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)74 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)46 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)44 XXUserPermission (org.apache.ranger.entity.XXUserPermission)36 UserSessionBase (org.apache.ranger.common.UserSessionBase)34 VXUser (org.apache.ranger.view.VXUser)34 WebApplicationException (javax.ws.rs.WebApplicationException)33 Date (java.util.Date)30 RangerSecurityContext (org.apache.ranger.security.context.RangerSecurityContext)29 XXUser (org.apache.ranger.entity.XXUser)27 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)25 XXModuleDef (org.apache.ranger.entity.XXModuleDef)25 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)20 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)19 VXUserPermission (org.apache.ranger.view.VXUserPermission)19