Search in sources :

Example 6 with XXGroup

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

the class TestXUserMgr method test27DeleteXGroup.

@Test
public void test27DeleteXGroup() {
    setup();
    boolean force = true;
    VXGroup vXGroup = new VXGroup();
    vXGroup.setId(userId);
    vXGroup.setDescription("group test");
    vXGroup.setName("grouptest");
    // XXGroup
    XXGroupDao xXGroupDao = Mockito.mock(XXGroupDao.class);
    XXGroup xXGroup = new XXGroup();
    Mockito.when(daoManager.getXXGroup()).thenReturn(xXGroupDao);
    Mockito.when(xXGroupDao.getById(vXGroup.getId())).thenReturn(xXGroup);
    Mockito.when(xGroupService.populateViewBean(xXGroup)).thenReturn(vXGroup);
    // VXGroupUser
    VXGroupUserList vxGroupUserList = new VXGroupUserList();
    XXGroupUserDao xGroupUserDao = Mockito.mock(XXGroupUserDao.class);
    VXGroupUser vxGroupUser = new VXGroupUser();
    vxGroupUser.setId(userId);
    vxGroupUser.setName("group user test");
    vxGroupUser.setOwner("Admin");
    vxGroupUser.setUserId(userId);
    vxGroupUser.setUpdatedBy("User");
    Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
    Mockito.when(daoManager.getXXGroupUser()).thenReturn(xGroupUserDao);
    // VXPermMap
    VXPermMapList vXPermMapList = new VXPermMapList();
    XXPermMapDao xXPermMapDao = Mockito.mock(XXPermMapDao.class);
    Mockito.when(xPermMapService.searchXPermMaps((SearchCriteria) Mockito.any())).thenReturn(vXPermMapList);
    Mockito.when(daoManager.getXXPermMap()).thenReturn(xXPermMapDao);
    // VXAuditMap
    VXAuditMapList vXAuditMapList = new VXAuditMapList();
    XXAuditMapDao xXAuditMapDao = Mockito.mock(XXAuditMapDao.class);
    Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(vXAuditMapList);
    Mockito.when(daoManager.getXXAuditMap()).thenReturn(xXAuditMapDao);
    // XXGroupGroup
    XXGroupGroupDao xXGroupGroupDao = Mockito.mock(XXGroupGroupDao.class);
    List<XXGroupGroup> xXGroupGroups = new ArrayList<XXGroupGroup>();
    Mockito.when(daoManager.getXXGroupGroup()).thenReturn(xXGroupGroupDao);
    Mockito.when(xXGroupGroupDao.findByGroupId(userId)).thenReturn(xXGroupGroups);
    // update XXGroupPermission
    XXGroupPermissionDao xXGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
    Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xXGroupPermissionDao);
    List<XXGroupPermission> xXGroupPermissions = new ArrayList<XXGroupPermission>();
    Mockito.when(xXGroupPermissionDao.findByGroupId(vXGroup.getId())).thenReturn(xXGroupPermissions);
    // update XXPolicyItemUserPerm
    XXPolicyDao xXPolicyDao = Mockito.mock(XXPolicyDao.class);
    List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
    Mockito.when(daoManager.getXXPolicy()).thenReturn(xXPolicyDao);
    Mockito.when(xXPolicyDao.findByGroupId(userId)).thenReturn(xXPolicyList);
    xUserMgr.deleteXGroup(vXGroup.getId(), force);
    Mockito.verify(xGroupUserService).searchXGroupUsers((SearchCriteria) Mockito.any());
}
Also used : VXGroupUserList(org.apache.ranger.view.VXGroupUserList) XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) XXAuditMapDao(org.apache.ranger.db.XXAuditMapDao) XXGroupPermissionDao(org.apache.ranger.db.XXGroupPermissionDao) ArrayList(java.util.ArrayList) VXGroupUser(org.apache.ranger.view.VXGroupUser) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) XXPolicy(org.apache.ranger.entity.XXPolicy) XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) XXGroup(org.apache.ranger.entity.XXGroup) XXPermMapDao(org.apache.ranger.db.XXPermMapDao) XXPolicyDao(org.apache.ranger.db.XXPolicyDao) VXPermMapList(org.apache.ranger.view.VXPermMapList) VXGroup(org.apache.ranger.view.VXGroup) XXGroupGroupDao(org.apache.ranger.db.XXGroupGroupDao) XXGroupDao(org.apache.ranger.db.XXGroupDao) XXGroupGroup(org.apache.ranger.entity.XXGroupGroup) Test(org.junit.Test)

Example 7 with XXGroup

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

the class RangerBaseModelService method getGroupName.

protected String getGroupName(Long groupId) {
    String ret = null;
    XXGroup xGroup = groupId == null ? null : daoMgr.getXXGroup().getById(groupId);
    if (xGroup != null) {
        ret = xGroup.getName();
    }
    return ret;
}
Also used : XXGroup(org.apache.ranger.entity.XXGroup)

Example 8 with XXGroup

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

the class RangerBizUtil method checkUsrPermForPolicy.

/**
 * returns true if given userID is having specified permission on specified
 * resource
 *
 * @param xUserId
 * @param permission
 * @param resourceId
 * @return
 */
private boolean checkUsrPermForPolicy(Long xUserId, int permission, Long resourceId) {
    // this snippet load user groups and permission map list from DB
    List<XXGroup> userGroups = new ArrayList<XXGroup>();
    List<XXPermMap> permMapList = new ArrayList<XXPermMap>();
    userGroups = daoManager.getXXGroup().findByUserId(xUserId);
    permMapList = daoManager.getXXPermMap().findByResourceId(resourceId);
    Long publicGroupId = getPublicGroupId();
    boolean matchFound = false;
    for (XXPermMap permMap : permMapList) {
        if (permMap.getPermType() == permission) {
            if (permMap.getPermFor() == AppConstants.XA_PERM_FOR_GROUP) {
                // check whether permission is enabled for public group or a
                // group to which user belongs
                matchFound = (publicGroupId != null && publicGroupId == permMap.getGroupId()) || isGroupInList(permMap.getGroupId(), userGroups);
            } else if (permMap.getPermFor() == AppConstants.XA_PERM_FOR_USER) {
                // check whether permission is enabled to user
                matchFound = permMap.getUserId().equals(xUserId);
            }
        }
        if (matchFound) {
            break;
        }
    }
    return matchFound;
}
Also used : XXGroup(org.apache.ranger.entity.XXGroup) ArrayList(java.util.ArrayList) XXPermMap(org.apache.ranger.entity.XXPermMap)

Example 9 with XXGroup

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

the class ServiceDBStore method createDefaultPolicyUsersAndGroups.

void createDefaultPolicyUsersAndGroups(List<RangerPolicy> defaultPolicies) {
    Set<String> defaultPolicyUsers = new HashSet<String>();
    Set<String> defaultPolicyGroups = new HashSet<String>();
    for (RangerPolicy defaultPolicy : defaultPolicies) {
        for (RangerPolicyItem defaultPolicyItem : defaultPolicy.getPolicyItems()) {
            defaultPolicyUsers.addAll(defaultPolicyItem.getUsers());
            defaultPolicyGroups.addAll(defaultPolicyItem.getGroups());
        }
        for (RangerPolicyItem defaultPolicyItem : defaultPolicy.getAllowExceptions()) {
            defaultPolicyUsers.addAll(defaultPolicyItem.getUsers());
            defaultPolicyGroups.addAll(defaultPolicyItem.getGroups());
        }
        for (RangerPolicyItem defaultPolicyItem : defaultPolicy.getDenyPolicyItems()) {
            defaultPolicyUsers.addAll(defaultPolicyItem.getUsers());
            defaultPolicyGroups.addAll(defaultPolicyItem.getGroups());
        }
        for (RangerPolicyItem defaultPolicyItem : defaultPolicy.getDenyExceptions()) {
            defaultPolicyUsers.addAll(defaultPolicyItem.getUsers());
            defaultPolicyGroups.addAll(defaultPolicyItem.getGroups());
        }
        for (RangerPolicyItem defaultPolicyItem : defaultPolicy.getDataMaskPolicyItems()) {
            defaultPolicyUsers.addAll(defaultPolicyItem.getUsers());
            defaultPolicyGroups.addAll(defaultPolicyItem.getGroups());
        }
        for (RangerPolicyItem defaultPolicyItem : defaultPolicy.getRowFilterPolicyItems()) {
            defaultPolicyUsers.addAll(defaultPolicyItem.getUsers());
            defaultPolicyGroups.addAll(defaultPolicyItem.getGroups());
        }
    }
    for (String policyUser : defaultPolicyUsers) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Checking policyUser:[" + policyUser + "] for existence");
        }
        if (StringUtils.isNotBlank(policyUser) && !StringUtils.equals(policyUser, RangerPolicyEngine.USER_CURRENT) && !StringUtils.equals(policyUser, RangerPolicyEngine.RESOURCE_OWNER)) {
            XXUser xxUser = daoMgr.getXXUser().findByUserName(policyUser);
            if (xxUser == null) {
                UserSessionBase usb = ContextUtil.getCurrentUserSession();
                if (usb != null && !usb.isKeyAdmin() && !usb.isUserAdmin() && !usb.isSpnegoEnabled()) {
                    throw restErrorUtil.createRESTException("User does not exist with given username: [" + policyUser + "] please use existing user", MessageEnums.OPER_NO_PERMISSION);
                }
                xUserMgr.createServiceConfigUser(policyUser);
            }
        }
    }
    for (String policyGroup : defaultPolicyGroups) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Checking policyGroup:[" + policyGroup + "] for existence");
        }
        if (StringUtils.isNotBlank(policyGroup)) {
            XXGroup xxGroup = daoMgr.getXXGroup().findByGroupName(policyGroup);
            if (xxGroup == null) {
                UserSessionBase usb = ContextUtil.getCurrentUserSession();
                if (usb != null && !usb.isKeyAdmin() && !usb.isUserAdmin() && !usb.isSpnegoEnabled()) {
                    throw restErrorUtil.createRESTException("Group does not exist with given groupname: [" + policyGroup + "] please use existing group", MessageEnums.OPER_NO_PERMISSION);
                }
                VXGroup vXGroup = new VXGroup();
                vXGroup.setName(policyGroup);
                vXGroup.setDescription(policyGroup);
                vXGroup.setGroupSource(RangerCommonEnums.GROUP_INTERNAL);
                vXGroup.setIsVisible(RangerCommonEnums.IS_VISIBLE);
                xGroupService.createResource(vXGroup);
            }
        }
    }
}
Also used : XXUser(org.apache.ranger.entity.XXUser) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXGroup(org.apache.ranger.entity.XXGroup) VXString(org.apache.ranger.view.VXString) RangerPolicyItem(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem) VXGroup(org.apache.ranger.view.VXGroup) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) UserSessionBase(org.apache.ranger.common.UserSessionBase)

Example 10 with XXGroup

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

the class XGroupPermissionService method getPopulatedVXGroupPermissionList.

public List<VXGroupPermission> getPopulatedVXGroupPermissionList(List<XXGroupPermission> xgroupPermissionList, Map<Long, XXGroup> xXGroupMap, VXModuleDef vModuleDef) {
    List<VXGroupPermission> vXGroupPermissionList = new ArrayList<VXGroupPermission>();
    XXGroup xXGroup = null;
    for (XXGroupPermission xgroupPermission : xgroupPermissionList) {
        if (xXGroupMap.containsKey(xgroupPermission.getGroupId())) {
            xXGroup = xXGroupMap.get(xgroupPermission.getGroupId());
            VXGroupPermission vXGrpPerm = new VXGroupPermission();
            vXGrpPerm.setId(xgroupPermission.getId());
            vXGrpPerm.setGroupId(xgroupPermission.getGroupId());
            vXGrpPerm.setModuleId(xgroupPermission.getModuleId());
            vXGrpPerm.setIsAllowed(xgroupPermission.getIsAllowed());
            vXGrpPerm.setCreateDate(xgroupPermission.getCreateTime());
            vXGrpPerm.setUpdateDate(xgroupPermission.getUpdateTime());
            vXGrpPerm.setGroupName(xXGroup.getName());
            vXGrpPerm.setModuleName(vModuleDef.getModule());
            vXGroupPermissionList.add(vXGrpPerm);
        }
    }
    return vXGroupPermissionList;
}
Also used : XXGroup(org.apache.ranger.entity.XXGroup) XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) VXGroupPermission(org.apache.ranger.view.VXGroupPermission) ArrayList(java.util.ArrayList)

Aggregations

XXGroup (org.apache.ranger.entity.XXGroup)24 ArrayList (java.util.ArrayList)11 XXUser (org.apache.ranger.entity.XXUser)10 VXGroup (org.apache.ranger.view.VXGroup)7 XXGroupDao (org.apache.ranger.db.XXGroupDao)6 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 XXTrxLog (org.apache.ranger.entity.XXTrxLog)4 XXGroupUserDao (org.apache.ranger.db.XXGroupUserDao)3 XXPermMap (org.apache.ranger.entity.XXPermMap)3 XXPortalUser (org.apache.ranger.entity.XXPortalUser)3 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)3 Field (java.lang.reflect.Field)2 Date (java.util.Date)2 Random (java.util.Random)2 SearchCriteria (org.apache.ranger.common.SearchCriteria)2 SearchField (org.apache.ranger.common.SearchField)2 VTrxLogAttr (org.apache.ranger.common.view.VTrxLogAttr)2 XXAuditMapDao (org.apache.ranger.db.XXAuditMapDao)2