VcapServiceCredentialsEnvironmentPostProcessor.java 文件源码

java
阅读 42 收藏 0 点赞 0 评论 0

项目:spring-cloud-cloudfoundry 作者:
@Override
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");
    }
    else {
        serviceId = environment.getProperty("security.oauth2.sso.service-id", "sso");
    }
    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.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");
    }
    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", "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);
    }
    environment.getPropertySources()
            .addLast(new MapPropertySource("cloudDefaultSecurityBindings", source));
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号