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.wizards;
20
21 import java.io.Serializable;
22 import java.nio.charset.StandardCharsets;
23 import java.util.Base64;
24 import org.apache.syncope.client.console.rest.SAML2IdPEntityRestClient;
25 import org.apache.syncope.client.console.wicket.markup.html.form.TextEditorPanel;
26 import org.apache.syncope.common.lib.to.SAML2IdPEntityTO;
27 import org.apache.wicket.PageReference;
28 import org.apache.wicket.extensions.wizard.WizardModel;
29 import org.apache.wicket.model.PropertyModel;
30
31 public class SAML2IdPEntityWizardBuilder extends SAML2EntityWizardBuilder<SAML2IdPEntityTO> {
32
33 private static final long serialVersionUID = -8013493490328546125L;
34
35 protected final SAML2IdPEntityRestClient saml2IdPEntityRestClient;
36
37 public SAML2IdPEntityWizardBuilder(
38 final SAML2IdPEntityTO defaultItem,
39 final SAML2IdPEntityRestClient saml2IdPEntityRestClient,
40 final PageReference pageRef) {
41
42 super(defaultItem, pageRef);
43 this.saml2IdPEntityRestClient = saml2IdPEntityRestClient;
44 }
45
46 @Override
47 protected Serializable onApplyInternal(final SAML2IdPEntityTO modelObject) {
48 if (modelObject.getMetadata() != null) {
49 modelObject.setMetadata(Base64.getEncoder().encodeToString(
50 modelObject.getMetadata().getBytes(StandardCharsets.UTF_8)));
51 }
52 if (modelObject.getSigningCertificate() != null) {
53 modelObject.setSigningCertificate(Base64.getEncoder().encodeToString(
54 modelObject.getSigningCertificate().getBytes(StandardCharsets.UTF_8)));
55 }
56 if (modelObject.getSigningKey() != null) {
57 modelObject.setSigningKey(Base64.getEncoder().encodeToString(
58 modelObject.getSigningKey().getBytes(StandardCharsets.UTF_8)));
59 }
60 if (modelObject.getEncryptionCertificate() != null) {
61 modelObject.setEncryptionCertificate(Base64.getEncoder().encodeToString(
62 modelObject.getEncryptionCertificate().getBytes(StandardCharsets.UTF_8)));
63 }
64 if (modelObject.getEncryptionKey() != null) {
65 modelObject.setEncryptionKey(Base64.getEncoder().encodeToString(
66 modelObject.getEncryptionKey().getBytes(StandardCharsets.UTF_8)));
67 }
68 saml2IdPEntityRestClient.set(modelObject);
69 return modelObject;
70 }
71
72 @Override
73 protected WizardModel buildModelSteps(final SAML2IdPEntityTO modelObject, final WizardModel wizardModel) {
74 if (modelObject.getMetadata() != null) {
75 modelObject.setMetadata(new String(Base64.getDecoder().decode(
76 modelObject.getMetadata()), StandardCharsets.UTF_8));
77 }
78 if (modelObject.getSigningCertificate() != null) {
79 modelObject.setSigningCertificate(new String(Base64.getDecoder().decode(
80 modelObject.getSigningCertificate()), StandardCharsets.UTF_8));
81 }
82 if (modelObject.getSigningKey() != null) {
83 modelObject.setSigningKey(new String(Base64.getDecoder().decode(
84 modelObject.getSigningKey()), StandardCharsets.UTF_8));
85 }
86 if (modelObject.getEncryptionCertificate() != null) {
87 modelObject.setEncryptionCertificate(new String(Base64.getDecoder().decode(
88 modelObject.getEncryptionCertificate()), StandardCharsets.UTF_8));
89 }
90 if (modelObject.getEncryptionKey() != null) {
91 modelObject.setEncryptionKey(new String(Base64.getDecoder().decode(
92 modelObject.getEncryptionKey()), StandardCharsets.UTF_8));
93 }
94
95 wizardModel.add(new Metadata(modelObject, pageRef));
96 wizardModel.add(new TextPem(modelObject, "signingCertificate", pageRef));
97 wizardModel.add(new TextPem(modelObject, "signingKey", pageRef));
98 wizardModel.add(new TextPem(modelObject, "encryptionCertificate", pageRef));
99 wizardModel.add(new TextPem(modelObject, "encryptionKey", pageRef));
100 return wizardModel;
101 }
102
103 protected class TextPem extends Pem {
104
105 private static final long serialVersionUID = 1L;
106
107 public TextPem(final SAML2IdPEntityTO entity, final String property, final PageReference pageRef) {
108 super(property);
109
110 add(new TextEditorPanel(null, new PropertyModel<>(entity, property), false, pageRef));
111 }
112 }
113 }