Search in sources :

Example 46 with RangerPolicy

use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.

the class AssetREST method createXResource.

@POST
@Path("/resources")
@Produces({ "application/xml", "application/json" })
public VXResource createXResource(VXResource vXResource) {
    if (logger.isDebugEnabled()) {
        logger.debug("==> AssetREST.createXResource(" + vXResource + ")");
    }
    RangerService service = serviceREST.getService(vXResource.getAssetId());
    RangerPolicy policy = serviceUtil.toRangerPolicy(vXResource, service);
    RangerPolicy createdPolicy = serviceREST.createPolicy(policy, null);
    VXResource ret = serviceUtil.toVXResource(createdPolicy, service);
    if (logger.isDebugEnabled()) {
        logger.debug("<== AssetREST.createXResource(" + vXResource + "): " + ret);
    }
    return ret;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerService(org.apache.ranger.plugin.model.RangerService) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 47 with RangerPolicy

use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.

the class PublicAPIs method getPolicy.

@GET
@Path("/api/policy/{id}")
@Produces({ "application/json", "application/xml" })
public VXPolicy getPolicy(@PathParam("id") Long id) {
    if (logger.isDebugEnabled()) {
        logger.debug("==> PublicAPIs.getPolicy() " + id);
    }
    RangerPolicy policy = null;
    RangerService service = null;
    policy = serviceREST.getPolicy(id);
    if (policy != null) {
        service = serviceREST.getServiceByName(policy.getService());
    }
    VXPolicy ret = serviceUtil.toVXPolicy(policy, service);
    if (logger.isDebugEnabled()) {
        logger.debug("<== PublicAPIs.getPolicy()" + ret);
    }
    return ret;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerService(org.apache.ranger.plugin.model.RangerService)

Example 48 with RangerPolicy

use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.

the class PublicAPIs method createPolicy.

@POST
@Path("/api/policy")
@Produces({ "application/json", "application/xml" })
public VXPolicy createPolicy(VXPolicy vXPolicy) {
    if (logger.isDebugEnabled()) {
        logger.debug("==> PublicAPIs.createPolicy()");
    }
    RangerService service = serviceREST.getServiceByName(vXPolicy.getRepositoryName());
    RangerPolicy policy = serviceUtil.toRangerPolicy(vXPolicy, service);
    VXPolicy ret = null;
    if (policy != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("RANGERPOLICY: " + policy.toString());
        }
        RangerPolicy createdPolicy = serviceREST.createPolicy(policy, null);
        ret = serviceUtil.toVXPolicy(createdPolicy, service);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("<== PublicAPIs.createPolicy(" + policy + "): " + ret);
    }
    return ret;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerService(org.apache.ranger.plugin.model.RangerService)

Example 49 with RangerPolicy

use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.

the class PublicAPIs method updatePolicy.

@PUT
@Path("/api/policy/{id}")
@Produces({ "application/json", "application/xml" })
public VXPolicy updatePolicy(VXPolicy vXPolicy, @PathParam("id") Long id) {
    if (logger.isDebugEnabled()) {
        logger.debug("==> PublicAPIs.updatePolicy(): " + vXPolicy);
    }
    XXPolicy existing = daoMgr.getXXPolicy().getById(id);
    if (existing == null) {
        throw restErrorUtil.createRESTException("Policy not found for Id: " + id, MessageEnums.DATA_NOT_FOUND);
    }
    vXPolicy.setId(id);
    RangerService service = serviceREST.getServiceByName(vXPolicy.getRepositoryName());
    RangerPolicy policy = serviceUtil.toRangerPolicy(vXPolicy, service);
    VXPolicy ret = null;
    if (policy != null) {
        policy.setVersion(existing.getVersion());
        RangerPolicy updatedPolicy = serviceREST.updatePolicy(policy);
        ret = serviceUtil.toVXPolicy(updatedPolicy, service);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("<== PublicAPIs.updatePolicy(" + policy + "): " + ret);
    }
    return ret;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerService(org.apache.ranger.plugin.model.RangerService) XXPolicy(org.apache.ranger.entity.XXPolicy)

Example 50 with RangerPolicy

use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.

the class PublicAPIs method searchPolicies.

@GET
@Path("/api/policy")
@Produces({ "application/json", "application/xml" })
public VXPolicyList searchPolicies(@Context HttpServletRequest request) {
    if (logger.isDebugEnabled()) {
        logger.debug("==> PublicAPIs.searchPolicies(): ");
    }
    SearchFilter filter = searchUtil.getSearchFilterFromLegacyRequest(request, policyService.sortFields);
    // get all policies from the store; pick the page to return after applying filter
    int savedStartIndex = filter.getStartIndex();
    int savedMaxRows = filter.getMaxRows();
    filter.setStartIndex(0);
    filter.setMaxRows(Integer.MAX_VALUE);
    List<RangerPolicy> rangerPolicyList = serviceREST.getPolicies(filter);
    filter.setStartIndex(savedStartIndex);
    filter.setMaxRows(savedMaxRows);
    VXPolicyList vXPolicyList = null;
    if (rangerPolicyList != null) {
        vXPolicyList = serviceUtil.rangerPolicyListToPublic(rangerPolicyList, filter);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("<== PublicAPIs.searchPolicies(): " + vXPolicyList);
    }
    return vXPolicyList;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) SearchFilter(org.apache.ranger.plugin.util.SearchFilter)

Aggregations

RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)196 ArrayList (java.util.ArrayList)78 Test (org.junit.Test)73 RangerService (org.apache.ranger.plugin.model.RangerService)52 VXString (org.apache.ranger.view.VXString)48 HashMap (java.util.HashMap)38 RangerPolicyItem (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem)36 RangerPolicyResource (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource)33 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)30 WebApplicationException (javax.ws.rs.WebApplicationException)29 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)27 RangerPolicyItemAccess (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemAccess)26 Path (javax.ws.rs.Path)23 Produces (javax.ws.rs.Produces)22 RangerPerfTracer (org.apache.ranger.plugin.util.RangerPerfTracer)20 Date (java.util.Date)19 IOException (java.io.IOException)18 XXService (org.apache.ranger.entity.XXService)18 ServicePolicies (org.apache.ranger.plugin.util.ServicePolicies)16 RangerPolicyList (org.apache.ranger.view.RangerPolicyList)15