syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [2/2] syncope git commit: [SYNCOPE-1270] Better error reporting when OIDC Provider's Discovery Document cannot be found
Date Fri, 06 Jul 2018 11:08:52 GMT
[SYNCOPE-1270] Better error reporting when OIDC Provider's Discovery Document cannot be found


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/9455410c
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/9455410c
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/9455410c

Branch: refs/heads/master
Commit: 9455410cc7f4ce5afdf0c27ee912a83f31d764b1
Parents: 76a323c
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
Authored: Fri Jul 6 13:07:39 2018 +0200
Committer: Francesco Chicchiriccò <ilgrosso@apache.org>
Committed: Fri Jul 6 13:08:44 2018 +0200

----------------------------------------------------------------------
 .../syncope/core/logic/OIDCProviderLogic.java    | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/9455410c/ext/oidcclient/logic/src/main/java/org/apache/syncope/core/logic/OIDCProviderLogic.java
----------------------------------------------------------------------
diff --git a/ext/oidcclient/logic/src/main/java/org/apache/syncope/core/logic/OIDCProviderLogic.java
b/ext/oidcclient/logic/src/main/java/org/apache/syncope/core/logic/OIDCProviderLogic.java
index 6ad6649..a73155d 100644
--- a/ext/oidcclient/logic/src/main/java/org/apache/syncope/core/logic/OIDCProviderLogic.java
+++ b/ext/oidcclient/logic/src/main/java/org/apache/syncope/core/logic/OIDCProviderLogic.java
@@ -24,6 +24,7 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.Set;
 import java.util.stream.Collectors;
+import javax.ws.rs.ClientErrorException;
 import javax.ws.rs.core.MediaType;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.cxf.jaxrs.client.WebClient;
@@ -61,10 +62,22 @@ public class OIDCProviderLogic extends AbstractTransactionalLogic<OIDCProviderTO
     }
 
     private OIDCProviderDiscoveryDocument getDiscoveryDocument(final String issuer) {
-        WebClient client = WebClient.create(
-                issuer + "/.well-known/openid-configuration", Arrays.asList(new JacksonJsonProvider())).
+        String discoveryDocumentURL = issuer + "/.well-known/openid-configuration";
+        WebClient client = WebClient.create(discoveryDocumentURL, Arrays.asList(new JacksonJsonProvider())).
                 accept(MediaType.APPLICATION_JSON);
-        return client.get(OIDCProviderDiscoveryDocument.class);
+        try {
+            return client.get(OIDCProviderDiscoveryDocument.class);
+        } catch (ClientErrorException e) {
+            LOG.error("While getting the Discovery Document at {}", discoveryDocumentURL,
e);
+
+            if (e instanceof javax.ws.rs.NotFoundException) {
+                throw new NotFoundException("Discovery Document cannot be found at " + discoveryDocumentURL);
+            } else {
+                SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Unknown);
+                sce.getElements().add(e.getMessage());
+                throw sce;
+            }
+        }
     }
 
     @PreAuthorize("hasRole('" + OIDCClientEntitlement.OP_CREATE + "')")


Mime
View raw message