From 4e8e39cd9f7c090ad37028b3e574db2abe40ac59 Mon Sep 17 00:00:00 2001 From: lolodomo Date: Fri, 5 May 2023 22:32:26 +0200 Subject: [PATCH] [homeconnect] Remove the access token when the thing is removed (#14935) Related to #14818 Signed-off-by: Laurent Garnier --- .../handler/HomeConnectBridgeHandler.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.binding.homeconnect/src/main/java/org/openhab/binding/homeconnect/internal/handler/HomeConnectBridgeHandler.java b/bundles/org.openhab.binding.homeconnect/src/main/java/org/openhab/binding/homeconnect/internal/handler/HomeConnectBridgeHandler.java index 8969c0bf79f..db483b3b1fd 100644 --- a/bundles/org.openhab.binding.homeconnect/src/main/java/org/openhab/binding/homeconnect/internal/handler/HomeConnectBridgeHandler.java +++ b/bundles/org.openhab.binding.homeconnect/src/main/java/org/openhab/binding/homeconnect/internal/handler/HomeConnectBridgeHandler.java @@ -84,7 +84,7 @@ public class HomeConnectBridgeHandler extends BaseBridgeHandler { private @Nullable List eventHistory; private @NonNullByDefault({}) OAuthClientService oAuthClientService; - private @NonNullByDefault({}) String oAuthServiceHandleId; + private @Nullable String oAuthServiceHandleId; private @NonNullByDefault({}) HomeConnectApiClient apiClient; private @NonNullByDefault({}) HomeConnectEventSourceClient eventSourceClient; @@ -221,6 +221,15 @@ public class HomeConnectBridgeHandler extends BaseBridgeHandler { } } + @Override + public void handleRemoval() { + String handleId = this.oAuthServiceHandleId; + if (handleId != null) { + oAuthFactory.deleteServiceAndAccessToken(handleId); + } + super.handleRemoval(); + } + @Override public Collection> getServices() { return Collections.singleton(HomeConnectDiscoveryService.class); @@ -285,7 +294,10 @@ public class HomeConnectBridgeHandler extends BaseBridgeHandler { eventSourceClient.getLatestEvents().clear(); eventSourceClient.dispose(immediate); - oAuthFactory.ungetOAuthService(oAuthServiceHandleId); + String handleId = this.oAuthServiceHandleId; + if (handleId != null) { + oAuthFactory.ungetOAuthService(handleId); + } homeConnectServlet.removeBridgeHandler(this); }