Package net.oauth

Examples of net.oauth.OAuthConsumer


    private OAuthConsumer createOAuthConsumer(OAuthServiceProvider provider,
                                              OAuthConsumerStore consumerStore) {
        String consumerKey = consumerStore.getConsumerKey();
        String consumerSecret = consumerStore.getConsumerSecret();

        OAuthConsumer consumer;
        switch (consumerStore.getKeyType()) {
            case RSA_PRIVATE:
                consumer = new OAuthConsumer(null, consumerKey, 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, defaultKey.getConsumerSecret());
                break;
            case HMAC_SYMMETRIC:
                consumer = new OAuthConsumer(null, consumerKey, consumerSecret, provider);
                consumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.HMAC_SHA1);
                break;
            case PLAINTEXT:
                consumer = new OAuthConsumer(null, consumerKey, consumerSecret, provider);
                consumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, "PLAINTEXT");
                break;
            default:
                throw new IllegalArgumentException("Cannot handle keytype " +
                        consumerStore.getKeyType());
        }
View Full Code Here


        }
        if (cks == null) {
            throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, "No key for gadget "
                    + securityToken.getAppUrl() + " and service " + serviceName);
        }
        OAuthConsumer consumer = null;
        if (cks.getKeyType() == 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 {
            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);
        return new ConsumerInfo(consumer, cks.getKeyName(), callback);
    }
View Full Code Here

  public FakeOAuthServiceProvider(TimeSource clock) {
    this.clock = clock;
    OAuthServiceProvider provider = new OAuthServiceProvider(
        REQUEST_TOKEN_URL, APPROVAL_URL, ACCESS_TOKEN_URL);

    signedFetchConsumer = new OAuthConsumer(null, null, null, null);
    signedFetchConsumer.setProperty(RSA_SHA1.X509_CERTIFICATE, CERTIFICATE_TEXT);

    oauthConsumer = new OAuthConsumer(null, CONSUMER_KEY, CONSUMER_SECRET, provider);

    tokenState = Maps.newHashMap();
    validParamLocations = Sets.newHashSet();
    validParamLocations.add(OAuthParamLocation.URI_QUERY);
    nonceCache =
View Full Code Here

  private HttpResponse handleRequestTokenUrl(HttpRequest request)
      throws Exception {
    MessageInfo info = parseMessage(request);
    String requestConsumer = info.message.getParameter(OAuth.OAUTH_CONSUMER_KEY);
    OAuthConsumer consumer;
    if (CONSUMER_KEY.equals(requestConsumer)) {
      consumer = oauthConsumer;
    } else {
      return makeOAuthProblemReport(
          OAuth.Problems.CONSUMER_KEY_UNKNOWN, "invalid consumer: " + requestConsumer,
View Full Code Here

  private HttpResponse handleResourceUrl(HttpRequest request)
      throws Exception {
    MessageInfo info = parseMessage(request);
    String consumerId = info.message.getParameter("oauth_consumer_key");
    OAuthConsumer consumer;
    if (CONSUMER_KEY.equals(consumerId)) {
      consumer = oauthConsumer;
    } else if ("signedfetch".equals(consumerId)) {
      consumer = signedFetchConsumer;
    } else if ("container.com".equals(consumerId)) {
View Full Code Here

  public void testInit() throws Exception {
    FakeGadgetToken t = new FakeGadgetToken();
    t.setAppUrl("http://localhost:8080/samplecontainer/examples/oauth.xml");
    OAuthServiceProvider provider = new OAuthServiceProvider("req", "authorize", "access");
    ConsumerInfo consumerInfo = store.getConsumerKeyAndSecret(t, "", provider);
    OAuthConsumer consumer = consumerInfo.getConsumer();
    assertEquals("gadgetConsumer", consumer.consumerKey);
    assertEquals("gadgetSecret", consumer.consumerSecret);
    assertEquals("HMAC-SHA1", consumer.getProperty("oauth_signature_method"));
    assertEquals(provider, consumer.serviceProvider);
    assertNull(consumerInfo.getKeyName());
    assertEquals("default callback", consumerInfo.getCallbackUrl());

    t.setAppUrl("http://rsagadget/test.xml");
    consumerInfo = store.getConsumerKeyAndSecret(t, "", provider);
    consumer = consumerInfo.getConsumer();
    assertEquals("rsaconsumer", consumer.consumerKey);
    assertNull(consumer.consumerSecret);
    assertEquals("RSA-SHA1", consumer.getProperty("oauth_signature_method"));
    assertEquals(provider, consumer.serviceProvider);
    assertEquals("rsaprivate", consumer.getProperty(RSA_SHA1.PRIVATE_KEY));
    assertNull(consumerInfo.getKeyName());
    assertEquals("callback", consumerInfo.getCallbackUrl());
  }
View Full Code Here

   
    FakeGadgetToken t = new FakeGadgetToken();
    t.setAppUrl("http://localhost:8080/samplecontainer/examples/oauth.xml");
    OAuthServiceProvider provider = new OAuthServiceProvider("req", "authorize", "access");
    ConsumerInfo consumerInfo = store.getConsumerKeyAndSecret(t, "", provider);
    OAuthConsumer consumer = consumerInfo.getConsumer();
    assertEquals("gadgetConsumer", consumer.consumerKey);
    assertNull(consumerInfo.getKeyName());
    assertNull(consumerInfo.getCallbackUrl());
  }
View Full Code Here

    if (consumerKey == null) {
      OAuthProblemException e = new OAuthProblemException(OAuth.Problems.PARAMETER_ABSENT);
      e.setParameter(OAuth.Problems.OAUTH_PARAMETERS_ABSENT, OAuth.OAUTH_CONSUMER_KEY);
      throw e;
    }
    OAuthConsumer consumer = dataStore.getConsumer(consumerKey);

    if (consumer == null)
      throw new OAuthProblemException(OAuth.Problems.CONSUMER_KEY_UNKNOWN);

    OAuthAccessor accessor = new OAuthAccessor(consumer);
View Full Code Here

    if (entry == null) {
      servletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "OAuth Entry not found");
      return;
    }

    OAuthConsumer consumer = dataStore.getConsumer(entry.getConsumerKey());

    // Extremely rare case where consumer dissappears
    if (consumer == null) {
      servletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "consumer for entry not found");
      return;
View Full Code Here

    String consumerKey = entry.getConsumerKey();
    if (!consumerKey.equals(requestMessage.getConsumerKey()))
      throw new OAuthProblemException(OAuth.Problems.CONSUMER_KEY_REFUSED);

    OAuthConsumer consumer = dataStore.getConsumer(consumerKey);
    if (consumer == null)
      throw new OAuthProblemException(OAuth.Problems.CONSUMER_KEY_UNKNOWN);

    OAuthAccessor accessor = new OAuthAccessor(consumer);
    accessor.requestToken = entry.getToken();
View Full Code Here

TOP

Related Classes of net.oauth.OAuthConsumer

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.