2222import io .quarkus .deployment .annotations .Record ;
2323import io .quarkus .deployment .builditem .CombinedIndexBuildItem ;
2424import io .quarkus .deployment .builditem .FeatureBuildItem ;
25+ import io .quarkus .runtime .RuntimeValue ;
2526
2627public class GeneratorProcessor {
2728
@@ -38,11 +39,32 @@ FeatureBuildItem feature() {
3839 return new FeatureBuildItem (FEATURE );
3940 }
4041
42+ @ BuildStep
43+ @ Record (ExecutionTime .STATIC_INIT )
44+ void produceCompositeProviders (AuthenticationRecorder recorder ,
45+ List <AuthProviderBuildItem > authProviders ,
46+ BuildProducer <SyntheticBeanBuildItem > producer ) {
47+ Map <String , List <AuthProviderBuildItem >> providersBySpec = authProviders .stream ()
48+ .collect (Collectors .groupingBy (AuthProviderBuildItem ::getOpenApiSpecId ));
49+ providersBySpec .forEach ((openApiSpecId , providers ) -> {
50+ producer .produce (SyntheticBeanBuildItem .configure (CompositeAuthenticationProvider .class )
51+ .scope (Dependent .class )
52+ .addQualifier ()
53+ .annotation (Authentication .class )
54+ .addValue ("openApiSpecId" , openApiSpecId )
55+ .done ()
56+ .runtimeValue (recorder
57+ .recordCompositeProvider (providers .stream ().map (AuthProviderBuildItem ::getAuthProvider ).toList ()))
58+ .done ());
59+
60+ });
61+ }
62+
4163 @ BuildStep
4264 @ Record (ExecutionTime .STATIC_INIT )
4365 void produceOauthAuthentication (CombinedIndexBuildItem beanArchiveBuildItem ,
4466 Capabilities capabilities ,
45- BuildProducer <SyntheticBeanBuildItem > producer ,
67+ BuildProducer <AuthProviderBuildItem > authenticationProviders ,
4668 AuthenticationRecorder recorder ) {
4769 Collection <AnnotationInstance > authenticationMarkers = beanArchiveBuildItem .getIndex ()
4870 .getAnnotations (OAUTH_AUTHENTICATION_MARKER );
@@ -56,29 +78,22 @@ void produceOauthAuthentication(CombinedIndexBuildItem beanArchiveBuildItem,
5678
5779 List <OperationAuthInfo > operations = getOperations (operationsBySpec , openApiSpecId , name );
5880
59- producer .produce (SyntheticBeanBuildItem .configure (OAuth2AuthenticationProvider .class )
60- .scope (Dependent .class )
61- .addQualifier ()
62- .annotation (Authentication .class )
63- .addValue ("name" , name )
64- .addValue ("openApiSpecId" , openApiSpecId )
65- .done ()
66- .runtimeValue (recorder .recordOauthAuthProvider (
67- sanitizeAuthName (name ),
68- openApiSpecId ,
69- capabilities .isPresent (Capability .REST_CLIENT_REACTIVE )
70- ? recorder .recordReactiveDelegate (sanitizeAuthName (name ))
71- : recorder .recordClassicDelegate (sanitizeAuthName (name )),
72- operations ))
73- .done ());
74- }
81+ RuntimeValue <AuthProvider > authProvider = recorder .recordOauthAuthProvider (
82+ sanitizeAuthName (name ),
83+ openApiSpecId ,
84+ capabilities .isPresent (Capability .REST_CLIENT_REACTIVE )
85+ ? recorder .recordReactiveDelegate (sanitizeAuthName (name ))
86+ : recorder .recordClassicDelegate (sanitizeAuthName (name )),
87+ operations );
7588
89+ authenticationProviders .produce (new AuthProviderBuildItem (openApiSpecId , authProvider ));
90+ }
7691 }
7792
7893 @ BuildStep
7994 @ Record (ExecutionTime .STATIC_INIT )
8095 void produceBasicAuthentication (CombinedIndexBuildItem beanArchiveBuildItem ,
81- BuildProducer <SyntheticBeanBuildItem > producer ,
96+ BuildProducer <AuthProviderBuildItem > authenticationProviders ,
8297 AuthenticationRecorder recorder ) {
8398
8499 Collection <AnnotationInstance > authenticationMarkers = beanArchiveBuildItem .getIndex ()
@@ -92,26 +107,19 @@ void produceBasicAuthentication(CombinedIndexBuildItem beanArchiveBuildItem,
92107
93108 List <OperationAuthInfo > operations = getOperations (operationsBySpec , openApiSpecId , name );
94109
95- producer .produce (SyntheticBeanBuildItem .configure (BasicAuthenticationProvider .class )
96- .scope (Dependent .class )
97- .addQualifier ()
98- .annotation (Authentication .class )
99- .addValue ("name" , name )
100- .addValue ("openApiSpecId" , openApiSpecId )
101- .done ()
102- .createWith (recorder .recordBasicAuthProvider (
103- sanitizeAuthName (name ),
104- openApiSpecId ,
105- operations ))
106- .done ());
107- }
110+ RuntimeValue <AuthProvider > authProvider = recorder .recordBasicAuthProvider (
111+ sanitizeAuthName (name ),
112+ openApiSpecId ,
113+ operations );
108114
115+ authenticationProviders .produce (new AuthProviderBuildItem (openApiSpecId , authProvider ));
116+ }
109117 }
110118
111119 @ BuildStep
112120 @ Record (ExecutionTime .STATIC_INIT )
113121 void produceBearerAuthentication (CombinedIndexBuildItem beanArchiveBuildItem ,
114- BuildProducer <SyntheticBeanBuildItem > producer ,
122+ BuildProducer <AuthProviderBuildItem > authenticationProviders ,
115123 AuthenticationRecorder recorder ) {
116124
117125 Collection <AnnotationInstance > authenticationMarkers = beanArchiveBuildItem .getIndex ()
@@ -126,27 +134,20 @@ void produceBearerAuthentication(CombinedIndexBuildItem beanArchiveBuildItem,
126134
127135 List <OperationAuthInfo > operations = getOperations (operationsBySpec , openApiSpecId , name );
128136
129- producer .produce (SyntheticBeanBuildItem .configure (BearerAuthenticationProvider .class )
130- .scope (Dependent .class )
131- .addQualifier ()
132- .annotation (Authentication .class )
133- .addValue ("name" , name )
134- .addValue ("openApiSpecId" , openApiSpecId )
135- .done ()
136- .createWith (recorder .recordBearerAuthProvider (
137- sanitizeAuthName (name ),
138- scheme ,
139- openApiSpecId ,
140- operations ))
141- .done ());
142- }
137+ RuntimeValue <AuthProvider > authProvider = recorder .recordBearerAuthProvider (
138+ sanitizeAuthName (name ),
139+ scheme ,
140+ openApiSpecId ,
141+ operations );
143142
143+ authenticationProviders .produce (new AuthProviderBuildItem (openApiSpecId , authProvider ));
144+ }
144145 }
145146
146147 @ BuildStep
147148 @ Record (ExecutionTime .STATIC_INIT )
148149 void produceApiKeyAuthentication (CombinedIndexBuildItem beanArchiveBuildItem ,
149- BuildProducer <SyntheticBeanBuildItem > producer ,
150+ BuildProducer <AuthProviderBuildItem > authenticationProviders ,
150151 AuthenticationRecorder recorder ) {
151152
152153 Collection <AnnotationInstance > authenticationMarkers = beanArchiveBuildItem .getIndex ()
@@ -162,20 +163,14 @@ void produceApiKeyAuthentication(CombinedIndexBuildItem beanArchiveBuildItem,
162163
163164 List <OperationAuthInfo > operations = getOperations (operationsBySpec , openApiSpecId , name );
164165
165- producer .produce (SyntheticBeanBuildItem .configure (ApiKeyAuthenticationProvider .class )
166- .scope (Dependent .class )
167- .addQualifier ()
168- .annotation (Authentication .class )
169- .addValue ("name" , name )
170- .addValue ("openApiSpecId" , openApiSpecId )
171- .done ()
172- .createWith (recorder .recordApiKeyAuthProvider (
173- sanitizeAuthName (name ),
174- openApiSpecId ,
175- apiKeyIn ,
176- apiKeyName ,
177- operations ))
178- .done ());
166+ RuntimeValue <AuthProvider > authProvider = recorder .recordApiKeyAuthProvider (
167+ sanitizeAuthName (name ),
168+ openApiSpecId ,
169+ apiKeyIn ,
170+ apiKeyName ,
171+ operations );
172+
173+ authenticationProviders .produce (new AuthProviderBuildItem (openApiSpecId , authProvider ));
179174 }
180175
181176 }
0 commit comments