ptupitsyn commented on code in PR #1918:
URL: https://github.com/apache/ignite-3/pull/1918#discussion_r1161417524


##########
modules/client-common/src/main/java/org/apache/ignite/internal/client/proto/Extension.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.client.proto;
+
+/** Extensions. */

Review Comment:
   ```suggestion
   /**
    * Handshake extensions.
    */
   ```



##########
modules/client-handler/src/integrationTest/java/org/apache/ignite/client/handler/TestServer.java:
##########
@@ -49,12 +52,15 @@ public class TestServer {
 
     private final TestSslConfig testSslConfig;
 
+    private final AuthenticationConfiguration authenticationConfiguration;
+
     private final ClientHandlerMetricSource metrics = new 
ClientHandlerMetricSource();
 
     private long idleTimeout = 5000;
 
-    TestServer(@Nullable TestSslConfig testSslConfig) {
+    TestServer(@Nullable TestSslConfig testSslConfig, 
AuthenticationConfiguration authenticationConfiguration) {

Review Comment:
   Can we make `authenticationConfiguration` nullable? It is not convenient to 
inject it in all tests where we don't actually need it.



##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java:
##########
@@ -608,4 +637,46 @@ public void exceptionCaught(ChannelHandlerContext ctx, 
Throwable cause) {
 
         ctx.close();
     }
+
+    @Override
+    public CompletableFuture<?> 
onUpdate(ConfigurationNotificationEvent<AuthenticationView> ctx) {
+        return CompletableFuture.runAsync(() -> {

Review Comment:
   Is there a reason to use `runAsync`? Looks like we can run the code 
synchroinously.



##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java:
##########
@@ -143,12 +152,17 @@ public class ClientInboundMessageHandler extends 
ChannelInboundHandlerAdapter {
     /** Context. */
     private ClientContext clientContext;
 
+    private ChannelHandlerContext channelHandlerContext;

Review Comment:
   All fields have javadocs in this file. `authenticationManager` added below 
also has it. Let's be consistent and add javadoc here too.



##########
modules/client-common/src/main/java/org/apache/ignite/internal/client/proto/Extension.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.client.proto;
+
+/** Extensions. */
+public enum Extension {
+    USERNAME("username", String.class),
+    PASSWORD("password", String.class),
+    ;
+
+    private final String key;
+
+    private final Class<?> valueType;
+
+    Extension(String key, Class<?> valueType) {
+        this.key = key;
+        this.valueType = valueType;
+    }
+
+    /**
+     * Finds an extension with a provided key.
+     *
+     * @param key Key.
+     * @return Extension.
+     */
+    public static Extension fromKey(String key) {
+        for (Extension e : values()) {
+            if (e.key.equalsIgnoreCase(key)) {
+                return e;
+            }
+        }
+        throw new IllegalArgumentException("Unknown extension key: " + key);

Review Comment:
   The point of handshake extensions is to be flexible and optional. We should 
skip unknown extensions instead of crashing.



##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java:
##########
@@ -608,4 +637,46 @@ public void exceptionCaught(ChannelHandlerContext ctx, 
Throwable cause) {
 
         ctx.close();
     }
+
+    @Override
+    public CompletableFuture<?> 
onUpdate(ConfigurationNotificationEvent<AuthenticationView> ctx) {
+        return CompletableFuture.runAsync(() -> {
+            if (clientContext != null && channelHandlerContext != null) {
+                onAuthenticationChange();
+            }
+        });
+    }
+
+    private void onAuthenticationChange() {
+        channelHandlerContext.close();
+    }
+
+    private Map<Extension, Object> extractExtensions(ClientMessageUnpacker 
unpacker) {
+        EnumMap<Extension, Object> extensions = new EnumMap<>(Extension.class);
+        int mapSize = unpacker.unpackMapHeader();
+        for (int i = 0; i < mapSize; i++) {
+            Extension extension = Extension.fromKey(unpacker.unpackString());
+            extensions.put(extension, unpackExtensionValue(extension, 
unpacker));
+        }
+        return extensions;
+    }
+
+    private Object unpackExtensionValue(Extension extension, 
ClientMessageUnpacker unpacker) {
+        Class<?> type = extension.valueType();
+        if (type == String.class) {
+            return unpacker.unpackString();
+        } else if (type == Integer.class) {
+            return unpacker.unpackInt();
+        } else if (type == Long.class) {
+            return unpacker.unpackLong();
+        } else if (type == Boolean.class) {
+            return unpacker.unpackBoolean();
+        } else if (type == Double.class) {
+            return unpacker.unpackDouble();
+        } else if (type == Float.class) {
+            return unpacker.unpackFloat();

Review Comment:
   We only use strings right now. Let's remove unused code.



##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java:
##########
@@ -608,4 +637,46 @@ public void exceptionCaught(ChannelHandlerContext ctx, 
Throwable cause) {
 
         ctx.close();
     }
+
+    @Override
+    public CompletableFuture<?> 
onUpdate(ConfigurationNotificationEvent<AuthenticationView> ctx) {
+        return CompletableFuture.runAsync(() -> {
+            if (clientContext != null && channelHandlerContext != null) {
+                onAuthenticationChange();

Review Comment:
   Inline this single-line method with a single call site?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to