[nest] Remove the access token when the thing is removed (#14940)
Related to #14818 Signed-off-by: Laurent Garnier <lg.hc@free.fr>pull/14989/head
parent
8a9ac6eccc
commit
c10f4f4051
|
@ -144,7 +144,9 @@ public class PubSubAPI {
|
||||||
private final Logger logger = LoggerFactory.getLogger(PubSubAPI.class);
|
private final Logger logger = LoggerFactory.getLogger(PubSubAPI.class);
|
||||||
|
|
||||||
private final HttpClient httpClient;
|
private final HttpClient httpClient;
|
||||||
|
private final OAuthFactory oAuthFactory;
|
||||||
private final OAuthClientService oAuthService;
|
private final OAuthClientService oAuthService;
|
||||||
|
private final String oAuthServiceHandleId;
|
||||||
private final String projectId;
|
private final String projectId;
|
||||||
private final ScheduledThreadPoolExecutor scheduler;
|
private final ScheduledThreadPoolExecutor scheduler;
|
||||||
private final Map<String, Set<PubSubSubscriptionListener>> subscriptionListeners = new HashMap<>();
|
private final Map<String, Set<PubSubSubscriptionListener>> subscriptionListeners = new HashMap<>();
|
||||||
|
@ -153,14 +155,21 @@ public class PubSubAPI {
|
||||||
String clientId, String clientSecret) {
|
String clientId, String clientSecret) {
|
||||||
this.httpClient = httpClientFactory.getCommonHttpClient();
|
this.httpClient = httpClientFactory.getCommonHttpClient();
|
||||||
this.projectId = projectId;
|
this.projectId = projectId;
|
||||||
this.oAuthService = oAuthFactory.createOAuthClientService(String.format(PUBSUB_HANDLE_FORMAT, ownerId),
|
this.oAuthFactory = oAuthFactory;
|
||||||
TOKEN_URL, AUTH_URL, clientId, clientSecret, PUBSUB_SCOPE, false);
|
this.oAuthServiceHandleId = String.format(PUBSUB_HANDLE_FORMAT, ownerId);
|
||||||
|
this.oAuthService = oAuthFactory.createOAuthClientService(oAuthServiceHandleId, TOKEN_URL, AUTH_URL, clientId,
|
||||||
|
clientSecret, PUBSUB_SCOPE, false);
|
||||||
scheduler = new ScheduledThreadPoolExecutor(3, new NamedThreadFactory(ownerId, true));
|
scheduler = new ScheduledThreadPoolExecutor(3, new NamedThreadFactory(ownerId, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
subscriptionListeners.clear();
|
subscriptionListeners.clear();
|
||||||
scheduler.shutdownNow();
|
scheduler.shutdownNow();
|
||||||
|
oAuthFactory.ungetOAuthService(oAuthServiceHandleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteOAuthServiceAndAccessToken() {
|
||||||
|
oAuthFactory.deleteServiceAndAccessToken(oAuthServiceHandleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void authorizeClient(String authorizationCode) throws InvalidPubSubAuthorizationCodeException, IOException {
|
public void authorizeClient(String authorizationCode) throws InvalidPubSubAuthorizationCodeException, IOException {
|
||||||
|
|
|
@ -84,7 +84,9 @@ public class SDMAPI {
|
||||||
private final Logger logger = LoggerFactory.getLogger(SDMAPI.class);
|
private final Logger logger = LoggerFactory.getLogger(SDMAPI.class);
|
||||||
|
|
||||||
private final HttpClient httpClient;
|
private final HttpClient httpClient;
|
||||||
|
private final OAuthFactory oAuthFactory;
|
||||||
private final OAuthClientService oAuthService;
|
private final OAuthClientService oAuthService;
|
||||||
|
private final String oAuthServiceHandleId;
|
||||||
private final String projectId;
|
private final String projectId;
|
||||||
|
|
||||||
private final Set<SDMAPIRequestListener> requestListeners = ConcurrentHashMap.newKeySet();
|
private final Set<SDMAPIRequestListener> requestListeners = ConcurrentHashMap.newKeySet();
|
||||||
|
@ -92,13 +94,20 @@ public class SDMAPI {
|
||||||
public SDMAPI(HttpClientFactory httpClientFactory, OAuthFactory oAuthFactory, String ownerId, String projectId,
|
public SDMAPI(HttpClientFactory httpClientFactory, OAuthFactory oAuthFactory, String ownerId, String projectId,
|
||||||
String clientId, String clientSecret) {
|
String clientId, String clientSecret) {
|
||||||
this.httpClient = httpClientFactory.getCommonHttpClient();
|
this.httpClient = httpClientFactory.getCommonHttpClient();
|
||||||
this.oAuthService = oAuthFactory.createOAuthClientService(String.format(SDM_HANDLE_FORMAT, ownerId), TOKEN_URL,
|
this.oAuthFactory = oAuthFactory;
|
||||||
AUTH_URL, clientId, clientSecret, SDM_SCOPE, false);
|
this.oAuthServiceHandleId = String.format(SDM_HANDLE_FORMAT, ownerId);
|
||||||
|
this.oAuthService = oAuthFactory.createOAuthClientService(oAuthServiceHandleId, TOKEN_URL, AUTH_URL, clientId,
|
||||||
|
clientSecret, SDM_SCOPE, false);
|
||||||
this.projectId = projectId;
|
this.projectId = projectId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
requestListeners.clear();
|
requestListeners.clear();
|
||||||
|
oAuthFactory.ungetOAuthService(oAuthServiceHandleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteOAuthServiceAndAccessToken() {
|
||||||
|
oAuthFactory.deleteServiceAndAccessToken(oAuthServiceHandleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void authorizeClient(String authorizationCode) throws InvalidSDMAuthorizationCodeException, IOException {
|
public void authorizeClient(String authorizationCode) throws InvalidSDMAuthorizationCodeException, IOException {
|
||||||
|
|
|
@ -263,6 +263,19 @@ public class SDMAccountHandler extends BaseBridgeHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleRemoval() {
|
||||||
|
PubSubAPI localPubSubAPI = pubSubAPI;
|
||||||
|
if (localPubSubAPI != null) {
|
||||||
|
localPubSubAPI.deleteOAuthServiceAndAccessToken();
|
||||||
|
}
|
||||||
|
SDMAPI localSDMAPI = sdmAPI;
|
||||||
|
if (localSDMAPI != null) {
|
||||||
|
localSDMAPI.deleteOAuthServiceAndAccessToken();
|
||||||
|
}
|
||||||
|
super.handleRemoval();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Class<? extends ThingHandlerService>> getServices() {
|
public Collection<Class<? extends ThingHandlerService>> getServices() {
|
||||||
return List.of(SDMDiscoveryService.class);
|
return List.of(SDMDiscoveryService.class);
|
||||||
|
|
Loading…
Reference in New Issue