Search in sources :

Example 1 with XXGroupUser

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

the class ServiceMgr method isZoneAdmin.

public boolean isZoneAdmin(String zoneName) {
    boolean isZoneAdmin = false;
    RangerSecurityZone securityZone = null;
    try {
        securityZone = zoneStore.getSecurityZoneByName(zoneName);
    } catch (Exception e) {
        LOG.error("Unexpected error when fetching security zone with name:[" + zoneName + "] from database", e);
    }
    if (securityZone != null) {
        String userId = rangerBizUtil.getCurrentUserLoginId();
        List<XXGroupUser> groupUsers = groupUserDao.findByUserId(rangerBizUtil.getXUserId());
        List<String> loggedInUsersGroups = new ArrayList<>();
        for (XXGroupUser groupUser : groupUsers) {
            loggedInUsersGroups.add(groupUser.getName());
        }
        for (String loggedInUsersGroup : loggedInUsersGroups) {
            if (securityZone != null && securityZone.getAdminUserGroups() != null && securityZone.getAdminUserGroups().contains(loggedInUsersGroup)) {
                isZoneAdmin = true;
                break;
            }
        }
        if ((securityZone != null && securityZone.getAdminUsers() != null && securityZone.getAdminUsers().contains(userId))) {
            isZoneAdmin = true;
        }
    }
    return isZoneAdmin;
}
Also used : XXGroupUser(org.apache.ranger.entity.XXGroupUser) RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) ArrayList(java.util.ArrayList) HadoopException(org.apache.ranger.plugin.client.HadoopException)

Example 2 with XXGroupUser

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

the class ServiceMgr method isZoneAuditor.

public boolean isZoneAuditor(String zoneName) {
    boolean isZoneAuditor = false;
    RangerSecurityZone securityZone = null;
    try {
        securityZone = zoneStore.getSecurityZoneByName(zoneName);
    } catch (Exception e) {
        LOG.error("Unexpected error when fetching security zone with name:[" + zoneName + "] from database", e);
    }
    if (securityZone != null) {
        String userId = rangerBizUtil.getCurrentUserLoginId();
        List<XXGroupUser> groupUsers = groupUserDao.findByUserId(rangerBizUtil.getXUserId());
        List<String> loggedInUsersGroups = new ArrayList<>();
        for (XXGroupUser groupUser : groupUsers) {
            loggedInUsersGroups.add(groupUser.getName());
        }
        for (String loggedInUsersGroup : loggedInUsersGroups) {
            if (securityZone != null && securityZone.getAuditUserGroups() != null && securityZone.getAuditUserGroups().contains(loggedInUsersGroup)) {
                isZoneAuditor = true;
                break;
            }
        }
        if ((securityZone != null && securityZone.getAuditUsers() != null && securityZone.getAuditUsers().contains(userId))) {
            isZoneAuditor = true;
        }
    }
    return isZoneAuditor;
}
Also used : XXGroupUser(org.apache.ranger.entity.XXGroupUser) RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) ArrayList(java.util.ArrayList) HadoopException(org.apache.ranger.plugin.client.HadoopException)

Example 3 with XXGroupUser

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

the class TestXUserMgr method test97updateXModuleDefPermission.

@Test
public void test97updateXModuleDefPermission() {
    XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    XXModuleDef xModuleDef = xxModuleDef();
    VXModuleDef vXModuleDef = vxModuleDef();
    Mockito.when(xModuleDefService.updateResource(vXModuleDef)).thenReturn(vXModuleDef);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
    Mockito.when(xModuleDefDao.getById(userId)).thenReturn(xModuleDef);
    Map<Long, String> xXGroupNameMap = new HashMap<Long, String>();
    xXGroupNameMap.put(userId, groupName);
    Mockito.when(xGroupService.getXXGroupIdNameMap()).thenReturn(xXGroupNameMap);
    Object[] objArr = new Object[] { userId, userId, userLoginID };
    Map<Long, Object[]> xXUserMap = new HashMap<Long, Object[]>();
    xXUserMap.put(userId, objArr);
    Mockito.when(xUserService.getXXPortalUserIdXXUserNameMap()).thenReturn(xXUserMap);
    Mockito.when(xModuleDefService.populateViewBean(xModuleDef, xXUserMap, xXGroupNameMap, true)).thenReturn(vXModuleDef);
    List<XXGroupPermission> xXGroupPermissions = new ArrayList<XXGroupPermission>();
    XXGroupPermission xGroupPermissionObj = xxGroupPermission();
    xXGroupPermissions.add(xGroupPermissionObj);
    VXGroupPermission vXGroupPermission = vxGroupPermission();
    vXGroupPermission.setIsAllowed(0);
    List<XXUserPermission> xXUserPermissions = new ArrayList<XXUserPermission>();
    XXUserPermission xUserPermissionObj = xxUserPermission();
    xXUserPermissions.add(xUserPermissionObj);
    VXUserPermission vxUserPermission = vxUserPermission();
    vxUserPermission.setIsAllowed(0);
    UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
    Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
    userSessions.add(userSession);
    XXGroupUserDao xxGroupUserDao = Mockito.mock(XXGroupUserDao.class);
    Mockito.when(daoManager.getXXGroupUser()).thenReturn(xxGroupUserDao);
    List<XXGroupUser> grpUsers = new ArrayList<XXGroupUser>();
    Mockito.when(xxGroupUserDao.findByGroupId(vXGroupPermission.getGroupId())).thenReturn(grpUsers);
    Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(vxUserPermission.getUserId())).thenReturn(userSessions);
    Mockito.when(xGroupPermissionService.createResource((VXGroupPermission) Mockito.any())).thenReturn(vXGroupPermission);
    Mockito.when(xUserPermissionService.createResource((VXUserPermission) Mockito.any())).thenReturn(vxUserPermission);
    VXModuleDef dbMuduleDef = xUserMgr.updateXModuleDefPermission(vXModuleDef);
    Assert.assertEquals(dbMuduleDef, vXModuleDef);
    Assert.assertNotNull(dbMuduleDef);
    Assert.assertEquals(dbMuduleDef, vXModuleDef);
    Assert.assertEquals(dbMuduleDef.getId(), vXModuleDef.getId());
    Assert.assertEquals(dbMuduleDef.getOwner(), vXModuleDef.getOwner());
    Assert.assertEquals(dbMuduleDef.getUpdatedBy(), vXModuleDef.getUpdatedBy());
    Assert.assertEquals(dbMuduleDef.getUrl(), vXModuleDef.getUrl());
    Assert.assertEquals(dbMuduleDef.getAddedById(), vXModuleDef.getAddedById());
    Assert.assertEquals(dbMuduleDef.getCreateDate(), vXModuleDef.getCreateDate());
    Assert.assertEquals(dbMuduleDef.getCreateTime(), vXModuleDef.getCreateTime());
    Assert.assertEquals(dbMuduleDef.getUserPermList(), vXModuleDef.getUserPermList());
    Assert.assertEquals(dbMuduleDef.getGroupPermList(), vXModuleDef.getGroupPermList());
    Mockito.verify(xModuleDefService).updateResource(vXModuleDef);
    Mockito.verify(daoManager).getXXModuleDef();
    Mockito.verify(xModuleDefService).populateViewBean(xModuleDef, xXUserMap, xXGroupNameMap, true);
    Mockito.verify(xGroupService).getXXGroupIdNameMap();
    Mockito.verify(xUserService).getXXPortalUserIdXXUserNameMap();
}
Also used : XXGroupUser(org.apache.ranger.entity.XXGroupUser) XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) XXUserPermission(org.apache.ranger.entity.XXUserPermission) VXUserPermission(org.apache.ranger.view.VXUserPermission) UserSessionBase(org.apache.ranger.common.UserSessionBase) XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXGroupPermission(org.apache.ranger.view.VXGroupPermission) VXModuleDef(org.apache.ranger.view.VXModuleDef) VXLong(org.apache.ranger.view.VXLong) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with XXGroupUser

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

the class TestXUserMgr method test96updateXModuleDefPermission.

@Test
public void test96updateXModuleDefPermission() {
    XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    XXModuleDef xModuleDef = xxModuleDef();
    VXModuleDef vXModuleDef = vxModuleDef();
    Mockito.when(xModuleDefService.updateResource(vXModuleDef)).thenReturn(vXModuleDef);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
    Mockito.when(xModuleDefDao.getById(userId)).thenReturn(xModuleDef);
    Map<Long, String> xXGroupNameMap = new HashMap<Long, String>();
    xXGroupNameMap.put(userId, groupName);
    Mockito.when(xGroupService.getXXGroupIdNameMap()).thenReturn(xXGroupNameMap);
    Object[] objArr = new Object[] { userId, userId, userLoginID };
    Map<Long, Object[]> xXUserMap = new HashMap<Long, Object[]>();
    xXUserMap.put(userId, objArr);
    Mockito.when(xUserService.getXXPortalUserIdXXUserNameMap()).thenReturn(xXUserMap);
    Mockito.when(xModuleDefService.populateViewBean(xModuleDef, xXUserMap, xXGroupNameMap, true)).thenReturn(vXModuleDef);
    List<XXGroupPermission> xXGroupPermissions = new ArrayList<XXGroupPermission>();
    XXGroupPermission xGroupPermissionObj = xxGroupPermission();
    xXGroupPermissions.add(xGroupPermissionObj);
    List<VXGroupPermission> vXGroupPermissions = new ArrayList<VXGroupPermission>();
    VXGroupPermission vXGroupPermission = vxGroupPermission();
    vXGroupPermission.setIsAllowed(0);
    vXGroupPermissions.add(vXGroupPermission);
    List<XXUserPermission> xXUserPermissions = new ArrayList<XXUserPermission>();
    XXUserPermission xUserPermissionObj = xxUserPermission();
    xXUserPermissions.add(xUserPermissionObj);
    VXUserPermission vxUserPermission = vxUserPermission();
    vxUserPermission.setIsAllowed(0);
    UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
    Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
    userSessions.add(userSession);
    Map<Long, VXGroupPermission> groupPermMapOld = new HashMap<Long, VXGroupPermission>();
    groupPermMapOld.put(vXGroupPermission.getGroupId(), vXGroupPermission);
    Mockito.when(xGroupPermissionService.convertVListToVMap((List<VXGroupPermission>) Mockito.any())).thenReturn(groupPermMapOld);
    Mockito.when(xGroupPermissionService.updateResource(vXGroupPermission)).thenReturn(vXGroupPermission);
    XXGroupUserDao xxGroupUserDao = Mockito.mock(XXGroupUserDao.class);
    Mockito.when(daoManager.getXXGroupUser()).thenReturn(xxGroupUserDao);
    List<XXGroupUser> grpUsers = new ArrayList<XXGroupUser>();
    Mockito.when(xxGroupUserDao.findByGroupId(vXGroupPermission.getGroupId())).thenReturn(grpUsers);
    List<VXUserPermission> userPermListOld = new ArrayList<VXUserPermission>();
    userPermListOld.add(vxUserPermission);
    Map<Long, VXUserPermission> userPermMapOld = new HashMap<Long, VXUserPermission>();
    userPermMapOld.put(vxUserPermission.getUserId(), vxUserPermission);
    Mockito.when(xUserPermissionService.convertVListToVMap((List<VXUserPermission>) Mockito.any())).thenReturn(userPermMapOld);
    Mockito.when(xUserPermissionService.updateResource(vxUserPermission)).thenReturn(vxUserPermission);
    Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(vxUserPermission.getUserId())).thenReturn(userSessions);
    VXModuleDef dbMuduleDef = xUserMgr.updateXModuleDefPermission(vXModuleDef);
    Assert.assertEquals(dbMuduleDef, vXModuleDef);
    Assert.assertNotNull(dbMuduleDef);
    Assert.assertEquals(dbMuduleDef, vXModuleDef);
    Assert.assertEquals(dbMuduleDef.getId(), vXModuleDef.getId());
    Assert.assertEquals(dbMuduleDef.getOwner(), vXModuleDef.getOwner());
    Assert.assertEquals(dbMuduleDef.getUpdatedBy(), vXModuleDef.getUpdatedBy());
    Assert.assertEquals(dbMuduleDef.getUrl(), vXModuleDef.getUrl());
    Assert.assertEquals(dbMuduleDef.getAddedById(), vXModuleDef.getAddedById());
    Assert.assertEquals(dbMuduleDef.getCreateDate(), vXModuleDef.getCreateDate());
    Assert.assertEquals(dbMuduleDef.getCreateTime(), vXModuleDef.getCreateTime());
    Assert.assertEquals(dbMuduleDef.getUserPermList(), vXModuleDef.getUserPermList());
    Assert.assertEquals(dbMuduleDef.getGroupPermList(), vXModuleDef.getGroupPermList());
    Mockito.verify(xModuleDefService).populateViewBean(xModuleDef, xXUserMap, xXGroupNameMap, true);
    Mockito.verify(xModuleDefService).updateResource(vXModuleDef);
    Mockito.verify(daoManager).getXXModuleDef();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) VXUserPermission(org.apache.ranger.view.VXUserPermission) UserSessionBase(org.apache.ranger.common.UserSessionBase) XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXGroupPermission(org.apache.ranger.view.VXGroupPermission) VXModuleDef(org.apache.ranger.view.VXModuleDef) HashSet(java.util.HashSet) XXGroupUser(org.apache.ranger.entity.XXGroupUser) XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) XXUserPermission(org.apache.ranger.entity.XXUserPermission) VXLong(org.apache.ranger.view.VXLong) Test(org.junit.Test)

Example 5 with XXGroupUser

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

the class XGroupUserService method readResourceWithOutLogin.

public VXGroupUser readResourceWithOutLogin(Long id) {
    XXGroupUser resource = getDao().getById(id);
    if (resource == null) {
        // Returns code 400 with DATA_NOT_FOUND as the error message
        throw restErrorUtil.createRESTException(getResourceName() + " not found", MessageEnums.DATA_NOT_FOUND, id, null, "preRead: " + id + " not found.");
    }
    VXGroupUser view = populateViewBean(resource);
    return view;
}
Also used : XXGroupUser(org.apache.ranger.entity.XXGroupUser) VXGroupUser(org.apache.ranger.view.VXGroupUser)

Aggregations

XXGroupUser (org.apache.ranger.entity.XXGroupUser)21 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)10 XXGroupUserDao (org.apache.ranger.db.XXGroupUserDao)8 VXGroupUser (org.apache.ranger.view.VXGroupUser)8 XXGroup (org.apache.ranger.entity.XXGroup)6 HashSet (java.util.HashSet)5 UserSessionBase (org.apache.ranger.common.UserSessionBase)5 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)4 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)4 VXGroup (org.apache.ranger.view.VXGroup)3 HashMap (java.util.HashMap)2 XXGroupDao (org.apache.ranger.db.XXGroupDao)2 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)2 XXModuleDef (org.apache.ranger.entity.XXModuleDef)2 XXUserPermission (org.apache.ranger.entity.XXUserPermission)2 HadoopException (org.apache.ranger.plugin.client.HadoopException)2 RangerSecurityZone (org.apache.ranger.plugin.model.RangerSecurityZone)2 VXLong (org.apache.ranger.view.VXLong)2 VXModuleDef (org.apache.ranger.view.VXModuleDef)2