IGNITE-8857 new IgnitePredicate filtering credential attribute introduced, 
HashMap was removed - Fixes #4272.

Signed-off-by: Alexey Goncharuk <[email protected]>


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

Branch: refs/heads/ignite-8446
Commit: a67b08cc0e76dfd1ee3810972bfe6781698550d4
Parents: 6ce01c1
Author: Sergey Chugunov <[email protected]>
Authored: Mon Jul 2 14:36:25 2018 +0300
Committer: Alexey Goncharuk <[email protected]>
Committed: Mon Jul 2 14:36:25 2018 +0300

----------------------------------------------------------------------
 .../SecurityCredentialsAttrFilterPredicate.java | 39 ++++++++++++++++++++
 .../zk/internal/ZookeeperClusterNode.java       |  8 +---
 .../zk/internal/ZookeeperDiscoverySpiTest.java  | 14 ++++++-
 3 files changed, 54 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/a67b08cc/modules/core/src/main/java/org/apache/ignite/internal/SecurityCredentialsAttrFilterPredicate.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/SecurityCredentialsAttrFilterPredicate.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/SecurityCredentialsAttrFilterPredicate.java
new file mode 100644
index 0000000..2f774bd
--- /dev/null
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/SecurityCredentialsAttrFilterPredicate.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal;
+
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.lang.IgnitePredicate;
+
+/**
+ * Predicate to filter out security credentials attribute by its name.
+ */
+public class SecurityCredentialsAttrFilterPredicate implements 
IgnitePredicate<String> {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** {@inheritDoc} */
+    @Override public boolean apply(String s) {
+        return !IgniteNodeAttributes.ATTR_SECURITY_CREDENTIALS.equals(s);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(SecurityCredentialsAttrFilterPredicate.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/a67b08cc/modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClusterNode.java
----------------------------------------------------------------------
diff --git 
a/modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClusterNode.java
 
b/modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClusterNode.java
index 02e4123..1c2a589 100644
--- 
a/modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClusterNode.java
+++ 
b/modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClusterNode.java
@@ -31,11 +31,11 @@ import org.apache.ignite.cache.CacheMetrics;
 import org.apache.ignite.cluster.ClusterMetrics;
 import org.apache.ignite.internal.ClusterMetricsSnapshot;
 import org.apache.ignite.internal.IgniteNodeAttributes;
+import org.apache.ignite.internal.SecurityCredentialsAttrFilterPredicate;
 import org.apache.ignite.internal.managers.discovery.IgniteClusterNode;
 import org.apache.ignite.internal.util.tostring.GridToStringExclude;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.lang.IgnitePredicate;
 import org.apache.ignite.lang.IgniteProductVersion;
 import org.apache.ignite.spi.discovery.DiscoveryMetricsProvider;
 import org.jetbrains.annotations.Nullable;
@@ -243,11 +243,7 @@ public class ZookeeperClusterNode implements 
IgniteClusterNode, Externalizable,
     /** {@inheritDoc} */
     @Override public Map<String, Object> attributes() {
         // Even though discovery SPI removes this attribute after 
authentication, keep this check for safety.
-        return new HashMap<>(F.view(attrs, new IgnitePredicate<String>() {
-            @Override public boolean apply(String s) {
-                return 
!IgniteNodeAttributes.ATTR_SECURITY_CREDENTIALS.equals(s);
-            }
-        }));
+        return F.view(attrs, new SecurityCredentialsAttrFilterPredicate());
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/a67b08cc/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiTest.java
----------------------------------------------------------------------
diff --git 
a/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiTest.java
 
b/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiTest.java
index 4cfc6cb..7ee9b45 100644
--- 
a/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiTest.java
+++ 
b/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiTest.java
@@ -73,6 +73,7 @@ import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.IgniteKernal;
 import org.apache.ignite.internal.IgnitionEx;
+import org.apache.ignite.internal.SecurityCredentialsAttrFilterPredicate;
 import org.apache.ignite.internal.TestRecordingCommunicationSpi;
 import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
 import org.apache.ignite.internal.managers.discovery.CustomEventListener;
@@ -90,6 +91,7 @@ import 
org.apache.ignite.internal.util.future.GridCompoundFuture;
 import org.apache.ignite.internal.util.future.IgniteFinishedFutureImpl;
 import org.apache.ignite.internal.util.lang.GridAbsPredicate;
 import org.apache.ignite.internal.util.lang.IgniteInClosure2X;
+import org.apache.ignite.internal.util.lang.gridfunc.PredicateMapView;
 import org.apache.ignite.internal.util.nio.GridCommunicationClient;
 import org.apache.ignite.internal.util.typedef.G;
 import org.apache.ignite.internal.util.typedef.T3;
@@ -487,7 +489,17 @@ public class ZookeeperDiscoverySpiTest extends 
GridCommonAbstractTest {
         try {
             IgniteEx ignite = startGrid(0);
 
-            assertTrue(ignite.cluster().localNode().attributes() instanceof 
HashMap);
+            Map<String, Object> attrs = 
ignite.cluster().localNode().attributes();
+
+            assertTrue(attrs instanceof PredicateMapView);
+
+            IgnitePredicate[] preds = GridTestUtils.getFieldValue(attrs, 
"preds");
+
+            assertNotNull(preds);
+
+            assertTrue(preds.length == 1);
+
+            assertTrue(preds[0] instanceof 
SecurityCredentialsAttrFilterPredicate);
         }
         finally {
             userAttrs = null;

Reply via email to