public void removeAllConsumerTokens(final ApplicationLink applicationLink) { Preconditions.checkNotNull(applicationLink, "applicationLink"); final Map<String, String> configuration = configurationManager.getConfiguration(applicationLink.getId(), OAuthAuthenticationProvider.class); verifyOAuthOutgoingEnabled(applicationLink.getId()); if (configuration.containsKey(ApplinksOAuth.AUTH_CONFIG_CONSUMER_KEY_OUTBOUND)) { final String consumerKey = configuration.get(ApplinksOAuth.AUTH_CONFIG_CONSUMER_KEY_OUTBOUND); consumerTokenStore.removeTokensForConsumer(consumerKey); } else { final String consumerKey = consumerService.getConsumer().getKey(); final Map<ConsumerTokenStore.Key, ConsumerToken> consumerTokens = consumerTokenStore.getConsumerTokens(consumerKey); for (ConsumerTokenStore.Key key : consumerTokens.keySet()) { final Map<String, String> tokenProperties = consumerTokens.get(key).getProperties(); if (tokenProperties.containsKey(APPLINKS_APPLICATION_LINK_ID) && tokenProperties.get(APPLINKS_APPLICATION_LINK_ID).equals(applicationLink.getId().get())) { consumerTokenStore.remove(key); } } } }
public boolean removeConsumerToken(final ApplicationId applicationId, final String username) { Preconditions.checkNotNull(applicationId, "applicationLink"); verifyOAuthOutgoingEnabled(applicationId); final ConsumerTokenStore.Key key = makeOAuthApplinksConsumerKey(username, applicationId.get()); if (consumerTokenStore.get(key) != null) { consumerTokenStore.remove(key); return true; } return false; }
private void cleanOAuth() { String consumerKey = consumerService.getConsumer().getKey(); final Map<ConsumerTokenStore.Key, ConsumerToken> consumerTokens = consumerTokenStore.getConsumerTokens(consumerKey); for (ConsumerTokenStore.Key key : consumerTokens.keySet()) { consumerTokenStore.remove(key); } for (final ApplicationLink link : ImmutableList.copyOf(linkService.getApplicationLinks())) { Map<String, String> config = authenticationConfigurationManager.getConfiguration(link.getId(), OAuthAuthenticationProvider.class); if (config != null && config.containsKey(AUTH_CONFIG_CONSUMER_KEY_OUTBOUND)) { final String key = config.get(AUTH_CONFIG_CONSUMER_KEY_OUTBOUND); consumerTokenStore.removeTokensForConsumer(key); } authenticationConfigurationManager.unregisterProvider(link.getId(), OAuthAuthenticationProvider.class); } // as a service provider (inbound): get rid of all the consumers for (final Consumer consumer : serviceProviderConsumerStore.getAll()) { serviceProviderTokenStore.removeByConsumer(consumer.getKey()); serviceProviderConsumerStore.remove(consumer.getKey()); } // as a consumer (outbound): get rid of all the service providers we talked to for (final Consumer consumer : consumerService.getAllServiceProviders()) { consumerService.removeConsumerByKey(consumer.getKey()); } } }