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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import io.quarkiverse.openapi.generator.oidc.providers.OAuth2AuthenticationProvider;
import io.quarkiverse.openapi.generator.providers.ApiKeyIn;
import io.quarkiverse.openapi.generator.providers.AuthProvider;
import io.quarkiverse.openapi.generator.providers.CompositeAuthenticationProvider;
import io.quarkiverse.openapi.generator.providers.BaseCompositeAuthenticationProvider;
import io.quarkiverse.openapi.generator.providers.OperationAuthInfo;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
Expand Down Expand Up @@ -110,12 +110,17 @@ void produceCompositeProviders(AuthenticationRecorder recorder, List<AuthProvide
Map<String, List<AuthProviderBuildItem>> providersBySpec = authProviders.stream()
.collect(Collectors.groupingBy(AuthProviderBuildItem::getOpenApiSpecId));
providersBySpec.forEach((openApiSpecId, providers) -> {
beanProducer.produce(SyntheticBeanBuildItem.configure(CompositeAuthenticationProvider.class).scope(Dependent.class)
.addQualifier().annotation(OpenApiSpec.class).addValue("openApiSpecId", openApiSpecId).done()
.addInjectionPoint(ParameterizedType.create(Instance.class, ClassType.create(AuthProvider.class)),
beanProducer.produce(SyntheticBeanBuildItem.configure(BaseCompositeAuthenticationProvider.class)
.scope(Dependent.class)
.addQualifier()
.annotation(OpenApiSpec.class)
.addValue("openApiSpecId", openApiSpecId)
.done()
.addInjectionPoint(
ParameterizedType.create(Instance.class, ClassType.create(AuthProvider.class)),
AnnotationInstance.builder(OpenApiSpec.class).add("openApiSpecId", openApiSpecId).build())
.createWith(recorder.recordCompositeProvider(openApiSpecId)).done());

.createWith(recorder.recordCompositeProvider(openApiSpecId))
.done());
});
}

Expand All @@ -131,7 +136,13 @@ void produceOauthAuthentication(CombinedIndexBuildItem beanArchiveBuildItem,
}
LOGGER.debug("{} class found in runtime, producing OAuth bean generation", ABSTRACT_TOKEN_PRODUCER);
Collection<AnnotationInstance> authenticationMarkers = beanArchiveBuildItem.getIndex()
.getAnnotationsWithRepeatable(OAUTH_AUTHENTICATION_MARKER, beanArchiveBuildItem.getIndex());
.getAnnotationsWithRepeatable(OAUTH_AUTHENTICATION_MARKER, beanArchiveBuildItem.getIndex())
.stream()
.collect(Collectors.toMap(
AnnotationInstance::equivalenceHashCode,
marker -> marker,
(existing, duplicate) -> existing))
.values();

Map<String, List<AnnotationInstance>> operationsBySpec = getOperationsBySpec(beanArchiveBuildItem);

Expand All @@ -140,13 +151,21 @@ void produceOauthAuthentication(CombinedIndexBuildItem beanArchiveBuildItem,
String openApiSpecId = authenticationMarker.value("openApiSpecId").asString();
List<OperationAuthInfo> operations = getOperations(operationsBySpec, openApiSpecId, name);
authenticationProviders.produce(new AuthProviderBuildItem(openApiSpecId, name));
beanProducer.produce(SyntheticBeanBuildItem.configure(AuthProvider.class).scope(Dependent.class).addQualifier()
.annotation(AuthName.class).addValue("name", name).done().addQualifier().annotation(OpenApiSpec.class)
.addValue("openApiSpecId", openApiSpecId).done()
beanProducer.produce(SyntheticBeanBuildItem.configure(AuthProvider.class)
.scope(Dependent.class)
.addQualifier()
.annotation(AuthName.class)
.addValue("name", name)
.done()
.addQualifier()
.annotation(OpenApiSpec.class)
.addValue("openApiSpecId", openApiSpecId)
.done()
.addInjectionPoint(ClassType.create(OAuth2AuthenticationProvider.OidcClientRequestFilterDelegate.class),
AnnotationInstance.builder(OidcClient.class).add("name", sanitizeAuthName(name)).build())
.createWith(oidcRecorder.recordOauthAuthProvider(sanitizeAuthName(name), openApiSpecId, operations))
.unremovable().done());
.unremovable()
.done());
}
}

Expand All @@ -157,7 +176,13 @@ void produceBasicAuthentication(CombinedIndexBuildItem beanArchiveBuildItem,
AuthenticationRecorder recorder) {

Collection<AnnotationInstance> authenticationMarkers = beanArchiveBuildItem.getIndex()
.getAnnotationsWithRepeatable(BASIC_AUTHENTICATION_MARKER, beanArchiveBuildItem.getIndex());
.getAnnotationsWithRepeatable(BASIC_AUTHENTICATION_MARKER, beanArchiveBuildItem.getIndex())
.stream()
.collect(Collectors.toMap(
AnnotationInstance::equivalenceHashCode,
marker -> marker,
(existing, duplicate) -> existing))
.values();

Map<String, List<AnnotationInstance>> operationsBySpec = getOperationsBySpec(beanArchiveBuildItem);
for (AnnotationInstance authenticationMarker : authenticationMarkers) {
Expand All @@ -167,12 +192,18 @@ void produceBasicAuthentication(CombinedIndexBuildItem beanArchiveBuildItem,
List<OperationAuthInfo> operations = getOperations(operationsBySpec, openApiSpecId, name);

authenticationProviders.produce(new AuthProviderBuildItem(openApiSpecId, name));

beanProducer.produce(SyntheticBeanBuildItem.configure(AuthProvider.class).scope(Dependent.class).addQualifier()
.annotation(AuthName.class).addValue("name", name).done().addQualifier().annotation(OpenApiSpec.class)
.addValue("openApiSpecId", openApiSpecId).done()
beanProducer.produce(SyntheticBeanBuildItem.configure(AuthProvider.class)
.scope(Dependent.class)
.addQualifier()
.annotation(AuthName.class)
.addValue("name", name).done()
.addQualifier()
.annotation(OpenApiSpec.class)
.addValue("openApiSpecId", openApiSpecId)
.done()
.createWith(recorder.recordBasicAuthProvider(sanitizeAuthName(name), openApiSpecId, operations))
.unremovable().done());
.unremovable()
.done());
}
}

Expand All @@ -183,7 +214,13 @@ void produceBearerAuthentication(CombinedIndexBuildItem beanArchiveBuildItem,
AuthenticationRecorder recorder) {

Collection<AnnotationInstance> authenticationMarkers = beanArchiveBuildItem.getIndex()
.getAnnotationsWithRepeatable(BEARER_AUTHENTICATION_MARKER, beanArchiveBuildItem.getIndex());
.getAnnotationsWithRepeatable(BEARER_AUTHENTICATION_MARKER, beanArchiveBuildItem.getIndex())
.stream()
.collect(Collectors.toMap(
AnnotationInstance::equivalenceHashCode,
marker -> marker,
(existing, duplicate) -> existing))
.values();

Map<String, List<AnnotationInstance>> operationsBySpec = getOperationsBySpec(beanArchiveBuildItem);
for (AnnotationInstance authenticationMarker : authenticationMarkers) {
Expand All @@ -193,11 +230,19 @@ void produceBearerAuthentication(CombinedIndexBuildItem beanArchiveBuildItem,

List<OperationAuthInfo> operations = getOperations(operationsBySpec, openApiSpecId, name);
authenticationProviders.produce(new AuthProviderBuildItem(openApiSpecId, name));
beanProducer.produce(SyntheticBeanBuildItem.configure(AuthProvider.class).scope(Dependent.class).addQualifier()
.annotation(AuthName.class).addValue("name", name).done().addQualifier().annotation(OpenApiSpec.class)
.addValue("openApiSpecId", openApiSpecId).done()
beanProducer.produce(SyntheticBeanBuildItem.configure(AuthProvider.class)
.scope(Dependent.class)
.addQualifier()
.annotation(AuthName.class)
.addValue("name", name)
.done()
.addQualifier()
.annotation(OpenApiSpec.class)
.addValue("openApiSpecId", openApiSpecId)
.done()
.createWith(recorder.recordBearerAuthProvider(sanitizeAuthName(name), scheme, openApiSpecId, operations))
.unremovable().done());
.unremovable()
.done());

}
}
Expand All @@ -209,7 +254,14 @@ void produceApiKeyAuthentication(CombinedIndexBuildItem beanArchiveBuildItem,
AuthenticationRecorder recorder) {

Collection<AnnotationInstance> authenticationMarkers = beanArchiveBuildItem.getIndex()
.getAnnotationsWithRepeatable(API_KEY_AUTHENTICATION_MARKER, beanArchiveBuildItem.getIndex());
.getAnnotationsWithRepeatable(API_KEY_AUTHENTICATION_MARKER, beanArchiveBuildItem.getIndex())
.stream()
.collect(Collectors.toMap(
AnnotationInstance::equivalenceHashCode,
marker -> marker,
(existing, duplicate) -> existing))
.values();

Map<String, List<AnnotationInstance>> operationsBySpec = getOperationsBySpec(beanArchiveBuildItem);
for (AnnotationInstance authenticationMarker : authenticationMarkers) {
String name = authenticationMarker.value("name").asString();
Expand All @@ -220,12 +272,20 @@ void produceApiKeyAuthentication(CombinedIndexBuildItem beanArchiveBuildItem,
List<OperationAuthInfo> operations = getOperations(operationsBySpec, openApiSpecId, name);

authenticationProviders.produce(new AuthProviderBuildItem(openApiSpecId, name));

beanProducer.produce(SyntheticBeanBuildItem.configure(AuthProvider.class).scope(Dependent.class).addQualifier()
.annotation(AuthName.class).addValue("name", name).done().addQualifier().annotation(OpenApiSpec.class)
.addValue("openApiSpecId", openApiSpecId).done().createWith(recorder
.recordApiKeyAuthProvider(sanitizeAuthName(name), openApiSpecId, apiKeyIn, apiKeyName, operations))
.unremovable().done());
beanProducer.produce(SyntheticBeanBuildItem.configure(AuthProvider.class)
.scope(Dependent.class)
.addQualifier()
.annotation(AuthName.class)
.addValue("name", name)
.done()
.addQualifier()
.annotation(OpenApiSpec.class)
.addValue("openApiSpecId", openApiSpecId)
.done()
.createWith(recorder.recordApiKeyAuthProvider(sanitizeAuthName(name), openApiSpecId, apiKeyIn, apiKeyName,
operations))
.unremovable()
.done());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class CompositeAuthenticationProvider implements jakarta.ws.rs.client.Cli

@jakarta.inject.Inject
@io.quarkiverse.openapi.generator.OpenApiSpec(openApiSpecId="{quarkus-generator.openApiSpecId}")
io.quarkiverse.openapi.generator.providers.CompositeAuthenticationProvider compositeProvider;
io.quarkiverse.openapi.generator.providers.BaseCompositeAuthenticationProvider compositeProvider;

@java.lang.Override
public void filter(jakarta.ws.rs.client.ClientRequestContext context) throws java.io.IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package {apiPackage}.auth;
public class AuthenticationPropagationHeadersFactory extends io.quarkiverse.openapi.generator.providers.AbstractAuthenticationPropagationHeadersFactory {

@jakarta.inject.Inject
public AuthenticationPropagationHeadersFactory(@io.quarkiverse.openapi.generator.OpenApiSpec(openApiSpecId="{quarkus-generator.openApiSpecId}") io.quarkiverse.openapi.generator.providers.CompositeAuthenticationProvider compositeProvider, io.quarkiverse.openapi.generator.OpenApiGeneratorConfig generatorConfig, io.quarkiverse.openapi.generator.providers.HeadersProvider headersProvider) {
public AuthenticationPropagationHeadersFactory(@io.quarkiverse.openapi.generator.OpenApiSpec(openApiSpecId="{quarkus-generator.openApiSpecId}") io.quarkiverse.openapi.generator.providers.BaseCompositeAuthenticationProvider compositeProvider, io.quarkiverse.openapi.generator.OpenApiGeneratorConfig generatorConfig, io.quarkiverse.openapi.generator.providers.HeadersProvider headersProvider) {
super(compositeProvider, generatorConfig, headersProvider);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import io.quarkiverse.openapi.generator.oidc.providers.OAuth2AuthenticationProvider;
import io.quarkiverse.openapi.generator.providers.ApiKeyAuthenticationProvider;
import io.quarkiverse.openapi.generator.providers.AuthProvider;
import io.quarkiverse.openapi.generator.providers.BaseCompositeAuthenticationProvider;
import io.quarkiverse.openapi.generator.providers.BasicAuthenticationProvider;
import io.quarkiverse.openapi.generator.providers.CompositeAuthenticationProvider;
import io.quarkus.test.QuarkusUnitTest;

public class OpenApiSpecProviderTest {
Expand All @@ -41,19 +41,19 @@ public class OpenApiSpecProviderTest {

@Inject
@OpenApiSpec(openApiSpecId = "spec_1")
CompositeAuthenticationProvider spec1CompositeProvider;
BaseCompositeAuthenticationProvider spec1CompositeProvider;

@Inject
@OpenApiSpec(openApiSpecId = "spec_2")
CompositeAuthenticationProvider spec2CompositeProvider;
BaseCompositeAuthenticationProvider spec2CompositeProvider;

@Inject
@OpenApiSpec(openApiSpecId = "spec_3")
CompositeAuthenticationProvider spec3CompositeProvider;
BaseCompositeAuthenticationProvider spec3CompositeProvider;

@Inject
@OpenApiSpec(openApiSpecId = "spec_multi")
CompositeAuthenticationProvider multiCompositeProvider;
BaseCompositeAuthenticationProvider multiCompositeProvider;

@Test
public void checkCompositeProvider() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import io.quarkiverse.openapi.generator.markers.BasicAuthenticationMarker;
import io.quarkiverse.openapi.generator.markers.OauthAuthenticationMarker;
import io.quarkiverse.openapi.generator.markers.OperationMarker;
import io.quarkiverse.openapi.generator.providers.CompositeAuthenticationProvider;
import io.quarkiverse.openapi.generator.providers.BaseCompositeAuthenticationProvider;
import io.quarkiverse.openapi.generator.providers.OperationAuthInfo;
import io.quarkus.test.QuarkusUnitTest;

Expand All @@ -40,10 +40,10 @@ public class OperationTest {

@Inject
@OpenApiSpec(openApiSpecId = "petstore_json")
CompositeAuthenticationProvider compositeProvider;
BaseCompositeAuthenticationProvider compositeProvider;
@Inject
@OpenApiSpec(openApiSpecId = "other_spec_json")
CompositeAuthenticationProvider otherProvider;
BaseCompositeAuthenticationProvider otherProvider;

@Test
public void test() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
import io.quarkiverse.openapi.generator.providers.ApiKeyAuthenticationProvider;
import io.quarkiverse.openapi.generator.providers.ApiKeyIn;
import io.quarkiverse.openapi.generator.providers.AuthProvider;
import io.quarkiverse.openapi.generator.providers.BaseCompositeAuthenticationProvider;
import io.quarkiverse.openapi.generator.providers.BasicAuthenticationProvider;
import io.quarkiverse.openapi.generator.providers.BearerAuthenticationProvider;
import io.quarkiverse.openapi.generator.providers.CompositeAuthenticationProvider;
import io.quarkiverse.openapi.generator.providers.OperationAuthInfo;
import io.quarkus.arc.SyntheticCreationalContext;
import io.quarkus.runtime.annotations.Recorder;

@Recorder
public class AuthenticationRecorder {

public Function<SyntheticCreationalContext<CompositeAuthenticationProvider>, CompositeAuthenticationProvider> recordCompositeProvider(
public Function<SyntheticCreationalContext<BaseCompositeAuthenticationProvider>, BaseCompositeAuthenticationProvider> recordCompositeProvider(
String openApiSpec) {
return ctx -> {
List<AuthProvider> providers = ctx.getInjectedReference(new TypeLiteral<Instance<AuthProvider>>() {
}, new Literal(openApiSpec)).stream().toList();
return new CompositeAuthenticationProvider(providers);
return new BaseCompositeAuthenticationProvider(providers);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public abstract class AbstractAuthenticationPropagationHeadersFactory implements
private static final String HEADER_NAME_PREFIX_FOR_TOKEN_PROPAGATION = "QCG_%s";
private static final String HEADER_NAME_FOR_TOKEN_PROPAGATION = "QCG_%s_%s_%s";

protected CompositeAuthenticationProvider compositeProvider;
protected BaseCompositeAuthenticationProvider compositeProvider;
protected OpenApiGeneratorConfig generatorConfig;
protected HeadersProvider headersProvider;

protected AbstractAuthenticationPropagationHeadersFactory(CompositeAuthenticationProvider compositeProvider,
protected AbstractAuthenticationPropagationHeadersFactory(BaseCompositeAuthenticationProvider compositeProvider,
OpenApiGeneratorConfig generatorConfig,
HeadersProvider headersProvider) {
this.compositeProvider = compositeProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
* Composition of supported {@link ClientRequestFilter} defined by a given OpenAPI interface.
* This class is used as the base class of generated code.
*/
public class CompositeAuthenticationProvider implements ClientRequestFilter {
public class BaseCompositeAuthenticationProvider implements ClientRequestFilter {

private final List<AuthProvider> authProviders;

public CompositeAuthenticationProvider(List<AuthProvider> authProviders) {
public BaseCompositeAuthenticationProvider(List<AuthProvider> authProviders) {
this.authProviders = List.copyOf(authProviders);
}

Expand Down