Updates for Finchley and boot 2.0
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-cloudfoundry</artifactId>
|
||||
<version>1.1.1.BUILD-SNAPSHOT</version>
|
||||
<version>2.0.0.BUILD-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-cloudfoundry-docs</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
12
pom.xml
12
pom.xml
@@ -4,21 +4,21 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>spring-cloud-cloudfoundry</artifactId>
|
||||
<version>1.1.1.BUILD-SNAPSHOT</version>
|
||||
<version>2.0.0.BUILD-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-build</artifactId>
|
||||
<version>1.3.1.BUILD-SNAPSHOT</version>
|
||||
<version>2.0.0.BUILD-SNAPSHOT</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<bintray.package>cloudfoundry</bintray.package>
|
||||
<main.basedir>${basedir}</main.basedir>
|
||||
<spring-cloud-netflix.version>1.3.0.BUILD-SNAPSHOT</spring-cloud-netflix.version>
|
||||
<spring-cloud-commons.version>1.2.0.BUILD-SNAPSHOT</spring-cloud-commons.version>
|
||||
<spring-cloud-netflix.version>2.0.0.BUILD-SNAPSHOT</spring-cloud-netflix.version>
|
||||
<spring-cloud-commons.version>2.0.0.BUILD-SNAPSHOT</spring-cloud-commons.version>
|
||||
</properties>
|
||||
|
||||
<scm>
|
||||
@@ -47,8 +47,8 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
<parent>
|
||||
<artifactId>spring-cloud-dependencies-parent</artifactId>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<version>1.3.1.BUILD-SNAPSHOT</version>
|
||||
<version>2.0.0.BUILD-SNAPSHOT</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-cloudfoundry-dependencies</artifactId>
|
||||
<version>1.1.1.BUILD-SNAPSHOT</version>
|
||||
<version>2.0.0.BUILD-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>spring-cloud-cloudfoundry-dependencies</name>
|
||||
<description>Spring Cloud Cloudfoundry Dependencies</description>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-cloudfoundry</artifactId>
|
||||
<version>1.1.1.BUILD-SNAPSHOT</version>
|
||||
<version>2.0.0.BUILD-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-cloudfoundry</artifactId>
|
||||
<version>1.1.1.BUILD-SNAPSHOT</version>
|
||||
<version>2.0.0.BUILD-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<build>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-cloudfoundry</artifactId>
|
||||
<version>1.1.1.BUILD-SNAPSHOT</version>
|
||||
<version>2.0.0.BUILD-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -15,16 +15,19 @@
|
||||
*/
|
||||
package org.springframework.cloud.cloudfoundry.environment;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.bind.RelaxedPropertyResolver;
|
||||
import org.springframework.boot.context.config.ConfigFileApplicationListener;
|
||||
import org.springframework.boot.context.properties.bind.Bindable;
|
||||
import org.springframework.boot.context.properties.bind.Binder;
|
||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.core.env.PropertyResolver;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -34,6 +37,9 @@ import org.springframework.util.StringUtils;
|
||||
public class VcapServiceCredentialsEnvironmentPostProcessor
|
||||
implements EnvironmentPostProcessor, Ordered {
|
||||
|
||||
static final Bindable<Map<String, Object>> STRING_OBJECT_MAP = Bindable
|
||||
.mapOf(String.class, Object.class);
|
||||
|
||||
// After VcapEnvironmentPostProcessor and ConfigFileEnvironmentPostProcessor so
|
||||
// values here can
|
||||
// use those ones
|
||||
@@ -47,43 +53,42 @@ implements EnvironmentPostProcessor, Ordered {
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment,
|
||||
SpringApplication application) {
|
||||
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment);
|
||||
Map<String, Object> properties = resolver.getSubProperties("vcap.services.");
|
||||
if (properties == null || properties.isEmpty()) {
|
||||
Map<String, Object> properties = Binder.get(environment)
|
||||
.bind("vcap.services", STRING_OBJECT_MAP).orElseGet(Collections::emptyMap);
|
||||
if (!hasChildProperties(environment, "vcap.services")) {
|
||||
return;
|
||||
}
|
||||
Map<String, Object> source = new HashMap<String, Object>();
|
||||
Map<String, Object> source = new HashMap<>();
|
||||
String serviceId;
|
||||
if (!resolver.getSubProperties("security.oauth2.resource.").isEmpty()) {
|
||||
serviceId = resolver.getProperty("security.oauth2.resource.serviceId",
|
||||
if (hasChildProperties(environment, "security.oauth2.resource")) {
|
||||
serviceId = environment.getProperty("security.oauth2.resource.service-id",
|
||||
"resource");
|
||||
}
|
||||
else {
|
||||
serviceId = resolver.getProperty("security.oauth2.sso.serviceId", "sso");
|
||||
serviceId = environment.getProperty("security.oauth2.sso.service-id", "sso");
|
||||
}
|
||||
String authDomain = (String) properties
|
||||
.get(serviceId + ".credentials.auth_domain");
|
||||
String authDomain = environment.getProperty("vcap.services." +serviceId + ".credentials.auth-domain");
|
||||
if (authDomain != null) {
|
||||
source.put("security.oauth2.resource.userInfoUri",
|
||||
source.put("security.oauth2.resource.user-info-uri",
|
||||
authDomain + "/userinfo");
|
||||
source.put("security.oauth2.resource.jwt.keyUri", authDomain + "/token_key");
|
||||
source.put("security.oauth2.client.accessTokenUri",
|
||||
source.put("security.oauth2.resource.jwt.key-uri", authDomain + "/token_key");
|
||||
source.put("security.oauth2.client.access-token-uri",
|
||||
authDomain + "/oauth/token");
|
||||
source.put("security.oauth2.client.userAuthorizationUri",
|
||||
source.put("security.oauth2.client.user-authorization-uri",
|
||||
authDomain + "/oauth/authorize");
|
||||
}
|
||||
else {
|
||||
addProperty(source, resolver, serviceId, "resource", "userInfoUri");
|
||||
addProperty(source, resolver, serviceId, "resource", "tokenInfoUri");
|
||||
addProperty(source, resolver, serviceId, "resource.jwt", "keyUri");
|
||||
addProperty(source, resolver, serviceId, "resource", "keyValue");
|
||||
addProperty(source, resolver, serviceId, "client", "accessTokenUri", "tokenUri");
|
||||
addProperty(source, resolver, serviceId, "client", "userAuthorizationUri", "authorizationUri");
|
||||
addProperty(source, environment, serviceId, "resource", "user-info-uri");
|
||||
addProperty(source, environment, serviceId, "resource", "token-info-uri");
|
||||
addProperty(source, environment, serviceId, "resource.jwt", "key-uri");
|
||||
addProperty(source, environment, serviceId, "resource", "key-value");
|
||||
addProperty(source, environment, serviceId, "client", "access-token-uri", "token-uri");
|
||||
addProperty(source, environment, serviceId, "client", "user-authorization-uri", "authorization-uri");
|
||||
}
|
||||
addProperty(source, resolver, serviceId, "client", "clientId");
|
||||
addProperty(source, resolver, serviceId, "client", "clientSecret");
|
||||
addProperty(source, resolver, serviceId, "client", "scope");
|
||||
String resourceId = resolver
|
||||
addProperty(source, environment, serviceId, "client", "client-id");
|
||||
addProperty(source, environment, serviceId, "client", "client-secret");
|
||||
addProperty(source, environment, serviceId, "client", "scope");
|
||||
String resourceId = environment
|
||||
.getProperty("vcap.services." + serviceId + ".credentials.id", "");
|
||||
if (StringUtils.hasText(resourceId)) {
|
||||
source.put("security.oauth2.resource.id", resourceId);
|
||||
@@ -92,8 +97,14 @@ implements EnvironmentPostProcessor, Ordered {
|
||||
.addLast(new MapPropertySource("cloudDefaultSecurityBindings", source));
|
||||
}
|
||||
|
||||
private boolean hasChildProperties(ConfigurableEnvironment environment, String name) {
|
||||
Map<String, Object> properties = Binder.get(environment)
|
||||
.bind(name, STRING_OBJECT_MAP).orElseGet(Collections::emptyMap);
|
||||
return !properties.isEmpty();
|
||||
}
|
||||
|
||||
private void addProperty(Map<String, Object> source,
|
||||
RelaxedPropertyResolver resolver, String serviceId, String stem, String key, String... altKeys) {
|
||||
PropertyResolver resolver, String serviceId, String stem, String key, String... altKeys) {
|
||||
String value = resolve(resolver, serviceId, key);
|
||||
if (StringUtils.hasText(value)) {
|
||||
source.put("security.oauth2."+stem+"." + key, value);
|
||||
@@ -108,7 +119,7 @@ implements EnvironmentPostProcessor, Ordered {
|
||||
}
|
||||
}
|
||||
|
||||
private String resolve(RelaxedPropertyResolver resolver, String serviceId,
|
||||
private String resolve(PropertyResolver resolver, String serviceId,
|
||||
String key) {
|
||||
return resolver.getProperty(
|
||||
String.format("vcap.services.%s.credentials.%s", serviceId, key),
|
||||
|
||||
@@ -15,18 +15,20 @@
|
||||
*/
|
||||
package org.springframework.cloud.cloudfoundry.environment;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.bind.RelaxedPropertyResolver;
|
||||
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
||||
import org.springframework.boot.context.properties.bind.Binder;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.cloud.cloudfoundry.environment.VcapServiceCredentialsEnvironmentPostProcessor.STRING_OBJECT_MAP;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
@@ -40,73 +42,66 @@ public class VcapServiceCredentialsEnvironmentPostProcessorTests {
|
||||
@Test
|
||||
public void noop() {
|
||||
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
|
||||
Map<String, Object> properties = new RelaxedPropertyResolver(this.environment)
|
||||
.getSubProperties("security.oauth2");
|
||||
assertTrue(properties == null || properties.isEmpty());
|
||||
Map<String, Object> properties = Binder.get(environment)
|
||||
.bind("security.oauth2", STRING_OBJECT_MAP).orElseGet(Collections::emptyMap);
|
||||
assertTrue(properties.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addClientId() {
|
||||
EnvironmentTestUtils.addEnvironment(this.environment,
|
||||
"vcap.services.sso.credentials.clientId:foo");
|
||||
TestPropertyValues.of("vcap.services.sso.credentials.clientId:foo").applyTo(this.environment);
|
||||
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
|
||||
assertEquals("foo", this.environment
|
||||
.resolvePlaceholders("${security.oauth2.client.clientId}"));
|
||||
.resolvePlaceholders("${security.oauth2.client.client-id}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addClientIdUnderscores() {
|
||||
EnvironmentTestUtils.addEnvironment(this.environment,
|
||||
"vcap.services.sso.credentials.client_id:foo");
|
||||
TestPropertyValues.of("vcap.services.sso.credentials.client-id:foo").applyTo(this.environment);
|
||||
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
|
||||
assertEquals("foo", this.environment
|
||||
.resolvePlaceholders("${security.oauth2.client.clientId}"));
|
||||
.resolvePlaceholders("${security.oauth2.client.client-id}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addTokenUri() {
|
||||
EnvironmentTestUtils.addEnvironment(this.environment,
|
||||
"vcap.services.sso.credentials.accessTokenUri:http://example.com");
|
||||
TestPropertyValues.of( "vcap.services.sso.credentials.accessTokenUri:http://example.com").applyTo(this.environment);
|
||||
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
|
||||
assertEquals("http://example.com", this.environment
|
||||
.resolvePlaceholders("${security.oauth2.client.accessTokenUri}"));
|
||||
.resolvePlaceholders("${security.oauth2.client.access-token-uri}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addTokenUriAuthDomain() {
|
||||
EnvironmentTestUtils.addEnvironment(this.environment,
|
||||
"vcap.services.sso.credentials.auth_domain:http://example.com");
|
||||
TestPropertyValues.of("vcap.services.sso.credentials.auth-domain:http://example.com").applyTo(this.environment);
|
||||
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
|
||||
assertEquals("http://example.com/oauth/token", this.environment
|
||||
.resolvePlaceholders("${security.oauth2.client.accessTokenUri}"));
|
||||
.resolvePlaceholders("${security.oauth2.client.access-token-uri}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addUserInfoUri() {
|
||||
EnvironmentTestUtils.addEnvironment(this.environment,
|
||||
"vcap.services.sso.credentials.userInfoUri:http://example.com");
|
||||
TestPropertyValues.of( "vcap.services.sso.credentials.userInfoUri:http://example.com").applyTo(this.environment);
|
||||
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
|
||||
assertEquals("http://example.com", this.environment
|
||||
.resolvePlaceholders("${security.oauth2.resource.userInfoUri}"));
|
||||
.resolvePlaceholders("${security.oauth2.resource.user-info-uri}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addServiceId() {
|
||||
EnvironmentTestUtils.addEnvironment(this.environment,
|
||||
"vcap.services.my.credentials.accessTokenUri:http://example.com",
|
||||
"security.oauth2.sso.serviceId:my");
|
||||
TestPropertyValues.of("vcap.services.my.credentials.accessTokenUri:http://example.com",
|
||||
"security.oauth2.sso.serviceId:my").applyTo(this.environment);
|
||||
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
|
||||
assertEquals("http://example.com", this.environment
|
||||
.resolvePlaceholders("${security.oauth2.client.accessTokenUri}"));
|
||||
.resolvePlaceholders("${security.oauth2.client.access-token-uri}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addJwtKeyUri() {
|
||||
EnvironmentTestUtils.addEnvironment(this.environment,
|
||||
"vcap.services.sso.credentials.keyUri:http://example.com");
|
||||
TestPropertyValues.of("vcap.services.sso.credentials.keyUri:http://example.com").applyTo(this.environment);
|
||||
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
|
||||
assertEquals("http://example.com", this.environment
|
||||
.resolvePlaceholders("${security.oauth2.resource.jwt.keyUri}"));
|
||||
.resolvePlaceholders("${security.oauth2.resource.jwt.key-uri}"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-cloudfoundry</artifactId>
|
||||
<version>1.1.1.BUILD-SNAPSHOT</version>
|
||||
<version>2.0.0.BUILD-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-starter-cloudfoundry</artifactId>
|
||||
|
||||
Reference in New Issue
Block a user