Skip to content

Commit 3668930

Browse files
Avoid stackoverflow in AuthenticationProvider (#129)
1 parent a89bf55 commit 3668930

File tree

2 files changed

+79
-72
lines changed

2 files changed

+79
-72
lines changed

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

Lines changed: 78 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -33,149 +33,155 @@ public class CompositeAuthenticationProvider extends AbstractCompositeAuthentica
3333
@PostConstruct
3434
public void init() {
3535
{#for auth in httpBasicMethods.orEmpty}
36-
this.addAuthenticationProvider(new BasicAuthenticationProvider("{quarkus-generator.openApiSpecId}", sanitizeAuthName("{auth.name}"), generatorConfig)
36+
BasicAuthenticationProvider basicAuthProvider = new BasicAuthenticationProvider("{quarkus-generator.openApiSpecId}", sanitizeAuthName("{auth.name}"), generatorConfig);
37+
this.addAuthenticationProvider(basicAuthProvider);
3738
{#for api in apiInfo.apis}
3839
{#for op in api.operations.operation}
3940
{#if op.hasAuthMethods}
4041
{#for authM in op.authMethods}
4142
{#if authM.name == auth.name}
42-
.addOperation(OperationAuthInfo.builder()
43-
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
44-
.withId("{op.operationId}")
45-
.withMethod("{op.httpMethod}")
46-
.build())
43+
basicAuthProvider.addOperation(OperationAuthInfo.builder()
44+
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
45+
.withId("{op.operationId}")
46+
.withMethod("{op.httpMethod}")
47+
.build());
4748
{/if}
4849
{/for}
4950
{#else if defaultSecurityScheme == auth.name}
50-
.addOperation(OperationAuthInfo.builder()
51-
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
52-
.withId("{op.operationId}")
53-
.withMethod("{op.httpMethod}")
54-
.build())
51+
basicAuthProvider.addOperation(OperationAuthInfo.builder()
52+
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
53+
.withId("{op.operationId}")
54+
.withMethod("{op.httpMethod}")
55+
.build());
5556
{/if}
5657
{/for}
57-
{/for});
58+
{/for}
5859
{/for}
5960
{#for auth in oauthMethods.orEmpty}
60-
this.addAuthenticationProvider(new OAuth2AuthenticationProvider("{quarkus-generator.openApiSpecId}", sanitizeAuthName("{auth.name}"), generatorConfig)
61+
OAuth2AuthenticationProvider oAuth2Provider = new OAuth2AuthenticationProvider("{quarkus-generator.openApiSpecId}", sanitizeAuthName("{auth.name}"), generatorConfig);
62+
this.addAuthenticationProvider(oAuth2Provider);
6163
{#for api in apiInfo.apis}
6264
{#for op in api.operations.operation}
6365
{#if op.hasAuthMethods}
6466
{#for authM in op.authMethods}
6567
{#if authM.name == auth.name}
66-
.addOperation(OperationAuthInfo.builder()
67-
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
68-
.withId("{op.operationId}")
69-
.withMethod("{op.httpMethod}")
70-
.build())
68+
oAuth2Provider.addOperation(OperationAuthInfo.builder()
69+
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
70+
.withId("{op.operationId}")
71+
.withMethod("{op.httpMethod}")
72+
.build());
7173
{/if}
7274
{/for}
7375
{#else if defaultSecurityScheme == auth.name}
74-
.addOperation(OperationAuthInfo.builder()
75-
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
76-
.withId("{op.operationId}")
77-
.withMethod("{op.httpMethod}")
78-
.build())
76+
oAuth2Provider.addOperation(OperationAuthInfo.builder()
77+
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
78+
.withId("{op.operationId}")
79+
.withMethod("{op.httpMethod}")
80+
.build());
7981
{/if}
8082
{/for}
81-
{/for});
83+
{/for}
8284
{/for}
8385
{#for auth in httpBearerMethods.orEmpty}
84-
this.addAuthenticationProvider(new BearerAuthenticationProvider("{quarkus-generator.openApiSpecId}", sanitizeAuthName("{auth.name}"), "{auth.scheme}", generatorConfig)
86+
BearerAuthenticationProvider bearerProvider = new BearerAuthenticationProvider("{quarkus-generator.openApiSpecId}", sanitizeAuthName("{auth.name}"), "{auth.scheme}", generatorConfig);
87+
this.addAuthenticationProvider(bearerProvider);
8588
{#for api in apiInfo.apis}
8689
{#for op in api.operations.operation}
8790
{#if op.hasAuthMethods}
8891
{#for authM in op.authMethods}
8992
{#if authM.name == auth.name}
90-
.addOperation(OperationAuthInfo.builder()
91-
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
92-
.withId("{op.operationId}")
93-
.withMethod("{op.httpMethod}")
94-
.build())
93+
bearerProvider.addOperation(OperationAuthInfo.builder()
94+
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
95+
.withId("{op.operationId}")
96+
.withMethod("{op.httpMethod}")
97+
.build());
9598
{/if}
9699
{/for}
97100
{#else if defaultSecurityScheme == auth.name}
98-
.addOperation(OperationAuthInfo.builder()
99-
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
100-
.withId("{op.operationId}")
101-
.withMethod("{op.httpMethod}")
102-
.build())
101+
bearerProvider.addOperation(OperationAuthInfo.builder()
102+
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
103+
.withId("{op.operationId}")
104+
.withMethod("{op.httpMethod}")
105+
.build());
103106
{/if}
104107
{/for}
105-
{/for});
108+
{/for}
106109
{/for}
107110
{#for auth in apiKeyMethods.orEmpty}
108111
{#if auth.isKeyInQuery}
109-
this.addAuthenticationProvider(new ApiKeyAuthenticationProvider("{quarkus-generator.openApiSpecId}", sanitizeAuthName("{auth.name}"), ApiKeyIn.query, "{auth.keyParamName}", generatorConfig)
112+
ApiKeyAuthenticationProvider apiKeyQueryProvider = new ApiKeyAuthenticationProvider("{quarkus-generator.openApiSpecId}", sanitizeAuthName("{auth.name}"), ApiKeyIn.query, "{auth.keyParamName}", generatorConfig);
113+
this.addAuthenticationProvider(apiKeyQueryProvider);
110114
{#for api in apiInfo.apis}
111115
{#for op in api.operations.operation}
112116
{#if op.hasAuthMethods}
113117
{#for authM in op.authMethods}
114118
{#if authM.name == auth.name}
115-
.addOperation(OperationAuthInfo.builder()
116-
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
117-
.withId("{op.operationId}")
118-
.withMethod("{op.httpMethod}")
119-
.build())
119+
apiKeyQueryProvider.addOperation(OperationAuthInfo.builder()
120+
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
121+
.withId("{op.operationId}")
122+
.withMethod("{op.httpMethod}")
123+
.build());
120124
{/if}
121125
{/for}
122126
{#else if defaultSecurityScheme == auth.name}
123-
.addOperation(OperationAuthInfo.builder()
124-
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
125-
.withId("{op.operationId}")
126-
.withMethod("{op.httpMethod}")
127-
.build())
127+
apiKeyQueryProvider.addOperation(OperationAuthInfo.builder()
128+
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
129+
.withId("{op.operationId}")
130+
.withMethod("{op.httpMethod}")
131+
.build());
128132
{/if}
129133
{/for}
130-
{/for});
134+
{/for}
131135
{/if}
132136
{#if auth.isKeyInHeader}
133-
this.addAuthenticationProvider(new ApiKeyAuthenticationProvider("{quarkus-generator.openApiSpecId}", sanitizeAuthName("{auth.name}"), ApiKeyIn.header, "{auth.keyParamName}", generatorConfig)
137+
ApiKeyAuthenticationProvider apiKeyHeaderProvider = new ApiKeyAuthenticationProvider("{quarkus-generator.openApiSpecId}", sanitizeAuthName("{auth.name}"), ApiKeyIn.header, "{auth.keyParamName}", generatorConfig);
138+
this.addAuthenticationProvider(apiKeyHeaderProvider);
134139
{#for api in apiInfo.apis}
135140
{#for op in api.operations.operation}
136141
{#if op.hasAuthMethods}
137142
{#for authM in op.authMethods}
138143
{#if authM.name == auth.name}
139-
.addOperation(OperationAuthInfo.builder()
140-
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
141-
.withId("{op.operationId}")
142-
.withMethod("{op.httpMethod}")
143-
.build())
144+
apiKeyHeaderProvider.addOperation(OperationAuthInfo.builder()
145+
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
146+
.withId("{op.operationId}")
147+
.withMethod("{op.httpMethod}")
148+
.build());
144149
{/if}
145150
{/for}
146151
{#else if defaultSecurityScheme == auth.name}
147-
.addOperation(OperationAuthInfo.builder()
148-
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
149-
.withId("{op.operationId}")
150-
.withMethod("{op.httpMethod}")
151-
.build())
152+
apiKeyHeaderProvider.addOperation(OperationAuthInfo.builder()
153+
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
154+
.withId("{op.operationId}")
155+
.withMethod("{op.httpMethod}")
156+
.build());
152157
{/if}
153158
{/for}
154-
{/for});
159+
{/for}
155160
{/if}
156161
{#if auth.isKeyInCookie}
157-
this.addAuthenticationProvider(new ApiKeyAuthenticationProvider("{quarkus-generator.openApiSpecId}", sanitizeAuthName("{auth.name}"), ApiKeyIn.cookie, "{auth.keyParamName}", generatorConfig)
162+
ApiKeyAuthenticationProvider apiKeyCookieProvider = new ApiKeyAuthenticationProvider("{quarkus-generator.openApiSpecId}", sanitizeAuthName("{auth.name}"), ApiKeyIn.cookie, "{auth.keyParamName}", generatorConfig);
163+
this.addAuthenticationProvider(apiKeyCookieProvider);
158164
{#for api in apiInfo.apis}
159165
{#for op in api.operations.operation}
160166
{#if op.hasAuthMethods}
161167
{#for authM in op.authMethods}
162168
{#if authM.name == auth.name}
163-
.addOperation(OperationAuthInfo.builder()
164-
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
165-
.withId("{op.operationId}")
166-
.withMethod("{op.httpMethod}")
167-
.build())
169+
apiKeyCookieProvider.addOperation(OperationAuthInfo.builder()
170+
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
171+
.withId("{op.operationId}")
172+
.withMethod("{op.httpMethod}")
173+
.build());
168174
{/if}
169175
{/for}
170176
{#else if defaultSecurityScheme == auth.name}
171-
.addOperation(OperationAuthInfo.builder()
172-
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
173-
.withId("{op.operationId}")
174-
.withMethod("{op.httpMethod}")
175-
.build())
177+
apiKeyCookieProvider.addOperation(OperationAuthInfo.builder()
178+
.withPath("{api.contextPath}{api.commonPath}{op.path.orEmpty}")
179+
.withId("{op.operationId}")
180+
.withMethod("{op.httpMethod}")
181+
.build());
176182
{/if}
177183
{/for}
178-
{/for});
184+
{/for}
179185
{/if}
180186
{/for}
181187
}

integration-tests/test-project/src/main/openapi/awx.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27429,6 +27429,7 @@
2742927429
}
2743027430
}
2743127431
},
27432+
"security": [ { "basic": [] } ],
2743227433
"schemes": [
2743327434
"https"
2743427435
],

0 commit comments

Comments
 (0)