Skip to content

Commit 3f64916

Browse files
Refactor based on feedback
Co-authored-by: Francisco Javier Tirado Sarti <[email protected]>
1 parent e5b6cf1 commit 3f64916

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

client/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/BasicAuthenticationProvider.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,13 @@ private String getPassword() {
3737

3838
@Override
3939
public void filter(ClientRequestContext requestContext) throws IOException {
40-
String basicToken;
40+
String basicToken = AuthUtils.basicAuthAccessTokenWithoutPrefix(getUsername(), getPassword());
41+
4142
if (isTokenPropagation()) {
4243
LOGGER.warn("Token propagation enabled for BasicAuthentication");
43-
basicToken = getTokenForPropagation(requestContext.getHeaders());
44-
basicToken = sanitizeBasicToken(basicToken);
45-
} else {
46-
basicToken = AuthUtils.basicAuthAccessTokenWithoutPrefix(getUsername(), getPassword());
44+
basicToken = sanitizeBasicToken(getTokenForPropagation(requestContext.getHeaders()));
4745
}
46+
4847
if (!basicToken.isBlank()) {
4948
requestContext.getHeaders().add(HttpHeaders.AUTHORIZATION,
5049
AuthUtils.basicAuthAccessToken(basicToken));

client/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/BearerAuthenticationProvider.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ public BearerAuthenticationProvider(final String openApiSpecId, final String nam
2727

2828
@Override
2929
public void filter(ClientRequestContext requestContext) throws IOException {
30-
String bearerToken;
30+
String bearerToken = getBearerToken();
31+
3132
if (isTokenPropagation()) {
32-
bearerToken = getTokenForPropagation(requestContext.getHeaders());
33-
bearerToken = sanitizeBearerToken(bearerToken);
34-
} else {
35-
bearerToken = getBearerToken();
33+
bearerToken = sanitizeBearerToken(getTokenForPropagation(requestContext.getHeaders()));
3634
}
35+
3736
if (!bearerToken.isBlank()) {
3837
requestContext.getHeaders().add(HttpHeaders.AUTHORIZATION,
3938
AuthUtils.authTokenOrBearer(this.scheme, bearerToken));

client/runtime/src/test/java/io/quarkiverse/openapi/generator/providers/BasicOpenApiSpecProviderTest.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,9 @@ private void filter(String expectedAuthorizationHeader) throws IOException {
5353
@MethodSource("filterWithPropagationTestValues")
5454
void filterWithPropagation(String headerName,
5555
String expectedAuthorizationHeader) throws IOException {
56-
String propagatedHeaderName;
57-
if (headerName == null) {
58-
propagatedHeaderName = propagationHeaderName(OPEN_API_FILE_SPEC_ID, AUTH_SCHEME_NAME,
59-
HttpHeaders.AUTHORIZATION);
60-
} else {
61-
propagatedHeaderName = propagationHeaderName(OPEN_API_FILE_SPEC_ID, AUTH_SCHEME_NAME,
62-
HEADER_NAME);
63-
}
56+
String propagatedHeaderName = headerName == null
57+
? propagationHeaderName(OPEN_API_FILE_SPEC_ID, AUTH_SCHEME_NAME, HttpHeaders.AUTHORIZATION)
58+
: propagationHeaderName(OPEN_API_FILE_SPEC_ID, AUTH_SCHEME_NAME, HEADER_NAME);
6459
try (MockedStatic<ConfigProvider> configProviderMocked = Mockito.mockStatic(ConfigProvider.class)) {
6560
Config mockedConfig = Mockito.mock(Config.class);
6661
configProviderMocked.when(ConfigProvider::getConfig).thenReturn(mockedConfig);

0 commit comments

Comments
 (0)