You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2020/05/06 10:39:18 UTC
[GitHub] [ignite] alex-plekhanov commented on a change in pull request #7671: IGNITE-12891 Add userAttributes map to all GridClient messages
alex-plekhanov commented on a change in pull request #7671:
URL: https://github.com/apache/ignite/pull/7671#discussion_r420678664
##########
File path: modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientNioTcpConnection.java
##########
@@ -638,6 +644,29 @@ private void removePending(long reqId) {
closedLatch.countDown();
}
+ /** */
+ private <R> GridClientFutureAdapter<R> makeAuthRequest() throws GridClientConnectionResetException {
+ TcpClientFuture<R> fut = new TcpClientFuture<>();
+
+ fut.retryState(TcpClientFuture.STATE_REQUEST_RETRY);
+
+ GridClientAuthenticationRequest req = buildAuthRequest();
+
+ pendingReqs.putIfAbsent(req.requestId(), fut);
+
+ GridNioFuture<?> sndFut = ses.send(req);
+
+ try {
+ sndFut.get();
+ }
+ catch (Exception e) {
+ throw new GridClientConnectionResetException("Failed to send message over connection " +
+ "(will try to reconnect): " + serverAddress(), e);
+ }
+
+ return fut;
Review comment:
Duplication of `makeRequest`, please reuse `makeRequest` instead.
##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientAuthenticationRequest.java
##########
@@ -50,13 +51,23 @@ public void credentials(Object cred) {
@Override public void writeExternal(ObjectOutput out) throws IOException {
super.writeExternal(out);
+ U.writeString(out, login());
+ U.writeString(out, password());
Review comment:
Login and password already included into `cred` object, we don't need to pass it twice.
Also login and password fields are useless and should be removed at all from `GridClientAbstractMessage`
`userAttrs` field should be moved to `GridClientAuthenticationRequest`
##########
File path: modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientNioTcpConnection.java
##########
@@ -646,10 +675,16 @@ private void removePending(long reqId) {
private GridClientAuthenticationRequest buildAuthRequest() {
GridClientAuthenticationRequest req = new GridClientAuthenticationRequest();
+ long reqId = reqIdCntr.getAndIncrement();
+
+ req.requestId(reqId);
+
Review comment:
It's redundant if `makeRequest` is used to send request.
##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientAuthenticationRequest.java
##########
@@ -50,13 +51,23 @@ public void credentials(Object cred) {
@Override public void writeExternal(ObjectOutput out) throws IOException {
super.writeExternal(out);
+ U.writeString(out, login());
+ U.writeString(out, password());
+
+ U.writeMap(out, userAttrs);
Review comment:
Should be serialized after `cred` (perhaps, in this case, compatibility will be supported)
##########
File path: modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientNioTcpConnection.java
##########
@@ -264,6 +264,12 @@ else if (marsh instanceof GridClientJdkMarshaller)
ses.addMeta(SES_META_CONN, this);
+ if (cred != null || userAttrs != null) {
Review comment:
`userAttrs != null` -> `!F.isEmpty(userAttrs)`
##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientAuthenticationRequest.java
##########
@@ -50,13 +51,23 @@ public void credentials(Object cred) {
@Override public void writeExternal(ObjectOutput out) throws IOException {
super.writeExternal(out);
+ U.writeString(out, login());
+ U.writeString(out, password());
+
+ U.writeMap(out, userAttrs);
Review comment:
Should be serialized after `cred` (perhaps, in this case, compatibility will be supported)
##########
File path: modules/core/src/test/java/org/apache/ignite/internal/processors/security/impl/TestAttributeSecurityPluginProvider.java
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.impl;
+
+import java.security.Permissions;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.function.Consumer;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.security.GridSecurityProcessor;
+import org.apache.ignite.plugin.security.SecurityPermissionSet;
+
+/**
+ *
+ */
+public class TestAttributeSecurityPluginProvider extends TestAdditionalSecurityPluginProvider {
+ /** Authentication handler. */
+ private Consumer<Map<String, Object>> hndlr;
Review comment:
Let's intercept not only user attributes, but whole `authCtx`, in this case, we can reuse this plugin provider in other tests in the future.
##########
File path: modules/core/src/test/java/org/apache/ignite/internal/processors/security/client/AttributeSecurityCheckTest.java
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.client;
+
+import java.util.Map;
+import java.util.function.Consumer;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.internal.client.GridClient;
+import org.apache.ignite.internal.client.GridClientClusterState;
+import org.apache.ignite.internal.client.GridClientConfiguration;
+import org.apache.ignite.internal.client.GridClientFactory;
+import org.apache.ignite.internal.processors.security.UserAttributesFactory;
+import org.apache.ignite.internal.processors.security.impl.TestAttributeSecurityPluginProvider;
+import org.apache.ignite.plugin.PluginProvider;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import static org.apache.ignite.plugin.security.SecurityPermissionSetBuilder.ALLOW_ALL;
+
+/**
+ * Security tests for thin client.
+ */
+@RunWith(JUnit4.class)
+public class AttributeSecurityCheckTest extends CommonSecurityCheckTest {
+ /** */
+ private static Map<String, Object> userAttrs;
+
+ /** */
+ private static final int TEST_KEY_CNT = 10;
+
+ /** {@inheritDoc} */
+ @Override protected PluginProvider<?> getPluginProvider(String name){
+ return new TestAttributeSecurityPluginProvider(name, null, ALLOW_ALL,
+ globalAuth, true, new Consumer<Map<String, Object>>() {
+ @Override public void accept(Map<String, Object> map) {
+ userAttrs = map;
+ }
+ }, clientData());
+ }
+
+ /** {@inheritDoc} */
+ @Override protected GridClientConfiguration getGridClientConfiguration() {
+ return super.getGridClientConfiguration()
+ .setUserAttributes(userAttributes());
+ }
+
+ /** */
+ @Test
+ public void testClientInfoGridClientNotFail() throws Exception {
+ Ignite ignite = startGrids(2);
+
+ assertEquals(2, ignite.cluster().topologyVersion());
+
+ ignite.cluster().state(ClusterState.ACTIVE);
+
+ try (GridClient client = GridClientFactory.start(getGridClientConfiguration())) {
+ assertTrue(client.connected());
+
+ GridClientClusterState state = client.state();
+
+ // Close a coordinator to force the client to send a CLUSTER_CURRENT_STATE message to the other node
+ // in the state.state() statement.
+ ignite.close();
+
+ userAttrs = null;
+
+ state.state();
+
+ for (int i = 0; i < TEST_KEY_CNT; i++)
Review comment:
It's enough to check only one custom attribute (or check the whole map of attributes)
##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
##########
@@ -245,19 +245,19 @@
boolean authenticationEnabled = ctx.authentication().enabled();
boolean securityEnabled = ctx.security().enabled();
- if (authenticationEnabled || securityEnabled) {
- Session ses;
+ Session ses;
- try {
- ses = session(req);
- }
- catch (IgniteAuthenticationException e) {
- return new GridFinishedFuture<>(new GridRestResponse(STATUS_AUTH_FAILED, e.getMessage()));
- }
- catch (IgniteCheckedException e) {
- return new GridFinishedFuture<>(new GridRestResponse(STATUS_FAILED, e.getMessage()));
- }
+ try {
+ ses = session(req);
Review comment:
Using such an approach you will lose user attributes when session will expire.
##########
File path: modules/core/src/test/java/org/apache/ignite/internal/processors/security/client/AttributeSecurityCheckTest.java
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.client;
+
+import java.util.Map;
+import java.util.function.Consumer;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.internal.client.GridClient;
+import org.apache.ignite.internal.client.GridClientClusterState;
+import org.apache.ignite.internal.client.GridClientConfiguration;
+import org.apache.ignite.internal.client.GridClientFactory;
+import org.apache.ignite.internal.processors.security.UserAttributesFactory;
+import org.apache.ignite.internal.processors.security.impl.TestAttributeSecurityPluginProvider;
+import org.apache.ignite.plugin.PluginProvider;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import static org.apache.ignite.plugin.security.SecurityPermissionSetBuilder.ALLOW_ALL;
+
+/**
+ * Security tests for thin client.
+ */
+@RunWith(JUnit4.class)
+public class AttributeSecurityCheckTest extends CommonSecurityCheckTest {
+ /** */
+ private static Map<String, Object> userAttrs;
+
+ /** */
+ private static final int TEST_KEY_CNT = 10;
+
+ /** {@inheritDoc} */
+ @Override protected PluginProvider<?> getPluginProvider(String name){
+ return new TestAttributeSecurityPluginProvider(name, null, ALLOW_ALL,
+ globalAuth, true, new Consumer<Map<String, Object>>() {
+ @Override public void accept(Map<String, Object> map) {
+ userAttrs = map;
+ }
+ }, clientData());
+ }
+
+ /** {@inheritDoc} */
+ @Override protected GridClientConfiguration getGridClientConfiguration() {
+ return super.getGridClientConfiguration()
+ .setUserAttributes(userAttributes());
+ }
+
+ /** */
+ @Test
+ public void testClientInfoGridClientNotFail() throws Exception {
+ Ignite ignite = startGrids(2);
+
+ assertEquals(2, ignite.cluster().topologyVersion());
+
+ ignite.cluster().state(ClusterState.ACTIVE);
+
+ try (GridClient client = GridClientFactory.start(getGridClientConfiguration())) {
+ assertTrue(client.connected());
Review comment:
You should also check attributes after the first connection.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org