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

ilgrosso pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/syncope.git


The following commit(s) were added to refs/heads/master by this push:
     new bec0a27  [SYNCOPE-1521] Role assignment filter
bec0a27 is described below

commit bec0a2718694d18b932e8777d4b51927a17ea15d
Author: Marco Di Sabatino Di Diodoro <[email protected]>
AuthorDate: Wed Dec 4 07:34:27 2019 +0100

    [SYNCOPE-1521] Role assignment filter
---
 .../syncope/client/console/wizards/any/Roles.java  | 41 ++++++++++++++++------
 1 file changed, 31 insertions(+), 10 deletions(-)

diff --git 
a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wizards/any/Roles.java
 
b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wizards/any/Roles.java
index 8b6a114..2c61872 100644
--- 
a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wizards/any/Roles.java
+++ 
b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wizards/any/Roles.java
@@ -20,7 +20,6 @@ package org.apache.syncope.client.console.wizards.any;
 
 import org.apache.syncope.client.ui.commons.wizards.any.UserWrapper;
 import org.apache.syncope.client.ui.commons.wizards.any.AnyWrapper;
-import java.util.Collections;
 import java.util.List;
 import java.util.stream.Collectors;
 import org.apache.commons.collections4.CollectionUtils;
@@ -31,7 +30,7 @@ import org.apache.syncope.client.console.rest.RoleRestClient;
 import org.apache.syncope.client.ui.commons.ajax.markup.html.LabelInfo;
 import org.apache.syncope.client.ui.commons.markup.html.form.AjaxPalettePanel;
 import org.apache.syncope.common.lib.to.AnyTO;
-import org.apache.syncope.common.lib.to.EntityTO;
+import org.apache.syncope.common.lib.to.RoleTO;
 import org.apache.syncope.common.lib.to.UserTO;
 import org.apache.syncope.common.lib.types.IdRepoEntitlement;
 import 
org.apache.wicket.authroles.authorization.strategies.role.metadata.ActionPermissions;
@@ -46,6 +45,8 @@ public class Roles extends WizardStep implements ICondition {
 
     private static final long serialVersionUID = 552437609667518888L;
 
+    private static final int MAX_ROLE_LIST_SIZE = 30;
+
     private final List<String> allRoles;
 
     public <T extends AnyTO> Roles(final AnyWrapper<?> modelObject) {
@@ -62,12 +63,12 @@ public class Roles extends WizardStep implements ICondition 
{
             add(new Label("changed", StringUtils.EMPTY));
         }
 
-        final UserTO entityTO = 
UserTO.class.cast(modelObject.getInnerObject());
+        UserTO entityTO = UserTO.class.cast(modelObject.getInnerObject());
 
         // -----------------------------------------------------------------
         // Pre-Authorizations
         // -----------------------------------------------------------------
-        final ActionPermissions permissions = new ActionPermissions();
+        ActionPermissions permissions = new ActionPermissions();
         setMetaData(MetaDataRoleAuthorizationStrategy.ACTION_PERMISSIONS, 
permissions);
         permissions.authorize(RENDER,
                 new 
org.apache.wicket.authroles.authorization.strategies.role.Roles(IdRepoEntitlement.ROLE_LIST));
@@ -77,16 +78,36 @@ public class Roles extends WizardStep implements ICondition 
{
 
         allRoles = 
SyncopeWebApplication.get().getSecuritySettings().getAuthorizationStrategy().
                 isActionAuthorized(this, RENDER)
-                ? 
RoleRestClient.list().stream().map(EntityTO::getKey).collect(Collectors.toList())
+                ? 
RoleRestClient.list().stream().map(RoleTO::getKey).sorted().collect(Collectors.toList())
                 : List.of();
-        Collections.sort(allRoles);
 
-        add(new AjaxPalettePanel.Builder<String>().build("roles",
-                new PropertyModel<List<String>>(entityTO, "roles"),
-                new 
ListModel<>(allRoles)).hideLabel().setOutputMarkupId(true));
+        add(new AjaxPalettePanel.Builder<String>().
+                withFilter().
+                setAllowOrder(true).
+                build("roles",
+                        new PropertyModel<>(modelObject.getInnerObject(), 
"roles"),
+                        new AjaxPalettePanel.Builder.Query<String>() {
+
+                    private static final long serialVersionUID = 
3900199363626636719L;
+
+                    @Override
+                    public List<String> execute(final String filter) {
+                        if (StringUtils.isEmpty(filter) || "*".equals(filter)) 
{
+                            return allRoles.size() > MAX_ROLE_LIST_SIZE
+                                    ? allRoles.subList(0, MAX_ROLE_LIST_SIZE)
+                                    : allRoles;
+
+                        }
+                        return allRoles.stream().
+                                filter(role -> 
StringUtils.containsIgnoreCase(role, filter)).
+                                collect(Collectors.toList());
+                    }
+                }).
+                hideLabel().
+                setOutputMarkupId(true));
 
         add(new AjaxPalettePanel.Builder<String>().build("dynroles",
-                new PropertyModel<List<String>>(entityTO, "dynRoles"),
+                new PropertyModel<>(entityTO, "dynRoles"),
                 new 
ListModel<>(allRoles)).hideLabel().setEnabled(false).setOutputMarkupId(true));
     }
 

Reply via email to