[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<?> reInitJob;
|
||||||
private @Nullable ScheduledFuture<?> bridgeRefreshJob;
|
private @Nullable ScheduledFuture<?> bridgeRefreshJob;
|
||||||
private @NonNullByDefault({}) LivisiBridgeConfiguration bridgeConfiguration;
|
private @NonNullByDefault({}) LivisiBridgeConfiguration bridgeConfiguration;
|
||||||
private @NonNullByDefault({}) OAuthClientService oAuthService;
|
private @Nullable OAuthClientService oAuthService;
|
||||||
private String configVersion = "";
|
private String configVersion = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -153,8 +153,9 @@ public class LivisiBridgeHandler extends BaseBridgeHandler
|
|||||||
*/
|
*/
|
||||||
private void initializeClient() {
|
private void initializeClient() {
|
||||||
String tokenURL = URLCreator.createTokenURL(bridgeConfiguration.host);
|
String tokenURL = URLCreator.createTokenURL(bridgeConfiguration.host);
|
||||||
oAuthService = oAuthFactory.createOAuthClientService(thing.getUID().getAsString(), tokenURL, tokenURL,
|
OAuthClientService oAuthService = oAuthFactory.createOAuthClientService(thing.getUID().getAsString(), tokenURL,
|
||||||
"clientId", "clientPass", null, true);
|
tokenURL, "clientId", "clientPass", null, true);
|
||||||
|
this.oAuthService = oAuthService;
|
||||||
client = createClient(oAuthService);
|
client = createClient(oAuthService);
|
||||||
deviceStructMan = new DeviceStructureManager(createFullDeviceManager(client));
|
deviceStructMan = new DeviceStructureManager(createFullDeviceManager(client));
|
||||||
oAuthService.addAccessTokenRefreshListener(this);
|
oAuthService.addAccessTokenRefreshListener(this);
|
||||||
@ -349,6 +350,12 @@ public class LivisiBridgeHandler extends BaseBridgeHandler
|
|||||||
unregisterDeviceStatusListener(bridgeId);
|
unregisterDeviceStatusListener(bridgeId);
|
||||||
cancelJobs();
|
cancelJobs();
|
||||||
stopWebSocket();
|
stopWebSocket();
|
||||||
|
OAuthClientService oAuthService = this.oAuthService;
|
||||||
|
if (oAuthService != null) {
|
||||||
|
oAuthService.removeAccessTokenRefreshListener(this);
|
||||||
|
oAuthFactory.ungetOAuthService(thing.getUID().getAsString());
|
||||||
|
this.oAuthService = null;
|
||||||
|
}
|
||||||
client = null;
|
client = null;
|
||||||
deviceStructMan = null;
|
deviceStructMan = null;
|
||||||
|
|
||||||
@ -356,6 +363,15 @@ public class LivisiBridgeHandler extends BaseBridgeHandler
|
|||||||
logger.debug("LIVISI SmartHome bridge handler shut down.");
|
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() {
|
private synchronized void cancelJobs() {
|
||||||
if (cancelJob(reInitJob)) {
|
if (cancelJob(reInitJob)) {
|
||||||
reInitJob = null;
|
reInitJob = null;
|
||||||
@ -884,6 +900,10 @@ public class LivisiBridgeHandler extends BaseBridgeHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void requestAccessToken() throws OAuthException, IOException, OAuthResponseException {
|
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,
|
oAuthService.getAccessTokenByResourceOwnerPasswordCredentials(LivisiBindingConstants.USERNAME,
|
||||||
bridgeConfiguration.password, null);
|
bridgeConfiguration.password, null);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user