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;
}
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;
}
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;
}
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.");
}
}
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.");
}
}
Aggregations