Apache Lucene open-source search software
SOLR-8692 moved the embedded json out to resources dir
Noble Paul8bcac81a219f
diff --git a/dev-tools/idea/solr/core/src/java/solr-core.iml b/dev-tools/idea/solr/core/src/java/solr-core.imlindex 9ec3eb6e13b..eb549422bec 100644--- a/dev-tools/idea/solr/core/src/java/solr-core.iml+++ b/dev-tools/idea/solr/core/src/java/solr-core.iml@@ -27,5 +27,14 @@<orderEntry type="module" module-name="queryparser" /><orderEntry type="module" module-name="join" /><orderEntry type="module" module-name="sandbox" />+ <orderEntry type="module-library">+ <library>+ <CLASSES>+ <root url="file://$MODULE_DIR$/resources" />+ </CLASSES>+ <JAVADOC />+ <SOURCES />+ </library>+ </orderEntry></component></module>diff --git a/dev-tools/idea/solr/core/src/solr-core-tests.iml b/dev-tools/idea/solr/core/src/solr-core-tests.imlindex eb27c57068d..6e2bb6f1590 100644--- a/dev-tools/idea/solr/core/src/solr-core-tests.iml+++ b/dev-tools/idea/solr/core/src/solr-core-tests.iml@@ -31,5 +31,14 @@<orderEntry type="module" scope="TEST" module-name="expressions" /><orderEntry type="module" scope="TEST" module-name="icu" /><orderEntry type="module" scope="TEST" module-name="analysis-extras" />+ <orderEntry type="module-library">+ <library>+ <CLASSES>+ <root url="file://$MODULE_DIR$/resources" />+ </CLASSES>+ <JAVADOC />+ <SOURCES />+ </library>+ </orderEntry></component></module>diff --git a/dev-tools/idea/solr/solrj/src/solrj-tests.iml b/dev-tools/idea/solr/solrj/src/solrj-tests.imlindex 13cdb588a99..0b3c2521108 100644--- a/dev-tools/idea/solr/solrj/src/solrj-tests.iml+++ b/dev-tools/idea/solr/solrj/src/solrj-tests.iml@@ -29,5 +29,14 @@<orderEntry type="module" scope="TEST" module-name="solr-core" /><orderEntry type="module" scope="TEST" module-name="analysis-common" /><orderEntry type="module" scope="TEST" module-name="lucene-core" />+ <orderEntry type="module-library">+ <library>+ <CLASSES>+ <root url="file://$MODULE_DIR$/../../core/src/resources" />+ </CLASSES>+ <JAVADOC />+ <SOURCES />+ </library>+ </orderEntry></component></module>diff --git a/solr/core/src/java/org/apache/solr/core/ConfigOverlay.java b/solr/core/src/java/org/apache/solr/core/ConfigOverlay.javaindex 0252bd5e6b8..ae3e0551840 100644--- a/solr/core/src/java/org/apache/solr/core/ConfigOverlay.java+++ b/solr/core/src/java/org/apache/solr/core/ConfigOverlay.java@@ -170,74 +170,10 @@ public class ConfigOverlay implements MapSerializable {private static final Long INT_NODE = 21L;private static final Long FLOAT_ATTR = 30L;private static final Long FLOAT_NODE = 31L;*/-- private static Map editable_prop_map;//The path maps to the xml xpath and value of 1 means it is a tag with a string value and value// of 0 means it is an attribute with string value- public static final String MAPPING = "{" +- " updateHandler:{" +- " autoCommit:{" +- " maxDocs:20," +- " maxTime:20," +- " openSearcher:11}," +- " autoSoftCommit:{" +- " maxDocs:20," +- " maxTime:20}," +- " commitWithin:{softCommit:11}," +- " indexWriter:{closeWaitsForMerges:11}}," +- " query:{" +- " filterCache:{" +- " class:0," +- " size:0," +- " initialSize:20," +- " autowarmCount:20," +- " maxRamMB:20," +- " regenerator:0}," +- " queryResultCache:{" +- " class:0," +- " size:20," +- " initialSize:20," +- " autowarmCount:20," +- " maxRamMB:20," +- " regenerator:0}," +- " documentCache:{" +- " class:0," +- " size:20," +- " initialSize:20," +- " autowarmCount:20," +- " regenerator:0}," +- " fieldValueCache:{" +- " class:0," +- " size:20," +- " initialSize:20," +- " autowarmCount:20," +- " regenerator:0}," +- " useFilterForSortedQuery:1," +- " queryResultWindowSize:1," +- " queryResultMaxDocsCached:1," +- " enableLazyFieldLoading:1," +- " boolTofilterOptimizer:1," +- " maxBooleanClauses:1}," +- " jmx:{" +- " agentId:0," +- " serviceUrl:0," +- " rootName:0}," +- " requestDispatcher:{" +- " handleSelect:0," +- " requestParsers:{" +- " multipartUploadLimitInKB:0," +- " formdataUploadLimitInKB:0," +- " enableRemoteStreaming:0," +- " addHttpRequestToContext:0}}}";-- static {- try {- editable_prop_map = (Map) new ObjectBuilder(new JSONParser(new StringReader(- MAPPING))).getObject();- } catch (IOException e) {- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "error parsing mapping ", e);- }- }++ private static Map editable_prop_map = (Map) Utils.fromJSONResource("EditableSolrConfigAttributes.json");public static boolean isEditableProp(String path, boolean isXpath, List<String> hierarchy) {return !(checkEditable(path, isXpath, hierarchy) == null);@@ -331,6 +267,7 @@ public class ConfigOverlay implements MapSerializable {public static final String NAME = "overlay";public static void main(String[] args) {+ System.out.println(Utils.toJSONString(editable_prop_map));}}diff --git a/solr/core/src/java/org/apache/solr/security/RuleBasedAuthorizationPlugin.java b/solr/core/src/java/org/apache/solr/security/RuleBasedAuthorizationPlugin.javaindex fa13e7c6f3c..1d4a9b8c44b 100644--- a/solr/core/src/java/org/apache/solr/security/RuleBasedAuthorizationPlugin.java+++ b/solr/core/src/java/org/apache/solr/security/RuleBasedAuthorizationPlugin.java@@ -40,6 +40,7 @@ import org.slf4j.Logger;import org.slf4j.LoggerFactory;import static java.util.Collections.singleton;+import static org.apache.solr.common.util.Utils.fromJSONResource;import static org.apache.solr.handler.admin.SecurityConfHandler.getListValue;import static org.apache.solr.handler.admin.SecurityConfHandler.getMapValue;import static org.apache.solr.common.params.CommonParams.NAME;@@ -437,40 +438,8 @@ public class RuleBasedAuthorizationPlugin implements AuthorizationPlugin, Configpublic static final Set<String> HTTP_METHODS = ImmutableSet.of("GET", "POST", "DELETE", "PUT", "HEAD");- private static final Map<String, Map<String,Object>> well_known_permissions = (Map) Utils.fromJSONString(- " { " +- " security-edit :{" +- " path:['/admin/authentication','/admin/authorization']," +- " collection:null," +- " method:POST }," +- " security-read :{" +- " path:['/admin/authentication','/admin/authorization']," +- " collection:null," +- " method:GET}," +- " schema-edit :{" +- " method:POST," +- " path:'/schema/*'}," +- " collection-admin-edit :{" +- " collection:null," +- " path:'/admin/collections'}," +- " collection-admin-read :{" +- " collection:null," +- " path:'/admin/collections'}," +- " schema-read :{" +- " method:GET," +- " path:'/schema/*'}," +- " config-read :{" +- " method:GET," +- " path:'/config/*'}," +- " update :{" +- " path:'/update/*'}," +- " read :{" +- " path:['/select', '/get','/browse','/tvrh','/terms','/clustering','/elevate', '/export','/spell','/clustering']}," +- " config-edit:{" +- " method:POST," +- " path:'/config/*'}," +- " all:{collection:['*', null]}" +- "}");+ private static final Map<String, Map<String,Object>> well_known_permissions =+ (Map<String, Map<String, Object>>) fromJSONResource("WellKnownPermissions.json");static {((Map) well_known_permissions.get("collection-admin-edit")).put(Predicate.class.getName(), getCollectionActionPredicate(true));diff --git a/solr/core/src/resources/EditableSolrConfigAttributes.json b/solr/core/src/resources/EditableSolrConfigAttributes.jsonnew file mode 100644index 00000000000..394d63457a8--- /dev/null+++ b/solr/core/src/resources/EditableSolrConfigAttributes.json@@ -0,0 +1,56 @@+{+ "updateHandler":{+ "autoCommit":{+ "maxDocs":20,+ "maxTime":20,+ "openSearcher":11},+ "autoSoftCommit":{+ "maxDocs":20,+ "maxTime":20},+ "commitWithin":{"softCommit":11},+ "indexWriter":{"closeWaitsForMerges":11}},+ "query":{+ "filterCache":{+ "class":0,+ "size":0,+ "initialSize":20,+ "autowarmCount":20,+ "maxRamMB":20,+ "regenerator":0},+ "queryResultCache":{+ "class":0,+ "size":20,+ "initialSize":20,+ "autowarmCount":20,+ "maxRamMB":20,+ "regenerator":0},+ "documentCache":{+ "class":0,+ "size":20,+ "initialSize":20,+ "autowarmCount":20,+ "regenerator":0},+ "fieldValueCache":{+ "class":0,+ "size":20,+ "initialSize":20,+ "autowarmCount":20,+ "regenerator":0},+ "useFilterForSortedQuery":1,+ "queryResultWindowSize":1,+ "queryResultMaxDocsCached":1,+ "enableLazyFieldLoading":1,+ "boolTofilterOptimizer":1,+ "maxBooleanClauses":1},+ "jmx":{+ "agentId":0,+ "serviceUrl":0,+ "rootName":0},+ "requestDispatcher":{+ "handleSelect":0,+ "requestParsers":{+ "multipartUploadLimitInKB":0,+ "formdataUploadLimitInKB":0,+ "enableRemoteStreaming":0,+ "addHttpRequestToContext":0}}+}\ No newline at end of filediff --git a/solr/core/src/resources/WellKnownPermissions.json b/solr/core/src/resources/WellKnownPermissions.jsonnew file mode 100644index 00000000000..026e511b75c--- /dev/null+++ b/solr/core/src/resources/WellKnownPermissions.json@@ -0,0 +1,47 @@+{+ "security-edit":{+ "path":[+ "/admin/authentication",+ "/admin/authorization"],+ "collection":null,+ "method":"POST"},+ "security-read":{+ "path":[+ "/admin/authentication",+ "/admin/authorization"],+ "collection":null,+ "method":"GET"},+ "schema-edit":{+ "method":"POST",+ "path":"/schema/*"},+ "collection-admin-edit":{+ "collection":null,+ "path":"/admin/collections"},+ "collection-admin-read":{+ "collection":null,+ "path":"/admin/collections"},+ "schema-read":{+ "method":"GET",+ "path":"/schema/*"},+ "config-read":{+ "method":"GET",+ "path":"/config/*"},+ "update":{"path":"/update/*"},+ "read":{"path":[+ "/select",+ "/get",+ "/browse",+ "/tvrh",+ "/terms",+ "/clustering",+ "/elevate",+ "/export",+ "/spell",+ "/clustering"]},+ "config-edit":{+ "method":"POST",+ "path":"/config/*"},+ "all":{"collection":[+ "*",+ null]}+}diff --git a/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerConcurrent.java b/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerConcurrent.javaindex 4f3756865ac..43b83e20c71 100644--- a/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerConcurrent.java+++ b/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerConcurrent.java@@ -81,8 +81,7 @@ public class TestSolrConfigHandlerConcurrent extends AbstractFullDistribZkTestBa@Testpublic void test() throws Exception {- Map editable_prop_map = (Map) new ObjectBuilder(new JSONParser(new StringReader(- ConfigOverlay.MAPPING))).getObject();+ Map editable_prop_map = (Map) Utils.fromJSONResource("EditableSolrConfigAttributes.json");Map caches = (Map) editable_prop_map.get("query");setupHarnesses();diff --git a/solr/solrj/src/java/org/apache/solr/common/util/Utils.java b/solr/solrj/src/java/org/apache/solr/common/util/Utils.javaindex 03b8b2c7656..ecc63ac8ed6 100644--- a/solr/solrj/src/java/org/apache/solr/common/util/Utils.java+++ b/solr/solrj/src/java/org/apache/solr/common/util/Utils.java@@ -18,6 +18,7 @@ package org.apache.solr.common.util;import java.io.IOException;import java.io.InputStream;+import java.io.InputStreamReader;import java.io.StringReader;import java.lang.invoke.MethodHandles;import java.nio.charset.StandardCharsets;@@ -120,6 +121,20 @@ public class Utils {return propMap;}+ public static Object fromJSON(InputStream is){+ try {+ return new ObjectBuilder(new JSONParser(new InputStreamReader(is, StandardCharsets.UTF_8))).getObject();+ } catch (IOException e) {+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Parse error", e);+ }+ }++ public static Object fromJSONResource(String resourceName){+ return fromJSON(Thread.currentThread()+ .getContextClassLoader().getResourceAsStream(resourceName));++ }+public static Object fromJSONString(String json) {try {return new ObjectBuilder(new JSONParser(new StringReader(