From 489abfa50d0c9c6d5644327460cfcf53f616e204 Mon Sep 17 00:00:00 2001 From: shekhar16 Date: Wed, 26 Jul 2023 00:33:23 +0530 Subject: [PATCH] fix(oxtrust-server): handle for invalid sector uri #2354 --- .../org/gluu/oxtrust/action/UpdateClientAction.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/org/gluu/oxtrust/action/UpdateClientAction.java b/server/src/main/java/org/gluu/oxtrust/action/UpdateClientAction.java index ed1e0c9ad..25594958f 100644 --- a/server/src/main/java/org/gluu/oxtrust/action/UpdateClientAction.java +++ b/server/src/main/java/org/gluu/oxtrust/action/UpdateClientAction.java @@ -9,6 +9,8 @@ import java.io.IOException; import java.io.Serializable; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; @@ -2042,13 +2044,14 @@ public List> getAvailableSpontaneousScripts() { } private boolean loadSector(String sectorIdentifierUri) throws ClientProtocolException, IOException { + try { String sectoruriContent = downloadSectorIdentifierUri(sectorIdentifierUri); if (sectoruriContent == null) { return false; } - try { + JSONArray uris = new JSONArray(sectoruriContent); this.loginUris.clear(); for (int i = 0; i < uris.length(); i++) { @@ -2058,7 +2061,7 @@ private boolean loadSector(String sectorIdentifierUri) throws ClientProtocolExce } return true; } catch (Exception e) { - log.error("", e.getMessage()); + log.error("exception in parsing the uri", e.getMessage()); return false; } } @@ -2082,8 +2085,10 @@ private String getResponseContent(HttpResponse httpResponse) throws IOException return new String(responseBytes, StandardCharsets.UTF_8); } - private String downloadSectorIdentifierUri(String sectorIdentifierUri) throws IOException, ClientProtocolException { - HttpGet httpGet = new HttpGet(); + private String downloadSectorIdentifierUri(String sectorIdentifierUri) throws IOException, ClientProtocolException, URISyntaxException { + + HttpGet httpGet = new HttpGet(); + httpGet.setURI(new URI(sectorIdentifierUri)); httpGet.setHeader("Accept", "application/json"); String fileContent = null;