mirror of https://github.com/apache/lucene.git
SOLR-8058: Fix the exclusion filter so that collections that start with js, css, img, tpl can be accessed.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1703441 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b570fb0352
commit
9e0061e157
|
@ -205,6 +205,8 @@ Bug Fixes
|
|||
when parallelUpdates is enabled (default) and multiple docs are sent as a single update.
|
||||
(kevin, hossman, shalin)
|
||||
|
||||
* SOLR-8058: Fix the exclusion filter so that collections that start with js, css, img, tpl
|
||||
can be accessed. (Upayavira, Steve Rowe, Anshum Gupta)
|
||||
|
||||
Optimizations
|
||||
----------------------
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.eclipse.jetty.server.Server;
|
|||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.server.SslConnectionFactory;
|
||||
import org.eclipse.jetty.server.session.HashSessionIdManager;
|
||||
import org.eclipse.jetty.servlet.BaseHolder;
|
||||
import org.eclipse.jetty.servlet.FilterHolder;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
|
@ -85,6 +86,8 @@ public class JettySolrRunner {
|
|||
private volatile boolean startedBefore = false;
|
||||
|
||||
private LinkedList<FilterHolder> extraFilters;
|
||||
|
||||
private static final String excludePatterns = "/css/.+,/js/.+,/img/.+,/tpl/.+";
|
||||
|
||||
private int proxyPort = -1;
|
||||
|
||||
|
@ -333,9 +336,10 @@ public class JettySolrRunner {
|
|||
String pathSpec = config.extraServlets.get(servletHolder);
|
||||
root.addServlet(servletHolder, pathSpec);
|
||||
}
|
||||
|
||||
dispatchFilter = root.addFilter(SolrDispatchFilter.class, "*", EnumSet.of(DispatcherType.REQUEST) );
|
||||
|
||||
dispatchFilter = root.getServletHandler().newFilterHolder(BaseHolder.Source.EMBEDDED);
|
||||
dispatchFilter.setHeldClass(SolrDispatchFilter.class);
|
||||
dispatchFilter.setInitParameter("excludePatterns", excludePatterns);
|
||||
root.addFilter(dispatchFilter, "*", EnumSet.of(DispatcherType.REQUEST));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -195,9 +195,13 @@ public class SolrDispatchFilter extends BaseSolrFilter {
|
|||
|
||||
// No need to even create the HttpSolrCall object if this path is excluded.
|
||||
if(excludePatterns != null) {
|
||||
String servletPath = ((HttpServletRequest) request).getServletPath();
|
||||
String requestPath = ((HttpServletRequest) request).getServletPath();
|
||||
String extraPath = ((HttpServletRequest)request).getPathInfo();
|
||||
if (extraPath != null) { // In embedded mode, servlet path is empty - include all post-context path here for testing
|
||||
requestPath += extraPath;
|
||||
}
|
||||
for (Pattern p : excludePatterns) {
|
||||
Matcher matcher = p.matcher(servletPath);
|
||||
Matcher matcher = p.matcher(requestPath);
|
||||
if (matcher.lookingAt()) {
|
||||
chain.doFilter(request, response);
|
||||
return;
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package org.apache.solr.cloud;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.apache.solr.client.solrj.SolrClient;
|
||||
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
|
||||
import org.junit.Test;
|
||||
|
||||
@LuceneTestCase.Slow
|
||||
public class TestExclusionRuleCollectionAccess extends AbstractFullDistribZkTestBase {
|
||||
|
||||
public TestExclusionRuleCollectionAccess() {
|
||||
schemaString = "schema15.xml"; // we need a string id
|
||||
sliceCount = 1;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doTest() throws Exception {
|
||||
CollectionAdminRequest.Create req = new CollectionAdminRequest.Create();
|
||||
req.setCollectionName("css33");
|
||||
req.setNumShards(1);
|
||||
req.process(cloudClient);
|
||||
|
||||
waitForRecoveriesToFinish("css33", false);
|
||||
|
||||
try (SolrClient c = createCloudClient("css33")) {
|
||||
c.add(getDoc("id", "1"));
|
||||
c.commit();
|
||||
|
||||
assertEquals("Should have returned 1 result", 1, c.query(params("q", "*:*", "collection", "css33")).getResults().getNumFound());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -56,7 +56,7 @@
|
|||
-->
|
||||
<init-param>
|
||||
<param-name>excludePatterns</param-name>
|
||||
<param-value>/css/*,/js/*,/img/*,/tpl/*</param-value>
|
||||
<param-value>/css/.+,/js/.+,/img/.+,/tpl/.+</param-value>
|
||||
</init-param>
|
||||
</filter>
|
||||
|
||||
|
|
Loading…
Reference in New Issue