Search in sources :

Example 6 with RangerContextEnricher

use of org.apache.ranger.plugin.contextenricher.RangerContextEnricher in project ranger by apache.

the class RangerPolicyRepository method buildContextEnricher.

private RangerContextEnricher buildContextEnricher(RangerServiceDef.RangerContextEnricherDef enricherDef) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> RangerPolicyRepository.buildContextEnricher(" + enricherDef + ")");
    }
    RangerContextEnricher ret = null;
    RangerPerfTracer perf = null;
    if (RangerPerfTracer.isPerfTraceEnabled(PERF_CONTEXTENRICHER_INIT_LOG)) {
        perf = RangerPerfTracer.getPerfTracer(PERF_CONTEXTENRICHER_INIT_LOG, "RangerContextEnricher.init(appId=" + appId + ",name=" + enricherDef.getName() + ")");
    }
    String name = enricherDef != null ? enricherDef.getName() : null;
    String clsName = enricherDef != null ? enricherDef.getEnricher() : null;
    if (!StringUtils.isEmpty(clsName)) {
        try {
            @SuppressWarnings("unchecked") Class<RangerContextEnricher> enricherClass = (Class<RangerContextEnricher>) Class.forName(clsName);
            ret = enricherClass.newInstance();
        } catch (Exception excp) {
            LOG.error("failed to instantiate context enricher '" + clsName + "' for '" + name + "'", excp);
        }
    }
    if (ret != null) {
        ret.setEnricherDef(enricherDef);
        ret.setServiceName(componentServiceName);
        ret.setServiceDef(componentServiceDef);
        ret.setAppId(appId);
        ret.init();
    }
    RangerPerfTracer.log(perf);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== RangerPolicyRepository.buildContextEnricher(" + enricherDef + "): " + ret);
    }
    return ret;
}
Also used : RangerContextEnricher(org.apache.ranger.plugin.contextenricher.RangerContextEnricher) RangerPerfTracer(org.apache.ranger.plugin.util.RangerPerfTracer)

Aggregations

RangerContextEnricher (org.apache.ranger.plugin.contextenricher.RangerContextEnricher)6 RangerPerfTracer (org.apache.ranger.plugin.util.RangerPerfTracer)3 RangerPolicyEvaluator (org.apache.ranger.plugin.policyevaluator.RangerPolicyEvaluator)2 ArrayList (java.util.ArrayList)1 RangerTagEnricher (org.apache.ranger.plugin.contextenricher.RangerTagEnricher)1 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)1 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)1 RangerServiceDefHelper (org.apache.ranger.plugin.model.validation.RangerServiceDefHelper)1