SGF-414 - Resolve incompatibility between the DistributedSystem created by the PoolFactoryBean and the DistributedSystem resolved by the ClientCacheFactoryBean when SSL is configured.
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright 2010-2013 the original author or authors.
|
||||
*
|
||||
* Licensed 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.springframework.data.gemfire.client;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.gemfire.fork.ServerProcess;
|
||||
import org.springframework.data.gemfire.process.ProcessExecutor;
|
||||
import org.springframework.data.gemfire.process.ProcessWrapper;
|
||||
import org.springframework.data.gemfire.test.support.FileSystemUtils;
|
||||
import org.springframework.data.gemfire.test.support.ThreadUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.gemstone.gemfire.cache.CacheLoader;
|
||||
import com.gemstone.gemfire.cache.CacheLoaderException;
|
||||
import com.gemstone.gemfire.cache.LoaderHelper;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
|
||||
/**
|
||||
* The ClientCacheSecurityTest class...
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class ClientCacheSecurityTest {
|
||||
|
||||
private static ProcessWrapper serverProcess;
|
||||
|
||||
@Resource(name = "Example")
|
||||
private Region<String, String> example;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() throws IOException {
|
||||
String serverName = "GemFireSecurityCacheServer";
|
||||
|
||||
File serverWorkingDirectory = new File(FileSystemUtils.WORKING_DIRECTORY, serverName.toLowerCase());
|
||||
|
||||
Assert.isTrue(serverWorkingDirectory.isDirectory() || serverWorkingDirectory.mkdirs());
|
||||
|
||||
List<String> arguments = new ArrayList<String>();
|
||||
|
||||
arguments.add(String.format("-Dgemfire.name=%1$s", serverName));
|
||||
arguments.add(String.format("-Djavax.net.ssl.keyStore=%1$s", System.getProperty("javax.net.ssl.keyStore")));
|
||||
arguments.add("/org/springframework/data/gemfire/client/ClientCacheSecurityTest-server-context.xml");
|
||||
|
||||
serverProcess = ProcessExecutor.launch(serverWorkingDirectory, ServerProcess.class,
|
||||
arguments.toArray(new String[arguments.size()]));
|
||||
|
||||
waitForServerStart(TimeUnit.SECONDS.toMillis(20));
|
||||
|
||||
System.out.println("GemFire Cache Server Process for ClientCache Security should be running...");
|
||||
}
|
||||
|
||||
private static void waitForServerStart(final long milliseconds) {
|
||||
ThreadUtils.timedWait(milliseconds, TimeUnit.MILLISECONDS.toMillis(500), new ThreadUtils.WaitCondition() {
|
||||
private File serverPidControlFile = new File(serverProcess.getWorkingDirectory(),
|
||||
ServerProcess.getServerProcessControlFilename());
|
||||
|
||||
@Override public boolean waiting() {
|
||||
return !serverPidControlFile.isFile();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() {
|
||||
serverProcess.shutdown();
|
||||
|
||||
if (Boolean.valueOf(System.getProperty("spring.gemfire.fork.clean", Boolean.TRUE.toString()))) {
|
||||
org.springframework.util.FileSystemUtils.deleteRecursively(serverProcess.getWorkingDirectory());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exampleRegionGet() {
|
||||
assertThat(String.valueOf(example.get("TestKey")), is(equalTo("TestValue")));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static class TestCacheLoader implements CacheLoader<String, String> {
|
||||
|
||||
@Override public String load(final LoaderHelper<String, String> helper) throws CacheLoaderException {
|
||||
return "TestValue";
|
||||
}
|
||||
|
||||
@Override public void close() {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:gfe="http://www.springframework.org/schema/gemfire"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
">
|
||||
|
||||
<util:properties id="client.properties">
|
||||
<prop key="client.server.host">localhost</prop>
|
||||
<prop key="client.server.port">31517</prop>
|
||||
<prop key="gemfire.security.ssl.enabled">true</prop>
|
||||
<prop key="gemfire.security.ssl.require-authentication">true</prop>
|
||||
<prop key="gemfire.security.ssl.protocols">any</prop>
|
||||
<prop key="gemfire.security.ssl.ciphers">any</prop>
|
||||
<prop key="gemfire.security.ssl.keystore.location">${javax.net.ssl.keyStore}</prop>
|
||||
<prop key="gemfire.security.ssl.keystore.password">s3cr3t</prop>
|
||||
<prop key="gemfire.security.ssl.keystore.type">jks</prop>
|
||||
</util:properties>
|
||||
|
||||
<context:property-placeholder properties-ref="client.properties" system-properties-mode="FALLBACK"/>
|
||||
|
||||
<util:properties id="gemfireProperties">
|
||||
<prop key="cluster-ssl-enabled">${gemfire.security.ssl.enabled}</prop>
|
||||
<prop key="cluster-ssl-require-authentication">${gemfire.security.ssl.require-authentication}</prop>
|
||||
<prop key="cluster-ssl-protocols">${gemfire.security.ssl.protocols}</prop>
|
||||
<prop key="cluster-ssl-ciphers">${gemfire.security.ssl.ciphers}</prop>
|
||||
<prop key="cluster-ssl-keystore">${gemfire.security.ssl.keystore.location}</prop>
|
||||
<prop key="cluster-ssl-keystore-password">${gemfire.security.ssl.keystore.password}</prop>
|
||||
<prop key="cluster-ssl-keystore-type">${gemfire.security.ssl.keystore.type}</prop>
|
||||
<prop key="cluster-ssl-truststore">${gemfire.security.ssl.keystore.location}</prop>
|
||||
<prop key="cluster-ssl-truststore-password">${gemfire.security.ssl.keystore.password}</prop>
|
||||
<prop key="log-level">warning</prop>
|
||||
<prop key="mcast-port">0</prop>
|
||||
</util:properties>
|
||||
|
||||
<gfe:pool id="gemfireServerPool" max-connections="1" min-connections="1">
|
||||
<gfe:server host="${client.server.host}" port="${client.server.port}"/>
|
||||
</gfe:pool>
|
||||
|
||||
<gfe:client-cache properties-ref="gemfireProperties" pool-name="gemfireServerPool"/>
|
||||
|
||||
<gfe:client-region id="Example" pool-name="gemfireServerPool" shortcut="PROXY"/>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:gfe="http://www.springframework.org/schema/gemfire"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
">
|
||||
|
||||
<util:properties id="server.properties">
|
||||
<prop key="gemfire.security.ssl.enabled">true</prop>
|
||||
<prop key="gemfire.security.ssl.require-authentication">true</prop>
|
||||
<prop key="gemfire.security.ssl.protocols">any</prop>
|
||||
<prop key="gemfire.security.ssl.ciphers">any</prop>
|
||||
<prop key="gemfire.security.ssl.keystore.location">${javax.net.ssl.keyStore}</prop>
|
||||
<prop key="gemfire.security.ssl.keystore.password">s3cr3t</prop>
|
||||
<prop key="gemfire.security.ssl.keystore.type">jks</prop>
|
||||
<prop key="gemfire.server.host">localhost</prop>
|
||||
<prop key="gemfire.server.port">31517</prop>
|
||||
</util:properties>
|
||||
|
||||
<context:property-placeholder properties-ref="server.properties"/>
|
||||
|
||||
<util:properties id="gemfireProperties">
|
||||
<prop key="name">ClientCacheSecurityTestServer</prop>
|
||||
<prop key="mcast-port">0</prop>
|
||||
<prop key="log-level">warning</prop>
|
||||
<prop key="cluster-ssl-enabled">${gemfire.security.ssl.enabled}</prop>
|
||||
<prop key="cluster-ssl-require-authentication">${gemfire.security.ssl.require-authentication}</prop>
|
||||
<prop key="cluster-ssl-protocols">${gemfire.security.ssl.protocols}</prop>
|
||||
<prop key="cluster-ssl-ciphers">${gemfire.security.ssl.ciphers}</prop>
|
||||
<prop key="cluster-ssl-keystore">${gemfire.security.ssl.keystore.location}</prop>
|
||||
<prop key="cluster-ssl-keystore-password">${gemfire.security.ssl.keystore.password}</prop>
|
||||
<prop key="cluster-ssl-keystore-type">${gemfire.security.ssl.keystore.type}</prop>
|
||||
<prop key="cluster-ssl-truststore">${gemfire.security.ssl.keystore.location}</prop>
|
||||
<prop key="cluster-ssl-truststore-password">${gemfire.security.ssl.keystore.password}</prop>
|
||||
</util:properties>
|
||||
|
||||
<gfe:cache properties-ref="gemfireProperties"/>
|
||||
|
||||
<gfe:cache-server auto-startup="true" bind-address="${gemfire.server.host}" port="${gemfire.server.port}"
|
||||
max-connections="1"/>
|
||||
|
||||
<gfe:replicated-region id="Example" persistent="false">
|
||||
<gfe:cache-loader>
|
||||
<bean class="org.springframework.data.gemfire.client.ClientCacheSecurityTest$TestCacheLoader"/>
|
||||
</gfe:cache-loader>
|
||||
</gfe:replicated-region>
|
||||
|
||||
</beans>
|
||||
BIN
src/test/resources/trusted.keystore
Normal file
BIN
src/test/resources/trusted.keystore
Normal file
Binary file not shown.
Reference in New Issue
Block a user