Search in sources :

Example 16 with VXPolicy

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

the class ServiceUtil method toVXPolicy.

public VXPolicy toVXPolicy(RangerPolicy policy, RangerService service) {
    if (policy == null || service == null || toAssetType(service.getType()) == null) {
        return null;
    }
    VXPolicy ret = new VXPolicy();
    rangerObjectToDataObject(policy, ret);
    ret.setPolicyName(StringUtils.trim(policy.getName()));
    ret.setDescription(policy.getDescription());
    ret.setRepositoryName(policy.getService());
    ret.setIsEnabled(policy.getIsEnabled() ? true : false);
    ret.setRepositoryType(service.getType());
    ret.setIsAuditEnabled(policy.getIsAuditEnabled());
    if (policy.getVersion() != null) {
        ret.setVersion(policy.getVersion().toString());
    } else {
        ret.setVersion(version);
    }
    for (Map.Entry<String, RangerPolicy.RangerPolicyResource> e : policy.getResources().entrySet()) {
        RangerPolicy.RangerPolicyResource res = e.getValue();
        String resType = e.getKey();
        String resString = getResourceString(res.getValues());
        if ("path".equalsIgnoreCase(resType)) {
            ret.setResourceName(resString);
            ret.setIsRecursive(Boolean.TRUE.equals(res.getIsRecursive()) ? true : false);
        } else if ("table".equalsIgnoreCase(resType)) {
            ret.setTables(resString);
            ret.setTableType(Boolean.TRUE.equals(res.getIsExcludes()) ? toVxPolicyIncExc(RangerCommonEnums.POLICY_EXCLUSION) : toVxPolicyIncExc(RangerCommonEnums.POLICY_INCLUSION));
        } else if ("column-family".equalsIgnoreCase(resType)) {
            ret.setColumnFamilies(resString);
        } else if ("column".equalsIgnoreCase(resType)) {
            ret.setColumns(resString);
            ret.setColumnType(Boolean.TRUE.equals(res.getIsExcludes()) ? toVxPolicyIncExc(RangerCommonEnums.POLICY_EXCLUSION) : toVxPolicyIncExc(RangerCommonEnums.POLICY_INCLUSION));
        } else if ("database".equalsIgnoreCase(resType)) {
            ret.setDatabases(resString);
        } else if ("udf".equalsIgnoreCase(resType)) {
            ret.setUdfs(resString);
        } else if ("topology".equalsIgnoreCase(resType)) {
            ret.setTopologies(resString);
        } else if ("service".equalsIgnoreCase(resType)) {
            ret.setServices(resString);
        }
    }
    updateResourceName(ret);
    List<VXPermMap> vXPermMapList = getVXPermMapList(policy);
    List<VXPermObj> vXPermObjList = mapPermMapToPermObj(vXPermMapList);
    ret.setPermMapList(vXPermObjList);
    return ret;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) VXPermMap(org.apache.ranger.view.VXPermMap) VXPolicy(org.apache.ranger.view.VXPolicy) VXPermObj(org.apache.ranger.view.VXPermObj) VXAuditMap(org.apache.ranger.view.VXAuditMap) VXPermMap(org.apache.ranger.view.VXPermMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

VXPolicy (org.apache.ranger.view.VXPolicy)16 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)11 RangerService (org.apache.ranger.plugin.model.RangerService)10 Test (org.junit.Test)9 WebApplicationException (javax.ws.rs.WebApplicationException)5 ArrayList (java.util.ArrayList)4 GrantRevokeRequest (org.apache.ranger.plugin.util.GrantRevokeRequest)4 VXPolicyList (org.apache.ranger.view.VXPolicyList)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 RESTResponse (org.apache.ranger.admin.client.datatype.RESTResponse)2 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)2 VXPermObj (org.apache.ranger.view.VXPermObj)2 VXResource (org.apache.ranger.view.VXResource)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 InvalidNameException (javax.naming.InvalidNameException)1 XXPolicyDao (org.apache.ranger.db.XXPolicyDao)1 XXPolicy (org.apache.ranger.entity.XXPolicy)1 RangerServiceNotFoundException (org.apache.ranger.plugin.util.RangerServiceNotFoundException)1 VXAuditMap (org.apache.ranger.view.VXAuditMap)1