Search in sources :

Example 1 with RangerDefaultResourceMatcher

use of org.apache.ranger.plugin.resourcematcher.RangerDefaultResourceMatcher in project ranger by apache.

the class RangerDefaultPolicyResourceMatcher method createResourceMatcher.

private static RangerResourceMatcher createResourceMatcher(RangerResourceDef resourceDef, RangerPolicyResource resource) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> RangerDefaultPolicyResourceMatcher.createResourceMatcher(" + resourceDef + ", " + resource + ")");
    }
    RangerResourceMatcher ret = null;
    if (resourceDef != null) {
        String resName = resourceDef.getName();
        String clsName = resourceDef.getMatcher();
        if (!StringUtils.isEmpty(clsName)) {
            try {
                @SuppressWarnings("unchecked") Class<RangerResourceMatcher> matcherClass = (Class<RangerResourceMatcher>) Class.forName(clsName);
                ret = matcherClass.newInstance();
            } catch (Exception excp) {
                LOG.error("failed to instantiate resource matcher '" + clsName + "' for '" + resName + "'. Default resource matcher will be used", excp);
            }
        }
        if (ret == null) {
            ret = new RangerDefaultResourceMatcher();
        }
        ret.setResourceDef(resourceDef);
        ret.setPolicyResource(resource);
        ret.init();
    } else {
        LOG.error("RangerDefaultPolicyResourceMatcher: RangerResourceDef is null");
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== RangerDefaultPolicyResourceMatcher.createResourceMatcher(" + resourceDef + ", " + resource + "): " + ret);
    }
    return ret;
}
Also used : RangerResourceMatcher(org.apache.ranger.plugin.resourcematcher.RangerResourceMatcher) RangerDefaultResourceMatcher(org.apache.ranger.plugin.resourcematcher.RangerDefaultResourceMatcher)

Aggregations

RangerDefaultResourceMatcher (org.apache.ranger.plugin.resourcematcher.RangerDefaultResourceMatcher)1 RangerResourceMatcher (org.apache.ranger.plugin.resourcematcher.RangerResourceMatcher)1