pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [pulsar] ivankelly commented on a change in pull request #3677: PIP-30: interface and mutual change authentication
Date Wed, 06 Mar 2019 11:35:25 GMT
ivankelly commented on a change in pull request #3677: PIP-30: interface and mutual change
authentication
URL: https://github.com/apache/pulsar/pull/3677#discussion_r262899525
 
 

 ##########
 File path: pulsar-broker/src/test/java/org/apache/pulsar/client/api/MutualAuthenticationTest.java
 ##########
 @@ -0,0 +1,225 @@
+/**
+ * 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.pulsar.client.api;
+
+import com.google.common.collect.Sets;
+import java.io.IOException;
+import java.net.SocketAddress;
+import java.net.URI;
+import java.nio.charset.Charset;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import javax.naming.AuthenticationException;
+import javax.net.ssl.SSLSession;
+import org.apache.pulsar.broker.ServiceConfiguration;
+import org.apache.pulsar.broker.authentication.AuthenticationDataSource;
+import org.apache.pulsar.broker.authentication.AuthenticationProvider;
+import org.apache.pulsar.broker.authentication.AuthenticationState;
+import org.apache.pulsar.common.api.AuthData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+
+/**
+ * Test Mutual Authentication.
+ * Test connect set success, and producer consumer works well.
+ */
+public class MutualAuthenticationTest extends ProducerConsumerBase {
+    private static final Logger log = LoggerFactory.getLogger(MutualAuthenticationTest.class);
+
+    private static String[] clientAuthStrings = {
+        "MutualClientAuthInit", // step 0
+        "MutualClientStep1"     // step 1
+    };
+
+    private static String[] serverAuthStrings = {
+        "ResponseMutualClientAuthInit", // step 0
+        "ResponseMutualClientStep1"     // step 1
+    };
+
+    private static int authStep = 0;
+
+    public static class MutualAuthenticationDataProvider implements AuthenticationDataProvider
{
+        @Override
+        public boolean hasDataFromCommand() {
+            return true;
+        }
+
+        @Override
+        public AuthData authenticate(AuthData data) throws IOException {
+            String dataString = new String(data.getBytes(), Charset.forName("UTF-8"));
+            if (!dataString.equalsIgnoreCase("init")) {
+                assertEquals(dataString, serverAuthStrings[authStep - 1]);
+            }
+            log.debug("authenticate in client. passed in :{}, send: clientAuthStrings[{}]:
{}",
+                dataString, authStep, clientAuthStrings[authStep]);
+            return AuthData.of(clientAuthStrings[authStep].getBytes());
+        }
+    }
+
+    public static class MutualAuthentication implements Authentication {
+        @Override
+        public void close() throws IOException {
+            // noop
+        }
+
+        @Override
+        public String getAuthMethodName() {
+            return "MutualAuthentication";
+        }
+
+        @Override
+        public AuthenticationDataProvider getAuthData(String broker) throws PulsarClientException
{
+            try {
+                return new MutualAuthenticationDataProvider();
+            } catch (Exception e) {
+                throw new PulsarClientException(e);
+            }
+        }
+
+        @Override
+        public void configure(Map<String, String> authParams) {
+            // noop
+        }
+
+        @Override
+        public void start() throws PulsarClientException {
+            // noop
+        }
+    }
+
+
+    public static class MutualAuthenticationState implements AuthenticationState {
+        @Override
+        public String getAuthRole() throws AuthenticationException {
+            return "admin";
+        }
+
+        @Override
+        public AuthData authenticate(AuthData authData) throws IOException {
+            String clientData = new String(authData.getBytes(), Charset.forName("UTF-8"));
+            assertEquals(clientData, clientAuthStrings[authStep]);
+            log.debug("authenticate in server. passed in :{}, send: serverAuthStrings[{}]:
{}",
+                clientData, authStep, serverAuthStrings[authStep]);
+            AuthData serverData =  AuthData.of(serverAuthStrings[authStep ++].getBytes());
+            return serverData;
+        }
+
+        @Override
+        public AuthenticationDataSource getAuthDataSource() {
+            return null;
+        }
+
+        @Override
+        public boolean isComplete() {
+            return authStep > 1;
+        }
+    }
+
+    public static class MutualAuthenticationProvider implements AuthenticationProvider {
+        @Override
+        public void close() throws IOException {
+        }
+
+        @Override
+        public void initialize(ServiceConfiguration config) throws IOException {
+        }
+
+        @Override
+        public String getAuthMethodName() {
+            return "MutualAuthentication";
+        }
+
+        @Override
+        public String authenticate(AuthenticationDataSource authData) throws AuthenticationException
{
+            return "admin";
 
 Review comment:
   should not be used so should throw an exception.

----------------------------------------------------------------
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


With regards,
Apache Git Services

Mime
View raw message