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_r262022910
 
 

 ##########
 File path: 
pulsar-common/src/main/java/org/apache/pulsar/common/api/Commands.java
 ##########
 @@ -168,6 +212,52 @@ public static ByteBuf newConnected(int 
clientProtocolVersion) {
         return res;
     }
 
+    public static ByteBuf newAuthChallenge(String authMethod, AuthData 
brokerData, int clientProtocolVersion) {
+        CommandAuthChallenge.Builder challengeBuilder = 
CommandAuthChallenge.newBuilder();
+
+        // If the broker supports a newer version of the protocol, it will 
anyway advertise the max version that the
+        // client supports, to avoid confusing the client.
+        int currentProtocolVersion = getCurrentProtocolVersion();
+        int versionToAdvertise = Math.min(currentProtocolVersion, 
clientProtocolVersion);
+
+        challengeBuilder.setProtocolVersion(versionToAdvertise);
+        challengeBuilder.setServerVersion("Pulsar Server");
+
+        CommandAuthChallenge challenge = challengeBuilder
+            .setChallenge(PulsarApi.AuthData.newBuilder()
+                .setAuthData(copyFrom(brokerData.getBytes()))
+                .setAuthMethodName(authMethod)
+                .build())
+            .build();
+
+        ByteBuf res = 
serializeWithSize(BaseCommand.newBuilder().setType(Type.AUTH_RESPONSE).setAuthChallenge(challenge));
+        challenge.recycle();
+        challengeBuilder.recycle();
+        return res;
+    }
+
+    public static ByteBuf newAuthResponse(String authMethod,
+                                           AuthData clientData,
+                                           int clientProtocolVersion,
+                                           String clientVersion) {
+        CommandAuthResponse.Builder responseBuilder  = 
CommandAuthResponse.newBuilder();
+
+        responseBuilder.setClientVersion(clientVersion != null ? clientVersion 
: "Pulsar Client");
+        responseBuilder.setProtocolVersion(clientProtocolVersion);
+
+        CommandAuthResponse response = responseBuilder
+            .setResponse(PulsarApi.AuthData.newBuilder()
+                .setAuthData(copyFrom(clientData.getBytes()))
+                .setAuthMethodName(authMethod)
+                .build())
+            .build();
+
+        ByteBuf res = 
serializeWithSize(BaseCommand.newBuilder().setType(Type.AUTH_CHALLENGE).setAuthResponse(response));
 
 Review comment:
   type doesn't match the method name.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to