Bumping versions
This commit is contained in:
@@ -35,11 +35,9 @@ import org.springframework.util.StringUtils;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class VcapServiceCredentialsEnvironmentPostProcessor
|
||||
implements EnvironmentPostProcessor, Ordered {
|
||||
public class VcapServiceCredentialsEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered {
|
||||
|
||||
static final Bindable<Map<String, Object>> STRING_OBJECT_MAP = Bindable
|
||||
.mapOf(String.class, Object.class);
|
||||
static final Bindable<Map<String, Object>> STRING_OBJECT_MAP = Bindable.mapOf(String.class, Object.class);
|
||||
|
||||
// After VcapEnvironmentPostProcessor and ConfigFileEnvironmentPostProcessor so
|
||||
// values here can
|
||||
@@ -52,63 +50,52 @@ public class VcapServiceCredentialsEnvironmentPostProcessor
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment,
|
||||
SpringApplication application) {
|
||||
Binder.get(environment).bind("vcap.services", STRING_OBJECT_MAP)
|
||||
.orElseGet(Collections::emptyMap);
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||
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 serviceId;
|
||||
if (hasChildProperties(environment, "security.oauth2.resource")) {
|
||||
serviceId = environment.getProperty("security.oauth2.resource.service-id",
|
||||
"resource");
|
||||
serviceId = environment.getProperty("security.oauth2.resource.service-id", "resource");
|
||||
}
|
||||
else {
|
||||
serviceId = environment.getProperty("security.oauth2.sso.service-id", "sso");
|
||||
}
|
||||
String authDomain = environment
|
||||
.getProperty("vcap.services." + serviceId + ".credentials.auth-domain");
|
||||
String authDomain = environment.getProperty("vcap.services." + serviceId + ".credentials.auth-domain");
|
||||
if (authDomain != null) {
|
||||
source.put("security.oauth2.resource.user-info-uri",
|
||||
authDomain + "/userinfo");
|
||||
source.put("security.oauth2.resource.user-info-uri", authDomain + "/userinfo");
|
||||
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.user-authorization-uri",
|
||||
authDomain + "/oauth/authorize");
|
||||
source.put("security.oauth2.client.access-token-uri", authDomain + "/oauth/token");
|
||||
source.put("security.oauth2.client.user-authorization-uri", authDomain + "/oauth/authorize");
|
||||
}
|
||||
else {
|
||||
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, environment, serviceId, "client", "access-token-uri", "token-uri");
|
||||
addProperty(source, environment, serviceId, "client", "user-authorization-uri", "authorization-uri");
|
||||
}
|
||||
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", "");
|
||||
String resourceId = environment.getProperty("vcap.services." + serviceId + ".credentials.id", "");
|
||||
if (StringUtils.hasText(resourceId)) {
|
||||
source.put("security.oauth2.resource.id", resourceId);
|
||||
}
|
||||
environment.getPropertySources()
|
||||
.addLast(new MapPropertySource("cloudDefaultSecurityBindings", source));
|
||||
environment.getPropertySources().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);
|
||||
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, PropertyResolver resolver,
|
||||
String serviceId, String stem, String key, String... altKeys) {
|
||||
private void addProperty(Map<String, Object> source, 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);
|
||||
@@ -124,8 +111,7 @@ public class VcapServiceCredentialsEnvironmentPostProcessor
|
||||
}
|
||||
|
||||
private String resolve(PropertyResolver resolver, String serviceId, String key) {
|
||||
return resolver.getProperty(
|
||||
String.format("vcap.services.%s.credentials.%s", serviceId, key), "");
|
||||
return resolver.getProperty(String.format("vcap.services.%s.credentials.%s", serviceId, key), "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,12 +49,10 @@ public class StickyFilterConfiguration {
|
||||
filter.setOrder(Ordered.LOWEST_PRECEDENCE);
|
||||
filter.setFilter(new OncePerRequestFilter() {
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request,
|
||||
HttpServletResponse response, FilterChain filterChain)
|
||||
throws ServletException, IOException {
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
|
||||
FilterChain filterChain) throws ServletException, IOException {
|
||||
if (!response.containsHeader("Set-Cookie")) {
|
||||
response.addCookie(new Cookie("JSESSIONID",
|
||||
StickyFilterConfiguration.this.cookie));
|
||||
response.addCookie(new Cookie("JSESSIONID", StickyFilterConfiguration.this.cookie));
|
||||
}
|
||||
filterChain.doFilter(request, response);
|
||||
}
|
||||
|
||||
@@ -43,85 +43,67 @@ public class VcapServiceCredentialsEnvironmentPostProcessorTests {
|
||||
@Test
|
||||
public void noop() {
|
||||
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
|
||||
Map<String, Object> properties = Binder.get(this.environment)
|
||||
.bind("security.oauth2", STRING_OBJECT_MAP)
|
||||
Map<String, Object> properties = Binder.get(this.environment).bind("security.oauth2", STRING_OBJECT_MAP)
|
||||
.orElseGet(Collections::emptyMap);
|
||||
assertThat(properties.isEmpty()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addClientId() {
|
||||
TestPropertyValues.of("vcap.services.sso.credentials.clientId:foo")
|
||||
.applyTo(this.environment);
|
||||
TestPropertyValues.of("vcap.services.sso.credentials.clientId:foo").applyTo(this.environment);
|
||||
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
|
||||
assertThat(this.environment
|
||||
.resolvePlaceholders("${security.oauth2.client.client-id}"))
|
||||
.isEqualTo("foo");
|
||||
assertThat(this.environment.resolvePlaceholders("${security.oauth2.client.client-id}")).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addClientIdUnderscores() {
|
||||
TestPropertyValues.of("vcap.services.sso.credentials.client-id:foo")
|
||||
.applyTo(this.environment);
|
||||
TestPropertyValues.of("vcap.services.sso.credentials.client-id:foo").applyTo(this.environment);
|
||||
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
|
||||
assertThat(this.environment
|
||||
.resolvePlaceholders("${security.oauth2.client.client-id}"))
|
||||
.isEqualTo("foo");
|
||||
assertThat(this.environment.resolvePlaceholders("${security.oauth2.client.client-id}")).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addTokenUri() {
|
||||
TestPropertyValues
|
||||
.of("vcap.services.sso.credentials.accessTokenUri:http://exampledomain")
|
||||
TestPropertyValues.of("vcap.services.sso.credentials.accessTokenUri:http://exampledomain")
|
||||
.applyTo(this.environment);
|
||||
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
|
||||
assertThat(this.environment
|
||||
.resolvePlaceholders("${security.oauth2.client.access-token-uri}"))
|
||||
.isEqualTo("http://exampledomain");
|
||||
assertThat(this.environment.resolvePlaceholders("${security.oauth2.client.access-token-uri}"))
|
||||
.isEqualTo("http://exampledomain");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addTokenUriAuthDomain() {
|
||||
TestPropertyValues
|
||||
.of("vcap.services.sso.credentials.auth-domain:http://exampledomain")
|
||||
TestPropertyValues.of("vcap.services.sso.credentials.auth-domain:http://exampledomain")
|
||||
.applyTo(this.environment);
|
||||
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
|
||||
assertThat(this.environment
|
||||
.resolvePlaceholders("${security.oauth2.client.access-token-uri}"))
|
||||
.isEqualTo("http://exampledomain/oauth/token");
|
||||
assertThat(this.environment.resolvePlaceholders("${security.oauth2.client.access-token-uri}"))
|
||||
.isEqualTo("http://exampledomain/oauth/token");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addUserInfoUri() {
|
||||
TestPropertyValues
|
||||
.of("vcap.services.sso.credentials.userInfoUri:http://exampledomain")
|
||||
TestPropertyValues.of("vcap.services.sso.credentials.userInfoUri:http://exampledomain")
|
||||
.applyTo(this.environment);
|
||||
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
|
||||
assertThat(this.environment
|
||||
.resolvePlaceholders("${security.oauth2.resource.user-info-uri}"))
|
||||
.isEqualTo("http://exampledomain");
|
||||
assertThat(this.environment.resolvePlaceholders("${security.oauth2.resource.user-info-uri}"))
|
||||
.isEqualTo("http://exampledomain");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addServiceId() {
|
||||
TestPropertyValues
|
||||
.of("vcap.services.my.credentials.accessTokenUri:http://exampledomain",
|
||||
"security.oauth2.sso.serviceId:my")
|
||||
.applyTo(this.environment);
|
||||
TestPropertyValues.of("vcap.services.my.credentials.accessTokenUri:http://exampledomain",
|
||||
"security.oauth2.sso.serviceId:my").applyTo(this.environment);
|
||||
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
|
||||
assertThat(this.environment
|
||||
.resolvePlaceholders("${security.oauth2.client.access-token-uri}"))
|
||||
.isEqualTo("http://exampledomain");
|
||||
assertThat(this.environment.resolvePlaceholders("${security.oauth2.client.access-token-uri}"))
|
||||
.isEqualTo("http://exampledomain");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addJwtKeyUri() {
|
||||
TestPropertyValues.of("vcap.services.sso.credentials.keyUri:http://exampledomain")
|
||||
.applyTo(this.environment);
|
||||
TestPropertyValues.of("vcap.services.sso.credentials.keyUri:http://exampledomain").applyTo(this.environment);
|
||||
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
|
||||
assertThat(this.environment
|
||||
.resolvePlaceholders("${security.oauth2.resource.jwt.key-uri}"))
|
||||
.isEqualTo("http://exampledomain");
|
||||
assertThat(this.environment.resolvePlaceholders("${security.oauth2.resource.jwt.key-uri}"))
|
||||
.isEqualTo("http://exampledomain");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user