Skip to content

Commit

Permalink
[SYNCOPE-1719] Long-waiting fix for Console and Enduser
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgrosso committed Oct 31, 2024
1 parent 556f806 commit 82e1252
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,35 @@ public abstract class AbstractGroupsModel extends ListModel<GroupTO> {

protected List<MembershipTO> memberships;

protected String realm;

@Override
public List<GroupTO> getObject() {
reload();
return groups;
}

/**
* Retrieve the first MAX_GROUP_LIST_CARDINALITY assignable.
*/
protected abstract void reloadObject();

public List<MembershipTO> getMemberships() {
reload();
return memberships;
@Override
public List<GroupTO> getObject() {
if (groups == null) {
reloadObject();
}
return groups;
}

/**
* Retrieve group memberships.
*/
protected abstract void reloadMemberships();

public abstract List<String> getDynMemberships();
public List<MembershipTO> 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<String> getDynMemberships();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -92,8 +91,9 @@ public <T extends AnyTO> Groups(final AnyWrapper<T> modelObject, final boolean t
addDynamicRealmsContainer();
}

protected List<GroupTO> searchAssignable(final String realm, final String term) {
return syncopeRestClient.searchAssignableGroups(realm, term, 1, Constants.MAX_GROUP_LIST_SIZE);
protected List<GroupTO> searchAssignable(final String term) {
return syncopeRestClient.searchAssignableGroups(
SyncopeConstants.ROOT_REALM, term, 1, Constants.MAX_GROUP_LIST_SIZE);
}

@Override
Expand Down Expand Up @@ -157,7 +157,7 @@ public List<MembershipTO> 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());
Expand Down Expand Up @@ -200,32 +200,14 @@ public class ConsoleGroupsModel extends AbstractGroupsModel {

private static final long serialVersionUID = -4541954630939063927L;

protected List<GroupTO> groupsObj;

protected List<MembershipTO> membershipsObj;

protected List<String> dynMembershipsObj;

protected String realmObj;

@Override
public List<GroupTO> getObject() {
reload();
return groupsObj;
}
protected List<String> dynMemberships;

/**
* Retrieve the first MAX_GROUP_LIST_SIZE assignable.
*/
@Override
protected void reloadObject() {
groupsObj = searchAssignable(realmObj, null);
}

@Override
public List<MembershipTO> getMemberships() {
reload();
return membershipsObj;
groups = searchAssignable(null);
}

/**
Expand All @@ -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,
Expand All @@ -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<String> 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();
Expand All @@ -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,
Expand All @@ -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<String> getDynMemberships() {
if (dynMemberships == null) {
reloadDynMemberships();
}
return dynMemberships;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -174,30 +175,18 @@ protected class EnduserGroupsModel extends AbstractGroupsModel {

private static final long serialVersionUID = -4541954630939063927L;

@Override
public List<GroupTO> 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<MembershipTO> getMemberships() {
reload();
return memberships;
}

/**
* Retrieve group memberships.
*/
Expand All @@ -206,32 +195,14 @@ protected void reloadMemberships() {
memberships = GroupableRelatableTO.class.cast(anyTO).getMemberships();
}

@Override
public List<String> 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<String> getDynMemberships() {
return List.of();
}
}
}

This file was deleted.

0 comments on commit 82e1252

Please sign in to comment.