SOLR-14087: disable package store API if -Denable.packages not set to true

This commit is contained in:
Noble Paul 2019-12-16 08:04:33 +11:00 committed by noble
parent 2b775d88eb
commit 3635a1bcdb
3 changed files with 13 additions and 2 deletions

View File

@ -47,6 +47,7 @@ import org.apache.solr.common.util.Utils;
import org.apache.solr.core.BlobRepository;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrCore;
import org.apache.solr.pkg.PackageAPI;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.security.PermissionNameProvider;
@ -64,7 +65,7 @@ import static org.apache.solr.handler.ReplicationHandler.FILE_STREAM;
public class PackageStoreAPI {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public static final String PACKAGESTORE_DIRECTORY = "filestore";
public static final String PACKAGESTORE_DIRECTORY = "$filestore";
private final CoreContainer coreContainer;
@ -135,6 +136,9 @@ public class PackageStoreAPI {
@Command
public void upload(SolrQueryRequest req, SolrQueryResponse rsp) {
if(!coreContainer.getPackageLoader().getPackageAPI().isEnabled()) {
throw new RuntimeException(PackageAPI.ERR_MSG);
}
try {
coreContainer.getZkController().getZkClient().create(TMP_ZK_NODE, "true".getBytes(UTF_8),
CreateMode.EPHEMERAL, true);

View File

@ -64,6 +64,8 @@ public class PackageAPI {
public final boolean enablePackages = Boolean.parseBoolean(System.getProperty("enable.packages", "false"));
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public static final String ERR_MSG = "Package loading is not enabled , Start your nodes with -Denable.packages=true";
final CoreContainer coreContainer;
private final ObjectMapper mapper = SolrJacksonAnnotationInspector.createObjectMapper();
private final PackageLoader packageLoader;
@ -331,9 +333,13 @@ public class PackageAPI {
}
public boolean isEnabled() {
return enablePackages;
}
private boolean checkEnabled(CommandOperation payload) {
if (!enablePackages) {
payload.addError("Package loading is not enabled , Start your nodes with -Denable.packages=true");
payload.addError(ERR_MSG);
return false;
}
return true;

View File

@ -55,6 +55,7 @@ import static org.apache.solr.core.TestDynamicLoading.getFileContent;
public class TestDistribPackageStore extends SolrCloudTestCase {
public void testPackageStoreManagement() throws Exception {
System.setProperty("enable.packages", "true");
MiniSolrCloudCluster cluster =
configureCluster(4)
.withJettyConfig(jetty -> jetty.enableV2(true))