alex-plekhanov commented on code in PR #11631:
URL: https://github.com/apache/ignite/pull/11631#discussion_r1822228912


##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java:
##########
@@ -1109,7 +1109,12 @@ public IgniteInternalFuture<?> changeGlobalState(
         boolean forceChangeBaselineTopology,
         boolean isAutoAdjust
     ) {
-        ctx.security().authorize(SecurityPermission.ADMIN_CLUSTER_STATE);
+        try {
+            ctx.security().authorize(SecurityPermission.ADMIN_CLUSTER_STATE);
+        }
+        catch (org.apache.ignite.plugin.security.SecurityException secEx) {

Review Comment:
   import org.apache.ignite.plugin.security.SecurityException?



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/security/cluster/ActivationOnJoinWithoutPermissionsWithPersistenceTest.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.processors.security.cluster;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.ConnectorConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.failure.StopNodeFailureHandler;
+import org.apache.ignite.internal.processors.security.AbstractSecurityTest;
+import 
org.apache.ignite.internal.processors.security.impl.TestSecurityPluginProvider;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.plugin.security.SecurityPermission;
+import org.junit.Test;
+
+import static org.apache.ignite.cluster.ClusterState.ACTIVE;
+import static org.apache.ignite.cluster.ClusterState.INACTIVE;
+import static 
org.apache.ignite.plugin.security.SecurityPermission.ADMIN_CLUSTER_STATE;
+import static 
org.apache.ignite.plugin.security.SecurityPermission.JOIN_AS_SERVER;
+import static 
org.apache.ignite.plugin.security.SecurityPermissionSetBuilder.create;
+
+/**
+ * Tests joining baseline node without permissions. It should join 
successfully, but
+ * cluster must be left in INACTIVE state. {@link 
org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor#onLocalJoin}
+ * must not complete exceptionally.
+ */
+public class ActivationOnJoinWithoutPermissionsWithPersistenceTest extends 
AbstractSecurityTest {
+    /** */
+    private static final int NUM_NODES = 3;
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        stopAllGrids();
+
+        cleanPersistenceDir();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
instanceName) throws Exception {
+        SecurityPermission[] srvPerms = F.asArray(ADMIN_CLUSTER_STATE);
+
+        return getConfiguration(instanceName, srvPerms);
+    }
+
+    /**
+     * @return Ignite configuration with given server and client permissions.
+     */
+    private IgniteConfiguration getConfiguration(
+        String instanceName,
+        SecurityPermission[] srvPerms
+    ) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+        cfg.setConsistentId(instanceName);
+
+        TestSecurityPluginProvider secPlugin = new TestSecurityPluginProvider(
+            instanceName,
+            "",
+            
create().defaultAllowAll(false).appendSystemPermissions(F.concat(srvPerms, 
JOIN_AS_SERVER)).build(),
+            false,
+            EMPTY_SECURITY_DATA
+        );
+
+        cfg.setPluginProviders(secPlugin);
+
+        cfg.setFailureHandler(new StopNodeFailureHandler());
+
+        cfg.setConnectorConfiguration(new ConnectorConfiguration());
+
+        if (!cfg.isClientMode()) {
+            cfg.setDataStorageConfiguration(new DataStorageConfiguration()
+                .setDefaultDataRegionConfiguration(new 
DataRegionConfiguration().setPersistenceEnabled(true)));
+        }
+
+        return cfg;
+    }
+
+    /** */
+    @Test
+    public void testNodeJoinWithoutPermissions() throws Exception {
+        // Start grids and activate them

Review Comment:
   Point at the EOL



##########
modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/ZookeeperDiscoverySpiTestSuite4.java:
##########
@@ -50,7 +51,8 @@
     IgniteNodeValidationFailedEventTest.class,
     DiscoverySpiDataExchangeTest.class,
     CacheCreateDestroyEventSecurityContextTest.class,
-    NodeJoinPermissionsTest.class
+    NodeJoinPermissionsTest.class,
+    ActivationOnJoinWithoutPermissionsWithPersistenceTest.class

Review Comment:
   Let's add comma at the EOL



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/security/cluster/ActivationOnJoinWithoutPermissionsWithPersistenceTest.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.processors.security.cluster;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.ConnectorConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.failure.StopNodeFailureHandler;
+import org.apache.ignite.internal.processors.security.AbstractSecurityTest;
+import 
org.apache.ignite.internal.processors.security.impl.TestSecurityPluginProvider;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.plugin.security.SecurityPermission;
+import org.junit.Test;
+
+import static org.apache.ignite.cluster.ClusterState.ACTIVE;
+import static org.apache.ignite.cluster.ClusterState.INACTIVE;
+import static 
org.apache.ignite.plugin.security.SecurityPermission.ADMIN_CLUSTER_STATE;
+import static 
org.apache.ignite.plugin.security.SecurityPermission.JOIN_AS_SERVER;
+import static 
org.apache.ignite.plugin.security.SecurityPermissionSetBuilder.create;
+
+/**
+ * Tests joining baseline node without permissions. It should join 
successfully, but
+ * cluster must be left in INACTIVE state. {@link 
org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor#onLocalJoin}
+ * must not complete exceptionally.
+ */
+public class ActivationOnJoinWithoutPermissionsWithPersistenceTest extends 
AbstractSecurityTest {
+    /** */
+    private static final int NUM_NODES = 3;
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {

Review Comment:
   We have only one test and afterTestsStopped already contains stopAllGrids 
and cleanPersistentDir, so afterTest looks redundant



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/security/cluster/ActivationOnJoinWithoutPermissionsWithPersistenceTest.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.processors.security.cluster;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.ConnectorConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.failure.StopNodeFailureHandler;
+import org.apache.ignite.internal.processors.security.AbstractSecurityTest;
+import 
org.apache.ignite.internal.processors.security.impl.TestSecurityPluginProvider;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.plugin.security.SecurityPermission;
+import org.junit.Test;
+
+import static org.apache.ignite.cluster.ClusterState.ACTIVE;
+import static org.apache.ignite.cluster.ClusterState.INACTIVE;
+import static 
org.apache.ignite.plugin.security.SecurityPermission.ADMIN_CLUSTER_STATE;
+import static 
org.apache.ignite.plugin.security.SecurityPermission.JOIN_AS_SERVER;
+import static 
org.apache.ignite.plugin.security.SecurityPermissionSetBuilder.create;
+
+/**
+ * Tests joining baseline node without permissions. It should join 
successfully, but
+ * cluster must be left in INACTIVE state. {@link 
org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor#onLocalJoin}
+ * must not complete exceptionally.
+ */
+public class ActivationOnJoinWithoutPermissionsWithPersistenceTest extends 
AbstractSecurityTest {
+    /** */
+    private static final int NUM_NODES = 3;
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        stopAllGrids();
+
+        cleanPersistenceDir();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
instanceName) throws Exception {
+        SecurityPermission[] srvPerms = F.asArray(ADMIN_CLUSTER_STATE);
+
+        return getConfiguration(instanceName, srvPerms);
+    }
+
+    /**
+     * @return Ignite configuration with given server and client permissions.
+     */
+    private IgniteConfiguration getConfiguration(
+        String instanceName,
+        SecurityPermission[] srvPerms
+    ) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+        cfg.setConsistentId(instanceName);
+
+        TestSecurityPluginProvider secPlugin = new TestSecurityPluginProvider(
+            instanceName,
+            "",
+            
create().defaultAllowAll(false).appendSystemPermissions(F.concat(srvPerms, 
JOIN_AS_SERVER)).build(),
+            false,
+            EMPTY_SECURITY_DATA
+        );
+
+        cfg.setPluginProviders(secPlugin);
+
+        cfg.setFailureHandler(new StopNodeFailureHandler());
+
+        cfg.setConnectorConfiguration(new ConnectorConfiguration());
+
+        if (!cfg.isClientMode()) {

Review Comment:
   We don't have client nodes in this test



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/security/cluster/ActivationOnJoinWithoutPermissionsWithPersistenceTest.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.processors.security.cluster;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.ConnectorConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.failure.StopNodeFailureHandler;
+import org.apache.ignite.internal.processors.security.AbstractSecurityTest;
+import 
org.apache.ignite.internal.processors.security.impl.TestSecurityPluginProvider;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.plugin.security.SecurityPermission;
+import org.junit.Test;
+
+import static org.apache.ignite.cluster.ClusterState.ACTIVE;
+import static org.apache.ignite.cluster.ClusterState.INACTIVE;
+import static 
org.apache.ignite.plugin.security.SecurityPermission.ADMIN_CLUSTER_STATE;
+import static 
org.apache.ignite.plugin.security.SecurityPermission.JOIN_AS_SERVER;
+import static 
org.apache.ignite.plugin.security.SecurityPermissionSetBuilder.create;
+
+/**
+ * Tests joining baseline node without permissions. It should join 
successfully, but
+ * cluster must be left in INACTIVE state. {@link 
org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor#onLocalJoin}
+ * must not complete exceptionally.
+ */
+public class ActivationOnJoinWithoutPermissionsWithPersistenceTest extends 
AbstractSecurityTest {
+    /** */
+    private static final int NUM_NODES = 3;
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        stopAllGrids();
+
+        cleanPersistenceDir();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
instanceName) throws Exception {
+        SecurityPermission[] srvPerms = F.asArray(ADMIN_CLUSTER_STATE);
+
+        return getConfiguration(instanceName, srvPerms);
+    }
+
+    /**
+     * @return Ignite configuration with given server and client permissions.
+     */
+    private IgniteConfiguration getConfiguration(
+        String instanceName,
+        SecurityPermission[] srvPerms
+    ) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+        cfg.setConsistentId(instanceName);
+
+        TestSecurityPluginProvider secPlugin = new TestSecurityPluginProvider(
+            instanceName,
+            "",
+            
create().defaultAllowAll(false).appendSystemPermissions(F.concat(srvPerms, 
JOIN_AS_SERVER)).build(),
+            false,
+            EMPTY_SECURITY_DATA
+        );
+
+        cfg.setPluginProviders(secPlugin);
+
+        cfg.setFailureHandler(new StopNodeFailureHandler());
+
+        cfg.setConnectorConfiguration(new ConnectorConfiguration());
+
+        if (!cfg.isClientMode()) {
+            cfg.setDataStorageConfiguration(new DataStorageConfiguration()
+                .setDefaultDataRegionConfiguration(new 
DataRegionConfiguration().setPersistenceEnabled(true)));
+        }
+
+        return cfg;
+    }
+
+    /** */
+    @Test
+    public void testNodeJoinWithoutPermissions() throws Exception {
+        // Start grids and activate them
+        startGrids(NUM_NODES);
+
+        grid(0).cluster().state(ACTIVE);
+        assertEquals(ACTIVE, grid(0).cluster().state());
+
+        // Fix consistent ids of the new baseline.
+        Set<Object> consistentIds = 
grid(0).cluster().forServers().nodes().stream().
+            map(ClusterNode::consistentId).collect(Collectors.toSet());
+
+        // Stop all of them and restart just the firsts
+        G.stopAll(true);
+
+        for (int i = 0; i < NUM_NODES - 1; i++)
+            startGrid(i);
+
+        // Start the last one with empty permissions.
+        startGrid(getConfiguration(getTestIgniteInstanceName(NUM_NODES - 1), 
EMPTY_PERMS));
+
+        // Check for state and topology.
+        waitForTopology(NUM_NODES);
+
+        assertTrue(grid(0).cluster().state() == INACTIVE);

Review Comment:
   assertEquals? (The output of assertEquals is more clear in case of 
unexpected value)



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/security/cluster/ActivationOnJoinWithoutPermissionsWithPersistenceTest.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.processors.security.cluster;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.ConnectorConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.failure.StopNodeFailureHandler;
+import org.apache.ignite.internal.processors.security.AbstractSecurityTest;
+import 
org.apache.ignite.internal.processors.security.impl.TestSecurityPluginProvider;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.plugin.security.SecurityPermission;
+import org.junit.Test;
+
+import static org.apache.ignite.cluster.ClusterState.ACTIVE;
+import static org.apache.ignite.cluster.ClusterState.INACTIVE;
+import static 
org.apache.ignite.plugin.security.SecurityPermission.ADMIN_CLUSTER_STATE;
+import static 
org.apache.ignite.plugin.security.SecurityPermission.JOIN_AS_SERVER;
+import static 
org.apache.ignite.plugin.security.SecurityPermissionSetBuilder.create;
+
+/**
+ * Tests joining baseline node without permissions. It should join 
successfully, but
+ * cluster must be left in INACTIVE state. {@link 
org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor#onLocalJoin}
+ * must not complete exceptionally.
+ */
+public class ActivationOnJoinWithoutPermissionsWithPersistenceTest extends 
AbstractSecurityTest {
+    /** */
+    private static final int NUM_NODES = 3;
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        stopAllGrids();
+
+        cleanPersistenceDir();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
instanceName) throws Exception {
+        SecurityPermission[] srvPerms = F.asArray(ADMIN_CLUSTER_STATE);
+
+        return getConfiguration(instanceName, srvPerms);
+    }
+
+    /**
+     * @return Ignite configuration with given server and client permissions.
+     */
+    private IgniteConfiguration getConfiguration(
+        String instanceName,
+        SecurityPermission[] srvPerms
+    ) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+        cfg.setConsistentId(instanceName);
+
+        TestSecurityPluginProvider secPlugin = new TestSecurityPluginProvider(
+            instanceName,
+            "",
+            
create().defaultAllowAll(false).appendSystemPermissions(F.concat(srvPerms, 
JOIN_AS_SERVER)).build(),
+            false,
+            EMPTY_SECURITY_DATA
+        );
+
+        cfg.setPluginProviders(secPlugin);
+
+        cfg.setFailureHandler(new StopNodeFailureHandler());
+
+        cfg.setConnectorConfiguration(new ConnectorConfiguration());
+
+        if (!cfg.isClientMode()) {
+            cfg.setDataStorageConfiguration(new DataStorageConfiguration()
+                .setDefaultDataRegionConfiguration(new 
DataRegionConfiguration().setPersistenceEnabled(true)));
+        }
+
+        return cfg;
+    }
+
+    /** */
+    @Test
+    public void testNodeJoinWithoutPermissions() throws Exception {
+        // Start grids and activate them
+        startGrids(NUM_NODES);
+
+        grid(0).cluster().state(ACTIVE);
+        assertEquals(ACTIVE, grid(0).cluster().state());
+
+        // Fix consistent ids of the new baseline.
+        Set<Object> consistentIds = 
grid(0).cluster().forServers().nodes().stream().
+            map(ClusterNode::consistentId).collect(Collectors.toSet());
+
+        // Stop all of them and restart just the firsts

Review Comment:
   Point at the EOL



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/security/cluster/ActivationOnJoinWithoutPermissionsWithPersistenceTest.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.processors.security.cluster;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.ConnectorConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.failure.StopNodeFailureHandler;
+import org.apache.ignite.internal.processors.security.AbstractSecurityTest;
+import 
org.apache.ignite.internal.processors.security.impl.TestSecurityPluginProvider;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.plugin.security.SecurityPermission;
+import org.junit.Test;
+
+import static org.apache.ignite.cluster.ClusterState.ACTIVE;
+import static org.apache.ignite.cluster.ClusterState.INACTIVE;
+import static 
org.apache.ignite.plugin.security.SecurityPermission.ADMIN_CLUSTER_STATE;
+import static 
org.apache.ignite.plugin.security.SecurityPermission.JOIN_AS_SERVER;
+import static 
org.apache.ignite.plugin.security.SecurityPermissionSetBuilder.create;
+
+/**
+ * Tests joining baseline node without permissions. It should join 
successfully, but
+ * cluster must be left in INACTIVE state. {@link 
org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor#onLocalJoin}
+ * must not complete exceptionally.
+ */
+public class ActivationOnJoinWithoutPermissionsWithPersistenceTest extends 
AbstractSecurityTest {
+    /** */
+    private static final int NUM_NODES = 3;
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        stopAllGrids();
+
+        cleanPersistenceDir();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
instanceName) throws Exception {
+        SecurityPermission[] srvPerms = F.asArray(ADMIN_CLUSTER_STATE);
+
+        return getConfiguration(instanceName, srvPerms);
+    }
+
+    /**
+     * @return Ignite configuration with given server and client permissions.
+     */
+    private IgniteConfiguration getConfiguration(
+        String instanceName,
+        SecurityPermission[] srvPerms
+    ) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+        cfg.setConsistentId(instanceName);
+
+        TestSecurityPluginProvider secPlugin = new TestSecurityPluginProvider(
+            instanceName,
+            "",
+            
create().defaultAllowAll(false).appendSystemPermissions(F.concat(srvPerms, 
JOIN_AS_SERVER)).build(),
+            false,
+            EMPTY_SECURITY_DATA
+        );
+
+        cfg.setPluginProviders(secPlugin);
+
+        cfg.setFailureHandler(new StopNodeFailureHandler());
+
+        cfg.setConnectorConfiguration(new ConnectorConfiguration());
+
+        if (!cfg.isClientMode()) {
+            cfg.setDataStorageConfiguration(new DataStorageConfiguration()
+                .setDefaultDataRegionConfiguration(new 
DataRegionConfiguration().setPersistenceEnabled(true)));
+        }
+
+        return cfg;
+    }
+
+    /** */
+    @Test
+    public void testNodeJoinWithoutPermissions() throws Exception {
+        // Start grids and activate them
+        startGrids(NUM_NODES);
+
+        grid(0).cluster().state(ACTIVE);
+        assertEquals(ACTIVE, grid(0).cluster().state());
+
+        // Fix consistent ids of the new baseline.
+        Set<Object> consistentIds = 
grid(0).cluster().forServers().nodes().stream().
+            map(ClusterNode::consistentId).collect(Collectors.toSet());
+
+        // Stop all of them and restart just the firsts
+        G.stopAll(true);
+
+        for (int i = 0; i < NUM_NODES - 1; i++)
+            startGrid(i);

Review Comment:
   Perhaps `startGrids(NUM_NODES - 1);` (up to you)



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/security/cluster/ActivationOnJoinWithoutPermissionsWithPersistenceTest.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.processors.security.cluster;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.ConnectorConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.failure.StopNodeFailureHandler;
+import org.apache.ignite.internal.processors.security.AbstractSecurityTest;
+import 
org.apache.ignite.internal.processors.security.impl.TestSecurityPluginProvider;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.plugin.security.SecurityPermission;
+import org.junit.Test;
+
+import static org.apache.ignite.cluster.ClusterState.ACTIVE;
+import static org.apache.ignite.cluster.ClusterState.INACTIVE;
+import static 
org.apache.ignite.plugin.security.SecurityPermission.ADMIN_CLUSTER_STATE;
+import static 
org.apache.ignite.plugin.security.SecurityPermission.JOIN_AS_SERVER;
+import static 
org.apache.ignite.plugin.security.SecurityPermissionSetBuilder.create;
+
+/**
+ * Tests joining baseline node without permissions. It should join 
successfully, but
+ * cluster must be left in INACTIVE state. {@link 
org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor#onLocalJoin}
+ * must not complete exceptionally.
+ */
+public class ActivationOnJoinWithoutPermissionsWithPersistenceTest extends 
AbstractSecurityTest {
+    /** */
+    private static final int NUM_NODES = 3;
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        stopAllGrids();
+
+        cleanPersistenceDir();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
instanceName) throws Exception {
+        SecurityPermission[] srvPerms = F.asArray(ADMIN_CLUSTER_STATE);
+
+        return getConfiguration(instanceName, srvPerms);
+    }
+
+    /**
+     * @return Ignite configuration with given server and client permissions.
+     */
+    private IgniteConfiguration getConfiguration(
+        String instanceName,
+        SecurityPermission[] srvPerms
+    ) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+        cfg.setConsistentId(instanceName);
+
+        TestSecurityPluginProvider secPlugin = new TestSecurityPluginProvider(
+            instanceName,
+            "",
+            
create().defaultAllowAll(false).appendSystemPermissions(F.concat(srvPerms, 
JOIN_AS_SERVER)).build(),
+            false,
+            EMPTY_SECURITY_DATA
+        );
+
+        cfg.setPluginProviders(secPlugin);
+
+        cfg.setFailureHandler(new StopNodeFailureHandler());
+
+        cfg.setConnectorConfiguration(new ConnectorConfiguration());

Review Comment:
   Looks redundant for this test



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/security/cluster/ActivationOnJoinWithoutPermissionsWithPersistenceTest.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.processors.security.cluster;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.ConnectorConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.failure.StopNodeFailureHandler;
+import org.apache.ignite.internal.processors.security.AbstractSecurityTest;
+import 
org.apache.ignite.internal.processors.security.impl.TestSecurityPluginProvider;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.plugin.security.SecurityPermission;
+import org.junit.Test;
+
+import static org.apache.ignite.cluster.ClusterState.ACTIVE;
+import static org.apache.ignite.cluster.ClusterState.INACTIVE;
+import static 
org.apache.ignite.plugin.security.SecurityPermission.ADMIN_CLUSTER_STATE;
+import static 
org.apache.ignite.plugin.security.SecurityPermission.JOIN_AS_SERVER;
+import static 
org.apache.ignite.plugin.security.SecurityPermissionSetBuilder.create;
+
+/**
+ * Tests joining baseline node without permissions. It should join 
successfully, but
+ * cluster must be left in INACTIVE state. {@link 
org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor#onLocalJoin}
+ * must not complete exceptionally.
+ */
+public class ActivationOnJoinWithoutPermissionsWithPersistenceTest extends 
AbstractSecurityTest {
+    /** */
+    private static final int NUM_NODES = 3;
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        stopAllGrids();
+
+        cleanPersistenceDir();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
instanceName) throws Exception {
+        SecurityPermission[] srvPerms = F.asArray(ADMIN_CLUSTER_STATE);
+
+        return getConfiguration(instanceName, srvPerms);
+    }
+
+    /**
+     * @return Ignite configuration with given server and client permissions.
+     */
+    private IgniteConfiguration getConfiguration(
+        String instanceName,
+        SecurityPermission[] srvPerms
+    ) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+        cfg.setConsistentId(instanceName);
+
+        TestSecurityPluginProvider secPlugin = new TestSecurityPluginProvider(
+            instanceName,
+            "",
+            
create().defaultAllowAll(false).appendSystemPermissions(F.concat(srvPerms, 
JOIN_AS_SERVER)).build(),
+            false,
+            EMPTY_SECURITY_DATA
+        );
+
+        cfg.setPluginProviders(secPlugin);
+
+        cfg.setFailureHandler(new StopNodeFailureHandler());
+
+        cfg.setConnectorConfiguration(new ConnectorConfiguration());
+
+        if (!cfg.isClientMode()) {
+            cfg.setDataStorageConfiguration(new DataStorageConfiguration()
+                .setDefaultDataRegionConfiguration(new 
DataRegionConfiguration().setPersistenceEnabled(true)));
+        }
+
+        return cfg;
+    }
+
+    /** */
+    @Test
+    public void testNodeJoinWithoutPermissions() throws Exception {
+        // Start grids and activate them
+        startGrids(NUM_NODES);
+
+        grid(0).cluster().state(ACTIVE);
+        assertEquals(ACTIVE, grid(0).cluster().state());
+
+        // Fix consistent ids of the new baseline.
+        Set<Object> consistentIds = 
grid(0).cluster().forServers().nodes().stream().
+            map(ClusterNode::consistentId).collect(Collectors.toSet());
+
+        // Stop all of them and restart just the firsts
+        G.stopAll(true);
+
+        for (int i = 0; i < NUM_NODES - 1; i++)
+            startGrid(i);
+
+        // Start the last one with empty permissions.
+        startGrid(getConfiguration(getTestIgniteInstanceName(NUM_NODES - 1), 
EMPTY_PERMS));
+
+        // Check for state and topology.
+        waitForTopology(NUM_NODES);
+
+        assertTrue(grid(0).cluster().state() == INACTIVE);
+        assertEquals(NUM_NODES, grid(0).cluster().forServers().nodes().size());
+
+        assertTrue(G.allGrids().stream().allMatch(ig -> 
consistentIds.contains(ig.cluster().localNode().consistentId())));

Review Comment:
   Why do we need this check? Consistent ID is set explicetely in 
configuration, so even if something went wrong this check will pass. Looks like 
redundant check.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to