Search in sources :

Example 96 with RangerService

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

the class AssetREST method updateXAsset.

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

Example 97 with RangerService

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

the class AssetREST method getResourceJSON.

@GET
@Path("/policyList/{repository}")
@Encoded
public String getResourceJSON(@Context HttpServletRequest request, @PathParam("repository") String repository) {
    String epoch = request.getParameter("epoch");
    X509Certificate[] certchain = (X509Certificate[]) request.getAttribute("javax.servlet.request.X509Certificate");
    String ipAddress = request.getHeader("X-FORWARDED-FOR");
    boolean isSecure = request.isSecure();
    String policyCount = request.getParameter("policyCount");
    String agentId = request.getParameter("agentId");
    Long lastKnowPolicyVersion = Long.valueOf(-1);
    if (ipAddress == null) {
        ipAddress = request.getRemoteAddr();
    }
    boolean httpEnabled = PropertiesUtil.getBooleanProperty("ranger.service.http.enabled", true);
    ServicePolicies servicePolicies = null;
    try {
        servicePolicies = serviceREST.getServicePoliciesIfUpdated(repository, lastKnowPolicyVersion, 0L, agentId, "", request);
    } catch (Exception excp) {
        logger.error("failed to retrieve policies for repository " + repository, excp);
    }
    RangerService service = serviceUtil.getServiceByName(repository);
    List<RangerPolicy> policies = servicePolicies != null ? servicePolicies.getPolicies() : null;
    long policyUpdTime = (servicePolicies != null && servicePolicies.getPolicyUpdateTime() != null) ? servicePolicies.getPolicyUpdateTime().getTime() : 0l;
    VXAsset vAsset = serviceUtil.toVXAsset(service);
    List<VXResource> vResourceList = new ArrayList<VXResource>();
    if (policies != null) {
        for (RangerPolicy policy : policies) {
            vResourceList.add(serviceUtil.toVXResource(policy, service));
        }
    }
    String file = assetMgr.getLatestRepoPolicy(vAsset, vResourceList, policyUpdTime, certchain, httpEnabled, epoch, ipAddress, isSecure, policyCount, agentId);
    return file;
}
Also used : ServicePolicies(org.apache.ranger.plugin.util.ServicePolicies) ArrayList(java.util.ArrayList) X509Certificate(java.security.cert.X509Certificate) WebApplicationException(javax.ws.rs.WebApplicationException) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerService(org.apache.ranger.plugin.model.RangerService) Path(javax.ws.rs.Path) Encoded(javax.ws.rs.Encoded) GET(javax.ws.rs.GET)

Example 98 with RangerService

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

the class AssetREST method updateXResource.

@PUT
@Path("/resources/{id}")
@Produces({ "application/xml", "application/json" })
public VXResource updateXResource(VXResource vXResource) {
    if (logger.isDebugEnabled()) {
        logger.debug("==> AssetREST.updateXResource(" + vXResource + ")");
    }
    RangerService service = serviceREST.getService(vXResource.getAssetId());
    RangerPolicy policy = serviceUtil.toRangerPolicy(vXResource, service);
    RangerPolicy updatedPolicy = serviceREST.updatePolicy(policy);
    VXResource ret = serviceUtil.toVXResource(updatedPolicy, service);
    if (logger.isDebugEnabled()) {
        logger.debug("<== AssetREST.updateXResource(" + 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) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 99 with RangerService

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

the class AssetREST method searchXAssets.

@GET
@Path("/assets")
@Produces({ "application/xml", "application/json" })
@PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.SEARCH_X_ASSETS + "\")")
public VXAssetList searchXAssets(@Context HttpServletRequest request) {
    if (logger.isDebugEnabled()) {
        logger.debug("==> AssetREST.searchXAssets()");
    }
    VXAssetList ret = new VXAssetList();
    SearchFilter filter = searchUtil.getSearchFilterFromLegacyRequestForRepositorySearch(request, xAssetService.sortFields);
    List<RangerService> services = serviceREST.getServices(filter);
    if (services != null) {
        List<VXAsset> assets = new ArrayList<VXAsset>();
        for (RangerService service : services) {
            VXAsset asset = serviceUtil.toVXAsset(service);
            if (asset != null) {
                assets.add(asset);
            }
        }
        ret.setVXAssets(assets);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("<== AssetREST.searchXAssets(): count=" + ret.getListSize());
    }
    return ret;
}
Also used : ArrayList(java.util.ArrayList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 100 with RangerService

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

the class PublicAPIs method updateRepository.

@PUT
@Path("/api/repository/{id}")
@Produces({ "application/json", "application/xml" })
public VXRepository updateRepository(VXRepository vXRepository, @PathParam("id") Long id) {
    if (logger.isDebugEnabled()) {
        logger.debug("==> PublicAPIs.updateRepository(" + id + ")");
    }
    XXService existing = daoMgr.getXXService().getById(id);
    if (existing == null) {
        throw restErrorUtil.createRESTException("Repository not found for Id: " + id, MessageEnums.DATA_NOT_FOUND);
    }
    vXRepository.setId(id);
    VXAsset vXAsset = serviceUtil.publicObjecttoVXAsset(vXRepository);
    RangerService service = serviceUtil.toRangerService(vXAsset);
    service.setVersion(existing.getVersion());
    RangerService updatedService = serviceREST.updateService(service, null);
    VXAsset retvXAsset = serviceUtil.toVXAsset(updatedService);
    VXRepository ret = serviceUtil.vXAssetToPublicObject(retvXAsset);
    if (logger.isDebugEnabled()) {
        logger.debug("<== PublicAPIs.updateRepository(" + ret + ")");
    }
    return ret;
}
Also used : RangerService(org.apache.ranger.plugin.model.RangerService) XXService(org.apache.ranger.entity.XXService)

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