Search in sources :

Example 56 with RangerService

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

the class AssetREST method createXAsset.

@POST
@Path("/assets")
@Produces({ "application/xml", "application/json" })
@PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.CREATE_X_ASSET + "\")")
public VXAsset createXAsset(VXAsset vXAsset) {
    if (logger.isDebugEnabled()) {
        logger.debug("==> AssetREST.createXAsset(" + vXAsset + ")");
    }
    RangerService service = serviceUtil.toRangerService(vXAsset);
    RangerService createdService = serviceREST.createService(service);
    VXAsset ret = serviceUtil.toVXAsset(createdService);
    if (logger.isDebugEnabled()) {
        logger.debug("<== AssetREST.createXAsset(" + vXAsset + "): " + ret);
    }
    return ret;
}
Also used : RangerService(org.apache.ranger.plugin.model.RangerService) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 57 with RangerService

use of org.apache.ranger.plugin.model.RangerService 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 58 with RangerService

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

the class PublicAPIs method searchRepositories.

@GET
@Path("/api/repository/")
@Produces({ "application/json", "application/xml" })
public VXRepositoryList searchRepositories(@Context HttpServletRequest request) {
    if (logger.isDebugEnabled()) {
        logger.debug("==> PublicAPIs.searchRepositories()");
    }
    SearchFilter filter = searchUtil.getSearchFilterFromLegacyRequestForRepositorySearch(request, xAssetService.sortFields);
    List<RangerService> serviceList = serviceREST.getServices(filter);
    VXRepositoryList ret = null;
    if (serviceList != null) {
        ret = serviceUtil.rangerServiceListToPublicObjectList(serviceList);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("<== PublicAPIs.searchRepositories(): count=" + (ret == null ? 0 : ret.getListSize()));
    }
    return ret;
}
Also used : SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService)

Example 59 with RangerService

use of org.apache.ranger.plugin.model.RangerService 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 60 with RangerService

use of org.apache.ranger.plugin.model.RangerService 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)

Aggregations

RangerService (org.apache.ranger.plugin.model.RangerService)163 Test (org.junit.Test)85 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)52 ArrayList (java.util.ArrayList)39 WebApplicationException (javax.ws.rs.WebApplicationException)30 XXServiceDef (org.apache.ranger.entity.XXServiceDef)26 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)24 VXString (org.apache.ranger.view.VXString)24 XXService (org.apache.ranger.entity.XXService)23 Path (javax.ws.rs.Path)22 Produces (javax.ws.rs.Produces)21 Date (java.util.Date)20 HashMap (java.util.HashMap)16 XXServiceDefDao (org.apache.ranger.db.XXServiceDefDao)16 HttpServletRequest (javax.servlet.http.HttpServletRequest)15 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)14 IOException (java.io.IOException)12 GET (javax.ws.rs.GET)12 XXTrxLog (org.apache.ranger.entity.XXTrxLog)12 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)12