Package org.apache.shindig.gadgets.oauth

Examples of org.apache.shindig.gadgets.oauth.BasicOAuthStoreConsumerKeyAndSecret


  public JSONArray getUserServices(String userId) throws JSONException {
    JSONArray array = new JSONArray();
    if(this.userStore.containsKey(userId)) {
      Map<String, BasicOAuthStoreConsumerKeyAndSecret> userMap = this.userStore.get(userId);
      for (Entry<String, BasicOAuthStoreConsumerKeyAndSecret> entry : userMap.entrySet()) {
        BasicOAuthStoreConsumerKeyAndSecret kas = entry.getValue();
        JSONObject service = new JSONObject();
        service.put("key", kas.getConsumerKey());
        service.put("secret", kas.getConsumerSecret());
        service.put("name", kas.getKeyName());
        service.put("keyType", kas.getKeyType().toString());
        service.put("callbackUrl", kas.getCallbackUrl());
        array.add(service);
      }
    }
    return array;
  }
View Full Code Here


          consumerSecret = BasicOAuthStore.convertFromOpenSsl(consumerSecret);
        } else if ("PLAINTEXT".equals(keyTypeStr)) {
          keyType = KeyType.PLAINTEXT;
        }

        BasicOAuthStoreConsumerKeyAndSecret kas = new BasicOAuthStoreConsumerKeyAndSecret(
            consumerKey, consumerSecret, keyType, null, callbackUrl, oauthBodyHash);
        //END code from code from org.apache.shindig.gadgets.oauth.BasicOAuthStore.realStoreConsumerInfo
       
        keyAndSecretStore.put(key, kas);
      }
View Full Code Here

  }

  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
  }
View Full Code Here

TOP

Related Classes of org.apache.shindig.gadgets.oauth.BasicOAuthStoreConsumerKeyAndSecret

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.