From 82e1252b32b68e30cec8d2e88dc0b8bb283670fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Chicchiricc=C3=B2?= Date: Thu, 31 Oct 2024 10:35:19 +0100 Subject: [PATCH] [SYNCOPE-1719] Long-waiting fix for Console and Enduser --- .../wizards/any/AbstractGroupsModel.java | 29 +++--- .../client/console/wizards/any/Groups.java | 68 +++----------- .../client/enduser/panels/any/Groups.java | 37 +------- .../api/dao/search/AssignableCond.java | 92 ------------------- 4 files changed, 31 insertions(+), 195 deletions(-) delete mode 100644 core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/search/AssignableCond.java diff --git a/client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/wizards/any/AbstractGroupsModel.java b/client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/wizards/any/AbstractGroupsModel.java index 66d799f4c7..395db18d56 100644 --- a/client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/wizards/any/AbstractGroupsModel.java +++ b/client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/wizards/any/AbstractGroupsModel.java @@ -31,22 +31,17 @@ public abstract class AbstractGroupsModel extends ListModel { protected List memberships; - protected String realm; - - @Override - public List getObject() { - reload(); - return groups; - } - /** * Retrieve the first MAX_GROUP_LIST_CARDINALITY assignable. */ protected abstract void reloadObject(); - public List getMemberships() { - reload(); - return memberships; + @Override + public List getObject() { + if (groups == null) { + reloadObject(); + } + return groups; } /** @@ -54,15 +49,17 @@ public List getMemberships() { */ protected abstract void reloadMemberships(); - public abstract List getDynMemberships(); + public List getMemberships() { + if (memberships == null) { + reloadMemberships(); + } + return memberships; + } /** * Retrieve dyn group memberships. */ protected abstract void reloadDynMemberships(); - /** - * Reload data if the realm changes (see SYNCOPE-1135). - */ - protected abstract void reload(); + public abstract List getDynMemberships(); } diff --git a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wizards/any/Groups.java b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wizards/any/Groups.java index ac6ff5496f..e1c83b6209 100644 --- a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wizards/any/Groups.java +++ b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wizards/any/Groups.java @@ -28,7 +28,6 @@ import org.apache.cxf.jaxrs.ext.search.client.CompleteCondition; import org.apache.syncope.client.console.SyncopeConsoleSession; import org.apache.syncope.client.console.SyncopeWebApplication; -import org.apache.syncope.client.console.commons.RealmsUtils; import org.apache.syncope.client.console.rest.GroupRestClient; import org.apache.syncope.client.console.rest.SyncopeRestClient; import org.apache.syncope.client.lib.SyncopeClient; @@ -92,8 +91,9 @@ public Groups(final AnyWrapper modelObject, final boolean t addDynamicRealmsContainer(); } - protected List searchAssignable(final String realm, final String term) { - return syncopeRestClient.searchAssignableGroups(realm, term, 1, Constants.MAX_GROUP_LIST_SIZE); + protected List searchAssignable(final String term) { + return syncopeRestClient.searchAssignableGroups( + SyncopeConstants.ROOT_REALM, term, 1, Constants.MAX_GROUP_LIST_SIZE); } @Override @@ -157,7 +157,7 @@ public List execute(final String filter) { ? List.of() : ("*".equals(filter) ? groupsModel.getObject() - : searchAssignable(anyTO.getRealm(), filter)).stream(). + : searchAssignable(filter)).stream(). map(group -> new MembershipTO.Builder(group.getKey()). groupName(group.getName()).build()). collect(Collectors.toList()); @@ -200,32 +200,14 @@ public class ConsoleGroupsModel extends AbstractGroupsModel { private static final long serialVersionUID = -4541954630939063927L; - protected List groupsObj; - - protected List membershipsObj; - - protected List dynMembershipsObj; - - protected String realmObj; - - @Override - public List getObject() { - reload(); - return groupsObj; - } + protected List dynMemberships; /** * Retrieve the first MAX_GROUP_LIST_SIZE assignable. */ @Override protected void reloadObject() { - groupsObj = searchAssignable(realmObj, null); - } - - @Override - public List getMemberships() { - reload(); - return membershipsObj; + groups = searchAssignable(null); } /** @@ -251,7 +233,7 @@ protected void reloadMemberships() { if (!conditions.isEmpty()) { assignedGroups.putAll(groupRestClient.search( - realmObj, + SyncopeConstants.ROOT_REALM, builder.or(conditions).query(), 1, Constants.MAX_GROUP_LIST_SIZE, @@ -266,19 +248,10 @@ protected void reloadMemberships() { forEach(m -> m.setGroupName(assignedGroups.get(m.getGroupKey()))); GroupableRelatableTO.class.cast(anyTO).getMemberships().removeIf(m -> m.getGroupName() == null); - membershipsObj = GroupableRelatableTO.class.cast(anyTO).getMemberships(); - membershipsObj.sort(Comparator.comparing(MembershipTO::getGroupName)); - } - - @Override - public List getDynMemberships() { - reload(); - return dynMembershipsObj; + memberships = GroupableRelatableTO.class.cast(anyTO).getMemberships(); + memberships.sort(Comparator.comparing(MembershipTO::getGroupName)); } - /** - * Retrieve dyn group memberships. - */ @Override protected void reloadDynMemberships() { GroupFiqlSearchConditionBuilder builder = SyncopeClient.getGroupSearchConditionBuilder(); @@ -288,9 +261,9 @@ protected void reloadDynMemberships() { equalTo(membership.getGroupKey()).wrap()). collect(Collectors.toList()); - dynMembershipsObj = new ArrayList<>(); + dynMemberships = new ArrayList<>(); if (SyncopeConsoleSession.get().owns(IdRepoEntitlement.GROUP_SEARCH) && !conditions.isEmpty()) { - dynMembershipsObj.addAll(groupRestClient.search( + dynMemberships.addAll(groupRestClient.search( SyncopeConstants.ROOT_REALM, builder.or(conditions).query(), -1, @@ -300,25 +273,12 @@ protected void reloadDynMemberships() { } } - /** - * Reload data if the realm changes (see SYNCOPE-1135). - */ @Override - protected void reload() { - boolean reload; - if (Groups.this.templateMode) { - reload = realmObj == null; - realmObj = SyncopeConstants.ROOT_REALM; - } else { - reload = !Groups.this.anyTO.getRealm().equalsIgnoreCase(realmObj); - realmObj = RealmsUtils.getFullPath(Groups.this.anyTO.getRealm()); - } - - if (reload) { - reloadObject(); - reloadMemberships(); + public List getDynMemberships() { + if (dynMemberships == null) { reloadDynMemberships(); } + return dynMemberships; } } } diff --git a/client/idrepo/enduser/src/main/java/org/apache/syncope/client/enduser/panels/any/Groups.java b/client/idrepo/enduser/src/main/java/org/apache/syncope/client/enduser/panels/any/Groups.java index 6de07c2974..c767c3544d 100644 --- a/client/idrepo/enduser/src/main/java/org/apache/syncope/client/enduser/panels/any/Groups.java +++ b/client/idrepo/enduser/src/main/java/org/apache/syncope/client/enduser/panels/any/Groups.java @@ -28,6 +28,7 @@ import org.apache.syncope.client.ui.commons.wizards.any.AbstractGroupsModel; import org.apache.syncope.client.ui.commons.wizards.any.AnyWrapper; import org.apache.syncope.client.ui.commons.wizards.any.UserWrapper; +import org.apache.syncope.common.lib.SyncopeConstants; import org.apache.syncope.common.lib.to.AnyTO; import org.apache.syncope.common.lib.to.GroupTO; import org.apache.syncope.common.lib.to.GroupableRelatableTO; @@ -174,30 +175,18 @@ protected class EnduserGroupsModel extends AbstractGroupsModel { private static final long serialVersionUID = -4541954630939063927L; - @Override - public List getObject() { - reload(); - return groups; - } - /** * Retrieve the first MAX_GROUP_LIST_CARDINALITY assignable. */ @Override protected void reloadObject() { groups = groupRestClient.searchAssignableGroups( - realm, + SyncopeConstants.ROOT_REALM, null, 1, MAX_GROUP_LIST_CARDINALITY); } - @Override - public List getMemberships() { - reload(); - return memberships; - } - /** * Retrieve group memberships. */ @@ -206,32 +195,14 @@ protected void reloadMemberships() { memberships = GroupableRelatableTO.class.cast(anyTO).getMemberships(); } - @Override - public List getDynMemberships() { - return List.of(); - } - - /** - * Retrieve dyn group memberships. - */ @Override protected void reloadDynMemberships() { // DO NOTHING } - /** - * Reload data if the realm changes (see SYNCOPE-1135). - */ @Override - protected void reload() { - boolean reload = Groups.this.anyTO.getRealm() != null - && !Groups.this.anyTO.getRealm().equalsIgnoreCase(realm); - realm = Groups.this.anyTO.getRealm(); - - if (reload) { - reloadObject(); - reloadMemberships(); - } + public List getDynMemberships() { + return List.of(); } } } diff --git a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/search/AssignableCond.java b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/search/AssignableCond.java deleted file mode 100644 index dae0a447b9..0000000000 --- a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/search/AssignableCond.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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.core.persistence.api.dao.search; - -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.commons.lang3.builder.ToStringBuilder; - -public class AssignableCond extends AbstractSearchCond { - - private static final long serialVersionUID = 1237627275756159522L; - - private String realmFullPath; - - /** - * Whether this condition should be evaluated from the assignable group's or instead the - * assignee's point of view (default). - * The converter from FIQL will ignore this setting, which is meant for internal usage. - */ - private boolean fromGroup = false; - - public String getRealmFullPath() { - return realmFullPath; - } - - public void setRealmFullPath(final String realmFullPath) { - this.realmFullPath = realmFullPath; - } - - public boolean isFromGroup() { - return fromGroup; - } - - public void setFromGroup(final boolean fromGroup) { - this.fromGroup = fromGroup; - } - - @Override - public final boolean isValid() { - return realmFullPath != null; - } - - @Override - public int hashCode() { - return new HashCodeBuilder(). - append(realmFullPath). - append(fromGroup). - build(); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final AssignableCond other = (AssignableCond) obj; - return new EqualsBuilder(). - append(realmFullPath, other.realmFullPath). - append(fromGroup, other.fromGroup). - build(); - } - - @Override - public String toString() { - return new ToStringBuilder(this). - append(realmFullPath). - append(fromGroup). - build(); - } -}