mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
Deauthenticate session on dispose (#13081)
Fixes #13080 Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
8a87450f4c
commit
e0494bf44c
@ -167,6 +167,21 @@ public class IndegoController {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deauthenticate session. This method should be called as part of cleanup to reduce
|
||||||
|
* lingering sessions. This can potentially avoid killed sessions in situation with
|
||||||
|
* multiple clients (e.g. openHAB and mobile app) if restrictions on concurrent
|
||||||
|
* number of sessions would be put on the service.
|
||||||
|
*
|
||||||
|
* @throws IndegoException if any communication or parsing error occurred
|
||||||
|
*/
|
||||||
|
public void deauthenticate() throws IndegoException {
|
||||||
|
if (session.isValid()) {
|
||||||
|
deleteRequest("authenticate");
|
||||||
|
session.invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps {@link #getRequest(String, Class)} into an authenticated session.
|
* Wraps {@link #getRequest(String, Class)} into an authenticated session.
|
||||||
*
|
*
|
||||||
@ -432,6 +447,32 @@ public class IndegoController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a DELETE request to the server.
|
||||||
|
*
|
||||||
|
* @param path the relative path to which the request should be sent
|
||||||
|
* @throws IndegoException if any communication or parsing error occurred
|
||||||
|
*/
|
||||||
|
private void deleteRequest(String path) throws IndegoException {
|
||||||
|
try {
|
||||||
|
Request request = httpClient.newRequest(BASE_URL + path).method(HttpMethod.DELETE)
|
||||||
|
.header(CONTEXT_HEADER_NAME, session.getContextId());
|
||||||
|
if (logger.isTraceEnabled()) {
|
||||||
|
logger.trace("DELETE request for {}", BASE_URL + path);
|
||||||
|
}
|
||||||
|
ContentResponse response = sendRequest(request);
|
||||||
|
int status = response.getStatus();
|
||||||
|
if (!HttpStatus.isSuccess(status)) {
|
||||||
|
throw new IndegoException("The request failed with error: " + status);
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
throw new IndegoException(e);
|
||||||
|
} catch (TimeoutException | ExecutionException e) {
|
||||||
|
throw new IndegoException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send request. This method exists for the purpose of avoiding multiple calls to
|
* Send request. This method exists for the purpose of avoiding multiple calls to
|
||||||
* the server at the same time.
|
* the server at the same time.
|
||||||
|
@ -121,6 +121,14 @@ public class BoschIndegoHandler extends BaseThingHandler {
|
|||||||
pollFuture.cancel(true);
|
pollFuture.cancel(true);
|
||||||
}
|
}
|
||||||
this.cuttingTimeMapPollFuture = null;
|
this.cuttingTimeMapPollFuture = null;
|
||||||
|
|
||||||
|
scheduler.execute(() -> {
|
||||||
|
try {
|
||||||
|
controller.deauthenticate();
|
||||||
|
} catch (IndegoException e) {
|
||||||
|
logger.debug("Deauthentication failed", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user