-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1276 from michalvavrik/feature/tls-registry-with-…
…strimzi Support TLS registry with Kafka Strimzi for SASL_SSL and SSL scenarios
- Loading branch information
Showing
6 changed files
with
128 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
examples/kafka/src/main/java/io/quarkus/qe/TlsRegistryResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.quarkus.qe; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.PathParam; | ||
|
||
import io.quarkus.logging.Log; | ||
import io.quarkus.tls.TlsConfigurationRegistry; | ||
|
||
@Path("tls-registry") | ||
public class TlsRegistryResource { | ||
|
||
@Inject | ||
TlsConfigurationRegistry tlsRegistry; | ||
|
||
@GET | ||
@Path("validate-config/{tls-config-name}") | ||
public boolean validateNamedTlsConfig(@PathParam("tls-config-name") String tlsConfigName) { | ||
var namedConfig = tlsRegistry.get(tlsConfigName); | ||
if (namedConfig.isEmpty()) { | ||
Log.error("TLS config '%s' is missing".formatted(tlsConfigName)); | ||
return false; | ||
} | ||
var truststore = namedConfig.get().getTrustStore(); | ||
if (truststore == null) { | ||
Log.error("TLS config '%s' truststore is not configured".formatted(tlsConfigName)); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
...s/kafka/src/test/java/io/quarkus/qe/StrimziKafkaWithTlsRegistryAndSaslSslMessagingIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.quarkus.qe; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
|
||
import java.time.Duration; | ||
|
||
import org.apache.http.HttpStatus; | ||
import org.awaitility.Awaitility; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.bootstrap.KafkaService; | ||
import io.quarkus.test.bootstrap.RestService; | ||
import io.quarkus.test.scenarios.QuarkusScenario; | ||
import io.quarkus.test.services.KafkaContainer; | ||
import io.quarkus.test.services.QuarkusApplication; | ||
import io.quarkus.test.services.containers.model.KafkaProtocol; | ||
import io.quarkus.test.services.containers.model.KafkaVendor; | ||
|
||
@QuarkusScenario | ||
public class StrimziKafkaWithTlsRegistryAndSaslSslMessagingIT { | ||
|
||
private static final String TLS_CONFIG_NAME = "tls-config-name-1"; | ||
|
||
@KafkaContainer(vendor = KafkaVendor.STRIMZI, protocol = KafkaProtocol.SASL_SSL, tlsConfigName = TLS_CONFIG_NAME, tlsRegistryEnabled = true) | ||
static final KafkaService kafka = new KafkaService(); | ||
|
||
@QuarkusApplication | ||
static final RestService app = new RestService() | ||
.withProperties(kafka::getSslProperties) | ||
.withProperty("kafka.bootstrap.servers", kafka::getBootstrapUrl); | ||
|
||
@Test | ||
public void checkUserResourceByNormalUser() { | ||
Awaitility.await().atMost(Duration.ofSeconds(5)).untilAsserted(() -> { | ||
app.given().get("/prices/poll") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testTlsRegistryContainNamedTlsConfig() { | ||
// this is but a smoke test so that we know @KafkaContainer#tlsConfigName had effect | ||
// while the 'checkUserResourceByNormalUser' tests that configured truststore works | ||
app.given() | ||
.pathParam("tls-config-name", TLS_CONFIG_NAME) | ||
.get("/tls-registry/validate-config/{tls-config-name}") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.body(is("true")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters