Java Code Examples for org.apache.ranger.plugin.util.ServicePolicies#setServiceConfig()
The following examples show how to use
org.apache.ranger.plugin.util.ServicePolicies#setServiceConfig() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServiceREST.java From ranger with Apache License 2.0 | 4 votes |
@GET @Path("/policies/download/{serviceName}") @Produces({ "application/json", "application/xml" }) public ServicePolicies getServicePoliciesIfUpdated( @PathParam("serviceName") String serviceName, @QueryParam("lastKnownVersion") Long lastKnownVersion, @DefaultValue("0") @QueryParam("lastActivationTime") Long lastActivationTime, @QueryParam("pluginId") String pluginId, @DefaultValue("") @QueryParam("clusterName") String clusterName, @DefaultValue("") @QueryParam("zoneName") String zoneName, @DefaultValue("false") @QueryParam("supportsPolicyDeltas") Boolean supportsPolicyDeltas, @DefaultValue("") @QueryParam("pluginCapabilities") String pluginCapabilities, @Context HttpServletRequest request) throws Exception { if (LOG.isDebugEnabled()) { LOG.debug("==> ServiceREST.getServicePoliciesIfUpdated(" + serviceName + ", " + lastKnownVersion + ", " + lastActivationTime + ", " + pluginId + ", " + clusterName + ", " + supportsPolicyDeltas + ")"); } ServicePolicies ret = null; int httpCode = HttpServletResponse.SC_OK; String logMsg = null; RangerPerfTracer perf = null; Long downloadedVersion = null; boolean isValid = false; try { bizUtil.failUnauthenticatedIfNotAllowed(); isValid = serviceUtil.isValidateHttpsAuthentication(serviceName, request); } catch (WebApplicationException webException) { httpCode = webException.getResponse().getStatus(); logMsg = webException.getResponse().getEntity().toString(); } catch (Exception e) { httpCode = HttpServletResponse.SC_BAD_REQUEST; logMsg = e.getMessage(); } if (isValid) { if (lastKnownVersion == null) { lastKnownVersion = Long.valueOf(-1); } try { if(RangerPerfTracer.isPerfTraceEnabled(PERF_LOG)) { perf = RangerPerfTracer.getPerfTracer(PERF_LOG, "ServiceREST.getServicePoliciesIfUpdated(serviceName=" + serviceName + ",lastKnownVersion=" + lastKnownVersion + ",lastActivationTime=" + lastActivationTime + ")"); } ServicePolicies servicePolicies = svcStore.getServicePoliciesIfUpdated(serviceName, lastKnownVersion, !supportsPolicyDeltas); if (servicePolicies == null) { downloadedVersion = lastKnownVersion; httpCode = HttpServletResponse.SC_NOT_MODIFIED; logMsg = "No change since last update"; } else { Map<String, RangerSecurityZone.RangerSecurityZoneService> securityZones = zoneStore.getSecurityZonesForService(serviceName); ServicePolicies updatedServicePolicies = servicePolicies; if (MapUtils.isNotEmpty(securityZones)) { updatedServicePolicies = RangerPolicyAdminCache.getUpdatedServicePoliciesForZones(servicePolicies, securityZones); patchAssociatedTagServiceInSecurityZoneInfos(updatedServicePolicies); } downloadedVersion = updatedServicePolicies.getPolicyVersion(); if (lastKnownVersion == -1L || !supportsPolicyDeltas) { ret = filterServicePolicies(updatedServicePolicies); } else { ret = updatedServicePolicies; } ret.setServiceConfig(svcStore.getServiceConfigForPlugin(ret.getServiceId())); httpCode = HttpServletResponse.SC_OK; logMsg = "Returning " + (ret.getPolicies() != null ? ret.getPolicies().size() : (ret.getPolicyDeltas() != null ? ret.getPolicyDeltas().size() : 0)) + " policies. Policy version=" + ret.getPolicyVersion(); } } catch (Throwable excp) { LOG.error("getServicePoliciesIfUpdated(" + serviceName + ", " + lastKnownVersion + ", " + lastActivationTime + ") failed", excp); httpCode = HttpServletResponse.SC_BAD_REQUEST; logMsg = excp.getMessage(); } finally { createPolicyDownloadAudit(serviceName, lastKnownVersion, pluginId, httpCode, clusterName, zoneName, request); RangerPerfTracer.log(perf); } } assetMgr.createPluginInfo(serviceName, pluginId, request, RangerPluginInfo.ENTITY_TYPE_POLICIES, downloadedVersion, lastKnownVersion, lastActivationTime, httpCode, clusterName, pluginCapabilities); if(httpCode != HttpServletResponse.SC_OK) { boolean logError = httpCode != HttpServletResponse.SC_NOT_MODIFIED; throw restErrorUtil.createRESTException(httpCode, logMsg, logError); } if(LOG.isDebugEnabled()) { LOG.debug("<== ServiceREST.getServicePoliciesIfUpdated(" + serviceName + ", " + lastKnownVersion + ", " + lastActivationTime + ", " + pluginId + ", " + clusterName + ", " + supportsPolicyDeltas + "): count=" + ((ret == null || ret.getPolicies() == null) ? 0 : ret.getPolicies().size())); } return ret; }