Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
0
 public void SetConsumerKeyAndSecret(BasicOAuthStoreConsumerIndex providerKey, BasicOAuthStoreConsumerKeyAndSecret keyAndSecret)
 {
     consumerInfos.Add(providerKey, keyAndSecret);
 }
Ejemplo n.º 4
0
 public void SetDefaultKey(BasicOAuthStoreConsumerKeyAndSecret key)
 {
     defaultKey = key;
 }
Ejemplo n.º 5
0
 public void SetConsumerKeyAndSecret(BasicOAuthStoreConsumerIndex providerKey, BasicOAuthStoreConsumerKeyAndSecret keyAndSecret)
 {
     consumerInfos.Add(providerKey, keyAndSecret);
 }
Ejemplo n.º 6
0
 public void SetDefaultKey(BasicOAuthStoreConsumerKeyAndSecret key)
 {
     defaultKey = key;
 }
Ejemplo n.º 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);
 }