ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [42/60] [abbrv] ignite git commit: IGNITE-5081 - Removed redundant duplication of permissions in SecurityPermissionSetBuilder
Date Thu, 04 May 2017 11:32:46 GMT
IGNITE-5081 - Removed redundant duplication of permissions in SecurityPermissionSetBuilder


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

Branch: refs/heads/ignite-5075-cacheStart
Commit: 56ec995199d12c3b257e77cb49296dc747bc7a93
Parents: 2f7172c
Author: Valentin Kulichenko <valentin.kulichenko@gmail.com>
Authored: Fri Apr 28 14:48:57 2017 +0200
Committer: Valentin Kulichenko <valentin.kulichenko@ing.be>
Committed: Tue May 2 12:59:53 2017 +0200

----------------------------------------------------------------------
 .../security/SecurityPermissionSetBuilder.java  | 17 +++---
 .../SecurityPermissionSetBuilderTest.java       | 63 ++++++++++++--------
 2 files changed, 46 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/56ec9951/modules/core/src/main/java/org/apache/ignite/plugin/security/SecurityPermissionSetBuilder.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/plugin/security/SecurityPermissionSetBuilder.java
b/modules/core/src/main/java/org/apache/ignite/plugin/security/SecurityPermissionSetBuilder.java
index cf38c0f..abac541 100644
--- a/modules/core/src/main/java/org/apache/ignite/plugin/security/SecurityPermissionSetBuilder.java
+++ b/modules/core/src/main/java/org/apache/ignite/plugin/security/SecurityPermissionSetBuilder.java
@@ -17,16 +17,17 @@
 
 package org.apache.ignite.plugin.security;
 
-import java.util.Map;
-import java.util.List;
-import java.util.HashMap;
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
 import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.util.typedef.internal.U;
 
-import static java.util.Collections.unmodifiableList;
 import static java.util.Collections.unmodifiableMap;
+import static java.util.Collections.unmodifiableSet;
 
 /**
  * Provides a convenient way to create a permission set.
@@ -61,7 +62,7 @@ public class SecurityPermissionSetBuilder {
     private Map<String, Collection<SecurityPermission>> srvcPerms = new HashMap<>();
 
     /** System permissions.*/
-    private List<SecurityPermission> sysPerms = new ArrayList<>();
+    private Set<SecurityPermission> sysPerms = new HashSet<>();
 
     /** Default allow all.*/
     private boolean dfltAllowAll;
@@ -193,7 +194,7 @@ public class SecurityPermissionSetBuilder {
     private final <T> Collection<T> toCollection(T... perms) {
         assert perms != null;
 
-        Collection<T> col = new ArrayList<>(perms.length);
+        Collection<T> col = U.newHashSet(perms.length);
 
         Collections.addAll(col, perms);
 
@@ -234,7 +235,7 @@ public class SecurityPermissionSetBuilder {
         permSet.setCachePermissions(unmodifiableMap(cachePerms));
         permSet.setTaskPermissions(unmodifiableMap(taskPerms));
         permSet.setServicePermissions(unmodifiableMap(srvcPerms));
-        permSet.setSystemPermissions(unmodifiableList(sysPerms));
+        permSet.setSystemPermissions(unmodifiableSet(sysPerms));
 
         return permSet;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/56ec9951/modules/core/src/test/java/org/apache/ignite/plugin/security/SecurityPermissionSetBuilderTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/plugin/security/SecurityPermissionSetBuilderTest.java
b/modules/core/src/test/java/org/apache/ignite/plugin/security/SecurityPermissionSetBuilderTest.java
index 5443cfd..0ac7bc7 100644
--- a/modules/core/src/test/java/org/apache/ignite/plugin/security/SecurityPermissionSetBuilderTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/plugin/security/SecurityPermissionSetBuilderTest.java
@@ -17,23 +17,24 @@
 
 package org.apache.ignite.plugin.security;
 
-import java.util.Map;
-import java.util.Arrays;
-import java.util.HashMap;
 import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.concurrent.Callable;
 import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 
+import static org.apache.ignite.plugin.security.SecurityPermission.ADMIN_VIEW;
 import static org.apache.ignite.plugin.security.SecurityPermission.CACHE_PUT;
 import static org.apache.ignite.plugin.security.SecurityPermission.CACHE_READ;
 import static org.apache.ignite.plugin.security.SecurityPermission.CACHE_REMOVE;
 import static org.apache.ignite.plugin.security.SecurityPermission.SERVICE_DEPLOY;
 import static org.apache.ignite.plugin.security.SecurityPermission.SERVICE_INVOKE;
+import static org.apache.ignite.plugin.security.SecurityPermission.EVENTS_ENABLE;
 import static org.apache.ignite.plugin.security.SecurityPermission.TASK_CANCEL;
 import static org.apache.ignite.plugin.security.SecurityPermission.TASK_EXECUTE;
-import static org.apache.ignite.plugin.security.SecurityPermission.EVENTS_ENABLE;
-import static org.apache.ignite.plugin.security.SecurityPermission.ADMIN_VIEW;
 import static org.apache.ignite.testframework.GridTestUtils.assertThrows;
 
 /**
@@ -41,31 +42,30 @@ import static org.apache.ignite.testframework.GridTestUtils.assertThrows;
  */
 public class SecurityPermissionSetBuilderTest extends GridCommonAbstractTest {
     /**
-     *
      */
     @SuppressWarnings({"ThrowableNotThrown", "ArraysAsListWithZeroOrOneArgument"})
     public void testPermissionBuilder() {
         SecurityBasicPermissionSet exp = new SecurityBasicPermissionSet();
 
         Map<String, Collection<SecurityPermission>> permCache = new HashMap<>();
-        permCache.put("cache1", Arrays.asList(CACHE_PUT, CACHE_REMOVE));
-        permCache.put("cache2", Arrays.asList(CACHE_READ));
+        permCache.put("cache1", permissions(CACHE_PUT, CACHE_REMOVE));
+        permCache.put("cache2", permissions(CACHE_READ));
 
         exp.setCachePermissions(permCache);
 
         Map<String, Collection<SecurityPermission>> permTask = new HashMap<>();
-        permTask.put("task1", Arrays.asList(TASK_CANCEL));
-        permTask.put("task2", Arrays.asList(TASK_EXECUTE));
+        permTask.put("task1", permissions(TASK_CANCEL));
+        permTask.put("task2", permissions(TASK_EXECUTE));
 
         exp.setTaskPermissions(permTask);
 
         Map<String, Collection<SecurityPermission>> permSrvc = new HashMap<>();
-        permSrvc.put("service1", Arrays.asList(SERVICE_DEPLOY));
-        permSrvc.put("service2", Arrays.asList(SERVICE_INVOKE));
+        permSrvc.put("service1", permissions(SERVICE_DEPLOY));
+        permSrvc.put("service2", permissions(SERVICE_INVOKE));
 
         exp.setServicePermissions(permSrvc);
 
-        exp.setSystemPermissions(Arrays.asList(ADMIN_VIEW, EVENTS_ENABLE));
+        exp.setSystemPermissions(permissions(ADMIN_VIEW, EVENTS_ENABLE));
 
         final SecurityPermissionSetBuilder permsBuilder = new SecurityPermissionSetBuilder();
 
@@ -105,19 +105,18 @@ public class SecurityPermissionSetBuilderTest extends GridCommonAbstractTest
{
             "you can assign permission only start with [EVENTS_, ADMIN_], but you try SERVICE_INVOKE"
         );
 
-        permsBuilder.appendCachePermissions(
-                "cache1", CACHE_PUT, CACHE_REMOVE
-        ).appendCachePermissions(
-                "cache2", CACHE_READ
-        ).appendTaskPermissions(
-                "task1", TASK_CANCEL
-        ).appendTaskPermissions(
-                "task2", TASK_EXECUTE
-        ).appendServicePermissions(
-            "service1", SERVICE_DEPLOY
-        ).appendServicePermissions(
-            "service2", SERVICE_INVOKE
-        ).appendSystemPermissions(ADMIN_VIEW, EVENTS_ENABLE);
+        permsBuilder
+            .appendCachePermissions("cache1", CACHE_PUT)
+            .appendCachePermissions("cache1", CACHE_PUT, CACHE_REMOVE)
+            .appendCachePermissions("cache2", CACHE_READ)
+            .appendTaskPermissions("task1", TASK_CANCEL)
+            .appendTaskPermissions("task2", TASK_EXECUTE)
+            .appendTaskPermissions("task2", TASK_EXECUTE)
+            .appendServicePermissions("service1", SERVICE_DEPLOY)
+            .appendServicePermissions("service2", SERVICE_INVOKE)
+            .appendServicePermissions("service2", SERVICE_INVOKE)
+            .appendSystemPermissions(ADMIN_VIEW)
+            .appendSystemPermissions(ADMIN_VIEW, EVENTS_ENABLE);
 
         SecurityPermissionSet actual = permsBuilder.build();
 
@@ -127,4 +126,16 @@ public class SecurityPermissionSetBuilderTest extends GridCommonAbstractTest
{
         assertEquals(exp.systemPermissions(), actual.systemPermissions());
         assertEquals(exp.defaultAllowAll(), actual.defaultAllowAll());
     }
+
+    /**
+     * @param perms Permissions.
+     * @return Collection.
+     */
+    private static Collection<SecurityPermission> permissions(SecurityPermission...
perms) {
+        Collection<SecurityPermission> col = U.newHashSet(perms.length);
+
+        Collections.addAll(col, perms);
+
+        return col;
+    }
 }


Mime
View raw message