Skip to content

Commit

Permalink
[homeconnect] Remove the access token when the thing is removed (#14935)
Browse files Browse the repository at this point in the history
Related to #14818

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
  • Loading branch information
lolodomo authored May 5, 2023
1 parent 3ae72c9 commit 4e8e39c
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class HomeConnectBridgeHandler extends BaseBridgeHandler {
private @Nullable List<Event> eventHistory;

private @NonNullByDefault({}) OAuthClientService oAuthClientService;
private @NonNullByDefault({}) String oAuthServiceHandleId;
private @Nullable String oAuthServiceHandleId;
private @NonNullByDefault({}) HomeConnectApiClient apiClient;
private @NonNullByDefault({}) HomeConnectEventSourceClient eventSourceClient;

Expand Down Expand Up @@ -221,6 +221,15 @@ public void handleConfigurationUpdate(Map<String, Object> configurationParameter
}
}

@Override
public void handleRemoval() {
String handleId = this.oAuthServiceHandleId;
if (handleId != null) {
oAuthFactory.deleteServiceAndAccessToken(handleId);
}
super.handleRemoval();
}

@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(HomeConnectDiscoveryService.class);
Expand Down Expand Up @@ -285,7 +294,10 @@ private void cleanup(boolean immediate) {
eventSourceClient.getLatestEvents().clear();
eventSourceClient.dispose(immediate);

oAuthFactory.ungetOAuthService(oAuthServiceHandleId);
String handleId = this.oAuthServiceHandleId;
if (handleId != null) {
oAuthFactory.ungetOAuthService(handleId);
}
homeConnectServlet.removeBridgeHandler(this);
}

Expand Down

0 comments on commit 4e8e39c

Please sign in to comment.