private List<OrphanedTrustCertificate> findOrphanedOAuthConsumers() { final List<OrphanedTrustCertificate> orphanedTrustCertificates = new ArrayList<>(); final Set<String> recognisedConsumerKeys = new HashSet<>(); for (final ApplicationLink link : applicationLinkService.getApplicationLinks()) { final Consumer consumer = serviceProviderStoreService.getConsumer(link); if (consumer != null) { recognisedConsumerKeys.add(consumer.getKey()); } } for (final Consumer consumer : serviceProviderConsumerStore.getAll()) { if (!recognisedConsumerKeys.contains(consumer.getKey())) { orphanedTrustCertificates.add( new OrphanedTrustCertificate(consumer.getKey(), consumer.getDescription(), OrphanedTrustCertificate.Type.OAUTH) ); } } return orphanedTrustCertificates; }
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()); } } }