You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "isapego (via GitHub)" <gi...@apache.org> on 2023/04/18 10:21:17 UTC

[GitHub] [ignite-3] isapego commented on a diff in pull request #1950: IGNITE-19100 .NET: Add basic authentication support

isapego commented on code in PR #1950:
URL: https://github.com/apache/ignite-3/pull/1950#discussion_r1169815679


##########
modules/platforms/dotnet/Apache.Ignite/BasicAuthenticator.cs:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite;
+
+using System;
+using Internal.Common;
+using Internal.Proto;
+
+/// <summary>
+/// Basic authenticator with username and password.
+/// <para />
+/// Credentials are sent to the server in plain text, unless SSL/TLS is enabled - see
+/// <see cref="IgniteClientConfiguration.SslStreamFactory"/>.
+/// </summary>
+public sealed class BasicAuthenticator : IAuthenticator
+{
+    private string _username = string.Empty;
+
+    private string _password = string.Empty;
+
+    /// <summary>
+    /// Gets or sets the username.
+    /// </summary>
+    public string Username
+    {
+        get => _username;
+        set => _username = value ?? throw new ArgumentNullException(nameof(value));
+    }
+
+    /// <summary>
+    /// Gets or sets the password.
+    /// </summary>
+    public string Password
+    {
+        get => _password;
+        set => _password = value ?? throw new ArgumentNullException(nameof(value));
+    }
+
+    /// <inheritdoc />
+    public string Type => HandshakeExtensions.AuthenticationTypeBasic;
+
+    /// <inheritdoc />
+    public object Identity => Username;
+
+    /// <inheritdoc />
+    public object Secret => Password;

Review Comment:
   Why these are `object` if we only support strings extensions?



##########
modules/platforms/dotnet/Apache.Ignite.Tests/BasicAuthenticatorTests.cs:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Tests;
+
+using System.Threading.Tasks;
+using NUnit.Framework;
+using Security;
+
+/// <summary>
+/// Tests for <see cref="BasicAuthenticator"/>.
+/// </summary>
+public class BasicAuthenticatorTests : IgniteTestsBase
+{
+    private const string EnableAuthnJob = "org.apache.ignite.internal.runner.app.PlatformTestNodeRunner$EnableAuthenticationJob";
+
+    private bool _authnEnabled;
+
+    [TearDown]
+    public async Task DisableAuthenticationAfterTest()
+    {
+        await EnableAuthn(false);
+
+        Assert.DoesNotThrowAsync(async () => await Client.Tables.GetTablesAsync());
+    }
+
+    [Test]
+    public async Task TestAuthnOnClientNoAuthnOnServer()
+    {
+        var cfg = new IgniteClientConfiguration(GetConfig())
+        {
+            Authenticator = new BasicAuthenticator
+            {
+                Username = "u",
+                Password = "p"
+            }
+        };

Review Comment:
   Why not?
   ```suggestion
           var cfg = new IgniteClientConfiguration(GetConfig(true));
   ```



##########
modules/platforms/dotnet/Apache.Ignite/IgniteClientConfiguration.cs:
##########
@@ -169,5 +170,12 @@ public IgniteClientConfiguration(IgniteClientConfiguration other)
         /// See <see cref="SslStreamFactory"/>.
         /// </summary>
         public ISslStreamFactory? SslStreamFactory { get; set; }
+
+        /// <summary>
+        /// Gets or sets the authenticator.

Review Comment:
   Probably should add that if it's `null` then auth is not used.



-- 
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-unsubscribe@ignite.apache.org

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