Repository: syncope
Updated Branches:
  refs/heads/master 704b3adb9 -> cf3eb46da


[SYNCOPE-1074] adds for entitlements check to enable realm list items


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/cf3eb46d
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/cf3eb46d
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/cf3eb46d

Branch: refs/heads/master
Commit: cf3eb46dad9dee4c5b04b212098e6dc9b87d208c
Parents: 704b3ad
Author: fmartelli <fabio.marte...@gmail.com>
Authored: Mon May 8 23:03:18 2017 +0200
Committer: fmartelli <fabio.marte...@gmail.com>
Committed: Mon May 8 23:04:04 2017 +0200

----------------------------------------------------------------------
 .../client/console/SyncopeConsoleSession.java   | 28 +++++++++++++++-----
 .../client/console/commons/ITabComponent.java   | 10 +++++++
 .../syncope/client/console/panels/Realm.java    | 12 ++++-----
 .../client/console/panels/RealmChoicePanel.java | 19 +++++++++++++
 .../console/wizards/any/Relationships.java      |  2 +-
 .../console/wizards/any/Relationships.html      |  2 +-
 6 files changed, 59 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/cf3eb46d/client/console/src/main/java/org/apache/syncope/client/console/SyncopeConsoleSession.java
----------------------------------------------------------------------
diff --git 
a/client/console/src/main/java/org/apache/syncope/client/console/SyncopeConsoleSession.java
 
b/client/console/src/main/java/org/apache/syncope/client/console/SyncopeConsoleSession.java
index 5c3c750..62f1a76 100644
--- 
a/client/console/src/main/java/org/apache/syncope/client/console/SyncopeConsoleSession.java
+++ 
b/client/console/src/main/java/org/apache/syncope/client/console/SyncopeConsoleSession.java
@@ -21,6 +21,7 @@ package org.apache.syncope.client.console;
 import java.text.DateFormat;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
@@ -28,6 +29,7 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import javax.ws.rs.core.EntityTag;
 import javax.ws.rs.core.MediaType;
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.time.FastDateFormat;
 import org.apache.commons.lang3.tuple.Pair;
@@ -148,8 +150,7 @@ public class SyncopeConsoleSession extends 
AuthenticatedWebSession {
         boolean authenticated = false;
 
         try {
-            client = clientFactory.
-                    setDomain(getDomain()).create(username, password);
+            client = clientFactory.setDomain(getDomain()).create(username, 
password);
 
             afterAuthentication();
 
@@ -165,8 +166,7 @@ public class SyncopeConsoleSession extends 
AuthenticatedWebSession {
         boolean authenticated = false;
 
         try {
-            client = clientFactory.
-                    setDomain(getDomain()).create(jwt);
+            client = clientFactory.setDomain(getDomain()).create(jwt);
 
             afterAuthentication();
 
@@ -217,6 +217,23 @@ public class SyncopeConsoleSession extends 
AuthenticatedWebSession {
         return selfTO;
     }
 
+    public Set<String> getAvailableRealms(final String... entitlements) {
+        final Set<String> availableRealms = new HashSet<>();
+        if (entitlements != null && entitlements.length > 0) {
+            for (String entitlement : entitlements) {
+                final Set<String> realms = auth.get(entitlement);
+                if (CollectionUtils.isNotEmpty(realms)) {
+                    availableRealms.addAll(realms);
+                }
+            }
+        } else {
+            for (Map.Entry<String, Set<String>> entitlement : auth.entrySet()) 
{
+                availableRealms.addAll(entitlement.getValue());
+            }
+        }
+        return availableRealms;
+    }
+
     public boolean owns(final String entitlement) {
         return auth != null && auth.containsKey(entitlement);
     }
@@ -266,8 +283,7 @@ public class SyncopeConsoleSession extends 
AuthenticatedWebSession {
         T service;
 
         synchronized (clientFactory) {
-            SyncopeClientFactoryBean.ContentType preType = clientFactory.
-                    getContentType();
+            SyncopeClientFactoryBean.ContentType preType = 
clientFactory.getContentType();
 
             clientFactory.
                     
setContentType(SyncopeClientFactoryBean.ContentType.fromString(mediaType.toString()));

http://git-wip-us.apache.org/repos/asf/syncope/blob/cf3eb46d/client/console/src/main/java/org/apache/syncope/client/console/commons/ITabComponent.java
----------------------------------------------------------------------
diff --git 
a/client/console/src/main/java/org/apache/syncope/client/console/commons/ITabComponent.java
 
b/client/console/src/main/java/org/apache/syncope/client/console/commons/ITabComponent.java
index a49c917..1c43d8d 100644
--- 
a/client/console/src/main/java/org/apache/syncope/client/console/commons/ITabComponent.java
+++ 
b/client/console/src/main/java/org/apache/syncope/client/console/commons/ITabComponent.java
@@ -18,6 +18,7 @@
  */
 package org.apache.syncope.client.console.commons;
 
+import java.util.Set;
 import java.util.UUID;
 import org.apache.wicket.Component;
 import org.apache.wicket.authroles.authorization.strategies.role.Roles;
@@ -42,6 +43,15 @@ public abstract class ITabComponent extends Component 
implements ITab {
      * @param title IModel used to represent the title of the tab. Must 
contain a string
      * @param roles authorized roles
      */
+    public ITabComponent(final IModel<String> title, final Set<String> roles) {
+        this(title, roles.toArray(new String[roles.size()]));
+    }
+    /**
+     * Constructor.
+     *
+     * @param title IModel used to represent the title of the tab. Must 
contain a string
+     * @param roles authorized roles
+     */
     public ITabComponent(final IModel<String> title, final String... roles) {
         super(UUID.randomUUID().toString());
         this.title = title;

http://git-wip-us.apache.org/repos/asf/syncope/blob/cf3eb46d/client/console/src/main/java/org/apache/syncope/client/console/panels/Realm.java
----------------------------------------------------------------------
diff --git 
a/client/console/src/main/java/org/apache/syncope/client/console/panels/Realm.java
 
b/client/console/src/main/java/org/apache/syncope/client/console/panels/Realm.java
index 3c78300..615b393 100644
--- 
a/client/console/src/main/java/org/apache/syncope/client/console/panels/Realm.java
+++ 
b/client/console/src/main/java/org/apache/syncope/client/console/panels/Realm.java
@@ -85,8 +85,8 @@ public abstract class Realm extends WizardMgtPanel<RealmTO> {
 
         setPageRef(pageRef);
 
-        AjaxBootstrapTabbedPanel<ITab> tabbedPanel =
-                new AjaxBootstrapTabbedPanel<>("tabbedPanel", 
buildTabList(pageRef));
+        AjaxBootstrapTabbedPanel<ITab> tabbedPanel
+                = new AjaxBootstrapTabbedPanel<>("tabbedPanel", 
buildTabList(pageRef));
         tabbedPanel.setSelectedTab(selectedIndex);
         addInnerObject(tabbedPanel);
         this.wizardBuilder = new RealmWizardBuilder(pageRef);
@@ -167,15 +167,15 @@ public abstract class Realm extends 
WizardMgtPanel<RealmTO> {
             }
         });
 
-        final Triple<UserFormLayoutInfo, GroupFormLayoutInfo, Map<String, 
AnyObjectFormLayoutInfo>> formLayoutInfo =
-                FormLayoutInfoUtils.fetch(anyTypeTOs);
+        final Triple<UserFormLayoutInfo, GroupFormLayoutInfo, Map<String, 
AnyObjectFormLayoutInfo>> formLayoutInfo
+                = FormLayoutInfoUtils.fetch(anyTypeTOs);
 
         Collections.sort(anyTypeTOs, new AnyTypeComparator());
         for (final AnyTypeTO anyTypeTO : anyTypeTOs) {
             tabs.add(new ITabComponent(
                     new Model<>(anyTypeTO.getKey()),
                     AnyTypeKind.GROUP.name().equals(anyTypeTO.getKey())
-                    ? null : String.format("%s_SEARCH", anyTypeTO.getKey())) {
+                    ? null : new String[]{String.format("%s_SEARCH", 
anyTypeTO.getKey())}) {
 
                 private static final long serialVersionUID = 
1169585538404171118L;
 
@@ -228,7 +228,7 @@ public abstract class Realm extends WizardMgtPanel<RealmTO> 
{
                             || 
CollectionUtils.isEmpty(afterObj.getAttrMap().get(ConnIdSpecialName.NAME).getValues())
                             ? StringUtils.EMPTY
                             : 
afterObj.getAttrMap().get(ConnIdSpecialName.NAME).getValues().
-                                    iterator().next();
+                            iterator().next();
 
                     return new Label("field", remoteId);
                 } else if ("status".equalsIgnoreCase(key)) {

http://git-wip-us.apache.org/repos/asf/syncope/blob/cf3eb46d/client/console/src/main/java/org/apache/syncope/client/console/panels/RealmChoicePanel.java
----------------------------------------------------------------------
diff --git 
a/client/console/src/main/java/org/apache/syncope/client/console/panels/RealmChoicePanel.java
 
b/client/console/src/main/java/org/apache/syncope/client/console/panels/RealmChoicePanel.java
index 48a31cd..2d985ef 100644
--- 
a/client/console/src/main/java/org/apache/syncope/client/console/panels/RealmChoicePanel.java
+++ 
b/client/console/src/main/java/org/apache/syncope/client/console/panels/RealmChoicePanel.java
@@ -32,8 +32,12 @@ import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import org.apache.commons.collections4.IterableUtils;
+import org.apache.commons.collections4.Predicate;
 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.rest.RealmRestClient;
 import org.apache.syncope.common.lib.to.RealmTO;
 import org.apache.syncope.common.lib.types.StandardEntitlement;
@@ -63,6 +67,8 @@ public class RealmChoicePanel extends Panel {
 
     private final Model<RealmTO> model;
 
+    private final Set<String> availableRealms;
+
     private final Map<String, Pair<RealmTO, List<RealmTO>>> tree;
 
     public RealmChoicePanel(final String id, final PageReference pageRef) {
@@ -109,6 +115,8 @@ public class RealmChoicePanel extends Panel {
         container.setOutputMarkupId(true);
         add(container);
 
+        availableRealms = SyncopeConsoleSession.get().getAvailableRealms();
+
         reloadRealmTree();
     }
 
@@ -143,6 +151,17 @@ public class RealmChoicePanel extends Panel {
                             target.add(label);
                             send(pageRef.getPage(), Broadcast.EXACT, new 
ChosenRealm<>(realmTO, target));
                         }
+
+                        @Override
+                        public boolean isEnabled() {
+                            return IterableUtils.matchesAny(availableRealms, 
new Predicate<String>() {
+
+                                @Override
+                                public boolean evaluate(final String 
availableRealm) {
+                                    return 
realmTO.getFullPath().startsWith(availableRealm);
+                                }
+                            });
+                        }
                     });
                 }
                 return links;

http://git-wip-us.apache.org/repos/asf/syncope/blob/cf3eb46d/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/Relationships.java
----------------------------------------------------------------------
diff --git 
a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/Relationships.java
 
b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/Relationships.java
index 9c43187..0d2c323 100644
--- 
a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/Relationships.java
+++ 
b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/Relationships.java
@@ -168,7 +168,7 @@ public class Relationships extends WizardStep {
                 addFragment.add(new Specification().setRenderBodyOnly(true));
                 target.add(Relationships.this);
             }
-        }, ActionType.CREATE, AnyEntitlement.UPDATE.getFor(anyTO.getType()));
+        }, ActionType.CREATE, 
AnyEntitlement.UPDATE.getFor(anyTO.getType())).hideLabel();
 
         return viewFragment;
     }

http://git-wip-us.apache.org/repos/asf/syncope/blob/cf3eb46d/client/console/src/main/resources/org/apache/syncope/client/console/wizards/any/Relationships.html
----------------------------------------------------------------------
diff --git 
a/client/console/src/main/resources/org/apache/syncope/client/console/wizards/any/Relationships.html
 
b/client/console/src/main/resources/org/apache/syncope/client/console/wizards/any/Relationships.html
index 6c86544..34e8266 100644
--- 
a/client/console/src/main/resources/org/apache/syncope/client/console/wizards/any/Relationships.html
+++ 
b/client/console/src/main/resources/org/apache/syncope/client/console/wizards/any/Relationships.html
@@ -25,7 +25,7 @@ under the License.
 
       <wicket:fragment wicket:id="viewFragment">
         <div wicket:id="relationships"/>
-        <div class="modal-footer">
+        <div id="inline-actions" class="modal-footer">
           <span wicket:id="actions" class="circular-actions">[ACTIONS]</span>
         </div>
       </wicket:fragment>

Reply via email to