[homeconnect] Remove the access token when the thing is removed (#14935)

Related to #14818

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
lolodomo 2023-05-05 22:32:26 +02:00 committed by GitHub
parent 3ae72c92e5
commit 4e8e39cd9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -84,7 +84,7 @@ public class HomeConnectBridgeHandler extends BaseBridgeHandler {
private @Nullable List<Event> eventHistory; private @Nullable List<Event> eventHistory;
private @NonNullByDefault({}) OAuthClientService oAuthClientService; private @NonNullByDefault({}) OAuthClientService oAuthClientService;
private @NonNullByDefault({}) String oAuthServiceHandleId; private @Nullable String oAuthServiceHandleId;
private @NonNullByDefault({}) HomeConnectApiClient apiClient; private @NonNullByDefault({}) HomeConnectApiClient apiClient;
private @NonNullByDefault({}) HomeConnectEventSourceClient eventSourceClient; 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 @Override
public Collection<Class<? extends ThingHandlerService>> getServices() { public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(HomeConnectDiscoveryService.class); return Collections.singleton(HomeConnectDiscoveryService.class);
@ -285,7 +294,10 @@ public class HomeConnectBridgeHandler extends BaseBridgeHandler {
eventSourceClient.getLatestEvents().clear(); eventSourceClient.getLatestEvents().clear();
eventSourceClient.dispose(immediate); eventSourceClient.dispose(immediate);
oAuthFactory.ungetOAuthService(oAuthServiceHandleId); String handleId = this.oAuthServiceHandleId;
if (handleId != null) {
oAuthFactory.ungetOAuthService(handleId);
}
homeConnectServlet.removeBridgeHandler(this); homeConnectServlet.removeBridgeHandler(this);
} }