Skip to content

Commit

Permalink
GEODE-9758: Configure locator serialization filtering by default on J…
Browse files Browse the repository at this point in the history
…ava 8 (#6962)
  • Loading branch information
jchen21 committed Nov 9, 2021
1 parent e341477 commit a8a23ba
Show file tree
Hide file tree
Showing 143 changed files with 5,921 additions and 1,106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ private DistributedMember startLocator() throws IOException {
"--port=" + locatorPort,
"--classpath=" + serviceJarPath + pathSeparator + functionJarPath,
"--http-service-port=0",
"--J=-Dgemfire.jmx-manager-port=" + locatorJmxPort);
"--J=-Dgemfire.jmx-manager-port=" + locatorJmxPort,
"--J=-Dgemfire.serializable-object-filter=*");

gfshRule.execute(startLocatorCommand);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* 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.geode.serialization.filter;

import static org.apache.commons.lang3.JavaVersion.JAVA_1_8;
import static org.apache.commons.lang3.JavaVersion.JAVA_9;
import static org.apache.commons.lang3.SystemUtils.isJavaVersionAtLeast;
import static org.apache.commons.lang3.SystemUtils.isJavaVersionAtMost;
import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts;
import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
import static org.assertj.core.api.Assumptions.assumeThat;

import java.io.File;
import java.nio.file.Path;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestName;

import org.apache.geode.rules.ServiceJarRule;
import org.apache.geode.test.assertj.LogFileAssert;
import org.apache.geode.test.junit.rules.gfsh.GfshRule;

public class LocatorLauncherGlobalSerialFilterAcceptanceTest {

@Rule
public GfshRule gfshRule = new GfshRule();

@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();

@Rule
public TestName testName = new TestName();

@Rule
public ServiceJarRule serviceJarRule = new ServiceJarRule();

private File locatorFolder;

@Test
public void startLocatorConfiguresGlobalSerialFilter_onJava8() {
assumeThat(isJavaVersionAtMost(JAVA_1_8)).isTrue();

locatorFolder = temporaryFolder.getRoot();

int[] ports = getRandomAvailableTCPPorts(2);

int locatorPort = ports[0];
int locatorJmxPort = ports[1];

String startLocatorCommand = String.join(" ",
"start locator",
"--name=locator",
"--dir=" + locatorFolder.getAbsolutePath(),
"--port=" + locatorPort,
"--J=-Dgemfire.jmx-manager-port=" + locatorJmxPort);

gfshRule.execute(startLocatorCommand);

try {
Path locatorLogFile = locatorFolder.toPath().resolve("locator.log");
await().untilAsserted(() -> {
LogFileAssert.assertThat(locatorLogFile.toFile()).exists()
.contains("Global serial filter is now configured.")
.doesNotContain("jdk.serialFilter");
});
} finally {
String stopLocatorCommand = "stop locator --dir=" + locatorFolder.getAbsolutePath();
gfshRule.execute(stopLocatorCommand);
}
}

// another test for java 9 that does not create global serial filter
@Test
public void startLocatorDoesNotConfigureGlobalSerialFilter_onJava9orGreater() {
assumeThat(isJavaVersionAtLeast(JAVA_9)).isTrue();

locatorFolder = temporaryFolder.getRoot();

int[] ports = getRandomAvailableTCPPorts(2);

int locatorPort = ports[0];
int locatorJmxPort = ports[1];

String startLocatorCommand = String.join(" ",
"start locator",
"--name=locator",
"--dir=" + locatorFolder.getAbsolutePath(),
"--port=" + locatorPort,
"--J=-Dgemfire.jmx-manager-port=" + locatorJmxPort);

gfshRule.execute(startLocatorCommand);

try {
Path locatorLogFile = locatorFolder.toPath().resolve("locator.log");
await().untilAsserted(() -> {
LogFileAssert.assertThat(locatorLogFile.toFile()).exists()
.doesNotContain("Global serial filter is now configured.")
.doesNotContain("jdk.serialFilter");
});
} finally {
String stopLocatorCommand = "stop locator --dir=" + locatorFolder.getAbsolutePath();
gfshRule.execute(stopLocatorCommand);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package org.apache.geode.management;
package org.apache.geode.serialization.filter;

import static org.apache.commons.lang3.JavaVersion.JAVA_1_8;
import static org.apache.commons.lang3.JavaVersion.JAVA_9;
import static org.apache.commons.lang3.SystemUtils.isJavaVersionAtLeast;
import static org.apache.commons.lang3.SystemUtils.isJavaVersionAtMost;
import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts;
import static org.apache.geode.management.internal.JmxRmiOpenTypesSerialFilter.PROPERTY_NAME;
import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
import static org.assertj.core.api.Assumptions.assumeThat;

import java.nio.file.Path;

import org.apache.commons.lang3.JavaVersion;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -33,9 +33,10 @@
import org.apache.geode.test.junit.rules.RequiresGeodeHome;
import org.apache.geode.test.junit.rules.gfsh.GfshRule;

public class LocatorManagerConfiguresJmxSerialFilterAcceptanceTest {
public class LocatorLauncherJmxSerialFilterAcceptanceTest {

private static final String NAME = "the-locator";
private static final String JMX_FILTER_PATTERN = "jmx.remote.rmi.server.serial.filter.pattern";

private Path workingDir;
private int locatorPort;
Expand Down Expand Up @@ -64,8 +65,8 @@ public void setUpRandomPorts() {
}

@Test
public void startingLocatorWithJmxManager_configuresSerialFilter_atLeastJava9() {
assumeThat(isJavaVersionAtLeast(JavaVersion.JAVA_9)).isTrue();
public void startLocatorConfiguresJmxSerialFilter_onJava9orGreater() {
assumeThat(isJavaVersionAtLeast(JAVA_9)).isTrue();

String startLocatorCommand = String.join(" ",
"start locator",
Expand All @@ -84,13 +85,13 @@ public void startingLocatorWithJmxManager_configuresSerialFilter_atLeastJava9()
LogFileAssert.assertThat(locatorLogFile.toFile())
.as(locatorLogFile.toFile().getAbsolutePath())
.exists()
.contains("System property " + PROPERTY_NAME + " is now configured with");
.contains("System property " + JMX_FILTER_PATTERN + " is now configured with");
});
}

@Test
public void startingLocatorWithJmxManager_configuresSerialFilter_atMostJava8() {
assumeThat(isJavaVersionAtMost(JavaVersion.JAVA_1_8)).isTrue();
public void startLocatorDoesNotConfigureJmxSerialFilter_onJava8O() {
assumeThat(isJavaVersionAtMost(JAVA_1_8)).isTrue();

String startLocatorCommand = String.join(" ",
"start locator",
Expand All @@ -109,7 +110,7 @@ public void startingLocatorWithJmxManager_configuresSerialFilter_atMostJava8() {
LogFileAssert.assertThat(locatorLogFile.toFile())
.as(locatorLogFile.toFile().getAbsolutePath())
.exists()
.doesNotContain("System property " + PROPERTY_NAME + " is now configured with");
.doesNotContain("System property " + JMX_FILTER_PATTERN + " is now configured with");
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package org.apache.geode.management;
package org.apache.geode.serialization.filter;

import static org.apache.commons.lang3.JavaVersion.JAVA_1_8;
import static org.apache.commons.lang3.JavaVersion.JAVA_9;
import static org.apache.commons.lang3.SystemUtils.isJavaVersionAtLeast;
import static org.apache.commons.lang3.SystemUtils.isJavaVersionAtMost;
import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPort;
import static org.apache.geode.management.internal.JmxRmiOpenTypesSerialFilter.PROPERTY_NAME;
import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
import static org.assertj.core.api.Assumptions.assumeThat;

import java.nio.file.Path;

import org.apache.commons.lang3.JavaVersion;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -33,9 +33,10 @@
import org.apache.geode.test.junit.rules.RequiresGeodeHome;
import org.apache.geode.test.junit.rules.gfsh.GfshRule;

public class ServerManagerConfiguresJmxSerialFilterAcceptanceTest {
public class ServerLauncherJmxSerialFilterAcceptanceTest {

private static final String NAME = "the-server";
private static final String JMX_FILTER_PATTERN = "jmx.remote.rmi.server.serial.filter.pattern";

private Path workingDir;
private int jmxPort;
Expand All @@ -60,8 +61,8 @@ public void setUpRandomPorts() {
}

@Test
public void startingServerWithJmxManager_configuresSerialFilter_atLeastJava9() {
assumeThat(isJavaVersionAtLeast(JavaVersion.JAVA_9)).isTrue();
public void startServerWithJmxManager_configuresJmxSerialFilter_onJava9orGreater() {
assumeThat(isJavaVersionAtLeast(JAVA_9)).isTrue();

String startServerCommand = String.join(" ",
"start server",
Expand All @@ -80,13 +81,13 @@ public void startingServerWithJmxManager_configuresSerialFilter_atLeastJava9() {
LogFileAssert.assertThat(serverLogFile.toFile())
.as(serverLogFile.toFile().getAbsolutePath())
.exists()
.contains("System property " + PROPERTY_NAME + " is now configured with");
.contains("System property " + JMX_FILTER_PATTERN + " is now configured with");
});
}

@Test
public void startingServerWithJmxManager_configuresSerialFilter_atMostJava8() {
assumeThat(isJavaVersionAtMost(JavaVersion.JAVA_1_8)).isTrue();
public void startServerWithJmxManager_doesNotConfigureJmxSerialFilter_onJava8() {
assumeThat(isJavaVersionAtMost(JAVA_1_8)).isTrue();

String startServerCommand = String.join(" ",
"start server",
Expand All @@ -105,7 +106,7 @@ public void startingServerWithJmxManager_configuresSerialFilter_atMostJava8() {
LogFileAssert.assertThat(serverLogFile.toFile())
.as(serverLogFile.toFile().getAbsolutePath())
.exists()
.doesNotContain("System property " + PROPERTY_NAME + " is now configured with");
.doesNotContain("System property " + JMX_FILTER_PATTERN + " is now configured with");
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.apache.geode.management.cluster.client.ClusterManagementServiceBuilder;
import org.apache.geode.management.configuration.Region;
import org.apache.geode.management.configuration.RegionType;
import org.apache.geode.test.dunit.Invoke;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.dunit.rules.DistributedRule;
import org.apache.geode.test.junit.rules.serializable.SerializableTemporaryFolder;
Expand Down Expand Up @@ -84,6 +85,8 @@ public void setUp() throws Exception {
httpPort = ports[0];
jmxManagerPort = ports[1];

Invoke.invokeInEveryVM(() -> System.setProperty("jdk.serialFilter", "*"));

locatorPort = locatorVM.invoke(this::startLocator);
serverVM.invoke(this::startServer);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.geode.connectors.jdbc.internal;

import org.junit.experimental.categories.Category;

import org.apache.geode.codeAnalysis.SanctionedSerializablesServiceIntegrationTestBase;
import org.apache.geode.internal.serialization.filter.SanctionedSerializablesService;
import org.apache.geode.test.junit.categories.SanctionedSerializablesTest;
import org.apache.geode.test.junit.categories.SerializationTest;

@Category({SerializationTest.class, SanctionedSerializablesTest.class})
public class ConnectorsSanctionedSerializablesServiceIntegrationTest
extends SanctionedSerializablesServiceIntegrationTestBase {

private final SanctionedSerializablesService service =
new ConnectorsSanctionedSerializablesService();

@Override
protected SanctionedSerializablesService getService() {
return service;
}

@Override
protected ServiceResourceExpectation getServiceResourceExpectation() {
return ServiceResourceExpectation.NON_EMPTY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import java.net.URL;

import org.apache.geode.internal.serialization.SanctionedSerializablesService;
import org.apache.geode.internal.serialization.filter.SanctionedSerializablesService;

public class ConnectorsSanctionedSerializablesService implements SanctionedSerializablesService {

Expand Down
2 changes: 2 additions & 0 deletions geode-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ dependencies {
exclude module: 'geode-core'
}
testImplementation(project(':geode-concurrency-test'))
testImplementation(project(':geode-serialization'))
testImplementation('org.apache.bcel:bcel')
testImplementation('org.assertj:assertj-core')
testImplementation('org.mockito:mockito-core')
Expand All @@ -354,6 +355,7 @@ dependencies {
integrationTestImplementation(project(':geode-dunit'))
integrationTestImplementation(project(':geode-log4j'))
integrationTestImplementation(project(':geode-concurrency-test'))
integrationTestImplementation(project(':geode-serialization'))
integrationTestImplementation('org.apache.bcel:bcel')
integrationTestImplementation('org.apache.logging.log4j:log4j-core')
integrationTestImplementation('pl.pragmatists:JUnitParams')
Expand Down
Loading

0 comments on commit a8a23ba

Please sign in to comment.