Search in sources :

Example 1 with IteratorEnumeration

use of org.apache.commons.collections.iterators.IteratorEnumeration in project head by mifos.

the class ModifiableParameterServletRequest method getParameterNames.

@Override
public Enumeration getParameterNames() {
    Enumeration parameterNames = getRequest().getParameterNames();
    List paramNames = new ArrayList();
    while (parameterNames.hasMoreElements()) {
        Object nextElement = parameterNames.nextElement();
        if (!removedParameterList.contains(nextElement)) {
            paramNames.add(nextElement);
        }
    }
    return new IteratorEnumeration(paramNames.iterator());
}
Also used : Enumeration(java.util.Enumeration) IteratorEnumeration(org.apache.commons.collections.iterators.IteratorEnumeration) IteratorEnumeration(org.apache.commons.collections.iterators.IteratorEnumeration) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with IteratorEnumeration

use of org.apache.commons.collections.iterators.IteratorEnumeration in project openhab1-addons by openhab.

the class JdbcConfiguration method setSqlTypes.

private void setSqlTypes() {
    @SuppressWarnings("unchecked") Enumeration<String> keys = new IteratorEnumeration(configuration.keySet().iterator());
    while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        Matcher matcher = EXTRACT_CONFIG_PATTERN.matcher(key);
        if (!matcher.matches()) {
            continue;
        }
        matcher.reset();
        matcher.find();
        if (!matcher.group(1).equals("sqltype")) {
            continue;
        }
        String itemType = matcher.group(2).toUpperCase() + "ITEM";
        String value = (String) configuration.get(key);
        logger.debug("JDBC::updateConfig: set sqlTypes: itemType={} value={}", itemType, value);
        dBDAO.sqlTypes.put(itemType, value);
    }
}
Also used : IteratorEnumeration(org.apache.commons.collections.iterators.IteratorEnumeration) Matcher(java.util.regex.Matcher)

Example 3 with IteratorEnumeration

use of org.apache.commons.collections.iterators.IteratorEnumeration in project lucene-solr by apache.

the class HadoopAuthPlugin method getInitFilterConfig.

@SuppressWarnings("unchecked")
protected FilterConfig getInitFilterConfig(Map<String, Object> pluginConfig) {
    Map<String, String> params = new HashMap<>();
    String type = (String) Objects.requireNonNull(pluginConfig.get(HADOOP_AUTH_TYPE));
    params.put(HADOOP_AUTH_TYPE, type);
    String sysPropPrefix = (String) pluginConfig.getOrDefault(SYSPROP_PREFIX_PROPERTY, "solr.");
    Collection<String> authConfigNames = (Collection<String>) pluginConfig.getOrDefault(AUTH_CONFIG_NAMES_PROPERTY, Collections.emptyList());
    Map<String, String> authConfigDefaults = (Map<String, String>) pluginConfig.getOrDefault(DEFAULT_AUTH_CONFIGS_PROPERTY, Collections.emptyMap());
    Map<String, String> proxyUserConfigs = (Map<String, String>) pluginConfig.getOrDefault(PROXY_USER_CONFIGS, Collections.emptyMap());
    for (String configName : authConfigNames) {
        String systemProperty = sysPropPrefix + configName;
        String defaultConfigVal = authConfigDefaults.get(configName);
        String configVal = System.getProperty(systemProperty, defaultConfigVal);
        if (configVal != null) {
            params.put(configName, configVal);
        }
    }
    // Configure proxy user settings.
    params.putAll(proxyUserConfigs);
    final ServletContext servletContext = new AttributeOnlyServletContext();
    log.info("Params: " + params);
    ZkController controller = coreContainer.getZkController();
    if (controller != null) {
        servletContext.setAttribute(DELEGATION_TOKEN_ZK_CLIENT, controller.getZkClient());
    }
    FilterConfig conf = new FilterConfig() {

        @Override
        public ServletContext getServletContext() {
            return servletContext;
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            return new IteratorEnumeration(params.keySet().iterator());
        }

        @Override
        public String getInitParameter(String param) {
            return params.get(param);
        }

        @Override
        public String getFilterName() {
            return "HadoopAuthFilter";
        }
    };
    return conf;
}
Also used : HashMap(java.util.HashMap) IteratorEnumeration(org.apache.commons.collections.iterators.IteratorEnumeration) ZkController(org.apache.solr.cloud.ZkController) Collection(java.util.Collection) ServletContext(javax.servlet.ServletContext) FilterConfig(javax.servlet.FilterConfig) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with IteratorEnumeration

use of org.apache.commons.collections.iterators.IteratorEnumeration in project lucene-solr by apache.

the class KerberosPlugin method getInitFilterConfig.

@VisibleForTesting
protected FilterConfig getInitFilterConfig(Map<String, Object> pluginConfig, boolean skipKerberosChecking) {
    Map<String, String> params = new HashMap();
    params.put("type", "kerberos");
    putParam(params, "kerberos.name.rules", NAME_RULES_PARAM, "DEFAULT");
    putParam(params, "token.valid", TOKEN_VALID_PARAM, "30");
    putParam(params, "cookie.path", COOKIE_PATH_PARAM, "/");
    if (!skipKerberosChecking) {
        putParam(params, "kerberos.principal", PRINCIPAL_PARAM, null);
        putParam(params, "kerberos.keytab", KEYTAB_PARAM, null);
    } else {
        putParamOptional(params, "kerberos.principal", PRINCIPAL_PARAM);
        putParamOptional(params, "kerberos.keytab", KEYTAB_PARAM);
    }
    String delegationTokenStr = System.getProperty(DELEGATION_TOKEN_ENABLED, null);
    boolean delegationTokenEnabled = (delegationTokenStr == null) ? false : Boolean.parseBoolean(delegationTokenStr);
    ZkController controller = coreContainer.getZkController();
    if (delegationTokenEnabled) {
        putParam(params, "delegation-token.token-kind", DELEGATION_TOKEN_KIND, DELEGATION_TOKEN_TYPE_DEFAULT);
        if (coreContainer.isZooKeeperAware()) {
            putParam(params, "signer.secret.provider", DELEGATION_TOKEN_SECRET_PROVIDER, "zookeeper");
            if ("zookeeper".equals(params.get("signer.secret.provider"))) {
                String zkHost = controller.getZkServerAddress();
                putParam(params, "token.validity", DELEGATION_TOKEN_VALIDITY, "36000");
                params.put("zk-dt-secret-manager.enable", "true");
                String chrootPath = zkHost.contains("/") ? zkHost.substring(zkHost.indexOf("/")) : "";
                String znodeWorkingPath = chrootPath + SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH + "/zkdtsm";
                // Note - Curator complains if the znodeWorkingPath starts with /
                znodeWorkingPath = znodeWorkingPath.startsWith("/") ? znodeWorkingPath.substring(1) : znodeWorkingPath;
                putParam(params, "zk-dt-secret-manager.znodeWorkingPath", DELEGATION_TOKEN_SECRET_MANAGER_ZNODE_WORKING_PATH, znodeWorkingPath);
                putParam(params, "signer.secret.provider.zookeeper.path", DELEGATION_TOKEN_SECRET_PROVIDER_ZK_PATH, "/token");
                // ensure krb5 is setup properly before running curator
                getHttpClientBuilder(SolrHttpClientBuilder.create());
            }
        } else {
            log.info("CoreContainer is not ZooKeeperAware, not setting ZK-related delegation token properties");
        }
    }
    // Special handling for the "cookie.domain" based on whether port should be
    // appended to the domain. Useful for situations where multiple solr nodes are
    // on the same host.
    String usePortStr = System.getProperty(COOKIE_PORT_AWARE_PARAM, null);
    boolean needPortAwareCookies = (usePortStr == null) ? false : Boolean.parseBoolean(usePortStr);
    if (!needPortAwareCookies || !coreContainer.isZooKeeperAware()) {
        putParam(params, "cookie.domain", COOKIE_DOMAIN_PARAM, null);
    } else {
        // we need port aware cookies and we are in SolrCloud mode.
        String host = System.getProperty(COOKIE_DOMAIN_PARAM, null);
        if (host == null) {
            throw new SolrException(ErrorCode.SERVER_ERROR, "Missing required parameter '" + COOKIE_DOMAIN_PARAM + "'.");
        }
        int port = controller.getHostPort();
        params.put("cookie.domain", host + ":" + port);
    }
    // check impersonator config
    for (Enumeration e = System.getProperties().propertyNames(); e.hasMoreElements(); ) {
        String key = e.nextElement().toString();
        if (key.startsWith(IMPERSONATOR_PREFIX)) {
            if (!delegationTokenEnabled) {
                throw new SolrException(ErrorCode.SERVER_ERROR, "Impersonator configuration requires delegation tokens to be enabled: " + key);
            }
            params.put(key, System.getProperty(key));
        }
    }
    final ServletContext servletContext = new AttributeOnlyServletContext();
    if (controller != null) {
        servletContext.setAttribute(DELEGATION_TOKEN_ZK_CLIENT, controller.getZkClient());
    }
    if (delegationTokenEnabled) {
        kerberosFilter = new DelegationTokenKerberosFilter();
    // pass an attribute-enabled context in order to pass the zkClient
    // and because the filter may pass a curator instance.
    } else {
        kerberosFilter = new KerberosFilter();
    }
    log.info("Params: " + params);
    FilterConfig conf = new FilterConfig() {

        @Override
        public ServletContext getServletContext() {
            return servletContext;
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            return new IteratorEnumeration(params.keySet().iterator());
        }

        @Override
        public String getInitParameter(String param) {
            return params.get(param);
        }

        @Override
        public String getFilterName() {
            return "KerberosFilter";
        }
    };
    return conf;
}
Also used : Enumeration(java.util.Enumeration) IteratorEnumeration(org.apache.commons.collections.iterators.IteratorEnumeration) HashMap(java.util.HashMap) IteratorEnumeration(org.apache.commons.collections.iterators.IteratorEnumeration) ZkController(org.apache.solr.cloud.ZkController) ServletContext(javax.servlet.ServletContext) FilterConfig(javax.servlet.FilterConfig) SolrException(org.apache.solr.common.SolrException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with IteratorEnumeration

use of org.apache.commons.collections.iterators.IteratorEnumeration in project ranger by apache.

the class RangerKRBAuthenticationFilter method init.

@Override
public void init(FilterConfig conf) throws ServletException {
    final FilterConfig globalConf = conf;
    final Map<String, String> params = new HashMap<String, String>();
    params.put(AUTH_TYPE, PropertiesUtil.getProperty(RANGER_AUTH_TYPE, "simple"));
    params.put(NAME_RULES_PARAM, PropertiesUtil.getProperty(NAME_RULES, "DEFAULT"));
    params.put(TOKEN_VALID_PARAM, PropertiesUtil.getProperty(TOKEN_VALID, "30"));
    params.put(COOKIE_DOMAIN_PARAM, PropertiesUtil.getProperty(COOKIE_DOMAIN, PropertiesUtil.getProperty(HOST_NAME, "localhost")));
    params.put(COOKIE_PATH_PARAM, PropertiesUtil.getProperty(COOKIE_PATH, "/"));
    params.put(ALLOW_TRUSTED_PROXY, PropertiesUtil.getProperty(ALLOW_TRUSTED_PROXY, "false"));
    params.put(RULES_MECHANISM_PARAM, PropertiesUtil.getProperty(RULES_MECHANISM, "hadoop"));
    try {
        params.put(PRINCIPAL_PARAM, SecureClientLogin.getPrincipal(PropertiesUtil.getProperty(PRINCIPAL, ""), PropertiesUtil.getProperty(HOST_NAME)));
    } catch (IOException ignored) {
    // do nothing
    }
    params.put(KEYTAB_PARAM, PropertiesUtil.getProperty(KEYTAB, ""));
    FilterConfig myConf = new FilterConfig() {

        @Override
        public ServletContext getServletContext() {
            if (globalConf != null) {
                return globalConf.getServletContext();
            } else {
                return noContext;
            }
        }

        @SuppressWarnings("unchecked")
        @Override
        public Enumeration<String> getInitParameterNames() {
            return new IteratorEnumeration(params.keySet().iterator());
        }

        @Override
        public String getInitParameter(String param) {
            return params.get(param);
        }

        @Override
        public String getFilterName() {
            return "KerberosFilter";
        }
    };
    super.init(myConf);
    Configuration conf1 = this.getProxyuserConfiguration();
    ProxyUsers.refreshSuperUserGroupsConfiguration(conf1, PROXY_PREFIX);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HashMap(java.util.HashMap) IteratorEnumeration(org.apache.commons.collections.iterators.IteratorEnumeration) FilterConfig(javax.servlet.FilterConfig) IOException(java.io.IOException)

Aggregations

IteratorEnumeration (org.apache.commons.collections.iterators.IteratorEnumeration)9 HashMap (java.util.HashMap)5 FilterConfig (javax.servlet.FilterConfig)5 IOException (java.io.IOException)3 UnknownHostException (java.net.UnknownHostException)2 Enumeration (java.util.Enumeration)2 LinkedHashMap (java.util.LinkedHashMap)2 Pattern (java.util.regex.Pattern)2 ServletContext (javax.servlet.ServletContext)2 ServletException (javax.servlet.ServletException)2 HttpServlet (javax.servlet.http.HttpServlet)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletRequestWrapper (javax.servlet.http.HttpServletRequestWrapper)2 AuthenticationException (org.apache.hadoop.security.authentication.client.AuthenticationException)2 SignerException (org.apache.hadoop.security.authentication.util.SignerException)2 ZkController (org.apache.solr.cloud.ZkController)2 ResourceProvider (org.structr.rest.ResourceProvider)2 IllegalPathException (org.structr.rest.exception.IllegalPathException)2 NotFoundException (org.structr.rest.exception.NotFoundException)2 Resource (org.structr.rest.resource.Resource)2