public OAuth2Client getClient(final String gadgetUri, final String serviceName) throws GadgetException { final boolean isLogging = BasicOAuth2Store.LOG.isLoggable(); if (isLogging) { BasicOAuth2Store.LOG.entering(BasicOAuth2Store.LOG_CLASS, "getClient", new Object[] { gadgetUri, serviceName }); } OAuth2Client client = this.cache.getClient(gadgetUri, serviceName); if (isLogging) { BasicOAuth2Store.LOG.log("client from cache = {0}", client); } if (client == null) { try { client = this.persister.findClient(gadgetUri, serviceName); if (client != null) { this.cache.storeClient(client); } } catch (final OAuth2PersistenceException e) { if (isLogging) { BasicOAuth2Store.LOG.log("Error loading OAuth2 client ", e); } throw new GadgetException(Code.OAUTH_STORAGE_ERROR, "Error loading OAuth2 client " + serviceName, e); } } if (isLogging) { BasicOAuth2Store.LOG.exiting(BasicOAuth2Store.LOG_CLASS, "getClient", client); } return client; }
if (token == null) { try { token = this.persister.findToken(processedGadgetUri, serviceName, user, scope, type); if (token != null) { synchronized (token) {
final Set<OAuth2Client> clients = this.persister.loadClients(); if (isLogging) { BasicOAuth2Store.LOG.log("clients = {0}", clients); final Set<OAuth2Token> tokens = this.persister.loadTokens(); if (isLogging) { BasicOAuth2Store.LOG.log("tokens = {0}", tokens);
try { if (existingToken == null) { this.persister.insertToken(token); } else { synchronized (existingToken) { existingToken.setGadgetUri(processedGadgetUri); this.cache.removeToken(existingToken); this.persister.updateToken(token); } finally { existingToken.setGadgetUri(gadgetUri);
this.persister.removeToken(processedGadgetUri, token.getServiceName(), token.getUser(), token.getScope(), token.getType()); } finally { token.setGadgetUri(origGadgetApi);