Search in sources :

Example 6 with RangerBaseService

use of org.apache.ranger.plugin.service.RangerBaseService in project ranger by apache.

the class ServiceMgr method lookupResource.

public List<String> lookupResource(String serviceName, ResourceLookupContext context, ServiceStore svcStore) throws Exception {
    List<String> ret = null;
    rangerBizUtil.blockAuditorRoleUser();
    RangerService service = svcDBStore.getServiceByName(serviceName);
    String authType = PropertiesUtil.getProperty(AUTHENTICATION_TYPE);
    String lookupPrincipal = SecureClientLogin.getPrincipal(PropertiesUtil.getProperty(LOOKUP_PRINCIPAL), PropertiesUtil.getProperty(HOST_NAME));
    String lookupKeytab = PropertiesUtil.getProperty(LOOKUP_KEYTAB);
    String nameRules = PropertiesUtil.getProperty(NAME_RULES);
    String rangerPrincipal = SecureClientLogin.getPrincipal(PropertiesUtil.getProperty(ADMIN_USER_PRINCIPAL), PropertiesUtil.getProperty(HOST_NAME));
    String rangerkeytab = PropertiesUtil.getProperty(ADMIN_USER_KEYTAB);
    if (!StringUtils.isEmpty(authType) && KERBEROS_TYPE.equalsIgnoreCase(authType.trim()) && SecureClientLogin.isKerberosCredentialExists(lookupPrincipal, lookupKeytab)) {
        if (service != null && service.getConfigs() != null) {
            service.getConfigs().put(HadoopConfigHolder.RANGER_LOOKUP_PRINCIPAL, lookupPrincipal);
            service.getConfigs().put(HadoopConfigHolder.RANGER_LOOKUP_KEYTAB, lookupKeytab);
            service.getConfigs().put(HadoopConfigHolder.RANGER_NAME_RULES, nameRules);
            service.getConfigs().put(HadoopConfigHolder.RANGER_AUTH_TYPE, authType);
        }
    }
    if (!StringUtils.isEmpty(authType) && KERBEROS_TYPE.equalsIgnoreCase(authType.trim()) && SecureClientLogin.isKerberosCredentialExists(rangerPrincipal, rangerkeytab)) {
        if (service != null && service.getConfigs() != null) {
            service.getConfigs().put(HadoopConfigHolder.RANGER_PRINCIPAL, rangerPrincipal);
            service.getConfigs().put(HadoopConfigHolder.RANGER_KEYTAB, rangerkeytab);
            service.getConfigs().put(HadoopConfigHolder.RANGER_NAME_RULES, nameRules);
            service.getConfigs().put(HadoopConfigHolder.RANGER_AUTH_TYPE, authType);
        }
    }
    Map<String, String> newConfigs = rangerSvcService.getConfigsWithDecryptedPassword(service);
    service.setConfigs(newConfigs);
    RangerBaseService svc = getRangerServiceByService(service, svcStore);
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> ServiceMgr.lookupResource for Service: (" + svc + "Context: " + context + ")");
    }
    if (svc != null) {
        if (StringUtils.equals(svc.getServiceDef().getName(), EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_TAG_NAME)) {
            ret = svc.lookupResource(context);
        } else {
            LookupCallable callable = new LookupCallable(svc, context);
            long time = getTimeoutValueForLookupInMilliSeconds(svc);
            ret = timedExecutor.timedTask(callable, time, TimeUnit.MILLISECONDS);
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> ServiceMgr.lookupResource for Response: (" + ret + ")");
    }
    return ret;
}
Also used : RangerBaseService(org.apache.ranger.plugin.service.RangerBaseService) RangerService(org.apache.ranger.plugin.model.RangerService)

Aggregations

RangerBaseService (org.apache.ranger.plugin.service.RangerBaseService)6 HadoopException (org.apache.ranger.plugin.client.HadoopException)2 RangerService (org.apache.ranger.plugin.model.RangerService)2 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 HashMap (java.util.HashMap)1 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)1 RangerPolicyItem (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem)1 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)1 RangerServiceTag (org.apache.ranger.services.tag.RangerServiceTag)1 VXResponse (org.apache.ranger.view.VXResponse)1 VXString (org.apache.ranger.view.VXString)1