mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
[livisismarthome] Remove the access token when the thing is removed (#14946)
* [livisismarthome] Remove the access token when the thing is removed Related to #14818 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
parent
ab4dace2e9
commit
a7ba3eee72
@ -114,7 +114,7 @@ public class LivisiBridgeHandler extends BaseBridgeHandler
|
||||
private @Nullable ScheduledFuture<?> reInitJob;
|
||||
private @Nullable ScheduledFuture<?> bridgeRefreshJob;
|
||||
private @NonNullByDefault({}) LivisiBridgeConfiguration bridgeConfiguration;
|
||||
private @NonNullByDefault({}) OAuthClientService oAuthService;
|
||||
private @Nullable OAuthClientService oAuthService;
|
||||
private String configVersion = "";
|
||||
|
||||
/**
|
||||
@ -153,8 +153,9 @@ public class LivisiBridgeHandler extends BaseBridgeHandler
|
||||
*/
|
||||
private void initializeClient() {
|
||||
String tokenURL = URLCreator.createTokenURL(bridgeConfiguration.host);
|
||||
oAuthService = oAuthFactory.createOAuthClientService(thing.getUID().getAsString(), tokenURL, tokenURL,
|
||||
"clientId", "clientPass", null, true);
|
||||
OAuthClientService oAuthService = oAuthFactory.createOAuthClientService(thing.getUID().getAsString(), tokenURL,
|
||||
tokenURL, "clientId", "clientPass", null, true);
|
||||
this.oAuthService = oAuthService;
|
||||
client = createClient(oAuthService);
|
||||
deviceStructMan = new DeviceStructureManager(createFullDeviceManager(client));
|
||||
oAuthService.addAccessTokenRefreshListener(this);
|
||||
@ -349,6 +350,12 @@ public class LivisiBridgeHandler extends BaseBridgeHandler
|
||||
unregisterDeviceStatusListener(bridgeId);
|
||||
cancelJobs();
|
||||
stopWebSocket();
|
||||
OAuthClientService oAuthService = this.oAuthService;
|
||||
if (oAuthService != null) {
|
||||
oAuthService.removeAccessTokenRefreshListener(this);
|
||||
oAuthFactory.ungetOAuthService(thing.getUID().getAsString());
|
||||
this.oAuthService = null;
|
||||
}
|
||||
client = null;
|
||||
deviceStructMan = null;
|
||||
|
||||
@ -356,6 +363,15 @@ public class LivisiBridgeHandler extends BaseBridgeHandler
|
||||
logger.debug("LIVISI SmartHome bridge handler shut down.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRemoval() {
|
||||
OAuthClientService oAuthService = this.oAuthService;
|
||||
if (oAuthService != null) {
|
||||
oAuthFactory.deleteServiceAndAccessToken(thing.getUID().getAsString());
|
||||
}
|
||||
super.handleRemoval();
|
||||
}
|
||||
|
||||
private synchronized void cancelJobs() {
|
||||
if (cancelJob(reInitJob)) {
|
||||
reInitJob = null;
|
||||
@ -884,6 +900,10 @@ public class LivisiBridgeHandler extends BaseBridgeHandler
|
||||
}
|
||||
|
||||
private void requestAccessToken() throws OAuthException, IOException, OAuthResponseException {
|
||||
OAuthClientService oAuthService = this.oAuthService;
|
||||
if (oAuthService == null) {
|
||||
throw new OAuthException("OAuth service is not initialized");
|
||||
}
|
||||
oAuthService.getAccessTokenByResourceOwnerPasswordCredentials(LivisiBindingConstants.USERNAME,
|
||||
bridgeConfiguration.password, null);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user