1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.client.console.panels;
20
21 import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.fileinput.BootstrapFileInputField;
22 import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.fileinput.FileInputConfig;
23 import java.io.Serializable;
24 import java.util.ArrayList;
25 import java.util.Locale;
26 import org.apache.syncope.client.console.SyncopeConsoleSession;
27 import org.apache.syncope.client.console.pages.BasePage;
28 import org.apache.syncope.client.console.rest.SAML2IdPsRestClient;
29 import org.apache.syncope.client.ui.commons.Constants;
30 import org.apache.wicket.PageReference;
31 import org.apache.wicket.ajax.AjaxRequestTarget;
32 import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
33 import org.apache.wicket.markup.html.WebMarkupContainer;
34 import org.apache.wicket.markup.html.form.Form;
35 import org.apache.wicket.markup.html.form.upload.FileUpload;
36 import org.apache.wicket.model.util.ListModel;
37 import org.apache.wicket.spring.injection.annot.SpringBean;
38
39 public class ImportMetadata extends TogglePanel<Serializable> {
40
41 private static final long serialVersionUID = 6959177759869415782L;
42
43 @SpringBean
44 protected SAML2IdPsRestClient saml2IdPsRestClient;
45
46 public ImportMetadata(final String id, final WebMarkupContainer container, final PageReference pageRef) {
47 super(id, pageRef);
48
49 Form<?> form = new Form<>("metadataForm");
50 addInnerObject(form);
51
52 FileInputConfig config = new FileInputConfig().
53 showUpload(false).showRemove(false).showPreview(false).
54 browseClass("btn btn-success").browseIcon("<i class=\"fas fa-folder-open\"></i> ");
55 String language = SyncopeConsoleSession.get().getLocale().getLanguage();
56 if (!Locale.ENGLISH.getLanguage().equals(language)) {
57 config.withLocale(language);
58 }
59 BootstrapFileInputField fileUpload =
60 new BootstrapFileInputField("fileUpload", new ListModel<>(new ArrayList<>()), config);
61 form.add(fileUpload.setOutputMarkupId(true));
62
63 form.add(new AjaxSubmitLink("doUpload", form) {
64
65 private static final long serialVersionUID = -7978723352517770644L;
66
67 @Override
68 protected void onSubmit(final AjaxRequestTarget target) {
69 FileUpload uploaded = fileUpload.getFileUpload();
70 if (uploaded != null) {
71 try {
72 saml2IdPsRestClient.importIdPs(uploaded.getInputStream());
73
74 SyncopeConsoleSession.get().success(getString(Constants.OPERATION_SUCCEEDED));
75 toggle(target, false);
76 target.add(container);
77 } catch (Exception e) {
78 LOG.error("While importing SAML 2.0 IdP metadata", e);
79 SyncopeConsoleSession.get().onException(e);
80 }
81 ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
82 }
83 }
84
85 @Override
86 protected void onError(final AjaxRequestTarget target) {
87 ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
88 }
89 });
90 }
91 }