Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 
 package org.apache.solr.cloud;
 
 import java.io.File;
 import java.util.List;
 import java.util.Map;
 
 
 
 
 
MiniSolrCloudCluster that supports HttpParam (via USER_PARAM http param) and DelegationToken authentication.
 
   public static final String USER_PARAM = "user";
   public static final String REMOTE_HOST_PARAM = "remoteHost";
 
   public HttpParamDelegationTokenMiniSolrCloudCluster(int numServersString hostContext,
       File solrXmlSortedMap<ServletHolderStringextraServlets,
       SSLConfig sslConfigthrows Exception {
     super(numServershostContextsolrXmlextraServletsnullsslConfig);
   }
 
   @Override
   public JettySolrRunner startJettySolrRunner(String hostContext,
       SortedMap<ServletHolderStringextraServlets,
       SortedMap<ClassStringextraRequestFiltersSSLConfig sslConfigthrows Exception {
     if (extraRequestFilters != null) {
       throw new IllegalArgumentException("non-null extra request filters not supported");
     }
     TreeMap<ClassStringextraFilters = new TreeMap<ClassString>(new Comparator<Class>() {
       // There's only one class, make this as simple as possible
       public int compare(Class o1Class o2) {
         return 0;
       }
 
       public boolean equals(Object obj) {
         return true;
       }
     });
     extraFilters.put(HttpParamToRequestFilter.class"*");
     return super.startJettySolrRunner(hostContextextraServletsextraFilterssslConfig);
   }
 
   private static String getHttpParam(HttpServletRequest requestString param) {
     List<NameValuePairpairs =
       URLEncodedUtils.parse(request.getQueryString(), Charset.forName("UTF-8"));
     for (NameValuePair nvp : pairs) {
       if(param.equals(nvp.getName())) {
         return nvp.getValue();
       }
     }
     return null;
   }
 
  public static class HttpParamAuthenticationHandler
      implements AuthenticationHandler {
    @Override
    public String getType() {
      return "dummy";
    }
    @Override
    public void init(Properties configthrows ServletException {
    }
    @Override
    public void destroy() {
    }
    @Override
    public boolean managementOperation(AuthenticationToken token,
        HttpServletRequest requestHttpServletResponse response)
        throws IOExceptionAuthenticationException {
      return false;
    }
    @Override
        HttpServletResponse response)
        throws IOExceptionAuthenticationException {
      AuthenticationToken token = null;
      String userName = getHttpParam(request);
      if (userName != null) {
        return new AuthenticationToken(userNameuserName"test");
      } else {
        response.setHeader("WWW-Authenticate""dummy");
      }
      return token;
    }
  }
  public static class HttpParamDelegationTokenAuthenticationHandler extends
      super(new HttpParamAuthenticationHandler());
    }
    @Override
    public void init(Properties configthrows ServletException {
      Properties conf = new Properties();
      for (Map.Entry entry : config.entrySet()) {
        conf.setProperty((Stringentry.getKey(), (Stringentry.getValue());
      }
      conf.setProperty("solr-dt");
      initTokenManager(conf);
    }
  }

  
Filter that converts http params to HttpServletRequest params
  public static class HttpParamToRequestFilter extends SolrHadoopAuthenticationFilter {
    @Override
    protected Properties getConfiguration(String configPrefix,
        FilterConfig filterConfig) {
      Properties conf = super.getConfiguration(configPrefixfilterConfig);
      conf.setProperty(,
      return conf;
    }
    @Override
    public void doFilter(ServletRequest requestServletResponse responseFilterChain chain)
    throws IOExceptionServletException {
      final HttpServletRequest httpRequest = (HttpServletRequest)request;
      final HttpServletRequestWrapper requestWrapper = new HttpServletRequestWrapper(httpRequest) {
        @Override
        public String getRemoteHost() {
          String param = getHttpParam(httpRequest);
          return param != null ? param : httpRequest.getRemoteHost();
        }
      };
      super.doFilter(requestWrapper, (HttpServletResponse)responsechain);
    }
  }
New to GrepCode? Check out our FAQ X