}
public ConsumerInfo getConsumerKeyAndSecret(SecurityToken securityToken, String serviceName,
OAuthServiceProvider provider) throws GadgetException {
BasicOAuthStoreConsumerKeyAndSecret cks;
String ownerId = securityToken.getOwnerId();
// Check user store if security token matches any keys
if(this.userStore.containsKey(ownerId)) {
cks = userStore.get(ownerId).get(serviceName);
// Check anon store
} else if (this.keyAndSecretStore.containsKey(serviceName)) {
cks = keyAndSecretStore.get(serviceName);
} else {
throw new GadgetException(Code.OAUTH_STORAGE_ERROR, "No OAuth key and secret defined for the service " + serviceName);
}
//BEGIN code from org.apache.shindig.gadgets.oauth.BasicOAuthStore.getConsumerKeyAndSercret
OAuthConsumer consumer;
final KeyType keyType = cks.getKeyType();
if (keyType == KeyType.RSA_PRIVATE) {
consumer = new OAuthConsumer(null, cks.getConsumerKey(), null, provider);
// The oauth.net java code has lots of magic. By setting this property here, code thousands
// of lines away knows that the consumerSecret value in the consumer should be treated as
// an RSA private key and not an HMAC key.
consumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.RSA_SHA1);
consumer.setProperty(RSA_SHA1.PRIVATE_KEY, cks.getConsumerSecret());
} else if (keyType == KeyType.PLAINTEXT) {
consumer = new OAuthConsumer(null, cks.getConsumerKey(), cks.getConsumerSecret(), provider);
consumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, "PLAINTEXT");
} else {
consumer = new OAuthConsumer(null, cks.getConsumerKey(), cks.getConsumerSecret(), provider);
consumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.HMAC_SHA1);
}
String callback = (cks.getCallbackUrl() != null ? cks.getCallbackUrl() : defaultCallbackUrl);
if (authority != null) {
callback = callback.replace("%authority%", authority.getAuthority());
}
return new ConsumerInfo(consumer, cks.getKeyName(), callback, cks.isOauthBodyHash());
//END code from org.apache.shindig.gadgets.oauth.BasicOAuthStore.getConsumerKeyAndSercret
}