ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vkuliche...@apache.org
Subject [11/11] ignite git commit: IGNITE-5081 - Removed redundant duplication of permissions SecurityPermissionSetBuilder
Date Thu, 27 Apr 2017 11:53:02 GMT
IGNITE-5081 - Removed redundant duplication of permissions SecurityPermissionSetBuilder


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

Branch: refs/heads/ignite-security-fixes
Commit: ea991cd28a882bde00f28ca03a3672a7afee7259
Parents: 2cfece4
Author: Valentin Kulichenko <valentin.lulichenko@gmail.com>
Authored: Tue Apr 25 16:33:46 2017 +0200
Committer: Valentin Kulichenko <valentin.lulichenko@gmail.com>
Committed: Tue Apr 25 16:33:46 2017 +0200

----------------------------------------------------------------------
 .../security/SecurityPermissionSetBuilder.java  | 17 +++----
 .../SecurityPermissionSetBuilderTest.java       | 48 ++++++++++++--------
 2 files changed, 37 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/ea991cd2/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 61ad77c..7774422 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.
@@ -58,7 +59,7 @@ public class SecurityPermissionSetBuilder {
     private Map<String, Collection<SecurityPermission>> taskPerms = new HashMap<>();
 
     /** System permissions.*/
-    private List<SecurityPermission> sysPerms = new ArrayList<>();
+    private Set<SecurityPermission> sysPerms = new HashSet<>();
 
     /** Default allow all.*/
     private boolean dfltAllowAll;
@@ -175,7 +176,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);
 
@@ -215,7 +216,7 @@ public class SecurityPermissionSetBuilder {
         permSet.setDefaultAllowAll(dfltAllowAll);
         permSet.setCachePermissions(unmodifiableMap(cachePerms));
         permSet.setTaskPermissions(unmodifiableMap(taskPerms));
-        permSet.setSystemPermissions(unmodifiableList(sysPerms));
+        permSet.setSystemPermissions(unmodifiableSet(sysPerms));
 
         return permSet;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/ea991cd2/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 f63f9a7..9303dd2 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,46 +17,54 @@
 
 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.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;
 
 /**
  * Test for check correct work {@link SecurityPermissionSetBuilder permission builder}
  */
 public class SecurityPermissionSetBuilderTest extends GridCommonAbstractTest {
+    private static Collection<SecurityPermission> permissions(SecurityPermission...
perms) {
+        Collection<SecurityPermission> col = U.newHashSet(perms.length);
+
+        Collections.addAll(col, perms);
+
+        return col;
+    }
+
     /**
-     *
      */
     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);
 
-        exp.setSystemPermissions(Arrays.asList(ADMIN_VIEW, EVENTS_ENABLE));
+        exp.setSystemPermissions(permissions(ADMIN_VIEW, EVENTS_ENABLE));
 
         final SecurityPermissionSetBuilder permsBuilder = new SecurityPermissionSetBuilder();
 
@@ -90,15 +98,15 @@ public class SecurityPermissionSetBuilderTest extends GridCommonAbstractTest
{
                 "you can assign permission only start with [EVENTS_, ADMIN_], but you try
TASK_EXECUTE"
         );
 
-        permsBuilder.appendCachePermissions(
-                "cache1", CACHE_PUT, CACHE_REMOVE
-        ).appendCachePermissions(
-                "cache2", CACHE_READ
-        ).appendTaskPermissions(
-                "task1", TASK_CANCEL
-        ).appendTaskPermissions(
-                "task2", TASK_EXECUTE
-        ).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)
+            .appendSystemPermissions(ADMIN_VIEW)
+            .appendSystemPermissions(ADMIN_VIEW, EVENTS_ENABLE);
 
         SecurityPermissionSet actual = permsBuilder.build();
 


Mime
View raw message