You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by fm...@apache.org on 2020/04/17 07:40:59 UTC

[syncope] branch 2_1_X updated: [SYNCOPE-957] provides the possibility to specify a layout for linked account management

This is an automated email from the ASF dual-hosted git repository.

fmartelli pushed a commit to branch 2_1_X
in repository https://gitbox.apache.org/repos/asf/syncope.git


The following commit(s) were added to refs/heads/2_1_X by this push:
     new 6c8824e  [SYNCOPE-957] provides the possibility to specify a layout for linked account management
6c8824e is described below

commit 6c8824e20016b9dd8025e3c7a62580dbcbb00fc8
Author: fmartelli <fa...@gmail.com>
AuthorDate: Fri Apr 17 09:40:04 2020 +0200

    [SYNCOPE-957] provides the possibility to specify a layout for linked account management
---
 .../syncope/client/console/layout/AnyLayout.java   |  2 +-
 .../client/console/layout/LinkedAccountForm.java   | 25 +++++++
 .../layout/LinkedAccountFormLayoutInfo.java        | 86 ++++++++++++++++++++++
 .../client/console/layout/UserFormLayoutInfo.java  | 13 ++++
 .../console/panels/LinkedAccountModalPanel.java    | 24 +++++-
 .../wizards/any/LinkedAccountCredentialsPanel.java | 14 +++-
 .../wizards/any/LinkedAccountPlainAttrsPanel.java  |  7 +-
 .../wizards/any/LinkedAccountWizardBuilder.java    | 29 ++++++--
 8 files changed, 185 insertions(+), 15 deletions(-)

diff --git a/client/console/src/main/java/org/apache/syncope/client/console/layout/AnyLayout.java b/client/console/src/main/java/org/apache/syncope/client/console/layout/AnyLayout.java
index 1978f78..2750851 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/layout/AnyLayout.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/layout/AnyLayout.java
@@ -30,7 +30,7 @@ public class AnyLayout implements Serializable {
     private static final long serialVersionUID = 488645029994410970L;
 
     private String anyPanelClass = AnyPanel.class.getName();
-
+    
     @JsonProperty("USER")
     private UserFormLayoutInfo user;
 
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/layout/LinkedAccountForm.java b/client/console/src/main/java/org/apache/syncope/client/console/layout/LinkedAccountForm.java
new file mode 100644
index 0000000..21bc0a3
--- /dev/null
+++ b/client/console/src/main/java/org/apache/syncope/client/console/layout/LinkedAccountForm.java
@@ -0,0 +1,25 @@
+/*
+ * 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.layout;
+
+import org.apache.syncope.client.console.wizards.ModalPanelBuilder;
+import org.apache.syncope.common.lib.to.LinkedAccountTO;
+
+public interface LinkedAccountForm extends ModalPanelBuilder<LinkedAccountTO> {
+}
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/layout/LinkedAccountFormLayoutInfo.java b/client/console/src/main/java/org/apache/syncope/client/console/layout/LinkedAccountFormLayoutInfo.java
new file mode 100644
index 0000000..5ba9115
--- /dev/null
+++ b/client/console/src/main/java/org/apache/syncope/client/console/layout/LinkedAccountFormLayoutInfo.java
@@ -0,0 +1,86 @@
+/*
+ * 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.layout;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.syncope.client.console.wizards.any.LinkedAccountWizardBuilder;
+
+public class LinkedAccountFormLayoutInfo implements Serializable {
+
+    private static final long serialVersionUID = -5573691733739618511L;
+
+    private Class<? extends LinkedAccountForm> formClass;
+
+    private boolean credentials = true;
+
+    private final List<String> whichCredentials = new ArrayList<>();
+
+    private boolean plainAttrs = true;
+
+    private final List<String> whichPlainAttrs = new ArrayList<>();
+
+    private boolean privileges = true;
+
+    protected Class<? extends LinkedAccountForm> getDefaultFormClass() {
+        return LinkedAccountWizardBuilder.class;
+    }
+
+    public Class<? extends LinkedAccountForm> getFormClass() {
+        return formClass == null ? getDefaultFormClass() : formClass;
+    }
+
+    public void setFormClass(final Class<? extends LinkedAccountForm> formClass) {
+        this.formClass = formClass;
+    }
+
+    public boolean isPlainAttrs() {
+        return plainAttrs;
+    }
+
+    public void setPlainAttrs(final boolean plainAttrs) {
+        this.plainAttrs = plainAttrs;
+    }
+
+    public List<String> getWhichPlainAttrs() {
+        return whichPlainAttrs;
+    }
+
+    public boolean isCredentials() {
+        return credentials;
+    }
+
+    public void setCredentials(final boolean credentials) {
+        this.credentials = credentials;
+    }
+
+    public List<String> getWhichCredentials() {
+        return whichCredentials;
+    }
+
+    public boolean isPrivileges() {
+        return privileges;
+    }
+
+    public void setPrivileges(final boolean privileges) {
+        this.privileges = privileges;
+    }
+
+}
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/layout/UserFormLayoutInfo.java b/client/console/src/main/java/org/apache/syncope/client/console/layout/UserFormLayoutInfo.java
index c100143..77f9ce8 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/layout/UserFormLayoutInfo.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/layout/UserFormLayoutInfo.java
@@ -31,6 +31,12 @@ public class UserFormLayoutInfo extends AbstractAnyFormLayout<UserTO, UserForm>
 
     private boolean relationships = true;
 
+    private LinkedAccountFormLayoutInfo linkedAccountFormLayoutInfo;
+
+    public UserFormLayoutInfo() {
+        this.linkedAccountFormLayoutInfo = new LinkedAccountFormLayoutInfo();
+    }
+
     @Override
     protected Class<? extends UserForm> getDefaultFormClass() {
         return UserWizardBuilder.class;
@@ -60,4 +66,11 @@ public class UserFormLayoutInfo extends AbstractAnyFormLayout<UserTO, UserForm>
         this.relationships = relationships;
     }
 
+    public LinkedAccountFormLayoutInfo getLinkedAccountFormLayoutInfo() {
+        return linkedAccountFormLayoutInfo;
+    }
+
+    public void setLinkedAccountFormLayoutInfo(final LinkedAccountFormLayoutInfo linkedAccountFormLayoutInfo) {
+        this.linkedAccountFormLayoutInfo = linkedAccountFormLayoutInfo;
+    }
 }
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/panels/LinkedAccountModalPanel.java b/client/console/src/main/java/org/apache/syncope/client/console/panels/LinkedAccountModalPanel.java
index 04956fe..f065462 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/panels/LinkedAccountModalPanel.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/panels/LinkedAccountModalPanel.java
@@ -21,10 +21,16 @@ package org.apache.syncope.client.console.panels;
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.List;
+import java.util.stream.Collectors;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.syncope.client.console.SyncopeConsoleSession;
 import org.apache.syncope.client.console.commons.Constants;
+import org.apache.syncope.client.console.layout.AnyLayout;
+import org.apache.syncope.client.console.layout.AnyLayoutUtils;
+import org.apache.syncope.client.console.layout.LinkedAccountForm;
+import org.apache.syncope.client.console.layout.LinkedAccountFormLayoutInfo;
 import org.apache.syncope.client.console.pages.BasePage;
+import org.apache.syncope.client.console.rest.AnyTypeRestClient;
 import org.apache.syncope.client.console.rest.UserRestClient;
 import org.apache.syncope.client.console.status.LinkedAccountStatusPanel;
 import org.apache.syncope.client.console.status.ReconTaskPanel;
@@ -37,6 +43,7 @@ import org.apache.syncope.client.console.wizards.any.LinkedAccountWizardBuilder;
 import org.apache.syncope.common.lib.SyncopeClientException;
 import org.apache.syncope.common.lib.patch.LinkedAccountPatch;
 import org.apache.syncope.common.lib.patch.UserPatch;
+import org.apache.syncope.common.lib.to.EntityTO;
 import org.apache.syncope.common.lib.to.LinkedAccountTO;
 import org.apache.syncope.common.lib.to.PullTaskTO;
 import org.apache.syncope.common.lib.to.PushTaskTO;
@@ -63,7 +70,7 @@ public class LinkedAccountModalPanel extends Panel implements ModalPanel {
 
     private static final Logger LOG = LoggerFactory.getLogger(LinkedAccountModalPanel.class);
 
-    private final LinkedAccountWizardBuilder wizard;
+    private LinkedAccountForm wizard;
 
     private final WizardMgtPanel<LinkedAccountTO> list;
 
@@ -73,6 +80,8 @@ public class LinkedAccountModalPanel extends Panel implements ModalPanel {
 
     private UserRestClient userRestClient = new UserRestClient();
 
+    private AnyTypeRestClient anyTypeRestClient = new AnyTypeRestClient();
+
     private final List<LinkedAccountTO> linkedAccountTOs;
 
     public LinkedAccountModalPanel(
@@ -91,7 +100,18 @@ public class LinkedAccountModalPanel extends Panel implements ModalPanel {
         actionTogglePanel = new ActionLinksTogglePanel<>("toggle", pageRef);
         add(actionTogglePanel);
 
-        wizard = new LinkedAccountWizardBuilder(model, pageRef);
+        AnyLayout anyLayout = AnyLayoutUtils.fetch(
+                anyTypeRestClient.listAnyTypes().stream().map(EntityTO::getKey).collect(Collectors.toList()));
+        LinkedAccountFormLayoutInfo linkedAccountFormLayoutInfo = anyLayout.getUser().getLinkedAccountFormLayoutInfo();
+
+        try {
+            wizard = linkedAccountFormLayoutInfo.getFormClass().
+                    getConstructor(model.getClass(), LinkedAccountFormLayoutInfo.class, PageReference.class).
+                    newInstance(model, linkedAccountFormLayoutInfo, pageRef);
+        } catch (Exception e) {
+            LOG.error("Error instantiating form layout", e);
+            wizard = new LinkedAccountWizardBuilder(model, linkedAccountFormLayoutInfo, pageRef);
+        }
 
         ListViewPanel.Builder<LinkedAccountTO> builder = new ListViewPanel.Builder<LinkedAccountTO>(
                 LinkedAccountTO.class, pageRef) {
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountCredentialsPanel.java b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountCredentialsPanel.java
index b8d0d89..3dc7175 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountCredentialsPanel.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountCredentialsPanel.java
@@ -20,6 +20,7 @@ package org.apache.syncope.client.console.wizards.any;
 
 import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkbox.bootstraptoggle.BootstrapToggle;
 import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkbox.bootstraptoggle.BootstrapToggleConfig;
+import java.util.List;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.syncope.client.console.commons.Constants;
 import org.apache.syncope.client.console.wicket.ajax.form.IndicatorAjaxFormComponentUpdatingBehavior;
@@ -48,12 +49,14 @@ public class LinkedAccountCredentialsPanel extends WizardStep {
 
     private final LinkedAccountTO linkedAccountTO;
 
-    public LinkedAccountCredentialsPanel(final EntityWrapper<LinkedAccountTO> modelObject) {
+    public LinkedAccountCredentialsPanel(
+            final EntityWrapper<LinkedAccountTO> modelObject, final List<String> whichCredentials) {
         super();
         setOutputMarkupId(true);
 
         linkedAccountTO = modelObject.getInnerObject();
 
+        boolean isUsernameManagementEnabled = whichCredentials.contains("username");
         AjaxTextFieldPanel usernameField = new AjaxTextFieldPanel(
                 "username",
                 "username",
@@ -63,9 +66,12 @@ public class LinkedAccountCredentialsPanel extends WizardStep {
         usernameProperty.setOverridable(StringUtils.isNotBlank(linkedAccountTO.getUsername()));
         usernameProperty.setSchema("username");
         usernameProperty.getValues().add(linkedAccountTO.getUsername());
-        usernameField.showExternAction(checkboxToggle(usernameProperty, usernameField));
+        usernameField.showExternAction(
+                checkboxToggle(usernameProperty, usernameField).setEnabled(isUsernameManagementEnabled));
         add(usernameField.setOutputMarkupId(true));
+        usernameField.setEnabled(isUsernameManagementEnabled);
 
+        boolean isPasswordManagementEnabled = whichCredentials.contains("password");
         AjaxPasswordFieldPanel passwordField = new AjaxPasswordFieldPanel(
                 "password",
                 "password",
@@ -78,9 +84,11 @@ public class LinkedAccountCredentialsPanel extends WizardStep {
         passwordProperty.setOverridable(StringUtils.isNotBlank(linkedAccountTO.getPassword()));
         passwordProperty.setSchema("password");
         passwordProperty.getValues().add(linkedAccountTO.getPassword());
-        passwordField.showExternAction(checkboxToggle(passwordProperty, passwordField));
+        passwordField.showExternAction(
+                checkboxToggle(passwordProperty, passwordField).setEnabled(isPasswordManagementEnabled));
         ((PasswordTextField) passwordField.getField()).setResetPassword(false);
         add(passwordField.setOutputMarkupId(true));
+        passwordField.setEnabled(isPasswordManagementEnabled);
     }
 
     private FormComponent<?> checkboxToggle(
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountPlainAttrsPanel.java b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountPlainAttrsPanel.java
index 0670892..b5c55f2 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountPlainAttrsPanel.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountPlainAttrsPanel.java
@@ -21,7 +21,6 @@ package org.apache.syncope.client.console.wizards.any;
 import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkbox.bootstraptoggle.BootstrapToggle;
 import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkbox.bootstraptoggle.BootstrapToggleConfig;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
@@ -44,7 +43,6 @@ import org.apache.syncope.common.lib.to.LinkedAccountTO;
 import org.apache.syncope.common.lib.to.PlainSchemaTO;
 import org.apache.syncope.common.lib.to.UserTO;
 import org.apache.syncope.client.console.commons.LinkedAccountPlainAttrProperty;
-import org.apache.syncope.client.console.layout.AnyLayoutUtils;
 import org.apache.syncope.common.lib.types.SchemaType;
 import org.apache.wicket.ajax.AjaxRequestTarget;
 import org.apache.wicket.extensions.markup.html.tabs.AbstractTab;
@@ -74,12 +72,13 @@ public class LinkedAccountPlainAttrsPanel extends AbstractAttrsWizardStep<PlainS
 
     public <T extends AnyTO> LinkedAccountPlainAttrsPanel(
             final EntityWrapper<LinkedAccountTO> modelObject,
-            final UserTO userTO) throws IllegalArgumentException {
+            final UserTO userTO,
+            final List<String> whichPlainAttrs) throws IllegalArgumentException {
 
         super(userTO,
                 AjaxWizard.Mode.EDIT,
                 new AnyTypeRestClient().read(userTO.getType()).getClasses(),
-                AnyLayoutUtils.fetch(Arrays.asList(userTO.getType())).getUser().getWhichPlainAttrs(),
+                whichPlainAttrs,
                 modelObject);
 
         this.linkedAccountTO = modelObject.getInnerObject();
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountWizardBuilder.java b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountWizardBuilder.java
index 8c5076d..2ae2f52 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountWizardBuilder.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountWizardBuilder.java
@@ -22,6 +22,8 @@ import java.io.Serializable;
 import java.util.HashSet;
 import java.util.Set;
 import java.util.stream.Collectors;
+import org.apache.syncope.client.console.layout.LinkedAccountForm;
+import org.apache.syncope.client.console.layout.LinkedAccountFormLayoutInfo;
 import org.apache.syncope.client.console.rest.UserRestClient;
 import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal.ModalEvent;
 import org.apache.syncope.client.console.wizards.AjaxWizard;
@@ -39,7 +41,7 @@ import org.apache.wicket.model.IModel;
 /**
  * Accounts wizard builder.
  */
-public class LinkedAccountWizardBuilder extends AjaxWizardBuilder<LinkedAccountTO> {
+public class LinkedAccountWizardBuilder extends AjaxWizardBuilder<LinkedAccountTO> implements LinkedAccountForm {
 
     private static final long serialVersionUID = -9142332740863374891L;
 
@@ -47,9 +49,15 @@ public class LinkedAccountWizardBuilder extends AjaxWizardBuilder<LinkedAccountT
 
     private final IModel<UserTO> model;
 
-    public LinkedAccountWizardBuilder(final IModel<UserTO> model, final PageReference pageRef) {
+    protected LinkedAccountFormLayoutInfo formLayoutInfo;
+
+    public LinkedAccountWizardBuilder(
+            final IModel<UserTO> model,
+            final LinkedAccountFormLayoutInfo formLayoutInfo,
+            final PageReference pageRef) {
         super(new LinkedAccountTO(), pageRef);
         this.model = model;
+        this.formLayoutInfo = formLayoutInfo;
     }
 
     @Override
@@ -60,9 +68,20 @@ public class LinkedAccountWizardBuilder extends AjaxWizardBuilder<LinkedAccountT
     @Override
     protected WizardModel buildModelSteps(final LinkedAccountTO modelObject, final WizardModel wizardModel) {
         wizardModel.add(new LinkedAccountDetailsPanel(modelObject));
-        wizardModel.add(new LinkedAccountCredentialsPanel(new EntityWrapper<>(modelObject)));
-        wizardModel.add(new LinkedAccountPlainAttrsPanel(new EntityWrapper<>(modelObject), model.getObject()));
-        wizardModel.add(new LinkedAccountPrivilegesPanel(modelObject));
+        if (formLayoutInfo.isCredentials()) {
+            wizardModel.add(new LinkedAccountCredentialsPanel(
+                    new EntityWrapper<>(modelObject), formLayoutInfo.getWhichCredentials()));
+        }
+
+        if (formLayoutInfo.isPlainAttrs()) {
+            wizardModel.add(new LinkedAccountPlainAttrsPanel(
+                    new EntityWrapper<>(modelObject), model.getObject(), formLayoutInfo.getWhichPlainAttrs()));
+        }
+
+        if (formLayoutInfo.isPrivileges()) {
+            wizardModel.add(new LinkedAccountPrivilegesPanel(modelObject));
+        }
+
         return wizardModel;
     }