Skip to content

Commit

Permalink
Move to separate extension
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartisk committed Sep 18, 2023
1 parent a1bb0b6 commit 588b1e0
Show file tree
Hide file tree
Showing 13 changed files with 207 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public enum Feature {
OIDC_CLIENT,
OIDC_CLIENT_FILTER,
OIDC_CLIENT_REACTIVE_FILTER,
OIDC_CLIENT_GRAPHQL_CLIENT_INTEGRATION,
OIDC_TOKEN_PROPAGATION,
OIDC_TOKEN_PROPAGATION_REACTIVE,
OPENSHIFT_CLIENT,
Expand Down
10 changes: 9 additions & 1 deletion extensions/oidc-client-graphql/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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-oidc-client-reactive-filter-parent</artifactId>
<artifactId>quarkus-oidc-client-graphql-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
<relativePath>../</relativePath>
Expand All @@ -14,6 +14,14 @@
<name>Quarkus - OpenID Connect Client GraphQL integration - Deployment</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-oidc-client-graphql</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.quarkus.oidc.client.graphql;

import static io.quarkus.deployment.annotations.ExecutionTime.RUNTIME_INIT;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.BeanContainerBuildItem;
import io.quarkus.deployment.Feature;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.oidc.client.graphql.runtime.GraphQLClientOidcClientAdder;
import io.quarkus.oidc.client.graphql.runtime.OidcGraphQLClientIntegrationRecorder;
import io.quarkus.oidc.client.runtime.GraphQLClientOidcTokenProducer;

public class OidcGraphQLClientIntegrationProcessor {

@BuildStep
void feature(BuildProducer<FeatureBuildItem> featureProducer) {
featureProducer.produce(new FeatureBuildItem(Feature.OIDC_CLIENT_GRAPHQL_CLIENT_INTEGRATION));
}

@BuildStep
AdditionalBeanBuildItem tokenProducerBean() {
return AdditionalBeanBuildItem.unremovableOf(GraphQLClientOidcTokenProducer.class);
}

@BuildStep
AdditionalBeanBuildItem adderBean() {
return AdditionalBeanBuildItem.unremovableOf(GraphQLClientOidcClientAdder.class);
}

@BuildStep
@Record(RUNTIME_INIT)
void initializeAdderBean(BeanContainerBuildItem containerBuildItem,
OidcGraphQLClientIntegrationRecorder recorder) {
recorder.initializeAdderBean();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.quarkus.oidc.client.reactive.filter;

import org.eclipse.microprofile.graphql.Query;

import io.quarkus.oidc.client.filter.OidcClientFilter;
import io.smallrye.graphql.client.typesafe.api.GraphQLClientApi;

@GraphQLClientApi
@OidcClientFilter("annotation")
public interface AnnotationTypesafeGraphQLClient {

@Query
String principalName();

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

import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;

@Path("/oidc-graphql-client")
public class GraphQLClientResource {

@Inject
AnnotationTypesafeGraphQLClient annotationTypesafeClient;

@GET
@Path("/annotation-typesafe")
public String annotationUserName() {
return annotationTypesafeClient.principalName();
}

//TODO:
// annotated dynamic client
// config-property based typesafe client
// config-property based dynamic client
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package io.quarkus.oidc.client.reactive.filter;

import static org.hamcrest.Matchers.equalTo;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusDevModeTest;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.keycloak.server.KeycloakTestResourceLifecycleManager;
import io.restassured.RestAssured;

@QuarkusTestResource(KeycloakTestResourceLifecycleManager.class)
public class GraphQLClientUsingOidcClientTest {

private static final Class<?>[] testClasses = {
ProtectedResource.class,
GraphQLClientResource.class,
AnnotationTypesafeGraphQLClient.class
};

@RegisterExtension
static final QuarkusDevModeTest test = new QuarkusDevModeTest()
.withApplicationRoot((jar) -> jar
.addClasses(testClasses)
.addAsResource("application.properties", "application.properties"));

@Test
public void doTest() { // TODO: name
// OidcClient selected via @OidcClient("clientName")
RestAssured.when().get("/oidc-graphql-client/annotation-typesafe")
.then()
.statusCode(200)
.body(equalTo("jdoe"));

/*
* // @OidcClientFilter: OidcClient selected via `quarkus.oidc-client-filter.client-name=config-property`
* RestAssured.when().get("/oidc-client/config-property/user-name")
* .then()
* .statusCode(200)
* .body(equalTo("alice"));
*
* // @RegisterProvider(OidcClientRequestReactiveFilter.class): OidcClient selected via
* `quarkus.oidc-client-filter.client-name=config-property`
* RestAssured.when().get("/oidc-client/custom-provider-config-property/user-name")
* .then()
* .statusCode(200)
* .body(equalTo("alice"));
*/
}

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

import java.security.Principal;

import jakarta.inject.Inject;

import org.eclipse.microprofile.graphql.GraphQLApi;
import org.eclipse.microprofile.graphql.Query;

import io.quarkus.security.Authenticated;

@GraphQLApi
@Authenticated
public class ProtectedResource {

@Inject
Principal principal;

@Query
public String principalName() {
return principal.getName();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
quarkus.oidc.auth-server-url=${keycloak.url}/realms/quarkus/
quarkus.oidc.client-id=quarkus-service-app
quarkus.oidc.credentials.secret=secret

#quarkus.oidc-client-reactive-filter.client-name=config-property
#quarkus.oidc-client.config-property.auth-server-url=${quarkus.oidc.auth-server-url}
#quarkus.oidc-client.config-property.client-id=${quarkus.oidc.client-id}
#quarkus.oidc-client.config-property.credentials.client-secret.value=${quarkus.oidc.credentials.secret}
#quarkus.oidc-client.config-property.credentials.client-secret.method=POST
#quarkus.oidc-client.config-property.grant.type=password
#quarkus.oidc-client.config-property.grant-options.password.username=alice
#quarkus.oidc-client.config-property.grant-options.password.password=alice

quarkus.oidc-client.annotation.auth-server-url=${quarkus.oidc.auth-server-url}
quarkus.oidc-client.annotation.client-id=${quarkus.oidc.client-id}
quarkus.oidc-client.annotation.credentials.client-secret.value=${quarkus.oidc.credentials.secret}
quarkus.oidc-client.annotation.credentials.client-secret.method=POST
quarkus.oidc-client.annotation.grant.type=password
quarkus.oidc-client.annotation.grant-options.password.username=jdoe
quarkus.oidc-client.annotation.grant-options.password.password=jdoe
10 changes: 9 additions & 1 deletion extensions/oidc-client-graphql/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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-oidc-client-reactive-filter-parent</artifactId>
<artifactId>quarkus-oidc-client-graphql-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
<relativePath>../</relativePath>
Expand All @@ -14,6 +14,14 @@
<name>Quarkus - OpenID Connect Client GraphQL integration - Runtime</name>
<description>Use GraphQL client and get and refresh access tokens with OpenId Connect Client and send them as HTTP Authorization Bearer tokens</description>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-oidc-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.smallrye.graphql.client.runtime;
package io.quarkus.oidc.client.graphql.runtime;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -8,6 +8,7 @@
import jakarta.inject.Singleton;

import io.quarkus.oidc.client.runtime.GraphQLClientOidcTokenProducer;
import io.quarkus.smallrye.graphql.client.runtime.GraphQLClientSupport;
import io.smallrye.graphql.client.impl.GraphQLClientsConfiguration;
import io.smallrye.mutiny.Uni;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.quarkus.oidc.client.graphql.runtime;

import io.quarkus.arc.Arc;
import io.quarkus.runtime.annotations.Recorder;

@Recorder
public class OidcGraphQLClientIntegrationRecorder {

public void initializeAdderBean() {
GraphQLClientOidcClientAdder adder = Arc.container().instance(GraphQLClientOidcClientAdder.class).get();
adder.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveHierarchyBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
import io.quarkus.oidc.client.runtime.GraphQLClientOidcTokenProducer;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.smallrye.graphql.client.runtime.GraphQLClientConfigurationMergerBean;
import io.quarkus.smallrye.graphql.client.runtime.GraphQLClientOidcClientAdder;
import io.quarkus.smallrye.graphql.client.runtime.GraphQLClientSupport;
import io.quarkus.smallrye.graphql.client.runtime.GraphQLClientsConfig;
import io.quarkus.smallrye.graphql.client.runtime.SmallRyeGraphQLClientRecorder;
Expand Down Expand Up @@ -209,23 +207,6 @@ void initializeClientSupport(BuildProducer<SyntheticBeanBuildItem> syntheticBean
syntheticBeans.produce(bean);
}

@BuildStep
AdditionalBeanBuildItem tokenProducerBean() {
return AdditionalBeanBuildItem.unremovableOf(GraphQLClientOidcTokenProducer.class);
}

@BuildStep
AdditionalBeanBuildItem adderBean() {
return AdditionalBeanBuildItem.unremovableOf(GraphQLClientOidcClientAdder.class);
}

@BuildStep
@Record(RUNTIME_INIT)
void initializeAdderBean(BeanContainerBuildItem containerBuildItem,
SmallRyeGraphQLClientRecorder recorder) {
recorder.initializeAdderBean();
}

@BuildStep
AdditionalBeanBuildItem configurationMergerBean() {
return AdditionalBeanBuildItem.unremovableOf(GraphQLClientConfigurationMergerBean.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,4 @@ public void setGlobalVertxInstance(Supplier<Vertx> vertx) {
VertxManager.setFromGlobal(vertx.get());
}

public void initializeAdderBean() {
GraphQLClientOidcClientAdder adder = Arc.container().instance(GraphQLClientOidcClientAdder.class).get();
adder.toString();
}
}

0 comments on commit 588b1e0

Please sign in to comment.