Пример #1
0
        public override ConsumerInfo getConsumerKeyAndSecret(ISecurityToken securityToken, String serviceName, OAuthServiceProvider provider)
        {
            ++consumerKeyLookupCount;
            BasicOAuthStoreConsumerIndex pk = new BasicOAuthStoreConsumerIndex();

            pk.setGadgetUri(securityToken.getAppUrl());
            pk.setServiceName(serviceName);
            BasicOAuthStoreConsumerKeyAndSecret cks = consumerInfos.ContainsKey(pk) ? consumerInfos[pk] : defaultKey;

            if (cks == null)
            {
                throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR,
                                          "No key for gadget " + securityToken.getAppUrl() + " and service " + serviceName);
            }
            OAuthConsumer consumer;

            if (cks.keyType == BasicOAuthStoreConsumerKeyAndSecret.KeyType.RSA_PRIVATE)
            {
                consumer = new OAuthConsumer(null, cks.ConsumerKey, null, provider);
                consumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.RSA_SHA1);
                consumer.setProperty(RSA_SHA1.X509_CERTIFICATE, cks.CertName);
                consumer.setProperty(RSA_SHA1.X509_CERTIFICATE_PASS, cks.CertPass);
            }
            else
            {
                consumer = new OAuthConsumer(null, cks.ConsumerKey, cks.ConsumerSecret, provider);
                consumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.HMAC_SHA1);
            }
            return(new ConsumerInfo(consumer, cks.ConsumerKey));
        }
Пример #2
0
        private void RealStoreConsumerInfo(Uri gadgetUri, String serviceName, JsonObject consumerInfo)
        {
            String consumerKey = consumerInfo[CONSUMER_KEY_KEY].ToString();
            String keyTypeStr  = consumerInfo[KEY_TYPE_KEY].ToString();

            BasicOAuthStoreConsumerKeyAndSecret.KeyType keyType;
            BasicOAuthStoreConsumerKeyAndSecret         kas;

            if (keyTypeStr.Equals("RSA_PRIVATE"))
            {
                String certName = consumerInfo[CERTIFICATE_LOC].ToString();
                String certPass = consumerInfo[CERTIFICATE_PASS].ToString();
                keyType = BasicOAuthStoreConsumerKeyAndSecret.KeyType.RSA_PRIVATE;
                kas     = new BasicOAuthStoreConsumerKeyAndSecret(consumerKey, null, keyType, certName, certPass);
            }
            else
            {
                String consumerSecret = consumerInfo[CONSUMER_SECRET_KEY].ToString();
                keyType = BasicOAuthStoreConsumerKeyAndSecret.KeyType.HMAC_SYMMETRIC;
                kas     = new BasicOAuthStoreConsumerKeyAndSecret(consumerKey, consumerSecret, keyType, null, null);
            }

            BasicOAuthStoreConsumerIndex index = new BasicOAuthStoreConsumerIndex();

            index.setGadgetUri(gadgetUri.ToString());
            index.setServiceName(serviceName);
            SetConsumerKeyAndSecret(index, kas);
        }
Пример #3
0
        public override bool Equals(Object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (obj == null)
            {
                return(false);
            }
            if (GetType() != obj.GetType())
            {
                return(false);
            }
            BasicOAuthStoreConsumerIndex other = (BasicOAuthStoreConsumerIndex)obj;

            if (gadgetUri == null)
            {
                if (other.gadgetUri != null)
                {
                    return(false);
                }
            }
            else if (!gadgetUri.Equals(other.gadgetUri))
            {
                return(false);
            }

            if (serviceName == null)
            {
                if (other.serviceName != null)
                {
                    return(false);
                }
            }
            else if (!serviceName.Equals(other.serviceName))
            {
                return(false);
            }
            return(true);
        }
Пример #4
0
 public void SetConsumerKeyAndSecret(BasicOAuthStoreConsumerIndex providerKey, BasicOAuthStoreConsumerKeyAndSecret keyAndSecret)
 {
     consumerInfos.Add(providerKey, keyAndSecret);
 }
Пример #5
0
 public override ConsumerInfo getConsumerKeyAndSecret(ISecurityToken securityToken, String serviceName, OAuthServiceProvider provider)
 {
     ++consumerKeyLookupCount;
     BasicOAuthStoreConsumerIndex pk = new BasicOAuthStoreConsumerIndex();
     pk.setGadgetUri(securityToken.getAppUrl());
     pk.setServiceName(serviceName);
     BasicOAuthStoreConsumerKeyAndSecret cks = consumerInfos.ContainsKey(pk) ? consumerInfos[pk] : defaultKey;
     if (cks == null)
     {
         throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR,
                                   "No key for gadget " + securityToken.getAppUrl() + " and service " + serviceName);
     }
     OAuthConsumer consumer;
     if (cks.keyType == BasicOAuthStoreConsumerKeyAndSecret.KeyType.RSA_PRIVATE)
     {
         consumer = new OAuthConsumer(null, cks.ConsumerKey, null, provider);
         consumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.RSA_SHA1);
         consumer.setProperty(RSA_SHA1.X509_CERTIFICATE, cks.CertName);
         consumer.setProperty(RSA_SHA1.X509_CERTIFICATE_PASS, cks.CertPass);
     }
     else
     {
         consumer = new OAuthConsumer(null, cks.ConsumerKey, cks.ConsumerSecret, provider);
         consumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.HMAC_SHA1);
     }
     return new ConsumerInfo(consumer, cks.ConsumerKey);
 }
Пример #6
0
 public void SetConsumerKeyAndSecret(BasicOAuthStoreConsumerIndex providerKey, BasicOAuthStoreConsumerKeyAndSecret keyAndSecret)
 {
     consumerInfos.Add(providerKey, keyAndSecret);
 }
Пример #7
0
 private void RealStoreConsumerInfo(Uri gadgetUri, String serviceName, JsonObject consumerInfo)
 {
     String consumerKey = consumerInfo[CONSUMER_KEY_KEY].ToString();
     String keyTypeStr = consumerInfo[KEY_TYPE_KEY].ToString();
     BasicOAuthStoreConsumerKeyAndSecret.KeyType keyType;
     BasicOAuthStoreConsumerKeyAndSecret kas;
     if (keyTypeStr.Equals("RSA_PRIVATE"))
     {
         String certName = consumerInfo[CERTIFICATE_LOC].ToString();
         String certPass = consumerInfo[CERTIFICATE_PASS].ToString();
         keyType = BasicOAuthStoreConsumerKeyAndSecret.KeyType.RSA_PRIVATE;
         kas = new BasicOAuthStoreConsumerKeyAndSecret(consumerKey, null, keyType, certName, certPass);
     }
     else
     {
         String consumerSecret = consumerInfo[CONSUMER_SECRET_KEY].ToString();
         keyType = BasicOAuthStoreConsumerKeyAndSecret.KeyType.HMAC_SYMMETRIC;
         kas = new BasicOAuthStoreConsumerKeyAndSecret(consumerKey, consumerSecret, keyType, null, null);
     }
     
     BasicOAuthStoreConsumerIndex index = new BasicOAuthStoreConsumerIndex();
     index.setGadgetUri(gadgetUri.ToString());
     index.setServiceName(serviceName);
     SetConsumerKeyAndSecret(index, kas);
 }