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/21 07:16:00 UTC
[syncope] branch master updated: [SYNCOPE-1521] Fix RealmChoicePanel
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 66563d8 [SYNCOPE-1521] Fix RealmChoicePanel
66563d8 is described below
commit 66563d866eb54557b98eedecc13ecb9bdcefa819
Author: Marco Di Sabatino Di Diodoro <ma...@tirasa.net>
AuthorDate: Mon Apr 20 19:04:06 2020 +0200
[SYNCOPE-1521] Fix RealmChoicePanel
---
.../client/console/SyncopeConsoleSession.java | 12 ++++++++++
.../client/console/commons/RealmsUtils.java | 19 +++++++++++-----
.../syncope/client/console/panels/AnyPanel.java | 2 +-
.../syncope/client/console/panels/Realm.java | 3 +--
.../client/console/panels/RealmChoicePanel.java | 26 ++++++++++++++++------
5 files changed, 46 insertions(+), 16 deletions(-)
diff --git a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/SyncopeConsoleSession.java b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/SyncopeConsoleSession.java
index a5a6c09..73d4833 100644
--- a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/SyncopeConsoleSession.java
+++ b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/SyncopeConsoleSession.java
@@ -253,6 +253,18 @@ public class SyncopeConsoleSession extends AuthenticatedWebSession implements Ba
return auth.values().stream().flatMap(Set::stream).distinct().sorted().collect(Collectors.toList());
}
+ public List<String> getSearchableRealms() {
+ Set<String> roots = auth.get(IdRepoEntitlement.REALM_LIST);
+ return roots.isEmpty()
+ ? Collections.emptyList()
+ : roots.stream().sorted().collect(Collectors.toList());
+ }
+
+ public Optional<String> getRootRealm() {
+ List<String> roots = getSearchableRealms();
+ return roots.isEmpty() ? Optional.empty() : roots.stream().findFirst();
+ }
+
public boolean owns(final String entitlements, final String... realms) {
if (StringUtils.isEmpty(entitlements)) {
return true;
diff --git a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/commons/RealmsUtils.java b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/commons/RealmsUtils.java
index 64b091f..7a8f157 100644
--- a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/commons/RealmsUtils.java
+++ b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/commons/RealmsUtils.java
@@ -18,6 +18,7 @@
*/
package org.apache.syncope.client.console.commons;
+import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.syncope.client.console.SyncopeConsoleSession;
import org.apache.syncope.client.console.rest.RealmRestClient;
@@ -33,12 +34,18 @@ public final class RealmsUtils {
}
public static boolean isSearchEnabled() {
- return new RealmRestClient().search(
- new RealmQuery.Builder().keyword(
- SyncopeConsoleSession.get().getAuthRealms().contains(SyncopeConstants.ROOT_REALM)
- ? SyncopeConstants.ROOT_REALM
- : SyncopeConsoleSession.get().getAuthRealms().get(0)).build()).
- getTotalCount() > REALMS_VIEW_SIZE;
+ return isSearchEnabled(SyncopeConsoleSession.get().getAuthRealms());
+ }
+
+ public static boolean isSearchEnabled(final List<String> realms) {
+ return realms.isEmpty()
+ ? false
+ : new RealmRestClient().search(
+ new RealmQuery.Builder().keyword(
+ realms.contains(SyncopeConstants.ROOT_REALM)
+ ? SyncopeConstants.ROOT_REALM
+ : realms.get(0)).build()).
+ getTotalCount() > REALMS_VIEW_SIZE;
}
public static boolean checkInput(final String input) {
diff --git a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/AnyPanel.java b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/AnyPanel.java
index f9594b1..31971bb 100644
--- a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/AnyPanel.java
+++ b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/AnyPanel.java
@@ -88,7 +88,7 @@ public class AnyPanel extends Panel implements ModalPanel {
final String realm;
final String dynRealm;
- if (realmTO.getFullPath().startsWith(SyncopeConstants.ROOT_REALM)) {
+ if (StringUtils.startsWith(realmTO.getFullPath(), SyncopeConstants.ROOT_REALM)) {
realm = realmTO.getFullPath();
dynRealm = null;
} else {
diff --git a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/Realm.java b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/Realm.java
index 541bbe3..793e1e6 100644
--- a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/Realm.java
+++ b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/Realm.java
@@ -108,8 +108,7 @@ public abstract class Realm extends WizardMgtPanel<RealmTO> {
public Panel getPanel(final String panelId) {
final ActionsPanel<RealmTO> actionPanel = new ActionsPanel<>("actions", null);
- if (realmTO.getFullPath().startsWith(SyncopeConstants.ROOT_REALM)) {
-
+ if (StringUtils.startsWith(realmTO.getFullPath(), SyncopeConstants.ROOT_REALM)) {
actionPanel.add(new ActionLink<RealmTO>(realmTO) {
private static final long serialVersionUID = 2802988981431379827L;
diff --git a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/RealmChoicePanel.java b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/RealmChoicePanel.java
index 28c24ab..40b579e 100644
--- a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/RealmChoicePanel.java
+++ b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/RealmChoicePanel.java
@@ -33,6 +33,7 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.syncope.client.console.SyncopeConsoleSession;
import org.apache.syncope.client.console.commons.RealmsUtils;
@@ -44,7 +45,6 @@ import org.apache.syncope.common.lib.SyncopeConstants;
import org.apache.syncope.common.lib.to.DynRealmTO;
import org.apache.syncope.common.lib.to.RealmTO;
import org.apache.syncope.common.lib.types.IdRepoEntitlement;
-import org.apache.syncope.common.rest.api.beans.RealmQuery;
import org.apache.wicket.PageReference;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.authroles.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy;
@@ -95,9 +95,9 @@ public class RealmChoicePanel extends Panel {
public RealmChoicePanel(final String id, final PageReference pageRef) {
super(id);
this.pageRef = pageRef;
- availableRealms = SyncopeConsoleSession.get().getAuthRealms();
+ availableRealms = SyncopeConsoleSession.get().getSearchableRealms();
tree = new HashMap<>();
- isSearchEnabled = RealmsUtils.isSearchEnabled();
+ isSearchEnabled = RealmsUtils.isSearchEnabled(SyncopeConsoleSession.get().getSearchableRealms());
realmTree = new LoadableDetachableModel<List<Pair<String, RealmTO>>>() {
@@ -149,9 +149,21 @@ public class RealmChoicePanel extends Panel {
}
};
- RealmTO realmTO = RealmRestClient.search(
- new RealmQuery.Builder().keyword("*" + availableRealms.stream().findFirst().get() + "*").build()).
- getResult().stream().findFirst().get();
+ RealmTO realmTO = SyncopeConsoleSession.get().getRootRealm().map(rootRealm -> {
+ String rootRealmName = StringUtils.substringAfterLast(rootRealm, "/");
+
+ List<RealmTO> realmTOs = RealmRestClient.search(
+ RealmsUtils.buildQuery(SyncopeConstants.ROOT_REALM.equals(rootRealm)
+ ? SyncopeConstants.ROOT_REALM : rootRealmName)).getResult();
+
+ return realmTOs.stream().filter(realm -> rootRealm.equals(realm.getFullPath())).findFirst().
+ orElseGet(() -> {
+ RealmTO placeholder = new RealmTO();
+ placeholder.setName(rootRealmName);
+ placeholder.setFullPath(rootRealm);
+ return placeholder;
+ });
+ }).orElseGet(() -> new RealmTO());
model = Model.of(realmTO);
searchQuery = realmTO.getName();
@@ -167,7 +179,7 @@ public class RealmChoicePanel extends Panel {
container.addOrReplace(realmLabel);
- if (model.getObject().getFullPath().startsWith(SyncopeConstants.ROOT_REALM)) {
+ if (StringUtils.startsWith(model.getObject().getFullPath(), SyncopeConstants.ROOT_REALM)) {
realmLabel.setDefaultModel(new ResourceModel("realmLabel", "Realm"));
} else {
realmLabel.setDefaultModel(new ResourceModel("dynRealmLabel", "Dynamic Realm"));