Log Apache Geode SSL configuration and state at 'error'.

This commit is contained in:
John Blum
2019-09-09 19:56:23 -07:00
parent 202e59b9d2
commit e7f99fd1e5
2 changed files with 96 additions and 0 deletions

View File

@@ -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")

View File

@@ -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;
}
};
}
}