Search in sources :

Example 1 with XXSecurityZoneRefUser

use of org.apache.ranger.entity.XXSecurityZoneRefUser in project ranger by apache.

the class SecurityZoneRefUpdater method createNewZoneMappingForRefTable.

public void createNewZoneMappingForRefTable(RangerSecurityZone rangerSecurityZone) throws Exception {
    if (rangerSecurityZone == null) {
        return;
    }
    cleanupRefTables(rangerSecurityZone);
    final Long zoneId = rangerSecurityZone == null ? null : rangerSecurityZone.getId();
    final Map<String, RangerSecurityZoneService> zoneServices = rangerSecurityZone.getServices();
    final Set<String> adminUsers = new HashSet<>();
    final Set<String> adminUserGroups = new HashSet<>();
    final Set<String> auditUsers = new HashSet<>();
    final Set<String> auditUserGroups = new HashSet<>();
    final Set<String> tagServices = new HashSet<>();
    XXServiceDef xServiceDef = new XXServiceDef();
    adminUsers.addAll(rangerSecurityZone.getAdminUsers());
    adminUserGroups.addAll(rangerSecurityZone.getAdminUserGroups());
    auditUsers.addAll(rangerSecurityZone.getAuditUsers());
    auditUserGroups.addAll(rangerSecurityZone.getAuditUserGroups());
    tagServices.addAll(rangerSecurityZone.getTagServices());
    for (Map.Entry<String, RangerSecurityZoneService> service : zoneServices.entrySet()) {
        String serviceName = service.getKey();
        if (StringUtils.isBlank(serviceName)) {
            continue;
        }
        XXService xService = daoMgr.getXXService().findByName(serviceName);
        RangerService rService = svcService.getPopulatedViewObject(xService);
        xServiceDef = daoMgr.getXXServiceDef().findByName(rService.getType());
        XXSecurityZoneRefService xZoneService = rangerAuditFields.populateAuditFieldsForCreate(new XXSecurityZoneRefService());
        xZoneService.setZoneId(zoneId);
        xZoneService.setServiceId(xService.getId());
        xZoneService.setServiceName(serviceName);
        daoMgr.getXXSecurityZoneRefService().create(xZoneService);
        for (Map<String, List<String>> resourceMap : service.getValue().getResources()) {
            // add all resourcedefs in pre defined set
            for (Map.Entry<String, List<String>> resource : resourceMap.entrySet()) {
                String resourceName = resource.getKey();
                if (StringUtils.isBlank(resourceName)) {
                    continue;
                }
                XXResourceDef xResourceDef = daoMgr.getXXResourceDef().findByNameAndServiceDefId(resourceName, xServiceDef.getId());
                XXSecurityZoneRefResource xZoneResource = rangerAuditFields.populateAuditFieldsForCreate(new XXSecurityZoneRefResource());
                xZoneResource.setZoneId(zoneId);
                xZoneResource.setResourceDefId(xResourceDef.getId());
                xZoneResource.setResourceName(resourceName);
                daoMgr.getXXSecurityZoneRefResource().create(xZoneResource);
            }
        }
    }
    if (CollectionUtils.isNotEmpty(tagServices)) {
        for (String tagService : tagServices) {
            if (StringUtils.isBlank(tagService)) {
                continue;
            }
            XXService xService = daoMgr.getXXService().findByName(tagService);
            if (xService == null || xService.getType() != RangerConstants.TAG_SERVICE_TYPE) {
                throw restErrorUtil.createRESTException("Tag Service named: " + tagService + " does not exist ", MessageEnums.INVALID_INPUT_DATA);
            }
            XXSecurityZoneRefTagService xZoneTagService = rangerAuditFields.populateAuditFieldsForCreate(new XXSecurityZoneRefTagService());
            xZoneTagService.setZoneId(zoneId);
            xZoneTagService.setTagServiceId(xService.getId());
            xZoneTagService.setTagServiceName(xService.getName());
            daoMgr.getXXSecurityZoneRefTagService().create(xZoneTagService);
        }
    }
    if (CollectionUtils.isNotEmpty(adminUsers)) {
        for (String adminUser : adminUsers) {
            if (StringUtils.isBlank(adminUser)) {
                continue;
            }
            XXUser xUser = daoMgr.getXXUser().findByUserName(adminUser);
            if (xUser == null) {
                throw restErrorUtil.createRESTException("user with name: " + adminUser + " does not exist ", MessageEnums.INVALID_INPUT_DATA);
            }
            XXSecurityZoneRefUser xZoneAdminUser = rangerAuditFields.populateAuditFieldsForCreate(new XXSecurityZoneRefUser());
            xZoneAdminUser.setZoneId(zoneId);
            xZoneAdminUser.setUserId(xUser.getId());
            xZoneAdminUser.setUserName(adminUser);
            xZoneAdminUser.setUserType(1);
            daoMgr.getXXSecurityZoneRefUser().create(xZoneAdminUser);
        }
    }
    if (CollectionUtils.isNotEmpty(adminUserGroups)) {
        for (String adminUserGroup : adminUserGroups) {
            if (StringUtils.isBlank(adminUserGroup)) {
                continue;
            }
            XXGroup xGroup = daoMgr.getXXGroup().findByGroupName(adminUserGroup);
            if (xGroup == null) {
                throw restErrorUtil.createRESTException("group with name: " + adminUserGroup + " does not exist ", MessageEnums.INVALID_INPUT_DATA);
            }
            XXSecurityZoneRefGroup xZoneAdminGroup = rangerAuditFields.populateAuditFieldsForCreate(new XXSecurityZoneRefGroup());
            xZoneAdminGroup.setZoneId(zoneId);
            xZoneAdminGroup.setGroupId(xGroup.getId());
            xZoneAdminGroup.setGroupName(adminUserGroup);
            xZoneAdminGroup.setGroupType(1);
            daoMgr.getXXSecurityZoneRefGroup().create(xZoneAdminGroup);
        }
    }
    if (CollectionUtils.isNotEmpty(auditUsers)) {
        for (String auditUser : auditUsers) {
            if (StringUtils.isBlank(auditUser)) {
                continue;
            }
            XXUser xUser = daoMgr.getXXUser().findByUserName(auditUser);
            if (xUser == null) {
                throw restErrorUtil.createRESTException("user with name: " + auditUser + " does not exist ", MessageEnums.INVALID_INPUT_DATA);
            }
            XXSecurityZoneRefUser xZoneAuditUser = rangerAuditFields.populateAuditFieldsForCreate(new XXSecurityZoneRefUser());
            xZoneAuditUser.setZoneId(zoneId);
            xZoneAuditUser.setUserId(xUser.getId());
            xZoneAuditUser.setUserName(auditUser);
            xZoneAuditUser.setUserType(0);
            daoMgr.getXXSecurityZoneRefUser().create(xZoneAuditUser);
        }
    }
    if (CollectionUtils.isNotEmpty(auditUserGroups)) {
        for (String auditUserGroup : auditUserGroups) {
            if (StringUtils.isBlank(auditUserGroup)) {
                continue;
            }
            XXGroup xGroup = daoMgr.getXXGroup().findByGroupName(auditUserGroup);
            if (xGroup == null) {
                throw restErrorUtil.createRESTException("group with name: " + auditUserGroup + " does not exist ", MessageEnums.INVALID_INPUT_DATA);
            }
            XXSecurityZoneRefGroup xZoneAuditGroup = rangerAuditFields.populateAuditFieldsForCreate(new XXSecurityZoneRefGroup());
            xZoneAuditGroup.setZoneId(zoneId);
            xZoneAuditGroup.setGroupId(xGroup.getId());
            xZoneAuditGroup.setGroupName(auditUserGroup);
            xZoneAuditGroup.setGroupType(0);
            daoMgr.getXXSecurityZoneRefGroup().create(xZoneAuditGroup);
        }
    }
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXUser(org.apache.ranger.entity.XXUser) XXSecurityZoneRefGroup(org.apache.ranger.entity.XXSecurityZoneRefGroup) RangerSecurityZoneService(org.apache.ranger.plugin.model.RangerSecurityZone.RangerSecurityZoneService) XXSecurityZoneRefUser(org.apache.ranger.entity.XXSecurityZoneRefUser) XXResourceDef(org.apache.ranger.entity.XXResourceDef) XXSecurityZoneRefService(org.apache.ranger.entity.XXSecurityZoneRefService) XXGroup(org.apache.ranger.entity.XXGroup) XXSecurityZoneRefTagService(org.apache.ranger.entity.XXSecurityZoneRefTagService) List(java.util.List) RangerService(org.apache.ranger.plugin.model.RangerService) XXSecurityZoneRefResource(org.apache.ranger.entity.XXSecurityZoneRefResource) XXService(org.apache.ranger.entity.XXService) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with XXSecurityZoneRefUser

use of org.apache.ranger.entity.XXSecurityZoneRefUser in project ranger by apache.

the class TestXUserMgr method test94DeleteXUser.

@Test
public void test94DeleteXUser() {
    setup();
    boolean force = false;
    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);
    VXGroupUserList vxGroupUserList = new VXGroupUserList();
    Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
    VXAuditMapList vXAuditMapList = new VXAuditMapList();
    Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(vXAuditMapList);
    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");
    XXAuthSessionDao xXAuthSessionDao = Mockito.mock(XXAuthSessionDao.class);
    XXUserPermissionDao xXUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    XXPortalUserRoleDao xXPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
    Mockito.when(daoManager.getXXAuthSession()).thenReturn(xXAuthSessionDao);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xXUserPermissionDao);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xXPortalUserRoleDao);
    List<XXAuthSession> xXAuthSessions = new ArrayList<XXAuthSession>();
    XXAuthSession xXAuthSession = new XXAuthSession();
    xXAuthSession.setId(userId);
    xXAuthSession.setLoginId(vXPortalUser.getLoginId());
    List<XXUserPermission> xXUserPermissions = new ArrayList<XXUserPermission>();
    List<XXPortalUserRole> xXPortalUserRoles = new ArrayList<XXPortalUserRole>();
    Mockito.when(xXAuthSessionDao.getAuthSessionByUserId(vXPortalUser.getId())).thenReturn(xXAuthSessions);
    Mockito.when(xXUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(xXUserPermissions);
    Mockito.when(xXPortalUserRoleDao.findByUserId(vXPortalUser.getId())).thenReturn(xXPortalUserRoles);
    XXPolicyDao xXPolicyDao = Mockito.mock(XXPolicyDao.class);
    List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
    Mockito.when(daoManager.getXXPolicy()).thenReturn(xXPolicyDao);
    Mockito.when(xXPolicyDao.findByUserId(vXUser.getId())).thenReturn(xXPolicyList);
    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>();
    XXRoleRefUserDao roleRefUserDao = Mockito.mock(XXRoleRefUserDao.class);
    Mockito.when(daoManager.getXXRoleRefUser()).thenReturn(roleRefUserDao);
    Mockito.when(roleRefUserDao.findByUserId(userId)).thenReturn(roleRefUser);
    xUserMgr.deleteXUser(vXUser.getId(), force);
    Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(new VXGroupUserList());
    XXPolicy xXPolicy = getXXPolicy();
    xXPolicyList.add(xXPolicy);
    Mockito.when(xXPolicyDao.findByUserId(userId)).thenReturn(xXPolicyList);
    xUserMgr.deleteXUser(vXUser.getId(), force);
    Mockito.when(xXPolicyDao.findByUserId(userId)).thenReturn(new ArrayList<XXPolicy>());
    VXPermMapList vXPermMapList = new VXPermMapList();
    VXPermMap vXPermMap1 = getVXPermMap();
    List<VXPermMap> vXPermMaps = new ArrayList<VXPermMap>();
    vXPermMaps.add(vXPermMap1);
    vXPermMapList.setVXPermMaps(vXPermMaps);
    Mockito.when(xPermMapService.searchXPermMaps((SearchCriteria) Mockito.any())).thenReturn(vXPermMapList);
    xUserMgr.deleteXUser(vXUser.getId(), force);
    Mockito.when(xPermMapService.searchXPermMaps((SearchCriteria) Mockito.any())).thenReturn(new VXPermMapList());
    List<VXAuditMap> vXAuditMaps = new ArrayList<VXAuditMap>();
    VXAuditMap vXAuditMap = getVXAuditMap();
    vXAuditMaps.add(vXAuditMap);
    vXAuditMapList.setVXAuditMaps(vXAuditMaps);
    Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(vXAuditMapList);
    xUserMgr.deleteXUser(vXUser.getId(), force);
    Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(new VXAuditMapList());
    xXAuthSessions.add(xXAuthSession);
    Mockito.when(xXAuthSessionDao.getAuthSessionByUserId(vXPortalUser.getId())).thenReturn(xXAuthSessions);
    xUserMgr.deleteXUser(vXUser.getId(), force);
    Mockito.when(xXAuthSessionDao.getAuthSessionByUserId(vXPortalUser.getId())).thenReturn(new ArrayList<XXAuthSession>());
    XXUserPermission xUserPermissionObj = xxUserPermission();
    xXUserPermissions.add(xUserPermissionObj);
    Mockito.when(xXUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(xXUserPermissions);
    xUserMgr.deleteXUser(vXUser.getId(), force);
    Mockito.when(xXUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(new ArrayList<XXUserPermission>());
    xXPortalUserRoles.add(XXPortalUserRole);
    Mockito.when(xXPortalUserRoleDao.findByUserId(vXPortalUser.getId())).thenReturn(xXPortalUserRoles);
    xUserMgr.deleteXUser(vXUser.getId(), force);
    Mockito.when(xXPortalUserRoleDao.findByUserId(vXPortalUser.getId())).thenReturn(new ArrayList<XXPortalUserRole>());
    xUserMgr.deleteXUser(vXUser.getId(), force);
    vXUser.setName("");
    Mockito.when(xXUserDao.getById(vXUser.getId())).thenReturn(xXUser);
    Mockito.when(xUserService.populateViewBean(xXUser)).thenReturn(vXUser);
    thrown.expect(NullPointerException.class);
    xUserMgr.deleteXUser(vXUser.getId(), force);
}
Also used : XXRoleRefUser(org.apache.ranger.entity.XXRoleRefUser) XXUser(org.apache.ranger.entity.XXUser) VXGroupUserList(org.apache.ranger.view.VXGroupUserList) VXPermMap(org.apache.ranger.view.VXPermMap) XXUserDao(org.apache.ranger.db.XXUserDao) ArrayList(java.util.ArrayList) XXSecurityZoneRefUser(org.apache.ranger.entity.XXSecurityZoneRefUser) XXPolicy(org.apache.ranger.entity.XXPolicy) XXAuthSessionDao(org.apache.ranger.db.XXAuthSessionDao) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) VXAuditMap(org.apache.ranger.view.VXAuditMap) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) VXPermMapList(org.apache.ranger.view.VXPermMapList) XXRoleRefUserDao(org.apache.ranger.db.XXRoleRefUserDao) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) 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) XXPolicyDao(org.apache.ranger.db.XXPolicyDao) Test(org.junit.Test)

Example 3 with XXSecurityZoneRefUser

use of org.apache.ranger.entity.XXSecurityZoneRefUser in project ranger by apache.

the class TestXUserMgr method test125DeleteXUser.

@Test
public void test125DeleteXUser() {
    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);
    XXSecurityZoneRefUser xZoneAdminUser = new XXSecurityZoneRefUser();
    xZoneAdminUser.setZoneId(2L);
    xZoneAdminUser.setUserId(userId);
    xZoneAdminUser.setUserName(vXUser.getName());
    xZoneAdminUser.setUserType(1);
    List<XXSecurityZoneRefUser> zoneSecRefUser = new ArrayList<XXSecurityZoneRefUser>();
    zoneSecRefUser.add(xZoneAdminUser);
    XXSecurityZoneRefUserDao zoneSecRefUserDao = Mockito.mock(XXSecurityZoneRefUserDao.class);
    Mockito.when(daoManager.getXXSecurityZoneRefUser()).thenReturn(zoneSecRefUserDao);
    Mockito.when(zoneSecRefUserDao.findByUserId(userId)).thenReturn(zoneSecRefUser);
    RangerSecurityZone securityZone = new RangerSecurityZone();
    securityZone.setId(2L);
    securityZone.setName("sz1");
    XXSecurityZone xxSecurityZone = new XXSecurityZone();
    xxSecurityZone.setId(2L);
    xxSecurityZone.setName("sz1");
    XXSecurityZoneDao xXSecurityZoneDao = Mockito.mock(XXSecurityZoneDao.class);
    Mockito.when(daoManager.getXXSecurityZoneDao()).thenReturn(xXSecurityZoneDao);
    Mockito.when(xXSecurityZoneDao.getById(xZoneAdminUser.getZoneId())).thenReturn(xxSecurityZone);
    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);
    XXRole xRole = new XXRole();
    xRole.setId(userId);
    xRole.setName("Role1");
    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) RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) XXSecurityZoneDao(org.apache.ranger.db.XXSecurityZoneDao) 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) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) VXUser(org.apache.ranger.view.VXUser) XXAuthSession(org.apache.ranger.entity.XXAuthSession) XXUserPermission(org.apache.ranger.entity.XXUserPermission) XXSecurityZone(org.apache.ranger.entity.XXSecurityZone) 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 4 with XXSecurityZoneRefUser

use of org.apache.ranger.entity.XXSecurityZoneRefUser 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 5 with XXSecurityZoneRefUser

use of org.apache.ranger.entity.XXSecurityZoneRefUser in project ranger by apache.

the class TestXUserMgr method test21DeleteXUser.

@Test
public void test21DeleteXUser() {
    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);
    VXGroupUserList vxGroupUserList = vxGroupUserList();
    XXGroupUserDao xGroupUserDao = Mockito.mock(XXGroupUserDao.class);
    Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
    Mockito.when(daoManager.getXXGroupUser()).thenReturn(xGroupUserDao);
    VXPermMapList vXPermMapList = new VXPermMapList();
    VXPermMap vXPermMap1 = getVXPermMap();
    List<VXPermMap> vXPermMaps = new ArrayList<VXPermMap>();
    vXPermMaps.add(vXPermMap1);
    vXPermMapList.setVXPermMaps(vXPermMaps);
    XXPermMapDao xXPermMapDao = Mockito.mock(XXPermMapDao.class);
    Mockito.when(xPermMapService.searchXPermMaps((SearchCriteria) Mockito.any())).thenReturn(vXPermMapList);
    Mockito.when(daoManager.getXXPermMap()).thenReturn(xXPermMapDao);
    VXAuditMapList vXAuditMapList = new VXAuditMapList();
    List<VXAuditMap> vXAuditMaps = new ArrayList<VXAuditMap>();
    VXAuditMap vXAuditMap = getVXAuditMap();
    vXAuditMaps.add(vXAuditMap);
    vXAuditMapList.setVXAuditMaps(vXAuditMaps);
    XXAuditMapDao xXAuditMapDao = Mockito.mock(XXAuditMapDao.class);
    Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(vXAuditMapList);
    Mockito.when(daoManager.getXXAuditMap()).thenReturn(xXAuditMapDao);
    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");
    XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
    XXModuleDef xModuleDef = xxModuleDef();
    Mockito.when(xModuleDefDao.findByModuleId(Mockito.anyLong())).thenReturn(xModuleDef);
    XXAuthSessionDao xXAuthSessionDao = Mockito.mock(XXAuthSessionDao.class);
    XXUserPermissionDao xXUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    XXPortalUserRoleDao xXPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
    Mockito.when(daoManager.getXXAuthSession()).thenReturn(xXAuthSessionDao);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xXUserPermissionDao);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xXPortalUserRoleDao);
    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);
    Mockito.when(xXAuthSessionDao.getAuthSessionByUserId(vXPortalUser.getId())).thenReturn(xXAuthSessions);
    Mockito.when(xXUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(xXUserPermissions);
    Mockito.when(xXPortalUserRoleDao.findByUserId(vXPortalUser.getId())).thenReturn(xXPortalUserRoles);
    XXPolicyDao xXPolicyDao = Mockito.mock(XXPolicyDao.class);
    List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
    XXPolicy xXPolicy = getXXPolicy();
    xXPolicyList.add(xXPolicy);
    Mockito.when(daoManager.getXXPolicy()).thenReturn(xXPolicyDao);
    Mockito.when(xXPolicyDao.findByUserId(vXUser.getId())).thenReturn(xXPolicyList);
    RangerPolicy rangerPolicy = rangerPolicy();
    Mockito.when(policyService.getPopulatedViewObject(xXPolicy)).thenReturn(rangerPolicy);
    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>();
    XXRoleRefUserDao roleRefUserDao = Mockito.mock(XXRoleRefUserDao.class);
    Mockito.when(daoManager.getXXRoleRefUser()).thenReturn(roleRefUserDao);
    Mockito.when(roleRefUserDao.findByUserId(userId)).thenReturn(roleRefUser);
    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) VXGroupUserList(org.apache.ranger.view.VXGroupUserList) VXPermMap(org.apache.ranger.view.VXPermMap) XXUserDao(org.apache.ranger.db.XXUserDao) ArrayList(java.util.ArrayList) XXSecurityZoneRefUser(org.apache.ranger.entity.XXSecurityZoneRefUser) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) XXPolicy(org.apache.ranger.entity.XXPolicy) XXAuthSessionDao(org.apache.ranger.db.XXAuthSessionDao) XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) XXModuleDef(org.apache.ranger.entity.XXModuleDef) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXPermMapDao(org.apache.ranger.db.XXPermMapDao) VXAuditMap(org.apache.ranger.view.VXAuditMap) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) VXPermMapList(org.apache.ranger.view.VXPermMapList) XXRoleRefUserDao(org.apache.ranger.db.XXRoleRefUserDao) XXAuditMapDao(org.apache.ranger.db.XXAuditMapDao) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) 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) XXPolicyDao(org.apache.ranger.db.XXPolicyDao) Test(org.junit.Test)

Aggregations

XXSecurityZoneRefUser (org.apache.ranger.entity.XXSecurityZoneRefUser)7 XXSecurityZoneRefUserDao (org.apache.ranger.db.XXSecurityZoneRefUserDao)5 XXUser (org.apache.ranger.entity.XXUser)5 ArrayList (java.util.ArrayList)4 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)4 XXUserDao (org.apache.ranger.db.XXUserDao)4 XXAuthSession (org.apache.ranger.entity.XXAuthSession)4 XXPolicy (org.apache.ranger.entity.XXPolicy)4 XXPortalUser (org.apache.ranger.entity.XXPortalUser)4 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)4 XXRoleRefUser (org.apache.ranger.entity.XXRoleRefUser)4 XXUserPermission (org.apache.ranger.entity.XXUserPermission)4 VXAuditMap (org.apache.ranger.view.VXAuditMap)4 VXAuditMapList (org.apache.ranger.view.VXAuditMapList)4 VXPermMap (org.apache.ranger.view.VXPermMap)4 VXPermMapList (org.apache.ranger.view.VXPermMapList)4 VXPortalUser (org.apache.ranger.view.VXPortalUser)4 VXUser (org.apache.ranger.view.VXUser)4 Test (org.junit.Test)4 XXRoleRefUserDao (org.apache.ranger.db.XXRoleRefUserDao)3