Skip to content

Commit

Permalink
Merge pull request #29940 from michalvavrik/feature/fix-oidc-client-f…
Browse files Browse the repository at this point in the history
…ilter-reactive-reg-provider

OIDC Client Reactive Filter - fix register provider with config property
  • Loading branch information
sberyozkin authored Dec 18, 2022
2 parents 173b208 + 4a57f27 commit fc20fb2
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,19 @@ public class ConfigPropertyOidcClientResource {
@RestClient
ProtectedResourceServiceConfigPropertyOidcClient protectedResourceServiceConfigPropertyOidcClient;

@Inject
@RestClient
ProtectedResourceServiceCustomProviderConfigPropOidcClient protectedResourceServiceCustomProviderConfigPropOidcClient;

@GET
@Path("user-name")
@Path("/annotation/user-name")
public String userName() {
return protectedResourceServiceConfigPropertyOidcClient.getUserName();
}

@GET
@Path("/custom-provider/user-name")
public String customProviderConfigPropertyUserName() {
return protectedResourceServiceCustomProviderConfigPropOidcClient.getUserName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class NamedOidcClientFilterDevModeTest {
ProtectedResource.class,
ProtectedResourceServiceNamedOidcClient.class,
ProtectedResourceServiceConfigPropertyOidcClient.class,
ProtectedResourceServiceCustomProviderConfigPropOidcClient.class,
NamedOidcClientResource.class,
ConfigPropertyOidcClientResource.class
};
Expand All @@ -35,8 +36,14 @@ public void testGerUserConfigPropertyAndAnnotation() {
.statusCode(200)
.body(equalTo("jdoe"));

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

// @RegisterProvider(OidcClientRequestFilter.class): OidcClient selected via `quarkus.oidc-client-filter.client-name=config-property`
RestAssured.when().get("/config-property-oidc-client/custom-provider/user-name")
.then()
.statusCode(200)
.body(equalTo("alice"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkus.oidc.client.filter;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

import org.eclipse.microprofile.rest.client.annotation.RegisterProvider;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

@RegisterProvider(OidcClientRequestFilter.class)
@RegisterRestClient
@Path("/")
public interface ProtectedResourceServiceCustomProviderConfigPropOidcClient {

@GET
String getUserName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ quarkus.oidc-client.named.grant-options.password.username=jdoe
quarkus.oidc-client.named.grant-options.password.password=jdoe

io.quarkus.oidc.client.filter.ProtectedResourceServiceNamedOidcClient/mp-rest/url=http://localhost:8080/protected
io.quarkus.oidc.client.filter.ProtectedResourceServiceConfigPropertyOidcClient/mp-rest/url=http://localhost:8080/protected
io.quarkus.oidc.client.filter.ProtectedResourceServiceConfigPropertyOidcClient/mp-rest/url=http://localhost:8080/protected
io.quarkus.oidc.client.filter.ProtectedResourceServiceCustomProviderConfigPropOidcClient/mp-rest/url=http://localhost:8080/protected
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,20 @@ public class OidcClientReactiveFilterBuildStep {
void oidcClientFilterSupport(CombinedIndexBuildItem indexBuildItem, BuildProducer<GeneratedBeanBuildItem> generatedBean,
BuildProducer<RegisterProviderAnnotationInstanceBuildItem> producer) {
final var helper = new OidcClientFilterDeploymentHelper<>(AbstractOidcClientRequestReactiveFilter.class, generatedBean);
final var defaultFilter = oidcClientReactiveFilterConfig.clientName.isPresent()
? helper.getOrCreateFilter(oidcClientReactiveFilterConfig.clientName.get())
: OIDC_CLIENT_REQUEST_REACTIVE_FILTER;

Collection<AnnotationInstance> instances = indexBuildItem.getIndex().getAnnotations(OIDC_CLIENT_FILTER);
for (AnnotationInstance instance : instances) {

// get client name from annotation @OidcClientFilter("clientName")
final String clientName = OidcClientFilterDeploymentHelper.getClientName(instance);
final AnnotationValue valueAttr;
if (clientName != null) {
if (clientName != null && !clientName.equals(oidcClientReactiveFilterConfig.clientName.orElse(null))) {
// create and use custom filter for named OidcClient
// we generate exactly one custom filter for each named client specified through annotation
valueAttr = createClassValue(helper.getOrCreateFilter(clientName));
} else {
// use default filter for either default OidcClient or the client configured with config properties
valueAttr = createClassValue(defaultFilter);
valueAttr = createClassValue(OIDC_CLIENT_REQUEST_REACTIVE_FILTER);
}

final AnnotationValue priorityAttr = AnnotationValue.createIntegerValue("priority", Priorities.AUTHENTICATION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class NamedOidcClientFilterDevModeTest {
ProtectedResource.class,
ProtectedResourceServiceAnnotationOidcClient.class,
ProtectedResourceServiceConfigPropertyOidcClient.class,
ProtectedResourceServiceCustomProviderConfigPropOidcClient.class,
OidcClientResource.class
};

Expand All @@ -36,11 +37,17 @@ public void testGerUserConfigPropertyAndAnnotation() {
.statusCode(200)
.body(equalTo("jdoe"));

// OidcClient selected via `quarkus.oidc-client-filter.client-name=config-property`
// @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
Expand Up @@ -17,6 +17,10 @@ public class OidcClientResource {
@RestClient
ProtectedResourceServiceConfigPropertyOidcClient protectedResourceServiceConfigPropertyOidcClient;

@Inject
@RestClient
ProtectedResourceServiceCustomProviderConfigPropOidcClient protectedResourceServiceCustomProviderConfigPropOidcClient;

@GET
@Path("/annotation/user-name")
public String annotationUserName() {
Expand All @@ -28,4 +32,10 @@ public String annotationUserName() {
public String configPropertyUserName() {
return protectedResourceServiceConfigPropertyOidcClient.getUserName();
}

@GET
@Path("/custom-provider-config-property/user-name")
public String customProviderConfigPropertyUserName() {
return protectedResourceServiceCustomProviderConfigPropOidcClient.getUserName();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkus.oidc.client.reactive.filter;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

import org.eclipse.microprofile.rest.client.annotation.RegisterProvider;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

@RegisterProvider(OidcClientRequestReactiveFilter.class)
@RegisterRestClient
@Path("/")
public interface ProtectedResourceServiceCustomProviderConfigPropOidcClient {

@GET
String getUserName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ quarkus.oidc-client.annotation.grant-options.password.username=jdoe
quarkus.oidc-client.annotation.grant-options.password.password=jdoe

io.quarkus.oidc.client.reactive.filter.ProtectedResourceServiceAnnotationOidcClient/mp-rest/url=http://localhost:8080/protected
io.quarkus.oidc.client.reactive.filter.ProtectedResourceServiceConfigPropertyOidcClient/mp-rest/url=http://localhost:8080/protected
io.quarkus.oidc.client.reactive.filter.ProtectedResourceServiceConfigPropertyOidcClient/mp-rest/url=http://localhost:8080/protected
io.quarkus.oidc.client.reactive.filter.ProtectedResourceServiceCustomProviderConfigPropOidcClient/mp-rest/url=http://localhost:8080/protected
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
package io.quarkus.oidc.client.reactive.filter;

import java.util.Optional;

import javax.annotation.Priority;
import javax.inject.Inject;
import javax.ws.rs.Priorities;

import io.quarkus.oidc.client.reactive.filter.runtime.AbstractOidcClientRequestReactiveFilter;
import io.quarkus.oidc.client.reactive.filter.runtime.OidcClientReactiveFilterConfig;

@Priority(Priorities.AUTHENTICATION)
public class OidcClientRequestReactiveFilter extends AbstractOidcClientRequestReactiveFilter {

@Inject
OidcClientReactiveFilterConfig config;

@Override
protected Optional<String> clientId() {
return config.clientName;
}
}

0 comments on commit fc20fb2

Please sign in to comment.