frankgh commented on code in PR #137:
URL: https://github.com/apache/cassandra-sidecar/pull/137#discussion_r1803634555


##########
vertx-auth-mtls/build.gradle:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.
+ */
+
+import java.nio.file.Paths
+
+plugins {
+    id('java-library')
+    id('idea')
+    id('maven-publish')
+}
+
+group 'org.apache.cassandra.sidecar'
+version project.version
+
+sourceCompatibility = 1.8
+
+repositories {
+    mavenCentral()
+}
+
+test {
+    useJUnitPlatform()
+    maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
+    reports {
+        junitXml.enabled = true
+        def destDir = Paths.get(rootProject.rootDir.absolutePath, "build", 
"test-results", "vertx-auth-mtls").toFile()
+        println("Destination directory for vertx-auth-mtls tests: ${destDir}")
+        junitXml.destination = destDir
+        html.enabled = true
+    }
+}
+
+configurations {
+    all*.exclude(group: 'ch.qos.logback')
+}
+
+dependencies {
+    implementation(group: 'io.vertx', name: 'vertx-auth-common', version: 
'4.5.8')
+    testImplementation(group: 'io.vertx', name: 'vertx-junit5', version: 
'4.5.8')

Review Comment:
   Any reason we are using a different version from the main project? Maybe you 
want to move the entire project to this vertx version?
   ```suggestion
       implementation(group: 'io.vertx', name: 'vertx-auth-common', version: 
"${project.vertxVersion}")
       testImplementation(group: 'io.vertx', name: 'vertx-junit5', version: 
"${project.vertxVersion}")
   ```



##########
vertx-auth-mtls/build.gradle:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.
+ */
+
+import java.nio.file.Paths
+
+plugins {
+    id('java-library')
+    id('idea')
+    id('maven-publish')

Review Comment:
   we can remove if we decide not to publish, which I think makes sense since 
this is an internal dependency



##########
vertx-auth-mtls/build.gradle:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.
+ */
+
+import java.nio.file.Paths
+
+plugins {
+    id('java-library')
+    id('idea')
+    id('maven-publish')
+}
+
+group 'org.apache.cassandra.sidecar'
+version project.version
+
+sourceCompatibility = 1.8
+
+repositories {
+    mavenCentral()
+}

Review Comment:
   this is not necessary



##########
vertx-auth-mtls/src/main/java/io/vertx/ext/auth/authentication/CertificateCredentials.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * 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 io.vertx.ext.auth.authentication;
+
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import java.util.Collections;
+import java.util.List;
+
+import io.vertx.core.http.HttpServerRequest;
+import io.vertx.core.json.JsonObject;
+
+/**
+ * Certificates based {@link Credentials} implementation, carries user's 
certificates, which can be used for
+ * authenticating or authorizing users.
+ */
+public class CertificateCredentials implements Credentials
+{
+    private final List<Certificate> certificateChain;
+    private final X509Certificate peerCertificate;
+
+    public CertificateCredentials(Certificate certificate)
+    {
+        this(Collections.singletonList(certificate));
+    }
+
+    public CertificateCredentials(List<Certificate> certificateChain)
+    {
+        this.certificateChain = Collections.unmodifiableList(certificateChain);
+        this.peerCertificate = getPeerCertificate();
+    }
+
+    /**
+     * Create {@link CertificateCredentials} from {@link HttpServerRequest}
+     * @return CertificateCredentials
+     */
+    public static CertificateCredentials fromHttpRequest(HttpServerRequest 
request)
+    {
+        try
+        {
+            return new 
CertificateCredentials(request.connection().peerCertificates());
+        }
+        catch (Exception e)
+        {
+            throw new IllegalArgumentException("Could not extract certificates 
from request", e);
+        }
+    }
+
+    /**
+     * @return The certificate chain contained in {@link 
CertificateCredentials}
+     */
+    public List<Certificate> certificateChain()
+    {
+        return certificateChain;
+    }
+
+    /**
+     * @return peer's certificate. It does not return null value once {@link 
#checkValid()} passes
+     */
+    public X509Certificate peerCertificate()
+    {
+        return peerCertificate;
+    }
+
+    public void checkValid() throws CredentialValidationException
+    {
+        checkValid(this);
+    }
+
+    @Override
+    public <V> void checkValid(V arg) throws CredentialValidationException
+    {
+        if (certificateChain.isEmpty())
+        {
+            throw new CredentialValidationException("Certificate Chain cannot 
be empty");
+        }
+    }
+
+    /**
+     * @deprecated {@link CertificateCredentials} currently not represented in 
Json format.
+     */
+    @Override
+    public JsonObject toJson()
+    {
+        throw new UnsupportedOperationException("Deprecated authentication 
method");
+    }
+
+    private X509Certificate getPeerCertificate()
+    {
+        // First certificate in the chain is peer's own cert
+        if (!certificateChain.isEmpty() && certificateChain.get(0) instanceof 
X509Certificate)
+        {
+            return (X509Certificate) certificateChain.get(0);
+        }
+
+        return null;

Review Comment:
   Should we allow for the first X509Certificate in the chain?
   ```suggestion
                   // First certificate in the chain is peer's own cert
           return certificateChain.stream()
                                  .filter(cert -> cert instanceof 
X509Certificate)
                                  .map(cert -> (X509Certificate) cert)
                                  .findFirst()
                                  .orElse(null);
   ```



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to