Skip to content

Commit

Permalink
improvement
Browse files Browse the repository at this point in the history
Signed-off-by: Jan N. Klug <[email protected]>
  • Loading branch information
J-N-K committed Aug 13, 2023
1 parent b64b910 commit 92532bb
Showing 1 changed file with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,23 @@ public void initialize() {
config.headers.removeIf(String::isBlank);

// configure authentication
if (!config.username.isEmpty() || !config.password.isEmpty()) {
try {
AuthenticationStore authStore = rateLimitedHttpClient.getAuthenticationStore();
URI uri = new URI(config.baseURL);
Authentication.Result authResult = authStore.findAuthenticationResult(uri);
if (authResult != null) {
authStore.removeAuthenticationResult(authResult);
}
for (String authType : List.of("Basic", "Digest")) {
Authentication authentication = authStore.findAuthentication(authType, uri,
Authentication.ANY_REALM);
if (authentication != null) {
authStore.removeAuthentication(authentication);
}
try {
AuthenticationStore authStore = rateLimitedHttpClient.getAuthenticationStore();
URI uri = new URI(config.baseURL);

// clear old auths if available
Authentication.Result authResult = authStore.findAuthenticationResult(uri);
if (authResult != null) {
authStore.removeAuthenticationResult(authResult);
}
for (String authType : List.of("Basic", "Digest")) {
Authentication authentication = authStore.findAuthentication(authType, uri, Authentication.ANY_REALM);
if (authentication != null) {
authStore.removeAuthentication(authentication);
}
}

if (!config.username.isEmpty() || !config.password.isEmpty()) {
switch (config.authMode) {
case BASIC_PREEMPTIVE:
config.headers.add("Authorization=Basic " + Base64.getEncoder()
Expand Down Expand Up @@ -219,12 +221,11 @@ public void initialize() {
logger.warn("Unknown authentication method '{}' for thing '{}'", config.authMode,
thing.getUID());
}
} catch (URISyntaxException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"failed to create authentication: baseUrl is invalid");
} else {
logger.debug("No authentication configured for thing '{}'", thing.getUID());
}
} else {
logger.debug("No authentication configured for thing '{}'", thing.getUID());
} catch (URISyntaxException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Cannot create URI from baseUrl.");
}

// create channels
Expand Down

0 comments on commit 92532bb

Please sign in to comment.