Search in sources :

Example 1 with VXPermMap

use of org.apache.ranger.view.VXPermMap in project ranger by apache.

the class TestXUserREST method test42createXPermMapNull.

@Test
public void test42createXPermMapNull() {
    Mockito.when(xUserMgr.createXPermMap(null)).thenReturn(null);
    VXPermMap retVxGroup = xUserRest.createXPermMap(null);
    Mockito.verify(xUserMgr).createXPermMap(null);
    assertNull(retVxGroup);
}
Also used : VXPermMap(org.apache.ranger.view.VXPermMap) Test(org.junit.Test)

Example 2 with VXPermMap

use of org.apache.ranger.view.VXPermMap in project ranger by apache.

the class TestXUserREST method testcreateXPermMap.

private VXPermMap testcreateXPermMap() {
    VXPermMap testVXPermMap = new VXPermMap();
    testVXPermMap.setCreateDate(new Date());
    testVXPermMap.setGroupId(id);
    testVXPermMap.setGroupName("testGroup");
    testVXPermMap.setId(id);
    testVXPermMap.setOwner("Admin");
    testVXPermMap.setPermGroup("testPermGroup");
    testVXPermMap.setPermType(1);
    testVXPermMap.setResourceId(id);
    testVXPermMap.setUpdateDate(new Date());
    testVXPermMap.setUpdatedBy("Admin");
    testVXPermMap.setUserId(id);
    testVXPermMap.setUserName("testUser");
    testVXPermMap.setPermFor(1);
    return testVXPermMap;
}
Also used : VXPermMap(org.apache.ranger.view.VXPermMap) Date(java.util.Date)

Example 3 with VXPermMap

use of org.apache.ranger.view.VXPermMap in project ranger by apache.

the class XPolicyService method mapPermMapToPermObj.

public List<VXPermObj> mapPermMapToPermObj(List<VXPermMap> permMapList) {
    List<VXPermObj> permObjList = new ArrayList<VXPermObj>();
    HashMap<String, List<VXPermMap>> sortedPemMap = new HashMap<String, List<VXPermMap>>();
    if (permMapList != null) {
        for (VXPermMap vXPermMap : permMapList) {
            String permGrp = vXPermMap.getPermGroup();
            List<VXPermMap> sortedList = sortedPemMap.get(permGrp);
            if (sortedList == null) {
                sortedList = new ArrayList<VXPermMap>();
                sortedPemMap.put(permGrp, sortedList);
            }
            sortedList.add(vXPermMap);
        }
    }
    for (Entry<String, List<VXPermMap>> entry : sortedPemMap.entrySet()) {
        VXPermObj vXPermObj = new VXPermObj();
        List<String> userList = new ArrayList<String>();
        List<String> groupList = new ArrayList<String>();
        List<String> permList = new ArrayList<String>();
        String ipAddress = "";
        List<VXPermMap> permListForGrp = entry.getValue();
        for (VXPermMap permMap : permListForGrp) {
            if (permMap.getPermFor() == AppConstants.XA_PERM_FOR_USER) {
                if (!userList.contains(permMap.getUserName())) {
                    userList.add(permMap.getUserName());
                }
            } else if (permMap.getPermFor() == AppConstants.XA_PERM_FOR_GROUP) {
                if (!groupList.contains(permMap.getGroupName())) {
                    groupList.add(permMap.getGroupName());
                }
            }
            String perm = AppConstants.getLabelFor_XAPermType(permMap.getPermType());
            if (!permList.contains(perm)) {
                permList.add(perm);
            }
            ipAddress = permMap.getIpAddress();
        }
        if (!userList.isEmpty()) {
            vXPermObj.setUserList(userList);
        }
        if (!groupList.isEmpty()) {
            vXPermObj.setGroupList(groupList);
        }
        vXPermObj.setPermList(permList);
        vXPermObj.setIpAddress(ipAddress);
        permObjList.add(vXPermObj);
    }
    return permObjList;
}
Also used : VXPermMap(org.apache.ranger.view.VXPermMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) VXResourceList(org.apache.ranger.view.VXResourceList) ArrayList(java.util.ArrayList) VXPolicyList(org.apache.ranger.view.VXPolicyList) VXPermMapList(org.apache.ranger.view.VXPermMapList) List(java.util.List) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) VXPermObj(org.apache.ranger.view.VXPermObj)

Example 4 with VXPermMap

use of org.apache.ranger.view.VXPermMap in project ranger by apache.

the class XPolicyService method mapPermObjToPermList.

private List<VXPermMap> mapPermObjToPermList(List<VXPermObj> permObjList, VXPolicy vXPolicy) {
    Long resId = vXPolicy.getId();
    List<VXPermMap> permMapList = new ArrayList<VXPermMap>();
    List<VXPermMap> updPermMapList = new ArrayList<VXPermMap>();
    Map<String, VXPermMap> newPermMap = new LinkedHashMap<String, VXPermMap>();
    Random rand = new Random();
    Map<String, XXPermMap> prevPermMap = getPrevPermMap(resId);
    if (permObjList == null) {
        permObjList = new ArrayList<VXPermObj>();
    }
    for (VXPermObj permObj : permObjList) {
        String permGrp = new Date() + " : " + rand.nextInt(9999);
        String ipAddress = permObj.getIpAddress();
        if (!stringUtil.isEmpty(permObj.getUserList())) {
            int permFor = AppConstants.XA_PERM_FOR_USER;
            for (String user : permObj.getUserList()) {
                XXUser xxUser = xaDaoMgr.getXXUser().findByUserName(user);
                if (xxUser == null) {
                    logger.error("No User found with this name : " + user);
                    throw restErrorUtil.createRESTException("No User found with name : " + user, MessageEnums.DATA_NOT_FOUND);
                }
                Long userId = xxUser.getId();
                for (String permission : permObj.getPermList()) {
                    int permType = AppConstants.getEnumFor_XAPermType(permission);
                    VXPermMap vXPermMap = new VXPermMap();
                    vXPermMap.setPermFor(AppConstants.XA_PERM_FOR_USER);
                    vXPermMap.setPermGroup(permGrp);
                    vXPermMap.setPermType(permType);
                    vXPermMap.setUserId(xxUser.getId());
                    vXPermMap.setResourceId(resId);
                    vXPermMap.setIpAddress(ipAddress);
                    permMapList.add(vXPermMap);
                    StringBuilder uniqueKey = new StringBuilder();
                    uniqueKey.append(resId + uniqueKeySeparator);
                    uniqueKey.append(permFor + uniqueKeySeparator);
                    uniqueKey.append(userId + uniqueKeySeparator);
                    uniqueKey.append(permType);
                    newPermMap.put(uniqueKey.toString(), vXPermMap);
                }
            }
        }
        if (!stringUtil.isEmpty(permObj.getGroupList())) {
            int permFor = AppConstants.XA_PERM_FOR_GROUP;
            for (String group : permObj.getGroupList()) {
                XXGroup xxGroup = xaDaoMgr.getXXGroup().findByGroupName(group);
                if (xxGroup == null) {
                    logger.error("No UserGroup found with this name : " + group);
                    throw restErrorUtil.createRESTException("No Group found with name : " + group, MessageEnums.DATA_NOT_FOUND);
                }
                Long grpId = xxGroup.getId();
                for (String permission : permObj.getPermList()) {
                    int permType = AppConstants.getEnumFor_XAPermType(permission);
                    VXPermMap vXPermMap = new VXPermMap();
                    vXPermMap.setPermFor(AppConstants.XA_PERM_FOR_GROUP);
                    vXPermMap.setPermGroup(permGrp);
                    vXPermMap.setPermType(permType);
                    vXPermMap.setGroupId(xxGroup.getId());
                    vXPermMap.setResourceId(resId);
                    vXPermMap.setIpAddress(ipAddress);
                    permMapList.add(vXPermMap);
                    StringBuilder uniqueKey = new StringBuilder();
                    uniqueKey.append(resId + uniqueKeySeparator);
                    uniqueKey.append(permFor + uniqueKeySeparator);
                    uniqueKey.append(grpId + uniqueKeySeparator);
                    uniqueKey.append(permType);
                    newPermMap.put(uniqueKey.toString(), vXPermMap);
                }
            }
        }
    }
    // Create Newly added permissions and Remove deleted permissions from DB
    if (prevPermMap.isEmpty()) {
        updPermMapList.addAll(permMapList);
    } else {
        for (Entry<String, VXPermMap> entry : newPermMap.entrySet()) {
            if (!prevPermMap.containsKey(entry.getKey())) {
                updPermMapList.add(entry.getValue());
            } else {
                VXPermMap vPMap = xPermMapService.populateViewBean(prevPermMap.get(entry.getKey()));
                VXPermMap vPMapNew = entry.getValue();
                vPMap.setIpAddress(vPMapNew.getIpAddress());
                updPermMapList.add(vPMap);
            }
        }
    }
    return updPermMapList;
}
Also used : XXUser(org.apache.ranger.entity.XXUser) VXPermMap(org.apache.ranger.view.VXPermMap) ArrayList(java.util.ArrayList) VXPermObj(org.apache.ranger.view.VXPermObj) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) XXGroup(org.apache.ranger.entity.XXGroup) Random(java.util.Random) XXPermMap(org.apache.ranger.entity.XXPermMap)

Example 5 with VXPermMap

use of org.apache.ranger.view.VXPermMap in project ranger by apache.

the class XPolicyService method mapPermObjToPermList.

private List<VXPermMap> mapPermObjToPermList(List<VXPermObj> permObjList) {
    List<VXPermMap> permMapList = new ArrayList<VXPermMap>();
    Random rand = new Random();
    for (VXPermObj permObj : permObjList) {
        String ipAddress = permObj.getIpAddress();
        if (!stringUtil.isEmpty(permObj.getUserList())) {
            String permGrp = new Date() + " : " + rand.nextInt(9999);
            for (String user : permObj.getUserList()) {
                XXUser xxUser = xaDaoMgr.getXXUser().findByUserName(user);
                if (xxUser == null) {
                    logger.error("No User found with this name : " + user);
                    throw restErrorUtil.createRESTException("No User found with name : " + user, MessageEnums.DATA_NOT_FOUND);
                }
                for (String permission : permObj.getPermList()) {
                    VXPermMap vXPermMap = new VXPermMap();
                    int permType = AppConstants.getEnumFor_XAPermType(permission);
                    vXPermMap.setPermFor(AppConstants.XA_PERM_FOR_USER);
                    vXPermMap.setPermGroup(permGrp);
                    vXPermMap.setPermType(permType);
                    vXPermMap.setUserId(xxUser.getId());
                    vXPermMap.setIpAddress(ipAddress);
                    permMapList.add(vXPermMap);
                }
            }
        }
        if (!stringUtil.isEmpty(permObj.getGroupList())) {
            String permGrp = new Date() + " : " + rand.nextInt(9999);
            for (String group : permObj.getGroupList()) {
                XXGroup xxGroup = xaDaoMgr.getXXGroup().findByGroupName(group);
                if (xxGroup == null) {
                    logger.error("No UserGroup found with this name : " + group);
                    throw restErrorUtil.createRESTException("No User found with name : " + group, MessageEnums.DATA_NOT_FOUND);
                }
                for (String permission : permObj.getPermList()) {
                    VXPermMap vXPermMap = new VXPermMap();
                    int permType = AppConstants.getEnumFor_XAPermType(permission);
                    vXPermMap.setPermFor(AppConstants.XA_PERM_FOR_GROUP);
                    vXPermMap.setPermGroup(permGrp);
                    vXPermMap.setPermType(permType);
                    vXPermMap.setGroupId(xxGroup.getId());
                    vXPermMap.setIpAddress(ipAddress);
                    permMapList.add(vXPermMap);
                }
            }
        }
    }
    return permMapList;
}
Also used : XXUser(org.apache.ranger.entity.XXUser) VXPermMap(org.apache.ranger.view.VXPermMap) XXGroup(org.apache.ranger.entity.XXGroup) Random(java.util.Random) ArrayList(java.util.ArrayList) VXPermObj(org.apache.ranger.view.VXPermObj) Date(java.util.Date)

Aggregations

VXPermMap (org.apache.ranger.view.VXPermMap)25 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)10 HashMap (java.util.HashMap)7 List (java.util.List)6 VXResource (org.apache.ranger.view.VXResource)6 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)5 VXPermMapList (org.apache.ranger.view.VXPermMapList)5 VXPermObj (org.apache.ranger.view.VXPermObj)5 VXPolicyList (org.apache.ranger.view.VXPolicyList)5 Date (java.util.Date)4 SearchCriteria (org.apache.ranger.common.SearchCriteria)4 VXAuditMap (org.apache.ranger.view.VXAuditMap)4 LinkedHashMap (java.util.LinkedHashMap)3 Random (java.util.Random)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 RangerPolicyItemAccess (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemAccess)3 VXAuditMapList (org.apache.ranger.view.VXAuditMapList)3 VXResourceList (org.apache.ranger.view.VXResourceList)3 Map (java.util.Map)2