diff --git a/geode-spring-boot-starter/src/main/java/org/springframework/boot/data/geode/autoconfigure/SslAutoConfiguration.java b/geode-spring-boot-starter/src/main/java/org/springframework/boot/data/geode/autoconfigure/SslAutoConfiguration.java index 0ae0994b..c32f6a1b 100644 --- a/geode-spring-boot-starter/src/main/java/org/springframework/boot/data/geode/autoconfigure/SslAutoConfiguration.java +++ b/geode-spring-boot-starter/src/main/java/org/springframework/boot/data/geode/autoconfigure/SslAutoConfiguration.java @@ -26,7 +26,7 @@ import java.net.URL; import java.util.Optional; import java.util.Properties; -import org.apache.geode.cache.client.ClientCache; +import org.apache.geode.cache.GemFireCache; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; @@ -46,7 +46,7 @@ import org.springframework.core.env.PropertiesPropertySource; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.core.type.AnnotatedTypeMetadata; -import org.springframework.data.gemfire.client.ClientCacheFactoryBean; +import org.springframework.data.gemfire.CacheFactoryBean; import org.springframework.data.gemfire.config.annotation.EnableSsl; import org.springframework.util.Assert; import org.springframework.util.FileCopyUtils; @@ -62,7 +62,7 @@ import org.springframework.util.StringUtils; * @see java.net.URL * @see java.util.Properties * @see org.springframework.boot.SpringApplication - * @see org.apache.geode.cache.client.ClientCache + * @see org.apache.geode.cache.GemFireCache * @see org.springframework.boot.autoconfigure.EnableAutoConfiguration * @see org.springframework.boot.data.geode.autoconfigure.ClientCacheAutoConfiguration * @see org.springframework.boot.env.EnvironmentPostProcessor @@ -72,14 +72,14 @@ import org.springframework.util.StringUtils; * @see org.springframework.core.env.ConfigurableEnvironment * @see org.springframework.core.env.Environment * @see org.springframework.core.io.Resource - * @see org.springframework.data.gemfire.client.ClientCacheFactoryBean + * @see org.springframework.data.gemfire.CacheFactoryBean * @see org.springframework.data.gemfire.config.annotation.EnableSsl * @since 1.0.0 */ @Configuration @AutoConfigureBefore(ClientCacheAutoConfiguration.class) @Conditional(SslAutoConfiguration.EnableSslCondition.class) -@ConditionalOnClass({ ClientCacheFactoryBean.class, ClientCache.class }) +@ConditionalOnClass({ CacheFactoryBean.class, GemFireCache.class }) @EnableSsl @SuppressWarnings("unused") public class SslAutoConfiguration { @@ -271,6 +271,7 @@ public class SslAutoConfiguration { @ConditionalOnProperty(prefix = "spring.data.gemfire.security.ssl", name = { "keystore", "truststore", }) static class SpringDataGeodeSslContextCondition {} + // TODO: ;-) @ConditionalOnProperty({ GEMFIRE_SSL_KEYSTORE_PROPERTY, GEMFIRE_SSL_TRUSTSTORE_PROPERTY, diff --git a/geode-spring-boot-starter/src/test/java/org/springframework/boot/data/geode/security/ssl/AutoConfiguredSslIntegrationTests.java b/geode-spring-boot-starter/src/test/java/org/springframework/boot/data/geode/security/ssl/AutoConfiguredSslIntegrationTests.java index 69343d35..7dcab3f8 100644 --- a/geode-spring-boot-starter/src/test/java/org/springframework/boot/data/geode/security/ssl/AutoConfiguredSslIntegrationTests.java +++ b/geode-spring-boot-starter/src/test/java/org/springframework/boot/data/geode/security/ssl/AutoConfiguredSslIntegrationTests.java @@ -17,13 +17,9 @@ package org.springframework.boot.data.geode.security.ssl; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray; -import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalStateException; -import java.io.File; import java.io.IOException; import java.util.List; -import java.util.Optional; import java.util.stream.Collectors; import org.apache.geode.cache.GemFireCache; @@ -33,28 +29,18 @@ 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.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.data.geode.core.util.ObjectUtils; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.PropertySource; -import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; import org.springframework.data.gemfire.PartitionedRegionFactoryBean; import org.springframework.data.gemfire.client.ClientRegionFactoryBean; import org.springframework.data.gemfire.config.annotation.CacheServerApplication; import org.springframework.data.gemfire.config.annotation.EnableLogging; -import org.springframework.data.gemfire.config.annotation.EnableSsl; -import org.springframework.data.gemfire.config.annotation.PeerCacheConfigurer; import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; import org.springframework.data.gemfire.tests.integration.config.ClientServerIntegrationTestsConfiguration; -import org.springframework.data.gemfire.tests.util.FileSystemUtils; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; import example.geode.cache.EchoCacheLoader; @@ -88,89 +74,7 @@ public class AutoConfiguredSslIntegrationTests extends ForkingClientServerIntegr @BeforeClass public static void startGemFireServer() throws IOException { - startGemFireServer(GemFireServerConfiguration.class, javaxNetSslKeyStorePropertyFromClassPath()); - } - - private static String javaxNetSslKeyStorePropertyFromClassPath() { - - return String.format("-Djavax.net.ssl.keyStore=%s", locateKeyStoreInClassPath() - .filter(StringUtils::hasText) - .orElseThrow(() -> newIllegalStateException("KeyStore file [%s] was not found", - TRUSTED_KEYSTORE_FILENAME))); - } - - private static String javaxNetSslKeyStorePropertyFromFileSystem() { - - return String.format("-Djavax.net.ssl.keyStore=%s", locateKeyStoreInFileSystem() - .map(File::getAbsolutePath) - .filter(StringUtils::hasText) - .orElseThrow(() -> newIllegalStateException("KeyStore file [%s] was not found", - TRUSTED_KEYSTORE_FILENAME))); - } - - private static Optional locateKeyStoreInClassPath() { - return locateKeyStoreInClassPath(TRUSTED_KEYSTORE_FILENAME); - } - - @SuppressWarnings("all") - private static Optional locateKeyStoreInClassPath(String keystoreName) { - - /* - System.err.printf("KEYSTORE LOCATION [%s]%n", ObjectUtils.doOperationSafely(() -> - new File(new ClassPathResource(keystoreName).getURL().toURI())).getAbsolutePath()); - */ - - return Optional.of(new ClassPathResource(keystoreName)) - .filter(Resource::exists) - .map(it -> ObjectUtils.doOperationSafely(() -> it.getURL())) - .map(url -> ObjectUtils.doOperationSafely(() -> url.toURI())) - .map(uri -> ObjectUtils.doOperationSafely(() -> new File(uri))) - .filter(File::isFile) - .map(File::getAbsolutePath); - } - - private static Optional locateKeyStoreInFileSystem() { - return locateKeyStoreInFileSystem(FileSystemUtils.WORKING_DIRECTORY); - } - - private static Optional locateKeyStoreInFileSystem(File directory) { - return locateKeyStoreInFileSystem(directory, TRUSTED_KEYSTORE_FILENAME); - } - - private static Optional locateKeyStoreInFileSystem(String keystoreFileName) { - return locateKeyStoreInFileSystem(FileSystemUtils.WORKING_DIRECTORY, keystoreFileName); - } - - @SuppressWarnings("all") - private static Optional locateKeyStoreInFileSystem(File directory, String keystoreFilename) { - - Assert.isTrue(directory != null && directory.isDirectory(), - String.format("[%s] is not a valid directory", directory)); - - //System.err.printf("Searching [%s]...%n", directory); - - for (File file : nullSafeArray(directory.listFiles(), File.class)) { - - //System.err.printf("Testing [%s]...%n", file); - - if (file.isDirectory()) { - - Optional theFile = locateKeyStoreInFileSystem(file, keystoreFilename); - - if (theFile.isPresent()) { - return theFile; - } - else { - continue; - } - } - - if (file.getName().equals(keystoreFilename)) { - return Optional.of(file); - } - } - - return Optional.empty(); + startGemFireServer(GemFireServerConfiguration.class, "-Dspring.profiles.active=ssl"); } @AfterClass @@ -216,27 +120,12 @@ public class AutoConfiguredSslIntegrationTests extends ForkingClientServerIntegr } } + @SpringBootApplication @CacheServerApplication(name = "AutoConfiguredSslIntegrationTests", logLevel = GEMFIRE_LOG_LEVEL) - @PropertySource(name = "gemfire-ssl", value = "application-ssl.properties") - @EnableSsl static class GemFireServerConfiguration { public static void main(String[] args) { - - AnnotationConfigApplicationContext applicationContext = - new AnnotationConfigApplicationContext(GemFireServerConfiguration.class); - - applicationContext.registerShutdownHook(); - } - - @Bean - PeerCacheConfigurer cacheServerSslConfigurer( - @Value("${javax.net.ssl.keyStore:trusted.keystore}") String keystoreLocation) { - - return (beanName, bean) -> { - bean.getProperties().setProperty("ssl-keystore", keystoreLocation); - bean.getProperties().setProperty("ssl-truststore", keystoreLocation); - }; + SpringApplication.run(GemFireServerConfiguration.class); } @Bean("Echo")