diff --git a/spring-geode-autoconfigure/src/main/java/org/springframework/geode/boot/autoconfigure/ClientSecurityAutoConfiguration.java b/spring-geode-autoconfigure/src/main/java/org/springframework/geode/boot/autoconfigure/ClientSecurityAutoConfiguration.java index 991d6ff5..26a70aed 100644 --- a/spring-geode-autoconfigure/src/main/java/org/springframework/geode/boot/autoconfigure/ClientSecurityAutoConfiguration.java +++ b/spring-geode-autoconfigure/src/main/java/org/springframework/geode/boot/autoconfigure/ClientSecurityAutoConfiguration.java @@ -105,6 +105,7 @@ public class ClientSecurityAutoConfiguration { private static final String MANAGEMENT_HTTP_HOST_PROPERTY = "spring.data.gemfire.management.http.host"; private static final String MANAGEMENT_HTTP_PORT_PROPERTY = "spring.data.gemfire.management.http.port"; + private static final String MANAGEMENT_REQUIRE_HTTPS_PROPERTY = "spring.data.gemfire.management.require-https"; private static final String MANAGEMENT_USE_HTTP_PROPERTY = "spring.data.gemfire.management.use-http"; private static final String POOL_LOCATORS_PROPERTY = "spring.data.gemfire.pool.locators"; @@ -206,6 +207,7 @@ public class ClientSecurityAutoConfiguration { cloudCacheService.getGfshUrl().ifPresent(url -> { cloudCacheProperties.setProperty(MANAGEMENT_USE_HTTP_PROPERTY, Boolean.TRUE.toString()); cloudCacheProperties.setProperty(MANAGEMENT_HTTP_HOST_PROPERTY, url.getHost()); + cloudCacheProperties.setProperty(MANAGEMENT_REQUIRE_HTTPS_PROPERTY, Boolean.TRUE.toString()); cloudCacheProperties.setProperty(MANAGEMENT_HTTP_PORT_PROPERTY, String.valueOf(url.getPort())); }); } diff --git a/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/cluster/ClusterConfigurationWithAuthenticationIntegrationTests.java b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/cluster/ClusterConfigurationWithAuthenticationIntegrationTests.java index 107fa8ee..4891979c 100644 --- a/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/cluster/ClusterConfigurationWithAuthenticationIntegrationTests.java +++ b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/cluster/ClusterConfigurationWithAuthenticationIntegrationTests.java @@ -114,9 +114,9 @@ public class ClusterConfigurationWithAuthenticationIntegrationTests extends Fork } @SpringBootApplication + @EnableClusterConfiguration(useHttp = true) @EnableLogging(logLevel = GEMFIRE_LOG_LEVEL) @EnableEntityDefinedRegions(basePackageClasses = Book.class) - @EnableClusterConfiguration(useHttp = true) static class GeodeClientConfiguration { } @SpringBootApplication diff --git a/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/cluster/ClusterConfigurationWithClusterAwareWhenNonSecureClusterAvailableIntegrationTests.java b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/cluster/ClusterConfigurationWithClusterAwareWhenNonSecureClusterAvailableIntegrationTests.java new file mode 100644 index 00000000..1b7848a2 --- /dev/null +++ b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/cluster/ClusterConfigurationWithClusterAwareWhenNonSecureClusterAvailableIntegrationTests.java @@ -0,0 +1,84 @@ +/* + * 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 org.springframework.geode.boot.autoconfigure.cluster; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.core.env.Environment; +import org.springframework.data.gemfire.config.annotation.ClusterConfigurationConfiguration; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; +import org.springframework.geode.config.annotation.EnableClusterAware; +import org.springframework.geode.core.util.ObjectUtils; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * Integration Tests for testing the {@link EnableClusterAware} annotation and expected configuration applied by SBDG + * when the Apache Geode cluster is NOT secure. + * + * @author John Blum + * @see org.junit.Test + * @see org.springframework.boot.autoconfigure.SpringBootApplication + * @see org.springframework.boot.test.context.SpringBootTest + * @see org.springframework.core.env.Environment + * @see org.springframework.data.gemfire.config.annotation.ClusterConfigurationConfiguration + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.geode.config.annotation.EnableClusterAware + * @see org.springframework.test.context.junit4.SpringRunner + * @since 1.2.0 + */ +@RunWith(SpringRunner.class) +@SpringBootTest( + webEnvironment = SpringBootTest.WebEnvironment.NONE, + properties = { "spring.boot.data.gemfire.cluster.condition.match=true" } +) +@SuppressWarnings("unused") +public class ClusterConfigurationWithClusterAwareWhenNonSecureClusterAvailableIntegrationTests + extends IntegrationTestsSupport { + + @Autowired + private Environment environment; + + @Autowired + private ClusterConfigurationConfiguration configuration; + + @Test + public void configurationStatesManagementRestApiRequiresHttps() { + + boolean configurationRequiresHttps = + ObjectUtils.invoke(this.configuration, "resolveManagementRequireHttps"); + + assertThat(configurationRequiresHttps).isFalse(); + } + + @Test + public void environmentStatesManagementRestApiRequiresHttps() { + assertThat(this.environment.containsProperty("spring.data.gemfire.management.require-https")).isFalse(); + } + + @SpringBootApplication + @EnableClusterAware + @EnableGemFireMockObjects + static class TestConfiguration { } + +} diff --git a/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/cluster/ClusterConfigurationWithClusterAwareWhenSecureClusterAvailableIntegrationTests.java b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/cluster/ClusterConfigurationWithClusterAwareWhenSecureClusterAvailableIntegrationTests.java new file mode 100644 index 00000000..3c8e63cd --- /dev/null +++ b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/cluster/ClusterConfigurationWithClusterAwareWhenSecureClusterAvailableIntegrationTests.java @@ -0,0 +1,89 @@ +/* + * 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 org.springframework.geode.boot.autoconfigure.cluster; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.core.env.Environment; +import org.springframework.data.gemfire.config.annotation.ClusterConfigurationConfiguration; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; +import org.springframework.geode.config.annotation.EnableClusterAware; +import org.springframework.geode.core.util.ObjectUtils; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * Integration Tests for testing the {@link EnableClusterAware} annotation and expected configuration applied by SBDG + * when the Apache Geode cluster is secure. + * + * @author John Blum + * @see org.junit.Test + * @see org.springframework.boot.autoconfigure.SpringBootApplication + * @see org.springframework.boot.test.context.SpringBootTest + * @see org.springframework.core.env.Environment + * @see org.springframework.data.gemfire.config.annotation.ClusterConfigurationConfiguration + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.geode.config.annotation.EnableClusterAware + * @see org.springframework.test.context.junit4.SpringRunner + * @since 1.2.0 + */ +@RunWith(SpringRunner.class) +@SpringBootTest( + webEnvironment = SpringBootTest.WebEnvironment.NONE, + properties = { + "VCAP_APPLICATION={ \"name\" : \"ClusterConfigurationWithClusterAwareWhenSecureClusterAvailableIntegrationTests\", \"uris\" : \"myapp.app.cloud.skullbox.com\"}", + "VCAP_SERVICES={ \"test-pcc\" : [{ \"name\" : \"test-pcc\", \"tags\" : \"cloudcache,database,gemfire,pivotal\", \"credentials\" : { \"urls\" : { \"gfsh\" : \"https://myapp.app.cloud.skullbox.com/gemfire/v1\" }}}]}", + "spring.boot.data.gemfire.cluster.condition.match=true" + } +) +@SuppressWarnings("unused") +public class ClusterConfigurationWithClusterAwareWhenSecureClusterAvailableIntegrationTests + extends IntegrationTestsSupport { + + @Autowired + private Environment environment; + + @Autowired + private ClusterConfigurationConfiguration configuration; + + @Test + public void configurationStatesManagementRestApiRequiresHttps() { + + boolean configurationRequiresHttps = + ObjectUtils.invoke(this.configuration, "resolveManagementRequireHttps"); + + assertThat(configurationRequiresHttps).isTrue(); + } + + @Test + public void environmentStatesManagementRestApiRequiresHttps() { + assertThat(this.environment.getProperty("spring.data.gemfire.management.require-https", Boolean.class)) + .isTrue(); + } + + @SpringBootApplication + @EnableClusterAware + @EnableGemFireMockObjects + static class TestConfiguration { } + +} diff --git a/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/security/auth/ClientSecurityAutoConfigurationUnitTests.java b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/security/auth/ClientSecurityAutoConfigurationUnitTests.java index 5c4d946a..65c4aee5 100644 --- a/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/security/auth/ClientSecurityAutoConfigurationUnitTests.java +++ b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/security/auth/ClientSecurityAutoConfigurationUnitTests.java @@ -141,7 +141,7 @@ public class ClientSecurityAutoConfigurationUnitTests { } @Test - public void clientSecurityIsDisabledWhenEnablePropertyIsTrueAndCloudFoundryIsInactive() { + public void clientSecurityIsDisabledWhenEnablePropertyIsTrueAndCloudFoundryIsNotActive() { AutoConfiguredCloudSecurityEnvironmentPostProcessor environmentPostProcessor = spy(new AutoConfiguredCloudSecurityEnvironmentPostProcessor()); @@ -167,6 +167,30 @@ public class ClientSecurityAutoConfigurationUnitTests { verify(environmentPostProcessor, never()).configureSecurityContext(eq(mockEnvironment)); } + @Test + public void clientSecurityIsDisabledWhenEnablePropertyIsUnsetAndCloudFoundryIsNotActive() { + + AutoConfiguredCloudSecurityEnvironmentPostProcessor environmentPostProcessor = + spy(new AutoConfiguredCloudSecurityEnvironmentPostProcessor()); + + doNothing().when(environmentPostProcessor).configureSecurityContext(any(ConfigurableEnvironment.class)); + + ConfigurableEnvironment mockEnvironment = spy(new StandardEnvironment()); + + doReturn(false).when(mockEnvironment).containsProperty(eq("VCAP_APPLICATION")); + doReturn(false).when(mockEnvironment).containsProperty(eq("VCAP_SERVICES")); + + environmentPostProcessor.postProcessEnvironment(mockEnvironment, null); + + verify(mockEnvironment, times(1)) + .getProperty(eq(ClientSecurityAutoConfiguration.CLOUD_SECURITY_ENVIRONMENT_POST_PROCESSOR_ENABLED_PROPERTY), + eq(Boolean.class), eq(true)); + + verify(mockEnvironment, times(1)).containsProperty(eq("VCAP_APPLICATION")); + verify(mockEnvironment, times(1)).containsProperty(eq("VCAP_SERVICES")); + verify(environmentPostProcessor, never()).configureSecurityContext(eq(mockEnvironment)); + } + @Test public void configuresSecurityContext() { @@ -214,6 +238,7 @@ public class ClientSecurityAutoConfigurationUnitTests { assertThat(propertySource.getProperty("spring.data.gemfire.pool.locators")) .isEqualTo("boombox[10334],skullbox[10334]"); assertThat(propertySource.getProperty("spring.data.gemfire.management.use-http")).isEqualTo("true"); + assertThat(propertySource.getProperty("spring.data.gemfire.management.require-https")).isEqualTo("true"); assertThat(propertySource.getProperty("spring.data.gemfire.management.http.host")).isEqualTo("cloud.skullbox.com"); assertThat(propertySource.getProperty("spring.data.gemfire.management.http.port")).isEqualTo("8080"); } @@ -266,6 +291,7 @@ public class ClientSecurityAutoConfigurationUnitTests { assertThat(propertySource.getProperty("spring.data.gemfire.pool.locators")) .isEqualTo("boombox[10334],skullbox[10334]"); assertThat(propertySource.containsProperty("spring.data.gemfire.management.use-http")).isFalse(); + assertThat(propertySource.containsProperty("spring.data.gemfire.management.require-https")).isFalse(); assertThat(propertySource.containsProperty("spring.data.gemfire.management.http.host")).isFalse(); assertThat(propertySource.containsProperty("spring.data.gemfire.management.http.port")).isFalse(); }