Skip to content

Commit

Permalink
Merge pull request #252 from /issues/251-null-password
Browse files Browse the repository at this point in the history
Fix #251: Improve error handling of DefaultRestClient for BasicAuth null password
  • Loading branch information
banterCZ authored Dec 12, 2023
2 parents 858e37c + 1d9fa79 commit fc0b1d0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,14 @@ private void initializeWebClient() throws RestClientException {
.build();
builder.exchangeStrategies(exchangeStrategies);

if (config.isHttpBasicAuthEnabled() && config.getHttpBasicAuthUsername() != null) {
logger.info("Configuring HTTP Basic Authentication");
builder.filter(ExchangeFilterFunctions
.basicAuthentication(config.getHttpBasicAuthUsername(), config.getHttpBasicAuthPassword()));
if (config.isHttpBasicAuthEnabled()) {
if (config.getHttpBasicAuthUsername() != null && config.getHttpBasicAuthPassword() != null) {
logger.info("Configuring HTTP Basic Authentication");
builder.filter(ExchangeFilterFunctions
.basicAuthentication(config.getHttpBasicAuthUsername(), config.getHttpBasicAuthPassword()));
} else {
logger.warn("HTTP Basic Authentication is enabled but username or password is null, baseUrl: {}", config.getBaseUrl());
}
}
if (config.isHttpDigestAuthEnabled() && config.getHttpDigestAuthUsername() != null) {
logger.info("Configuring HTTP Digest Authentication");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,19 @@ void testGetWithResponseDigestAuthFailed() throws RestClientException {
assertEquals(HttpStatus.UNAUTHORIZED, exception.getStatusCode());
}

@Test
void testBasicAuthNullPassword() throws Exception {
final RestClientConfiguration config = new RestClientConfiguration();
config.setHttpBasicAuthEnabled(true);
config.setHttpBasicAuthUsername("john");
config.setHttpBasicAuthPassword(null);
config.setBaseUrl("https://localhost:" + port);

final DefaultRestClient result = new DefaultRestClient(config);

assertNotNull(result);
}

private static Object getField(final Object parentBean, String path) {
final String[] pathParts = path.split("\\.");
final String fieldName = pathParts[0];
Expand Down

0 comments on commit fc0b1d0

Please sign in to comment.