Search in sources :

Example 1 with RangerPluginContext

use of org.apache.ranger.plugin.policyengine.RangerPluginContext in project ranger by apache.

the class RangerBasePlugin method getRangerRoleForPrincipal.

public Set<RangerRole> getRangerRoleForPrincipal(String principal, String type) {
    Set<RangerRole> ret = new HashSet<>();
    Set<RangerRole> rangerRoles = null;
    Map<String, Set<String>> roleMapping = null;
    RangerRoles roles = getRangerRoles();
    if (roles != null) {
        rangerRoles = roles.getRangerRoles();
    }
    if (rangerRoles != null) {
        RangerPluginContext rangerPluginContext = policyEngine.getPluginContext();
        if (rangerPluginContext != null) {
            RangerAuthContext rangerAuthContext = rangerPluginContext.getAuthContext();
            if (rangerAuthContext != null) {
                RangerRolesUtil rangerRolesUtil = rangerAuthContext.getRangerRolesUtil();
                if (rangerRolesUtil != null) {
                    switch(type) {
                        case "USER":
                            roleMapping = rangerRolesUtil.getUserRoleMapping();
                            break;
                        case "GROUP":
                            roleMapping = rangerRolesUtil.getGroupRoleMapping();
                            break;
                        case "ROLE":
                            roleMapping = rangerRolesUtil.getRoleRoleMapping();
                            break;
                    }
                }
            }
        }
        if (roleMapping != null) {
            Set<String> principalRoles = roleMapping.get(principal);
            if (CollectionUtils.isNotEmpty(principalRoles)) {
                for (String role : principalRoles) {
                    for (RangerRole rangerRole : rangerRoles) {
                        if (rangerRole.getName().equals(role)) {
                            ret.add(rangerRole);
                        }
                    }
                }
            }
        }
    }
    return ret;
}
Also used : RangerPluginContext(org.apache.ranger.plugin.policyengine.RangerPluginContext) RangerRole(org.apache.ranger.plugin.model.RangerRole)

Example 2 with RangerPluginContext

use of org.apache.ranger.plugin.policyengine.RangerPluginContext in project ranger by apache.

the class RangerAbstractContextEnricher method getBooleanConfig.

public boolean getBooleanConfig(String configName, boolean defaultValue) {
    RangerPluginContext pluginContext = this.pluginContext;
    boolean ret = defaultValue;
    Configuration config = pluginContext != null ? pluginContext.getConfig() : null;
    if (config != null) {
        ret = config.getBoolean(configName, defaultValue);
    }
    return ret;
}
Also used : RangerPluginContext(org.apache.ranger.plugin.policyengine.RangerPluginContext) Configuration(org.apache.hadoop.conf.Configuration)

Example 3 with RangerPluginContext

use of org.apache.ranger.plugin.policyengine.RangerPluginContext in project ranger by apache.

the class RangerAbstractContextEnricher method getIntConfig.

public int getIntConfig(String configName, int defaultValue) {
    RangerPluginContext pluginContext = this.pluginContext;
    int ret = defaultValue;
    Configuration config = pluginContext != null ? pluginContext.getConfig() : null;
    if (config != null) {
        ret = config.getInt(configName, defaultValue);
    }
    return ret;
}
Also used : RangerPluginContext(org.apache.ranger.plugin.policyengine.RangerPluginContext) Configuration(org.apache.hadoop.conf.Configuration)

Example 4 with RangerPluginContext

use of org.apache.ranger.plugin.policyengine.RangerPluginContext in project ranger by apache.

the class RangerAdminTagRetriever method init.

@Override
public void init(Map<String, String> options) {
    if (StringUtils.isNotBlank(serviceName) && serviceDef != null && StringUtils.isNotBlank(appId)) {
        RangerPluginConfig pluginConfig = super.pluginConfig;
        if (pluginConfig == null) {
            pluginConfig = new RangerPluginConfig(serviceDef.getName(), serviceName, appId, null, null, null);
        }
        RangerPluginContext pluginContext = getPluginContext();
        RangerAdminClient rangerAdmin = pluginContext.getAdminClient();
        this.adminClient = (rangerAdmin != null) ? rangerAdmin : pluginContext.createAdminClient(pluginConfig);
    } else {
        LOG.error("FATAL: Cannot find service/serviceDef to use for retrieving tags. Will NOT be able to retrieve tags.");
    }
}
Also used : RangerPluginConfig(org.apache.ranger.authorization.hadoop.config.RangerPluginConfig) RangerAdminClient(org.apache.ranger.admin.client.RangerAdminClient) RangerPluginContext(org.apache.ranger.plugin.policyengine.RangerPluginContext)

Example 5 with RangerPluginContext

use of org.apache.ranger.plugin.policyengine.RangerPluginContext in project ranger by apache.

the class RangerAdminUserStoreRetriever method init.

@Override
public void init(Map<String, String> options) {
    if (StringUtils.isNotBlank(serviceName) && serviceDef != null && StringUtils.isNotBlank(appId)) {
        RangerPluginConfig pluginConfig = super.pluginConfig;
        if (pluginConfig == null) {
            pluginConfig = new RangerPluginConfig(serviceDef.getName(), serviceName, appId, null, null, null);
        }
        RangerPluginContext pluginContext = getPluginContext();
        RangerAdminClient rangerAdmin = pluginContext.getAdminClient();
        this.adminClient = (rangerAdmin != null) ? rangerAdmin : pluginContext.createAdminClient(pluginConfig);
    } else {
        LOG.error("FATAL: Cannot find service/serviceDef to use for retrieving userstore. Will NOT be able to retrieve userstore.");
    }
}
Also used : RangerPluginConfig(org.apache.ranger.authorization.hadoop.config.RangerPluginConfig) RangerAdminClient(org.apache.ranger.admin.client.RangerAdminClient) RangerPluginContext(org.apache.ranger.plugin.policyengine.RangerPluginContext)

Aggregations

RangerPluginContext (org.apache.ranger.plugin.policyengine.RangerPluginContext)11 RangerPluginConfig (org.apache.ranger.authorization.hadoop.config.RangerPluginConfig)6 Configuration (org.apache.hadoop.conf.Configuration)3 RangerAdminClient (org.apache.ranger.admin.client.RangerAdminClient)2 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)2 RangerAccessRequest (org.apache.ranger.plugin.policyengine.RangerAccessRequest)2 RangerPolicyEngineImpl (org.apache.ranger.plugin.policyengine.RangerPolicyEngineImpl)2 RangerPolicyEngineOptions (org.apache.ranger.plugin.policyengine.RangerPolicyEngineOptions)2 ServicePolicies (org.apache.ranger.plugin.util.ServicePolicies)2 HashSet (java.util.HashSet)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TestData (org.apache.ranger.authorization.hbase.TestPolicyEngine.PolicyEngineTestCase.TestData)1 TestData (org.apache.ranger.biz.TestPolicyDb.PolicyDbTestCase.TestData)1 RangerDefaultAuditHandler (org.apache.ranger.plugin.audit.RangerDefaultAuditHandler)1 RangerRole (org.apache.ranger.plugin.model.RangerRole)1 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)1 RangerAccessResult (org.apache.ranger.plugin.policyengine.RangerAccessResult)1 RangerAccessResultProcessor (org.apache.ranger.plugin.policyengine.RangerAccessResultProcessor)1 RangerPolicyEngine (org.apache.ranger.plugin.policyengine.RangerPolicyEngine)1 Test (org.junit.Test)1