Skip to content

Commit 1c50838

Browse files
Add indexed name auth provider (#130)
1 parent 3668930 commit 1c50838

File tree

2 files changed

+72
-24
lines changed

2 files changed

+72
-24
lines changed

deployment/src/main/resources/templates/auth/compositeAuthenticationProvider.qute

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,22 @@ public class CompositeAuthenticationProvider extends AbstractCompositeAuthentica
3333
@PostConstruct
3434
public void init() {
3535
{#for auth in httpBasicMethods.orEmpty}
36-
BasicAuthenticationProvider basicAuthProvider = new BasicAuthenticationProvider("{quarkus-generator.openApiSpecId}", sanitizeAuthName("{auth.name}"), generatorConfig);
37-
this.addAuthenticationProvider(basicAuthProvider);
36+
BasicAuthenticationProvider basicAuthProvider{auth_index} = new BasicAuthenticationProvider("{quarkus-generator.openApiSpecId}", sanitizeAuthName("{auth.name}"), generatorConfig);
37+
this.addAuthenticationProvider(basicAuthProvider{auth_index});
3838
{#for api in apiInfo.apis}
3939
{#for op in api.operations.operation}
4040
{#if op.hasAuthMethods}
4141
{#for authM in op.authMethods}
4242
{#if authM.name == auth.name}
43-
basicAuthProvider.addOperation(OperationAuthInfo.builder()
43+
basicAuthProvider{auth_index}.addOperation(OperationAuthInfo.builder()
4444
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
4545
.withId("{op.operationId}")
4646
.withMethod("{op.httpMethod}")
4747
.build());
4848
{/if}
4949
{/for}
5050
{#else if defaultSecurityScheme == auth.name}
51-
basicAuthProvider.addOperation(OperationAuthInfo.builder()
51+
basicAuthProvider{auth_index}.addOperation(OperationAuthInfo.builder()
5252
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
5353
.withId("{op.operationId}")
5454
.withMethod("{op.httpMethod}")
@@ -58,22 +58,22 @@ public class CompositeAuthenticationProvider extends AbstractCompositeAuthentica
5858
{/for}
5959
{/for}
6060
{#for auth in oauthMethods.orEmpty}
61-
OAuth2AuthenticationProvider oAuth2Provider = new OAuth2AuthenticationProvider("{quarkus-generator.openApiSpecId}", sanitizeAuthName("{auth.name}"), generatorConfig);
62-
this.addAuthenticationProvider(oAuth2Provider);
61+
OAuth2AuthenticationProvider oAuth2Provider{auth_index} = new OAuth2AuthenticationProvider("{quarkus-generator.openApiSpecId}", sanitizeAuthName("{auth.name}"), generatorConfig);
62+
this.addAuthenticationProvider(oAuth2Provider{auth_index});
6363
{#for api in apiInfo.apis}
6464
{#for op in api.operations.operation}
6565
{#if op.hasAuthMethods}
6666
{#for authM in op.authMethods}
6767
{#if authM.name == auth.name}
68-
oAuth2Provider.addOperation(OperationAuthInfo.builder()
68+
oAuth2Provider{auth_index}.addOperation(OperationAuthInfo.builder()
6969
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
7070
.withId("{op.operationId}")
7171
.withMethod("{op.httpMethod}")
7272
.build());
7373
{/if}
7474
{/for}
7575
{#else if defaultSecurityScheme == auth.name}
76-
oAuth2Provider.addOperation(OperationAuthInfo.builder()
76+
oAuth2Provider{auth_index}.addOperation(OperationAuthInfo.builder()
7777
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
7878
.withId("{op.operationId}")
7979
.withMethod("{op.httpMethod}")
@@ -83,22 +83,22 @@ public class CompositeAuthenticationProvider extends AbstractCompositeAuthentica
8383
{/for}
8484
{/for}
8585
{#for auth in httpBearerMethods.orEmpty}
86-
BearerAuthenticationProvider bearerProvider = new BearerAuthenticationProvider("{quarkus-generator.openApiSpecId}", sanitizeAuthName("{auth.name}"), "{auth.scheme}", generatorConfig);
87-
this.addAuthenticationProvider(bearerProvider);
86+
BearerAuthenticationProvider bearerProvider{auth_index} = new BearerAuthenticationProvider("{quarkus-generator.openApiSpecId}", sanitizeAuthName("{auth.name}"), "{auth.scheme}", generatorConfig);
87+
this.addAuthenticationProvider(bearerProvider{auth_index});
8888
{#for api in apiInfo.apis}
8989
{#for op in api.operations.operation}
9090
{#if op.hasAuthMethods}
9191
{#for authM in op.authMethods}
9292
{#if authM.name == auth.name}
93-
bearerProvider.addOperation(OperationAuthInfo.builder()
93+
bearerProvider{auth_index}.addOperation(OperationAuthInfo.builder()
9494
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
9595
.withId("{op.operationId}")
9696
.withMethod("{op.httpMethod}")
9797
.build());
9898
{/if}
9999
{/for}
100100
{#else if defaultSecurityScheme == auth.name}
101-
bearerProvider.addOperation(OperationAuthInfo.builder()
101+
bearerProvider{auth_index}.addOperation(OperationAuthInfo.builder()
102102
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
103103
.withId("{op.operationId}")
104104
.withMethod("{op.httpMethod}")
@@ -109,22 +109,22 @@ public class CompositeAuthenticationProvider extends AbstractCompositeAuthentica
109109
{/for}
110110
{#for auth in apiKeyMethods.orEmpty}
111111
{#if auth.isKeyInQuery}
112-
ApiKeyAuthenticationProvider apiKeyQueryProvider = new ApiKeyAuthenticationProvider("{quarkus-generator.openApiSpecId}", sanitizeAuthName("{auth.name}"), ApiKeyIn.query, "{auth.keyParamName}", generatorConfig);
113-
this.addAuthenticationProvider(apiKeyQueryProvider);
112+
ApiKeyAuthenticationProvider apiKeyQueryProvider{auth_index} = new ApiKeyAuthenticationProvider("{quarkus-generator.openApiSpecId}", sanitizeAuthName("{auth.name}"), ApiKeyIn.query, "{auth.keyParamName}", generatorConfig);
113+
this.addAuthenticationProvider(apiKeyQueryProvider{auth_index});
114114
{#for api in apiInfo.apis}
115115
{#for op in api.operations.operation}
116116
{#if op.hasAuthMethods}
117117
{#for authM in op.authMethods}
118118
{#if authM.name == auth.name}
119-
apiKeyQueryProvider.addOperation(OperationAuthInfo.builder()
119+
apiKeyQueryProvider{auth_index}.addOperation(OperationAuthInfo.builder()
120120
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
121121
.withId("{op.operationId}")
122122
.withMethod("{op.httpMethod}")
123123
.build());
124124
{/if}
125125
{/for}
126126
{#else if defaultSecurityScheme == auth.name}
127-
apiKeyQueryProvider.addOperation(OperationAuthInfo.builder()
127+
apiKeyQueryProvider{auth_index}.addOperation(OperationAuthInfo.builder()
128128
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
129129
.withId("{op.operationId}")
130130
.withMethod("{op.httpMethod}")
@@ -134,22 +134,22 @@ public class CompositeAuthenticationProvider extends AbstractCompositeAuthentica
134134
{/for}
135135
{/if}
136136
{#if auth.isKeyInHeader}
137-
ApiKeyAuthenticationProvider apiKeyHeaderProvider = new ApiKeyAuthenticationProvider("{quarkus-generator.openApiSpecId}", sanitizeAuthName("{auth.name}"), ApiKeyIn.header, "{auth.keyParamName}", generatorConfig);
138-
this.addAuthenticationProvider(apiKeyHeaderProvider);
137+
ApiKeyAuthenticationProvider apiKeyHeaderProvider{auth_index} = new ApiKeyAuthenticationProvider("{quarkus-generator.openApiSpecId}", sanitizeAuthName("{auth.name}"), ApiKeyIn.header, "{auth.keyParamName}", generatorConfig);
138+
this.addAuthenticationProvider(apiKeyHeaderProvider{auth_index});
139139
{#for api in apiInfo.apis}
140140
{#for op in api.operations.operation}
141141
{#if op.hasAuthMethods}
142142
{#for authM in op.authMethods}
143143
{#if authM.name == auth.name}
144-
apiKeyHeaderProvider.addOperation(OperationAuthInfo.builder()
144+
apiKeyHeaderProvider{auth_index}.addOperation(OperationAuthInfo.builder()
145145
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
146146
.withId("{op.operationId}")
147147
.withMethod("{op.httpMethod}")
148148
.build());
149149
{/if}
150150
{/for}
151151
{#else if defaultSecurityScheme == auth.name}
152-
apiKeyHeaderProvider.addOperation(OperationAuthInfo.builder()
152+
apiKeyHeaderProvider{auth_index}.addOperation(OperationAuthInfo.builder()
153153
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
154154
.withId("{op.operationId}")
155155
.withMethod("{op.httpMethod}")
@@ -159,22 +159,22 @@ public class CompositeAuthenticationProvider extends AbstractCompositeAuthentica
159159
{/for}
160160
{/if}
161161
{#if auth.isKeyInCookie}
162-
ApiKeyAuthenticationProvider apiKeyCookieProvider = new ApiKeyAuthenticationProvider("{quarkus-generator.openApiSpecId}", sanitizeAuthName("{auth.name}"), ApiKeyIn.cookie, "{auth.keyParamName}", generatorConfig);
163-
this.addAuthenticationProvider(apiKeyCookieProvider);
162+
ApiKeyAuthenticationProvider apiKeyCookieProvider{auth_index} = new ApiKeyAuthenticationProvider("{quarkus-generator.openApiSpecId}", sanitizeAuthName("{auth.name}"), ApiKeyIn.cookie, "{auth.keyParamName}", generatorConfig);
163+
this.addAuthenticationProvider(apiKeyCookieProvider{auth_index});
164164
{#for api in apiInfo.apis}
165165
{#for op in api.operations.operation}
166166
{#if op.hasAuthMethods}
167167
{#for authM in op.authMethods}
168168
{#if authM.name == auth.name}
169-
apiKeyCookieProvider.addOperation(OperationAuthInfo.builder()
169+
apiKeyCookieProvider{auth_index}.addOperation(OperationAuthInfo.builder()
170170
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
171171
.withId("{op.operationId}")
172172
.withMethod("{op.httpMethod}")
173173
.build());
174174
{/if}
175175
{/for}
176176
{#else if defaultSecurityScheme == auth.name}
177-
apiKeyCookieProvider.addOperation(OperationAuthInfo.builder()
177+
apiKeyCookieProvider{auth_index}.addOperation(OperationAuthInfo.builder()
178178
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
179179
.withId("{op.operationId}")
180180
.withMethod("{op.httpMethod}")
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
openapi: 3.0.3
3+
info:
4+
title: Generated API
5+
version: "1.0"
6+
paths:
7+
/:
8+
post:
9+
operationId: doOperation
10+
security:
11+
- client_id: [ ]
12+
- oauth: [ read, write ]
13+
- bearerAuth: [ ]
14+
requestBody:
15+
content:
16+
application/json:
17+
schema:
18+
$ref: '#/components/schemas/MultiplicationOperation'
19+
responses:
20+
"200":
21+
description: OK
22+
components:
23+
schemas:
24+
MultiplicationOperation:
25+
type: object
26+
securitySchemes:
27+
client_id:
28+
type: apiKey
29+
in: header
30+
name: X-Client-Id
31+
x-key-type: clientId
32+
bearerAuth:
33+
type: http
34+
scheme: bearer
35+
oauth:
36+
type: oauth2
37+
flows:
38+
authorizationCode:
39+
authorizationUrl: https://example.com/oauth/authorize
40+
tokenUrl: https://example.com/oauth/token
41+
scopes:
42+
read: Grants read access
43+
write: Grants write access
44+
admin: Grants read and write access to administrative information
45+
clientCredentials:
46+
tokenUrl: http://localhost:8382/oauth/token
47+
scopes:
48+
read: read

0 commit comments

Comments
 (0)