Search in sources :

Example 1 with XXRole

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

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

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

the class TestXUserMgr method test126DeleteXGroup.

@Test
public void test126DeleteXGroup() {
    destroySession();
    setup();
    boolean force = true;
    VXGroup vXGroup = vxGroup();
    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);
    List<XXGroupGroup> xXGroupGroups = new ArrayList<XXGroupGroup>();
    XXGroupGroup xXGroupGroup = xxGroupGroup();
    xXGroupGroups.add(xXGroupGroup);
    List<XXGroupPermission> xXGroupPermissions = new ArrayList<XXGroupPermission>();
    XXGroupPermission xGroupPermissionObj = xxGroupPermission();
    xXGroupPermissions.add(xGroupPermissionObj);
    List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
    XXPolicy xXPolicy = getXXPolicy();
    xXPolicyList.add(xXPolicy);
    List<XXResource> xResourceList = new ArrayList<XXResource>();
    XXResource xXResource = new XXResource();
    xXResource.setId(userId);
    xXResource.setName("hadoopdev");
    xXResource.setIsRecursive(AppConstants.BOOL_TRUE);
    xXResource.setResourceStatus(AppConstants.STATUS_ENABLED);
    xResourceList.add(xXResource);
    XXSecurityZoneRefGroup xZoneAdminGroup = new XXSecurityZoneRefGroup();
    xZoneAdminGroup.setZoneId(2L);
    xZoneAdminGroup.setGroupId(vXGroup.getId());
    xZoneAdminGroup.setGroupName(vXGroup.getName());
    xZoneAdminGroup.setGroupType(1);
    List<XXSecurityZoneRefGroup> zoneSecRefGroup = new ArrayList<XXSecurityZoneRefGroup>();
    zoneSecRefGroup.add(xZoneAdminGroup);
    XXSecurityZoneRefGroupDao zoneSecRefGroupDao = Mockito.mock(XXSecurityZoneRefGroupDao.class);
    Mockito.when(daoManager.getXXSecurityZoneRefGroup()).thenReturn(zoneSecRefGroupDao);
    Mockito.when(zoneSecRefGroupDao.findByGroupId(userId)).thenReturn(zoneSecRefGroup);
    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(xZoneAdminGroup.getZoneId())).thenReturn(xxSecurityZone);
    List<XXRoleRefGroup> roleRefGroup = new ArrayList<XXRoleRefGroup>();
    XXRoleRefGroup xRoleRefGroup = new XXRoleRefGroup();
    xRoleRefGroup.setRoleId(userId);
    xRoleRefGroup.setGroupId(userId);
    xRoleRefGroup.setGroupName(groupName);
    xRoleRefGroup.setGroupType(0);
    roleRefGroup.add(xRoleRefGroup);
    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 Group '" + vXGroup.getName().trim() + "' as its present in " + RangerConstants.ROLE_FIELD);
    Mockito.when(restErrorUtil.generateRESTException((VXResponse) Mockito.any())).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    xUserMgr.deleteXGroup(vXGroup.getId(), force);
}
Also used : XXSecurityZoneRefGroup(org.apache.ranger.entity.XXSecurityZoneRefGroup) RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) XXSecurityZoneDao(org.apache.ranger.db.XXSecurityZoneDao) VXPermMap(org.apache.ranger.view.VXPermMap) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) XXSecurityZoneRefGroupDao(org.apache.ranger.db.XXSecurityZoneRefGroupDao) XXPolicy(org.apache.ranger.entity.XXPolicy) XXRoleRefGroup(org.apache.ranger.entity.XXRoleRefGroup) VXAuditMap(org.apache.ranger.view.VXAuditMap) VXPermMapList(org.apache.ranger.view.VXPermMapList) VXResponse(org.apache.ranger.view.VXResponse) XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) XXResource(org.apache.ranger.entity.XXResource) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) XXSecurityZone(org.apache.ranger.entity.XXSecurityZone) VXGroup(org.apache.ranger.view.VXGroup) XXGroupGroup(org.apache.ranger.entity.XXGroupGroup) XXRole(org.apache.ranger.entity.XXRole) Test(org.junit.Test)

Example 4 with XXRole

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

the class XUserMgr method blockIfRoleGroup.

private void blockIfRoleGroup(Long id) {
    List<XXRoleRefGroup> roleRefGroups = this.daoManager.getXXRoleRefGroup().findByGroupId(id);
    if (CollectionUtils.isNotEmpty(roleRefGroups)) {
        StringBuilder roles = new StringBuilder();
        for (XXRoleRefGroup roleRefGroup : roleRefGroups) {
            XXRole xxRole = this.daoManager.getXXRole().getById(roleRefGroup.getRoleId());
            final String roleName = xxRole.getName();
            if (roles.indexOf(roleName) < 0)
                roles.append(roleName + ",");
        }
        final String roleRefGroupName = roleRefGroups.get(0).getGroupName();
        this.prepareAndThrow(roleRefGroupName, RangerConstants.ROLE_FIELD, roles, GROUP);
    }
}
Also used : XXRoleRefGroup(org.apache.ranger.entity.XXRoleRefGroup) XXRole(org.apache.ranger.entity.XXRole)

Example 5 with XXRole

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

the class XUserMgr method blockIfRoleUser.

private void blockIfRoleUser(Long id) {
    List<XXRoleRefUser> roleRefUsers = this.daoManager.getXXRoleRefUser().findByUserId(id);
    if (CollectionUtils.isNotEmpty(roleRefUsers)) {
        StringBuilder roles = new StringBuilder();
        for (XXRoleRefUser roleRefUser : roleRefUsers) {
            XXRole xxRole = this.daoManager.getXXRole().getById(roleRefUser.getRoleId());
            final String roleName = xxRole.getName();
            if (roles.indexOf(roleName) < 0)
                roles.append(roleName + ",");
        }
        final String roleRefUserName = roleRefUsers.get(0).getUserName();
        this.prepareAndThrow(roleRefUserName, RangerConstants.ROLE_FIELD, roles, USER);
    }
}
Also used : XXRoleRefUser(org.apache.ranger.entity.XXRoleRefUser) XXRole(org.apache.ranger.entity.XXRole)

Aggregations

XXRole (org.apache.ranger.entity.XXRole)7 ArrayList (java.util.ArrayList)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 XXPolicy (org.apache.ranger.entity.XXPolicy)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 VXResponse (org.apache.ranger.view.VXResponse)4 Test (org.junit.Test)4 XXRoleRefGroup (org.apache.ranger.entity.XXRoleRefGroup)3 XXRoleRefUser (org.apache.ranger.entity.XXRoleRefUser)3 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)2 XXRoleDao (org.apache.ranger.db.XXRoleDao)2 XXSecurityZoneDao (org.apache.ranger.db.XXSecurityZoneDao)2 XXSecurityZoneRefGroupDao (org.apache.ranger.db.XXSecurityZoneRefGroupDao)2 XXSecurityZoneRefUserDao (org.apache.ranger.db.XXSecurityZoneRefUserDao)2 XXUserDao (org.apache.ranger.db.XXUserDao)2 XXAuthSession (org.apache.ranger.entity.XXAuthSession)2 XXGroupGroup (org.apache.ranger.entity.XXGroupGroup)2