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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user