Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bom/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,11 @@
<artifactId>quarkus-vault-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-credentials-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-logging-json-deployment</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bom/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vault-spi</artifactId>
<artifactId>quarkus-credentials</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down
5 changes: 4 additions & 1 deletion extensions/agroal/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-narayana-jta-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-credentials-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-health-spi</artifactId>
Expand All @@ -46,7 +50,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-metrics-spi</artifactId>
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
Expand Down
2 changes: 1 addition & 1 deletion extensions/agroal/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vault-spi</artifactId>
<artifactId>quarkus-credentials</artifactId>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package io.quarkus.agroal.runtime;

import java.util.Map;
import java.util.Properties;

import io.agroal.api.security.SimplePassword;
import io.quarkus.vault.CredentialsProvider;
import io.quarkus.credentials.CredentialsProvider;

public class AgroalVaultCredentialsProviderPassword extends SimplePassword {

Expand All @@ -16,6 +17,9 @@ public AgroalVaultCredentialsProviderPassword(String credentialsProviderName, Cr

@Override
public Properties asProperties() {
return credentialsProvider.getCredentials(getWord());
Properties properties = new Properties();
Map<String, String> credentials = credentialsProvider.getCredentials(getWord());
credentials.entrySet().forEach(entry -> properties.setProperty(entry.getKey(), entry.getValue()));
return properties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import io.quarkus.arc.Arc;
import io.quarkus.arc.ArcContainer;
import io.quarkus.arc.InstanceHandle;
import io.quarkus.credentials.CredentialsProvider;
import io.quarkus.credentials.runtime.CredentialsProviderFinder;
import io.quarkus.datasource.common.runtime.DataSourceUtil;
import io.quarkus.datasource.runtime.DataSourceBuildTimeConfig;
import io.quarkus.datasource.runtime.DataSourceRuntimeConfig;
Expand All @@ -41,7 +43,6 @@
import io.quarkus.datasource.runtime.LegacyDataSourceRuntimeConfig;
import io.quarkus.datasource.runtime.LegacyDataSourcesRuntimeConfig;
import io.quarkus.runtime.configuration.ConfigurationException;
import io.quarkus.vault.CredentialsProvider;

/**
* This class is sort of a producer for {@link AgroalDataSource}.
Expand Down Expand Up @@ -238,18 +239,10 @@ private void applyNewConfiguration(AgroalDataSourceConfigurationSupplier dataSou
.credential(new SimplePassword(dataSourceRuntimeConfig.password.get()));
}

// Vault credentials provider
// credentials provider
if (dataSourceRuntimeConfig.credentialsProvider.isPresent()) {
ArcContainer container = Arc.container();
String type = dataSourceRuntimeConfig.credentialsProviderType.orElse(null);
CredentialsProvider credentialsProvider = type != null
? (CredentialsProvider) container.instance(type).get()
: container.instance(CredentialsProvider.class).get();

if (credentialsProvider == null) {
throw new RuntimeException("unable to find credentials provider of type " + (type == null ? "default" : type));
}

CredentialsProvider credentialsProvider = CredentialsProviderFinder.find(type);
String name = dataSourceRuntimeConfig.credentialsProvider.get();
connectionFactoryConfiguration
.credential(new AgroalVaultCredentialsProviderPassword(name, credentialsProvider));
Expand Down
48 changes: 48 additions & 0 deletions extensions/credentials/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-credentials-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-credentials-deployment</artifactId>
<name>Quarkus - Credentials - Deployment</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-credentials</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkus.credentials;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.deployment.annotations.BuildStep;

public class CredentialsProcessor {

@BuildStep
AdditionalBeanBuildItem registerAdditionalBeans() {
return new AdditionalBeanBuildItem.Builder()
.setUnremovable()
.addBeanClass(CredentialsProvider.class)
.build();
}

}
13 changes: 9 additions & 4 deletions extensions/vault/spi/pom.xml → extensions/credentials/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-agroal-parent</artifactId>
<artifactId>quarkus-build-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
<relativePath>../../agroal</relativePath>
<relativePath>../../build-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-vault-spi</artifactId>
<name>Quarkus - Vault - SPI</name>
<artifactId>quarkus-credentials-parent</artifactId>
<name>Quarkus - Credentials</name>
<packaging>pom</packaging>
<modules>
<module>deployment</module>
<module>runtime</module>
</modules>

</project>
23 changes: 23 additions & 0 deletions extensions/credentials/runtime/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-credentials-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-credentials</artifactId>
<name>Quarkus - Credentials - Runtime</name>

<dependencies>
<dependency>
<groupId>io.quarkus.arc</groupId>
<artifactId>arc</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.quarkus.vault;
package io.quarkus.credentials;

import java.util.Properties;
import java.util.Map;

public interface CredentialsProvider {

String USER_PROPERTY_NAME = "user";
String PASSWORD_PROPERTY_NAME = "password";

Properties getCredentials(String credentialsProviderName);
Map<String, String> getCredentials(String credentialsProviderName);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.quarkus.credentials.runtime;

import io.quarkus.arc.Arc;
import io.quarkus.arc.ArcContainer;
import io.quarkus.credentials.CredentialsProvider;

public class CredentialsProviderFinder {

public static CredentialsProvider find(String type) {
ArcContainer container = Arc.container();
CredentialsProvider credentialsProvider = type != null
? (CredentialsProvider) container.instance(type).get()
: container.instance(CredentialsProvider.class).get();

if (credentialsProvider == null) {
throw new RuntimeException("unable to find credentials provider of type " + (type == null ? "default" : type));
}

return credentialsProvider;
}

}
2 changes: 1 addition & 1 deletion extensions/datasource/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vault-spi</artifactId>
<artifactId>quarkus-credentials</artifactId>
</dependency>
</dependencies>

Expand Down
1 change: 1 addition & 0 deletions extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@

<!-- Vault -->
<module>vault</module>
<module>credentials</module>

<!-- GraphQL -->
<module>vertx-graphql</module>
Expand Down
10 changes: 10 additions & 0 deletions extensions/reactive-mysql-client/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-credentials-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-reactive-mysql-client</artifactId>
Expand Down Expand Up @@ -72,6 +76,12 @@
</dependencies>

<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.quarkus.reactive.mysql.client;

import static io.restassured.RestAssured.given;

import org.hamcrest.CoreMatchers;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;

public class CredentialsTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addClass(CustomCredentialsProvider.class)
.addClass(CredentialsTestResource.class)
.addAsResource("application-credentials.properties", "application.properties"));

@Test
public void testConnect() {
given()
.when().get("/test")
.then()
.statusCode(200)
.body(CoreMatchers.equalTo("OK"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.quarkus.reactive.mysql.client;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.concurrent.CompletionStage;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import io.vertx.mutiny.mysqlclient.MySQLPool;

@Path("/test")
public class CredentialsTestResource {

@Inject
MySQLPool client;

@GET
@Produces(MediaType.TEXT_PLAIN)
public CompletionStage<String> connect() {

return client.query("SELECT 1").execute()
.map(mysqlRowSet -> {
assertEquals(1, mysqlRowSet.size());
assertEquals(1, mysqlRowSet.iterator().next().getInteger(0));
return "OK";
})
.subscribeAsCompletionStage();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.quarkus.reactive.mysql.client;

import java.util.HashMap;
import java.util.Map;

import javax.enterprise.context.ApplicationScoped;

import org.jboss.logging.Logger;

import io.quarkus.arc.Unremovable;
import io.quarkus.credentials.CredentialsProvider;

@ApplicationScoped
@Unremovable
public class CustomCredentialsProvider implements CredentialsProvider {

private static final Logger log = Logger.getLogger(CustomCredentialsProvider.class.getName());

@Override
public Map<String, String> getCredentials(String credentialsProviderName) {
Map<String, String> properties = new HashMap<>();
properties.put(USER_PROPERTY_NAME, "hibernate_orm_test");
properties.put(PASSWORD_PROPERTY_NAME, "hibernate_orm_test");
log.info("credentials provider returning " + properties);
return properties;
}
}
Loading