diff --git a/spring-geode-samples/boot/configuration/src/test/java/example/app/crm/CustomerServiceApplicationIntegrationTests.java b/spring-geode-samples/boot/configuration/src/test/java/example/app/crm/CustomerServiceApplicationIntegrationTests.java index a70c2cb8..212f62cd 100644 --- a/spring-geode-samples/boot/configuration/src/test/java/example/app/crm/CustomerServiceApplicationIntegrationTests.java +++ b/spring-geode-samples/boot/configuration/src/test/java/example/app/crm/CustomerServiceApplicationIntegrationTests.java @@ -28,6 +28,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import example.app.crm.model.Customer; @@ -41,12 +42,14 @@ import example.app.crm.repo.CustomerRepository; * @see org.apache.geode.cache.Region * @see org.springframework.boot.test.context.SpringBootTest * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.test.context.ActiveProfiles * @see org.springframework.test.context.junit4.SpringRunner * @see example.app.crm.model.Customer * @see example.app.crm.repo.CustomerRepository * @since 1.1.0 */ // tag::class[] +@ActiveProfiles("debug") @RunWith(SpringRunner.class) @SpringBootTest @SuppressWarnings("unused") diff --git a/spring-geode-samples/boot/configuration/src/test/java/example/app/crm/support/GemFireDebugConfiguration.java b/spring-geode-samples/boot/configuration/src/test/java/example/app/crm/support/GemFireDebugConfiguration.java new file mode 100644 index 00000000..ff68327e --- /dev/null +++ b/spring-geode-samples/boot/configuration/src/test/java/example/app/crm/support/GemFireDebugConfiguration.java @@ -0,0 +1,93 @@ +/* + * Copyright 2019 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 + * + * https://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 example.app.crm.support; + +import java.util.Arrays; +import java.util.Optional; + +import org.apache.geode.cache.GemFireCache; +import org.apache.geode.distributed.internal.InternalDistributedSystem; +import org.apache.geode.internal.admin.SSLConfig; +import org.apache.geode.internal.net.SSLConfigurationFactory; +import org.apache.geode.internal.security.SecurableCommunicationChannel; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.data.gemfire.util.ArrayUtils; +import org.springframework.lang.Nullable; + +/** + * Debug {@link Configuration} for Apache Geode based Spring Boot Tests. + * + * @author John Blum + * @see org.slf4j.Logger + * @see org.springframework.beans.factory.config.BeanPostProcessor + * @see org.springframework.context.annotation.Bean + * @see org.springframework.context.annotation.Configuration + * @see org.springframework.context.annotation.Profile + * @since 1.2.0 + */ +@Configuration +@Profile("debug") +@SuppressWarnings("unused") +public class GemFireDebugConfiguration { + + private static final Logger logger = LoggerFactory.getLogger(GemFireDebugConfiguration.class); + + @Bean + public BeanPostProcessor gemfireCacheSslConfigurationBeanPostProcessor() { + + return new BeanPostProcessor() { + + @Nullable @Override + public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { + + Optional.ofNullable(bean) + .filter(GemFireCache.class::isInstance) + .map(GemFireCache.class::cast) + .map(GemFireCache::getDistributedSystem) + .filter(InternalDistributedSystem.class::isInstance) + .map(InternalDistributedSystem.class::cast) + .map(InternalDistributedSystem::getConfig) + .ifPresent(distributionConfig -> { + + SecurableCommunicationChannel[] securableCommunicationChannels = + ArrayUtils.nullSafeArray(distributionConfig.getSecurableCommunicationChannels(), + SecurableCommunicationChannel.class); + + logger.error("SECURABLE COMMUNICATION CHANNELS {}", + Arrays.toString(securableCommunicationChannels)); + + Arrays.stream(securableCommunicationChannels).forEach(securableCommunicationChannel -> { + + SSLConfig sslConfig = SSLConfigurationFactory + .getSSLConfigForComponent(distributionConfig, securableCommunicationChannel); + + logger.error("{} SSL CONFIGURATION [{}]", securableCommunicationChannel.name(), sslConfig); + }); + }); + + return bean; + } + }; + } +}