diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 41d3816eaa0..864009a8273 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -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 ---------------------- diff --git a/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java b/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java index fa44fe5860b..58ac41baa00 100644 --- a/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java +++ b/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java @@ -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 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 diff --git a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java index 28107056d1b..2e49a97edd5 100644 --- a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java +++ b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java @@ -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; diff --git a/solr/core/src/test/org/apache/solr/cloud/TestExclusionRuleCollectionAccess.java b/solr/core/src/test/org/apache/solr/cloud/TestExclusionRuleCollectionAccess.java new file mode 100644 index 00000000000..79627ada789 --- /dev/null +++ b/solr/core/src/test/org/apache/solr/cloud/TestExclusionRuleCollectionAccess.java @@ -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()); + } + } + +} diff --git a/solr/webapp/web/WEB-INF/web.xml b/solr/webapp/web/WEB-INF/web.xml index 0a11fff8f0e..ed3036cd34e 100644 --- a/solr/webapp/web/WEB-INF/web.xml +++ b/solr/webapp/web/WEB-INF/web.xml @@ -56,7 +56,7 @@ --> excludePatterns - /css/*,/js/*,/img/*,/tpl/* + /css/.+,/js/.+,/img/.+,/tpl/.+