You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2018/07/06 11:08:52 UTC

[2/2] syncope git commit: [SYNCOPE-1270] Better error reporting when OIDC Provider's Discovery Document cannot be found

[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ò <il...@apache.org>
Authored: Fri Jul 6 13:07:39 2018 +0200
Committer: Francesco Chicchiriccò <il...@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 + "')")