Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.oneidentity.safeguard.safeguardjava.Utils;
import com.oneidentity.safeguard.safeguardjava.data.AccessTokenBody;
import com.oneidentity.safeguard.safeguardjava.data.JsonBody;
import com.oneidentity.safeguard.safeguardjava.exceptions.ObjectDisposedException;
import com.oneidentity.safeguard.safeguardjava.exceptions.SafeguardForJavaException;
import com.oneidentity.safeguard.safeguardjava.restclient.RestClient;
Expand Down Expand Up @@ -169,22 +168,12 @@ public String resolveProviderToScope(String provider) throws SafeguardForJavaExc
{
CloseableHttpResponse response;
Map<String,String> headers = new HashMap<>();
Map<String,String> parameters = new HashMap<>();

headers.clear();
parameters.clear();

headers.put(HttpHeaders.ACCEPT, "application/json");
headers.put(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
parameters.put("response_type", "token");
parameters.put("redirect_uri", "urn:InstalledApplication");
parameters.put("loginRequestStep", "1");

response = rstsClient.execPOST("UserLogin/LoginController", parameters, headers, null, new JsonBody("RelayState="));

if (response == null || (!Utils.isSuccessful(response.getStatusLine().getStatusCode())))
response = rstsClient.execGET("UserLogin/LoginController", parameters, headers, null);


response = coreClient.execGET("AuthenticationProviders", null, headers, null);

if (response == null)
throw new SafeguardForJavaException("Unable to connect to RSTS to find identity provider scopes");

Expand All @@ -204,20 +193,20 @@ public String resolveProviderToScope(String provider) throws SafeguardForJavaExc
// - This allows the caller to specify the provider Id rather than the full RSTSProviderId.
// - Such a broad check could provide some issues with false matching, however since this
// was in the original code, this check has been left in place.
Provider scope = getMatchingScope(provider, knownScopes);
String scope = getMatchingScope(provider, knownScopes);

if (scope == null)
{
StringBuilder s = new StringBuilder();
knownScopes.forEach((p) -> {
if (s.length() > 0)
s.append(", ");
s.append(p.DisplayName + ", " + p.Id);
s.append(p.Name + ", " + p.RstsProviderId);
});
throw new SafeguardForJavaException(String.format("Unable to find scope matching '%s' in [%s]", provider, s.toString()));
}

return String.format("rsts:sts:primaryproviderid:%s", scope.Id);
return scope;
}
catch (SafeguardForJavaException ex) {
throw ex;
Expand Down Expand Up @@ -252,35 +241,29 @@ protected void finalize() throws Throwable {
}

private class Provider {
private String Id;
private String DisplayName;

public Provider(String Id, String DisplayName) {
this.Id = Id;
this.DisplayName = DisplayName;
}

public String getId() {
return Id;
}

public String getDisplayName() {
return DisplayName;
private String RstsProviderId;
private String Name;
private String RstsProviderScope;

public Provider(String RstsProviderId, String Name, String RstsProviderScope) {
this.RstsProviderId = RstsProviderId;
this.Name = Name;
this.RstsProviderScope = RstsProviderScope;
}
}

private List<Provider> parseLoginResponse(String response) {

List<Provider> providers = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper();

try {
JsonNode jsonNodeRoot = mapper.readTree(response);
JsonNode jsonNodeProviders = jsonNodeRoot.get("Providers");
JsonNode jsonNodeProviders = mapper.readTree(response);
Iterator<JsonNode> iter = jsonNodeProviders.elements();

while(iter.hasNext()){
JsonNode providerNode=iter.next();
Provider p = new Provider(getJsonValue(providerNode, "Id"), getJsonValue(providerNode, "DisplayName"));
Provider p = new Provider(getJsonValue(providerNode, "RstsProviderId"), getJsonValue(providerNode, "Name"), getJsonValue(providerNode, "RstsProviderScope"));
providers.add(p);
}
} catch (IOException ex) {
Expand All @@ -290,10 +273,10 @@ private List<Provider> parseLoginResponse(String response) {
return providers;
}

private Provider getMatchingScope(String provider, List<Provider> providers) {
private String getMatchingScope(String provider, List<Provider> providers) {
for (Provider s : providers) {
if (s.DisplayName.equalsIgnoreCase(provider) || s.Id.equalsIgnoreCase(provider))
return s;
if (s.Name.equalsIgnoreCase(provider) || s.RstsProviderId.equalsIgnoreCase(provider))
return s.RstsProviderScope;
}
return null;
}
Expand All @@ -304,5 +287,4 @@ private String getJsonValue(JsonNode node, String propName) {
}
return null;
}

}