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 2020/04/14 06:15:47 UTC

[syncope] branch 2_1_X updated: cleanup for better extendability

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

ilgrosso 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 32b190b  cleanup for better extendability
32b190b is described below

commit 32b190b7ca77c76711f93211b9a18b4ff4991f4d
Author: Francesco Chicchiriccò <il...@apache.org>
AuthorDate: Tue Apr 14 08:15:33 2020 +0200

    cleanup for better extendability
---
 .../console/wizards/any/AnyWizardBuilder.java      | 26 ++++------
 .../syncope/client/console/wizards/any/Roles.java  | 57 +++++++++++-----------
 2 files changed, 37 insertions(+), 46 deletions(-)

diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/AnyWizardBuilder.java b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/AnyWizardBuilder.java
index e629d17..e8a7ab6 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/AnyWizardBuilder.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/AnyWizardBuilder.java
@@ -31,7 +31,6 @@ import org.apache.syncope.common.lib.to.AnyTO;
 import org.apache.syncope.common.lib.to.AttrTO;
 import org.apache.syncope.common.lib.to.GroupTO;
 import org.apache.syncope.common.lib.to.GroupableRelatableTO;
-import org.apache.syncope.common.lib.to.UserTO;
 import org.apache.wicket.PageReference;
 import org.apache.wicket.extensions.wizard.WizardModel;
 
@@ -109,12 +108,8 @@ public abstract class AnyWizardBuilder<A extends AnyTO> extends AjaxWizardBuilde
 
         // attributes panel steps
         if (formLayoutInfo.isPlainAttrs()) {
-            wizardModel.add(new PlainAttrs(
-                    modelObject,
-                    null,
-                    mode,
-                    anyTypeClasses,
-                    formLayoutInfo.getWhichPlainAttrs()) {
+            wizardModel.add(
+                    new PlainAttrs(modelObject, null, mode, anyTypeClasses, formLayoutInfo.getWhichPlainAttrs()) {
 
                 private static final long serialVersionUID = 8167894751609598306L;
 
@@ -122,31 +117,28 @@ public abstract class AnyWizardBuilder<A extends AnyTO> extends AjaxWizardBuilde
                 public PageReference getPageReference() {
                     return pageRef;
                 }
-
             });
         }
         if (formLayoutInfo.isDerAttrs() && mode != AjaxWizard.Mode.TEMPLATE) {
-            wizardModel.add(new DerAttrs(
-                    modelObject, anyTypeClasses, formLayoutInfo.getWhichDerAttrs()));
+            wizardModel.add(new DerAttrs(modelObject, anyTypeClasses, formLayoutInfo.getWhichDerAttrs()));
         }
         if (formLayoutInfo.isVirAttrs()) {
-            wizardModel.add(new VirAttrs(
-                    modelObject, mode, anyTypeClasses, formLayoutInfo.getWhichVirAttrs()));
+            wizardModel.add(new VirAttrs(modelObject, mode, anyTypeClasses, formLayoutInfo.getWhichVirAttrs()));
         }
 
         // role panel step (just available for users)
         if ((this instanceof UserWizardBuilder)
-                && (modelObject.getInnerObject() instanceof UserTO)
-                && (formLayoutInfo instanceof UserFormLayoutInfo)
+                && modelObject instanceof UserWrapper
+                && formLayoutInfo instanceof UserFormLayoutInfo
                 && UserFormLayoutInfo.class.cast(formLayoutInfo).isRoles()) {
 
-            wizardModel.add(new Roles(modelObject));
+            wizardModel.add(new Roles((UserWrapper) modelObject));
         }
 
         // relationship panel step (available for users and any objects)
-        if (((formLayoutInfo instanceof UserFormLayoutInfo)
+        if ((formLayoutInfo instanceof UserFormLayoutInfo
                 && UserFormLayoutInfo.class.cast(formLayoutInfo).isRelationships())
-                || ((formLayoutInfo instanceof AnyObjectFormLayoutInfo)
+                || (formLayoutInfo instanceof AnyObjectFormLayoutInfo
                 && AnyObjectFormLayoutInfo.class.cast(formLayoutInfo).isRelationships())) {
 
             wizardModel.add(new Relationships(modelObject, pageRef));
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/Roles.java b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/Roles.java
index 0a57a5a..66890a0 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/Roles.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/Roles.java
@@ -22,7 +22,6 @@ import java.util.Collections;
 import java.util.List;
 import java.util.stream.Collectors;
 import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.collections4.ListUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.syncope.client.console.SyncopeConsoleApplication;
 import org.apache.syncope.client.console.commons.Constants;
@@ -33,6 +32,7 @@ import org.apache.syncope.common.lib.to.AnyTO;
 import org.apache.syncope.common.lib.to.RoleTO;
 import org.apache.syncope.common.lib.to.UserTO;
 import org.apache.syncope.common.lib.types.StandardEntitlement;
+import org.apache.wicket.Component;
 import org.apache.wicket.authroles.authorization.strategies.role.metadata.ActionPermissions;
 import org.apache.wicket.authroles.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy;
 import org.apache.wicket.extensions.wizard.WizardModel.ICondition;
@@ -46,27 +46,22 @@ public class Roles extends WizardStep implements ICondition {
 
     private static final long serialVersionUID = 552437609667518888L;
 
-    private final List<String> allRoles;
+    protected final List<String> allRoles;
 
     protected final UserTO userTO;
 
     protected WebMarkupContainer dynrolesContainer;
 
-    public <T extends AnyTO> Roles(final AnyWrapper<?> modelObject) {
-        if (!(modelObject.getInnerObject() instanceof UserTO)) {
-            throw new IllegalStateException("Invalid instance " + modelObject.getInnerObject());
-        }
+    public <T extends AnyTO> Roles(final UserWrapper modelObject) {
+        if (modelObject.getPreviousUserTO() != null
+                && !modelObject.getInnerObject().getRoles().equals(modelObject.getPreviousUserTO().getRoles())) {
 
-        if (UserWrapper.class.cast(modelObject).getPreviousUserTO() != null
-                && !ListUtils.isEqualList(
-                        UserWrapper.class.cast(modelObject).getInnerObject().getRoles(),
-                        UserWrapper.class.cast(modelObject).getPreviousUserTO().getRoles())) {
             add(new LabelInfo("changed", StringUtils.EMPTY));
         } else {
             add(new Label("changed", StringUtils.EMPTY));
         }
 
-        userTO = UserTO.class.cast(modelObject.getInnerObject());
+        userTO = modelObject.getInnerObject();
 
         // -----------------------------------------------------------------
         // Pre-Authorizations
@@ -81,7 +76,27 @@ public class Roles extends WizardStep implements ICondition {
 
         allRoles = getManagedRoles();
 
-        add(new AjaxPalettePanel.Builder<String>().
+        add(buildRolesSelector(modelObject));
+
+        dynrolesContainer = new WebMarkupContainer("dynrolesContainer");
+        dynrolesContainer.setOutputMarkupId(true);
+        dynrolesContainer.setOutputMarkupPlaceholderTag(true);
+        add(dynrolesContainer);
+
+        dynrolesContainer.add(new AjaxPalettePanel.Builder<String>().build("dynroles",
+                new PropertyModel<>(userTO, "dynRoles"),
+                new ListModel<>(allRoles)).hideLabel().setEnabled(false).setOutputMarkupId(true));
+    }
+
+    protected List<String> getManagedRoles() {
+        return SyncopeConsoleApplication.get().getSecuritySettings().getAuthorizationStrategy().
+                isActionAuthorized(this, RENDER)
+                ? new RoleRestClient().list().stream().map(RoleTO::getKey).sorted().collect(Collectors.toList())
+                : Collections.emptyList();
+    }
+
+    protected Component buildRolesSelector(final UserWrapper modelObject) {
+        return new AjaxPalettePanel.Builder<String>().
                 withFilter().
                 setAllowOrder(true).
                 build("roles",
@@ -104,16 +119,7 @@ public class Roles extends WizardStep implements ICondition {
                     }
                 }).
                 hideLabel().
-                setOutputMarkupId(true));
-
-        dynrolesContainer = new WebMarkupContainer("dynrolesContainer");
-        dynrolesContainer.setOutputMarkupId(true);
-        dynrolesContainer.setOutputMarkupPlaceholderTag(true);
-        add(dynrolesContainer);
-
-        dynrolesContainer.add(new AjaxPalettePanel.Builder<String>().build("dynroles",
-                new PropertyModel<>(userTO, "dynRoles"),
-                new ListModel<>(allRoles)).hideLabel().setEnabled(false).setOutputMarkupId(true));
+                setOutputMarkupId(true);
     }
 
     @Override
@@ -122,11 +128,4 @@ public class Roles extends WizardStep implements ICondition {
                 && SyncopeConsoleApplication.get().getSecuritySettings().getAuthorizationStrategy().
                         isActionAuthorized(this, RENDER);
     }
-
-    protected List<String> getManagedRoles() {
-        return SyncopeConsoleApplication.get().getSecuritySettings().getAuthorizationStrategy().
-                isActionAuthorized(this, RENDER)
-                ? new RoleRestClient().list().stream().map(RoleTO::getKey).sorted().collect(Collectors.toList())
-                : Collections.<String>emptyList();
-    }
 }