All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sap.cloudfoundry.client.facade.util.AuthorizationEndpointGetter Maven / Gradle / Ivy

There is a newer version: 2.56.0
Show newest version
package com.sap.cloudfoundry.client.facade.util;

import java.util.Map;

import org.springframework.web.reactive.function.client.WebClient;

public class AuthorizationEndpointGetter {

    private final WebClient webClient;

    public AuthorizationEndpointGetter(WebClient webClient) {
        this.webClient = webClient;
    }

    public String getAuthorizationEndpoint() {
        return getAuthorizationEndpoint("");
    }

    public String getAuthorizationEndpoint(String controllerUrl) {
        String response = webClient.get()
                                   .uri(controllerUrl + "/")
                                   .retrieve()
                                   .bodyToMono(String.class)
                                   .block();
        return getLoginHref(response);
    }

    @SuppressWarnings("unchecked")
    private String getLoginHref(String response) {
        Map resource = JsonUtil.convertJsonToMap(response);
        Map links = (Map) resource.get("links");
        Map login = (Map) links.get("login");
        return (String) login.get("href");
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy