use of org.apache.ranger.plugin.util.SearchFilter 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;
}
use of org.apache.ranger.plugin.util.SearchFilter 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;
}
use of org.apache.ranger.plugin.util.SearchFilter in project ranger by apache.
the class PublicAPIsv2 method getPolicyByName.
@GET
@Path("/api/service/{servicename}/policy/{policyname}")
@Produces({ "application/json", "application/xml" })
public RangerPolicy getPolicyByName(@PathParam("servicename") String serviceName, @PathParam("policyname") String policyName, @Context HttpServletRequest request) {
if (logger.isDebugEnabled()) {
logger.debug("==> PublicAPIsv2.getPolicyByName(" + serviceName + "," + policyName + ")");
}
SearchFilter filter = new SearchFilter();
filter.setParam(SearchFilter.SERVICE_NAME, serviceName);
filter.setParam(SearchFilter.POLICY_NAME, policyName);
List<RangerPolicy> policies = serviceREST.getPolicies(filter);
if (policies.size() != 1) {
throw restErrorUtil.createRESTException(HttpServletResponse.SC_NOT_FOUND, "Not found", true);
}
RangerPolicy policy = policies.get(0);
if (logger.isDebugEnabled()) {
logger.debug("<== PublicAPIsv2.getPolicyByName(" + serviceName + "," + policyName + ")" + policy);
}
return policy;
}
use of org.apache.ranger.plugin.util.SearchFilter in project ranger by apache.
the class ServiceREST method getPolicyByGuid.
private RangerPolicy getPolicyByGuid(String guid) {
RangerPolicy ret = null;
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceREST.getPolicyByGuid(" + guid + ")");
}
SearchFilter filter = new SearchFilter();
filter.setParam(SearchFilter.GUID, guid);
List<RangerPolicy> policies = getPolicies(filter);
if (CollectionUtils.isNotEmpty(policies)) {
ret = policies.get(0);
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== ServiceREST.getPolicyByGuid(" + guid + ")" + ret);
}
return ret;
}
use of org.apache.ranger.plugin.util.SearchFilter in project ranger by apache.
the class ServiceREST method getPoliciesInJson.
@GET
@Path("/policies/exportJson")
@Produces("text/json")
public void getPoliciesInJson(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam("checkPoliciesExists") Boolean checkPoliciesExists) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceREST.getPoliciesInJson()");
}
RangerPerfTracer perf = null;
SearchFilter filter = searchUtil.getSearchFilter(request, policyService.sortFields);
try {
if (RangerPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = RangerPerfTracer.getPerfTracer(PERF_LOG, "ServiceREST.getPoliciesInJson()");
}
if (checkPoliciesExists == null) {
checkPoliciesExists = false;
}
List<RangerPolicy> policyLists = new ArrayList<RangerPolicy>();
policyLists = getAllFilteredPolicyList(filter, request, policyLists);
if (CollectionUtils.isNotEmpty(policyLists)) {
for (RangerPolicy rangerPolicy : policyLists) {
if (rangerPolicy != null) {
ensureAdminAndAuditAccess(rangerPolicy);
}
}
bizUtil.blockAuditorRoleUser();
svcStore.getPoliciesInJson(policyLists, response);
} else {
checkPoliciesExists = true;
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
LOG.error("There is no Policy to Export!!");
}
if (!checkPoliciesExists) {
RangerExportPolicyList rangerExportPolicyList = new RangerExportPolicyList();
svcStore.putMetaDataInfo(rangerExportPolicyList);
String metaDataInfo = new ObjectMapper().writeValueAsString(rangerExportPolicyList.getMetaDataInfo());
List<XXTrxLog> trxLogList = new ArrayList<XXTrxLog>();
XXTrxLog xxTrxLog = new XXTrxLog();
xxTrxLog.setAction("EXPORT JSON");
xxTrxLog.setObjectClassType(AppConstants.CLASS_TYPE_RANGER_POLICY);
xxTrxLog.setPreviousValue(metaDataInfo);
trxLogList.add(xxTrxLog);
bizUtil.createTrxLog(trxLogList);
}
} catch (WebApplicationException excp) {
throw excp;
} catch (Throwable excp) {
LOG.error("Error while exporting policy file!!", excp);
throw restErrorUtil.createRESTException(excp.getMessage());
} finally {
RangerPerfTracer.log(perf);
}
}
Aggregations