public void removeConsumerByKey(String consumerKey) { if (isEmpty(consumerKey)) { throw new IllegalArgumentException("consumerKey is an empty string"); } tokenStore.removeTokensForConsumer(consumerKey); store.removeByKey(consumerKey); }
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; }
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 ConsumerToken getConsumerToken(final ApplicationLink applicationLink, final String username) { checkNotNull(username, "Username cannot be null!"); checkNotNull(applicationLink, "Application Link cannot be null!"); return consumerTokenStore.get(makeOAuthApplinksConsumerKey(username, applicationLink.getId().get())); }
public void addConsumerToken(final ApplicationLink applicationLink, final String username, final ConsumerToken consumerToken) { Preconditions.checkNotNull(applicationLink, "applicationLink"); Preconditions.checkNotNull(username, "username"); Preconditions.checkNotNull(consumerToken, "consumerToken"); verifyOAuthOutgoingEnabled(applicationLink.getId()); final Map<String, String> tokenProperties = new HashMap<String, String>(); tokenProperties.put(APPLINKS_APPLICATION_LINK_ID, applicationLink.getId().get()); final ConsumerTokenStore.Key key = makeOAuthApplinksConsumerKey(username, applicationLink.getId().get()); ConsumerToken.ConsumerTokenBuilder tokenBuilder; if (consumerToken.isAccessToken()) { tokenBuilder = ConsumerToken.newAccessToken(consumerToken.getToken()); } else { tokenBuilder = ConsumerToken.newRequestToken(consumerToken.getToken()); } tokenBuilder.tokenSecret(consumerToken.getTokenSecret()).consumer(consumerToken.getConsumer()).properties(tokenProperties); consumerTokenStore.put(key, tokenBuilder.build()); }
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()); } } }
public ConsumerToken getConsumerToken(final ApplicationLink applicationLink, final String username) { Preconditions.checkNotNull(username, "Username cannot be null!"); Preconditions.checkNotNull(applicationLink, "Application Link cannot be null!"); verifyOAuthOutgoingEnabled(applicationLink.getId()); return consumerTokenStore.get(makeOAuthApplinksConsumerKey(username, applicationLink.getId().get())); }