Add integration test testing auto-configuration of Apache Geode/Pivotal GemFire Security in a cloud, managed environemnt.
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright 2018 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.boot.data.geode.security.auth.cloud;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.data.geode.autoconfigure.SslAutoConfiguration;
|
||||
import org.springframework.boot.data.geode.security.auth.AbstractAutoConfiguredSecurityContextIntegrationTests;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.data.gemfire.config.annotation.CacheServerApplication;
|
||||
import org.springframework.data.gemfire.config.annotation.EnableLocator;
|
||||
import org.springframework.data.gemfire.config.annotation.EnableLogging;
|
||||
import org.springframework.data.gemfire.config.annotation.EnableSecurity;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Integration test testing the auto-configuration of Apache Geode/Pivotal GemFire Security
|
||||
* authentication/authorization in a cloud, managed context (e.g. Pivotal CloudFoundry)
|
||||
*
|
||||
* @author John Blum
|
||||
* @see java.security.Principal
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.cache.GemFireCache
|
||||
* @see org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
* @see org.springframework.boot.data.geode.autoconfigure.SecurityAutoConfiguration
|
||||
* @see org.springframework.boot.data.geode.security.auth.AbstractAutoConfiguredSecurityContextIntegrationTests
|
||||
* @see org.springframework.boot.test.context.SpringBootTest
|
||||
* @see org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
* @see org.springframework.data.gemfire.config.annotation.CacheServerApplication
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableLocator
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableSecurity
|
||||
* @see org.springframework.test.context.ActiveProfiles
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = AutoConfiguredCloudSecurityContextIntegrationTests.GemFireClientConfiguration.class,
|
||||
webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
@SuppressWarnings("unused")
|
||||
public class AutoConfiguredCloudSecurityContextIntegrationTests
|
||||
extends AbstractAutoConfiguredSecurityContextIntegrationTests {
|
||||
|
||||
private static final String VCAP_APPLICATION_PROPERTIES = "application-vcap.properties";
|
||||
private static final String GEMFIRE_LOG_LEVEL = "error";
|
||||
|
||||
public static void loadVcapApplicationProperties() throws IOException {
|
||||
|
||||
Properties vcapApplicationProperties = new Properties();
|
||||
|
||||
vcapApplicationProperties.load(new ClassPathResource(VCAP_APPLICATION_PROPERTIES).getInputStream());
|
||||
|
||||
vcapApplicationProperties.stringPropertyNames()
|
||||
.forEach(property -> System.setProperty(property, vcapApplicationProperties.getProperty(property)));
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void startGemFireServer() throws IOException {
|
||||
startGemFireServer(GemFireServerConfiguration.class);
|
||||
loadVcapApplicationProperties();
|
||||
}
|
||||
|
||||
@EnableLogging(logLevel = GEMFIRE_LOG_LEVEL)
|
||||
@SpringBootApplication(exclude = SslAutoConfiguration.class)
|
||||
static class GemFireClientConfiguration extends BaseGemFireClientConfiguration { }
|
||||
|
||||
@CacheServerApplication(name = "AutoConfiguredCloudSecurityContextIntegrationTests", logLevel = GEMFIRE_LOG_LEVEL,
|
||||
useBeanFactoryLocator = true)
|
||||
@EnableLocator(port = 55221)
|
||||
@EnableSecurity(securityManagerClassName =
|
||||
"org.springframework.boot.data.geode.security.support.SecurityManagerProxy")
|
||||
@PropertySource(name = "security-cloud", value = "application-security-cloud.properties")
|
||||
static class GemFireServerConfiguration extends BaseGemFireServerConfiguration {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
AnnotationConfigApplicationContext applicationContext =
|
||||
new AnnotationConfigApplicationContext(GemFireServerConfiguration.class);
|
||||
|
||||
applicationContext.registerShutdownHook();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
# Spring Boot application.properties for testing security in a cloud context.
|
||||
|
||||
vcap.application.application_id=c50bb519-2739-4fa3-8750-02c051e35735
|
||||
vcap.application.application_name=boot-test
|
||||
vcap.application.application_uris=boot-test.apps.tunis.cf-app.com
|
||||
vcap.application.application_uris[0]=boot-test.apps.tunis.cf-app.com
|
||||
vcap.application.cf_api=https://api.sys.tunis.cf-app.com
|
||||
vcap.application.host=0.0.0.0
|
||||
vcap.application.instance_id=babcf301-3b34-4dcf-720e-ccfc
|
||||
vcap.application.instance_index=0
|
||||
vcap.application.limits.disk=1024
|
||||
vcap.application.limits.fds=16384
|
||||
vcap.application.limits.mem=1024
|
||||
vcap.application.name=boot-test
|
||||
vcap.application.port=8080
|
||||
vcap.application.space_id=271cf083-7855-4b5e-be19-65342d099099
|
||||
vcap.application.space_name=jblum-space
|
||||
vcap.application.uris=boot-test.apps.tunis.cf-app.com
|
||||
vcap.application.uris[0]=boot-test.apps.tunis.cf-app.com
|
||||
vcap.application.version=d34bbbbd-c35c-4057-baf2-6300cb9aa2aa
|
||||
vcap.application.application_version=d34bbbbd-c35c-4057-baf2-6300cb9aa2aa
|
||||
|
||||
vcap.services.jblum-pcc.credentials.distributed_system_id=0
|
||||
vcap.services.jblum-pcc.credentials.locators=localhost[55221]
|
||||
vcap.services.jblum-pcc.credentials.locators[0]=10.0.8.19[55221]
|
||||
vcap.services.jblum-pcc.credentials.locators[1]=10.0.8.21[55221]
|
||||
vcap.services.jblum-pcc.credentials.locators[2]=10.0.8.20[55221]
|
||||
#vcap.services.jblum-pcc.credentials.urls.gfsh=http://cloudcache-9defb33a-6b8b-49f0-bd35-cf6f7b2f222f.sys.tunis.cf-app.com/gemfire/v1
|
||||
vcap.services.jblum-pcc.credentials.urls.pulse=http://cloudcache-9defb33a-6b8b-49f0-bd35-cf6f7b2f222f.sys.tunis.cf-app.com/pulse
|
||||
vcap.services.jblum-pcc.credentials.users={password=vaxAi8UuJkBp9csgDvJ5YA, roles=[cluster_operator], username=cluster_operator_CQhqoDaEIT1gobjLryfpBg},{password=egSyyyaM5Q5yUMOVZD6pXA, roles=[developer], username=developer_krCFKddILf8EfWs0laUQ}
|
||||
vcap.services.jblum-pcc.credentials.users[0].username=cluster_operator_CQhqoDaEIT1gobjLryfpBg
|
||||
vcap.services.jblum-pcc.credentials.users[0].password=vaxAi8UuJkBp9csgDvJ5YA
|
||||
vcap.services.jblum-pcc.credentials.users[0].roles=cluster_operator
|
||||
vcap.services.jblum-pcc.credentials.users[0].roles[0]=cluster_operator
|
||||
vcap.services.jblum-pcc.credentials.users[1].username=developer_krCFKddILf8EfWs0laUQ
|
||||
vcap.services.jblum-pcc.credentials.users[1].password=egSyyyaM5Q5yUMOVZD6pXA
|
||||
vcap.services.jblum-pcc.credentials.users[1].roles=developer
|
||||
vcap.services.jblum-pcc.credentials.users[1].roles[0]=developer
|
||||
vcap.services.jblum-pcc.credentials.wan.sender_credentials.active.username=gateway_sender_UJ0YO1pJBEnQP03yt7sVXQ
|
||||
vcap.services.jblum-pcc.credentials.wan.sender_credentials.active.password=tYHFwByaMN675FuBWDZQiQ
|
||||
vcap.services.jblum-pcc.label=p-cloudcache
|
||||
vcap.services.jblum-pcc.name=jblum-pcc
|
||||
vcap.services.jblum-pcc.plan=small
|
||||
vcap.services.jblum-pcc.provider=
|
||||
vcap.services.jblum-pcc.syslog_drain_url=
|
||||
vcap.services.jblum-pcc.tags=gemfire,cloudcache,database,pivotal
|
||||
vcap.services.jblum-pcc.tags[0]=gemfire
|
||||
vcap.services.jblum-pcc.tags[1]=cloudcache
|
||||
vcap.services.jblum-pcc.tags[2]=database
|
||||
vcap.services.jblum-pcc.tags[3]=pivotal
|
||||
vcap.services.jblum-pcc.volume_mounts=
|
||||
|
||||
security.context.username.property=${vcap.services.jblum-pcc.credentials.users[0].username}
|
||||
security.context.password.property=${vcap.services.jblum-pcc.credentials.users[0].password}
|
||||
@@ -0,0 +1,4 @@
|
||||
# Spring Boot application.properties for testing security in a Pivotal CloudFoundry (PCF) context.
|
||||
|
||||
VCAP_APPLICATION={"application_id":"c50bb519-2739-4fa3-8750-02c051e35735","application_name":"boot-test","application_uris":["boot-example.apps.tunis.cf-app.com"],"application_version":"d34bbbbd-c35c-4057-baf2-6300cb9aa2aa","cf_api":"https://api.sys.tunis.cf-app.com","host":"0.0.0.0","instance_id":"babcf301-3b34-4dcf-720e-ccfc","instance_index":0,"limits":{"disk":1024,"fds":16384,"mem":1024},"name":"boot-example","port":8080,"space_id":"271cf083-7855-4b5e-be19-65342d099099","space_name":"jblum-space","uris":["boot-example.apps.tunis.cf-app.com"],"version":"d34bbbbd-c35c-4057-baf2-6300cb9aa2aa"}
|
||||
VCAP_SERVICES={"p-cloudcache":[{ "credentials": { "distributed_system_id": "0", "locators": [ "localhost[55221]" ], "urls": { "pulse": "http://cloudcache-9defb33a-6b8b-49f0-bd35-cf6f7b2f222f.sys.tunis.cf-app.com/pulse" }, "users": [ { "password": "vaxAi8UuJkBp9csgDvJ5YA", "roles": [ "cluster_operator" ], "username": "cluster_operator_CQhqoDaEIT1gobjLryfpBg" }, { "password": "egSyyyaM5Q5yUMOVZD6pXA", "roles": [ "developer" ], "username": "developer_krCFKddILf8EfWs0laUQ" } ], "wan": { "sender_credentials": { "active": { "password": "tYHFwByaMN675FuBWDZQiQ", "username": "gateway_sender_UJ0YO1pJBEnQP03yt7sVXQ" } } } }, "syslog_drain_url": null, "volume_mounts": [ ], "label": "p-cloudcache", "provider": null, "plan": "small", "name": "jblum-pcc", "tags": [ "gemfire", "cloudcache", "database", "pivotal" ] }]}
|
||||
Reference in New Issue
Block a user