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 2023/07/21 14:42:52 UTC
[syncope] branch 3_0_X updated: Fixing SAML 2.0 SP metadata download from Console from different locations
This is an automated email from the ASF dual-hosted git repository.
ilgrosso pushed a commit to branch 3_0_X
in repository https://gitbox.apache.org/repos/asf/syncope.git
The following commit(s) were added to refs/heads/3_0_X by this push:
new 789a5d728b Fixing SAML 2.0 SP metadata download from Console from different locations
789a5d728b is described below
commit 789a5d728b8090158f2045f4a97f7d9cf0392a12
Author: Francesco Chicchiriccò <il...@apache.org>
AuthorDate: Fri Jul 21 16:38:56 2023 +0200
Fixing SAML 2.0 SP metadata download from Console from different locations
---
.../console/rest/ReconciliationRestClient.java | 5 +-
.../client/console/rest/BpmnProcessRestClient.java | 5 +-
.../client/console/SAML2SP4UIConsoleContext.java | 7 +++
.../syncope/client/console/pages/SAML2SP4UI.java | 9 ++--
.../client/console/panels/SAML2SPPanel.java | 23 ++++----
.../client/console/rest/SAML2IdPsRestClient.java | 3 +-
.../client/console/rest/SAML2SPRestClient.java | 61 ++++++++++++++++++++++
7 files changed, 90 insertions(+), 23 deletions(-)
diff --git a/client/idm/console/src/main/java/org/apache/syncope/client/console/rest/ReconciliationRestClient.java b/client/idm/console/src/main/java/org/apache/syncope/client/console/rest/ReconciliationRestClient.java
index b9618e5776..50496d1fde 100644
--- a/client/idm/console/src/main/java/org/apache/syncope/client/console/rest/ReconciliationRestClient.java
+++ b/client/idm/console/src/main/java/org/apache/syncope/client/console/rest/ReconciliationRestClient.java
@@ -24,7 +24,6 @@ import java.util.stream.Collectors;
import javax.ws.rs.core.Response;
import org.apache.cxf.jaxrs.client.Client;
import org.apache.cxf.jaxrs.client.WebClient;
-import org.apache.syncope.client.console.SyncopeConsoleSession;
import org.apache.syncope.common.lib.to.ProvisioningReport;
import org.apache.syncope.common.lib.to.PullTaskTO;
import org.apache.syncope.common.lib.to.PushTaskTO;
@@ -59,7 +58,7 @@ public class ReconciliationRestClient extends BaseRestClient {
Response response = service.push(anyQuery, spec);
- SyncopeConsoleSession.get().resetClient(ReconciliationService.class);
+ resetClient(ReconciliationService.class);
return response;
}
@@ -72,7 +71,7 @@ public class ReconciliationRestClient extends BaseRestClient {
ArrayList<ProvisioningReport> result = service.pull(spec, csv).stream().
collect(Collectors.toCollection(ArrayList::new));
- SyncopeConsoleSession.get().resetClient(ReconciliationService.class);
+ resetClient(ReconciliationService.class);
return result;
}
diff --git a/ext/flowable/client-console/src/main/java/org/apache/syncope/client/console/rest/BpmnProcessRestClient.java b/ext/flowable/client-console/src/main/java/org/apache/syncope/client/console/rest/BpmnProcessRestClient.java
index 62e1e1cb00..3d2610b082 100644
--- a/ext/flowable/client-console/src/main/java/org/apache/syncope/client/console/rest/BpmnProcessRestClient.java
+++ b/ext/flowable/client-console/src/main/java/org/apache/syncope/client/console/rest/BpmnProcessRestClient.java
@@ -26,7 +26,6 @@ import javax.ws.rs.core.Response;
import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.jaxrs.impl.MetadataMap;
-import org.apache.syncope.client.console.SyncopeConsoleSession;
import org.apache.syncope.common.lib.to.BpmnProcess;
import org.apache.syncope.common.rest.api.RESTHeaders;
import org.apache.syncope.common.rest.api.service.BpmnProcessService;
@@ -52,14 +51,14 @@ public class BpmnProcessRestClient extends BaseRestClient {
public InputStream getDefinition(final MediaType mediaType, final String key) {
Response response = getService(mediaType).get(key);
- SyncopeConsoleSession.get().resetClient(BpmnProcessService.class);
+ resetClient(BpmnProcessService.class);
return (InputStream) response.getEntity();
}
public void setDefinition(final MediaType mediaType, final String key, final String definition) {
getService(mediaType).set(key, definition);
- SyncopeConsoleSession.get().resetClient(BpmnProcessService.class);
+ resetClient(BpmnProcessService.class);
}
public byte[] getDiagram(final String key) {
diff --git a/ext/saml2sp4ui/client-console/src/main/java/org/apache/syncope/client/console/SAML2SP4UIConsoleContext.java b/ext/saml2sp4ui/client-console/src/main/java/org/apache/syncope/client/console/SAML2SP4UIConsoleContext.java
index 30620cf670..0bdfbb1814 100644
--- a/ext/saml2sp4ui/client-console/src/main/java/org/apache/syncope/client/console/SAML2SP4UIConsoleContext.java
+++ b/ext/saml2sp4ui/client-console/src/main/java/org/apache/syncope/client/console/SAML2SP4UIConsoleContext.java
@@ -21,6 +21,7 @@ package org.apache.syncope.client.console;
import org.apache.syncope.client.console.resources.saml2sp4ui.ConsoleAssertionConsumerResource;
import org.apache.syncope.client.console.resources.saml2sp4ui.ConsoleLogoutResource;
import org.apache.syncope.client.console.rest.SAML2IdPsRestClient;
+import org.apache.syncope.client.console.rest.SAML2SPRestClient;
import org.apache.syncope.client.ui.commons.resources.saml2sp4ui.LoginResource;
import org.apache.syncope.client.ui.commons.resources.saml2sp4ui.MetadataResource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@@ -36,6 +37,12 @@ public class SAML2SP4UIConsoleContext {
return new SAML2IdPsRestClient();
}
+ @ConditionalOnMissingBean
+ @Bean
+ public SAML2SPRestClient saml2SPRestClient() {
+ return new SAML2SPRestClient();
+ }
+
@ConditionalOnMissingBean
@Bean
public MetadataResource metadataResource() {
diff --git a/ext/saml2sp4ui/client-console/src/main/java/org/apache/syncope/client/console/pages/SAML2SP4UI.java b/ext/saml2sp4ui/client-console/src/main/java/org/apache/syncope/client/console/pages/SAML2SP4UI.java
index 2fb4b3a4ca..c2f9c71e95 100644
--- a/ext/saml2sp4ui/client-console/src/main/java/org/apache/syncope/client/console/pages/SAML2SP4UI.java
+++ b/ext/saml2sp4ui/client-console/src/main/java/org/apache/syncope/client/console/pages/SAML2SP4UI.java
@@ -25,6 +25,7 @@ import org.apache.syncope.client.console.BookmarkablePageLinkBuilder;
import org.apache.syncope.client.console.panels.SAML2IdPsDirectoryPanel;
import org.apache.syncope.client.console.panels.SAML2SPPanel;
import org.apache.syncope.client.console.rest.SAML2IdPsRestClient;
+import org.apache.syncope.client.console.rest.SAML2SPRestClient;
import org.apache.syncope.client.ui.commons.annotations.ExtPage;
import org.apache.syncope.common.lib.types.SAML2SP4UIEntitlement;
import org.apache.wicket.extensions.markup.html.tabs.AbstractTab;
@@ -44,6 +45,9 @@ public class SAML2SP4UI extends BaseExtPage {
@SpringBean
protected SAML2IdPsRestClient saml2IdPsRestClient;
+ @SpringBean
+ protected SAML2SPRestClient saml2SPRestClient;
+
public SAML2SP4UI(final PageParameters parameters) {
super(parameters);
@@ -56,8 +60,7 @@ public class SAML2SP4UI extends BaseExtPage {
}
protected List<ITab> buildTabList() {
-
- final List<ITab> tabs = new ArrayList<>(2);
+ List<ITab> tabs = new ArrayList<>();
tabs.add(new AbstractTab(new ResourceModel("idps")) {
@@ -75,7 +78,7 @@ public class SAML2SP4UI extends BaseExtPage {
@Override
public Panel getPanel(final String panelId) {
- return new SAML2SPPanel(panelId);
+ return new SAML2SPPanel(panelId, saml2SPRestClient);
}
});
diff --git a/ext/saml2sp4ui/client-console/src/main/java/org/apache/syncope/client/console/panels/SAML2SPPanel.java b/ext/saml2sp4ui/client-console/src/main/java/org/apache/syncope/client/console/panels/SAML2SPPanel.java
index 9385a2948e..5a93f31861 100644
--- a/ext/saml2sp4ui/client-console/src/main/java/org/apache/syncope/client/console/panels/SAML2SPPanel.java
+++ b/ext/saml2sp4ui/client-console/src/main/java/org/apache/syncope/client/console/panels/SAML2SPPanel.java
@@ -18,11 +18,10 @@
*/
package org.apache.syncope.client.console.panels;
-import javax.ws.rs.client.ClientBuilder;
+import org.apache.commons.lang3.StringUtils;
import org.apache.syncope.client.console.SyncopeConsoleSession;
-import org.apache.syncope.client.ui.commons.HttpResourceStream;
+import org.apache.syncope.client.console.rest.SAML2SPRestClient;
import org.apache.syncope.client.ui.commons.SAML2SP4UIConstants;
-import org.apache.syncope.client.ui.commons.rest.ResponseHolder;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.request.Url;
@@ -30,6 +29,7 @@ import org.apache.wicket.request.UrlUtils;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler;
import org.apache.wicket.request.resource.ContentDisposition;
+import org.apache.wicket.util.resource.IResourceStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,7 +39,7 @@ public class SAML2SPPanel extends Panel {
protected static final Logger LOG = LoggerFactory.getLogger(SAML2SPPanel.class);
- public SAML2SPPanel(final String id) {
+ public SAML2SPPanel(final String id, final SAML2SPRestClient restClient) {
super(id);
add(new Link<Void>("downloadMetadata") {
@@ -49,16 +49,15 @@ public class SAML2SPPanel extends Panel {
@Override
public void onClick() {
try {
- HttpResourceStream stream = new HttpResourceStream(new ResponseHolder(ClientBuilder.newClient().
- target(RequestCycle.get().getUrlRenderer().renderFullUrl(Url.parse(
- UrlUtils.rewriteToContextRelative(SAML2SP4UIConstants.URL_CONTEXT + "/metadata",
- RequestCycle.get())))).
- request().get()));
+ String spEntityID = StringUtils.substringBefore(
+ RequestCycle.get().getUrlRenderer().renderFullUrl(
+ Url.parse(UrlUtils.rewriteToContextRelative(
+ SAML2SP4UIConstants.URL_CONTEXT, RequestCycle.get()))),
+ SAML2SP4UIConstants.URL_CONTEXT);
+ IResourceStream stream = restClient.getMetadata(spEntityID);
ResourceStreamRequestHandler rsrh = new ResourceStreamRequestHandler(stream);
- rsrh.setFileName(stream.getFilename() == null
- ? SyncopeConsoleSession.get().getDomain() + "-SAML-SP-Metadata.xml"
- : stream.getFilename());
+ rsrh.setFileName(SyncopeConsoleSession.get().getDomain() + "-SAML-SP-Metadata.xml");
rsrh.setContentDisposition(ContentDisposition.ATTACHMENT);
getRequestCycle().scheduleRequestHandlerAfterCurrent(rsrh);
diff --git a/ext/saml2sp4ui/client-console/src/main/java/org/apache/syncope/client/console/rest/SAML2IdPsRestClient.java b/ext/saml2sp4ui/client-console/src/main/java/org/apache/syncope/client/console/rest/SAML2IdPsRestClient.java
index a2f9610dd3..17898fc9e9 100644
--- a/ext/saml2sp4ui/client-console/src/main/java/org/apache/syncope/client/console/rest/SAML2IdPsRestClient.java
+++ b/ext/saml2sp4ui/client-console/src/main/java/org/apache/syncope/client/console/rest/SAML2IdPsRestClient.java
@@ -23,7 +23,6 @@ import java.util.List;
import javax.ws.rs.core.MediaType;
import org.apache.cxf.jaxrs.client.Client;
import org.apache.cxf.jaxrs.client.WebClient;
-import org.apache.syncope.client.console.SyncopeConsoleSession;
import org.apache.syncope.common.lib.to.SAML2SP4UIIdPTO;
import org.apache.syncope.common.rest.api.service.SAML2SP4UIIdPService;
@@ -42,7 +41,7 @@ public class SAML2IdPsRestClient extends BaseRestClient {
service.importFromMetadata(input);
- SyncopeConsoleSession.get().resetClient(SAML2SP4UIIdPService.class);
+ resetClient(SAML2SP4UIIdPService.class);
}
public SAML2SP4UIIdPTO read(final String key) {
diff --git a/ext/saml2sp4ui/client-console/src/main/java/org/apache/syncope/client/console/rest/SAML2SPRestClient.java b/ext/saml2sp4ui/client-console/src/main/java/org/apache/syncope/client/console/rest/SAML2SPRestClient.java
new file mode 100644
index 0000000000..0d63bc894e
--- /dev/null
+++ b/ext/saml2sp4ui/client-console/src/main/java/org/apache/syncope/client/console/rest/SAML2SPRestClient.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.client.console.rest;
+
+import java.io.IOException;
+import java.io.InputStream;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.syncope.client.console.SyncopeConsoleSession;
+import org.apache.syncope.client.ui.commons.SAML2SP4UIConstants;
+import org.apache.syncope.common.rest.api.service.SAML2SP4UIService;
+import org.apache.wicket.util.io.IOUtils;
+import org.apache.wicket.util.resource.AbstractResourceStream;
+import org.apache.wicket.util.resource.IResourceStream;
+import org.apache.wicket.util.resource.ResourceStreamNotFoundException;
+
+public class SAML2SPRestClient extends BaseRestClient {
+
+ private static final long serialVersionUID = -5084300184764037527L;
+
+ public IResourceStream getMetadata(final String spEntityID) {
+ SAML2SP4UIService service = SyncopeConsoleSession.get().getAnonymousService(SAML2SP4UIService.class);
+ WebClient.client(service).accept(MediaType.APPLICATION_XML_TYPE).type(MediaType.APPLICATION_XML_TYPE);
+ Response metadataResponse = service.getMetadata(spEntityID, SAML2SP4UIConstants.URL_CONTEXT);
+ WebClient.client(service).reset();
+
+ InputStream inputStream = (InputStream) metadataResponse.getEntity();
+
+ return new AbstractResourceStream() {
+
+ private static final long serialVersionUID = -2268011115723452312L;
+
+ @Override
+ public InputStream getInputStream() throws ResourceStreamNotFoundException {
+ return inputStream;
+ }
+
+ @Override
+ public void close() throws IOException {
+ IOUtils.closeQuietly(inputStream);
+ }
+ };
+ }
+}