Package net.oauth

Examples of net.oauth.OAuthMessage


    private String defaultScope;
    private String defaultURI;
   
    public Response handle(MessageContext mc, OAuthDataProvider dataProvider) {
        try {
            OAuthMessage oAuthMessage =
                OAuthUtils.getOAuthMessage(mc, mc.getHttpServletRequest(), REQUIRED_PARAMETERS);

            Client client = dataProvider
                .getClient(oAuthMessage.getParameter(OAuth.OAUTH_CONSUMER_KEY));
            //client credentials not found
            if (client == null) {
                OAuthProblemException problemEx = new OAuthProblemException(
                    OAuth.Problems.CONSUMER_KEY_UNKNOWN);
                problemEx
                    .setParameter(OAuthProblemException.HTTP_STATUS_CODE,
                        HttpServletResponse.SC_UNAUTHORIZED);
                throw problemEx;
            }

            OAuthUtils.validateMessage(oAuthMessage, client, null, dataProvider);

            String callback = oAuthMessage.getParameter(OAuth.OAUTH_CALLBACK);
            validateCallbackURL(client, callback);

            List<String> scopes = OAuthUtils.parseParamValue(
                    oAuthMessage.getParameter(OAuthConstants.X_OAUTH_SCOPE), defaultScope);
            List<String> uris = OAuthUtils.parseParamValue(
                    oAuthMessage.getParameter(OAuthConstants.X_OAUTH_URI), defaultURI);
           
            RequestTokenRegistration reg = new RequestTokenRegistration();
            reg.setClient(client);
            reg.setCallback(callback);
            reg.setState(oAuthMessage.getParameter("state"));
            reg.setUris(uris);
            reg.setScopes(scopes);
            reg.setLifetime(tokenLifetime);
            reg.setIssuedAt(System.currentTimeMillis() / 1000);
           
View Full Code Here


   *     </ul>
   */
  private static String createOAuthUrlString(String jsonBody, String rpcServerUrl,
      String consumerKey, String consumerSecret)
      throws IOException, URISyntaxException, OAuthException {
    OAuthMessage message = new OAuthMessage(POST, rpcServerUrl,
        Collections.<Entry<String, String>>emptyList());

    // Compute the hash of the body.
    byte[] hash = DigestUtils.sha(jsonBody);
    byte[] encodedHash = Base64.encodeBase64(hash, false);
    message.addParameter(OAUTH_BODY_HASH, new String(encodedHash, UTF_8));

    // Add other parameters.
    OAuthConsumer consumer = new OAuthConsumer(null, OAUTH_CONSUMER_KEY_DOMAIN + ":" + consumerKey,
        consumerSecret, null);
    consumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.HMAC_SHA1);
    OAuthAccessor accessor = new OAuthAccessor(consumer);
    message.addRequiredParameters(accessor);
    LOG.info("Signature base string: " + OAuthSignatureMethod.getBaseString(message));

    // Construct the resulting URL.
    StringBuilder sb = new StringBuilder(rpcServerUrl);
    char connector = '?';
    for (Map.Entry<String, String> p : message.getParameters()) {
      if (!p.getKey().equals(jsonBody)) {
        sb.append(connector);
        sb.append(URLEncoder.encode(p.getKey(), "UTF-8"));
        sb.append('=');
        sb.append(URLEncoder.encode(p.getValue(), "UTF-8"));
View Full Code Here

    for (Entry<String, String[]> entry : requestParams.entrySet()) {
      for (String value : entry.getValue()) {
        params.add(new OAuth.Parameter(entry.getKey(), value));
      }
    }
    OAuthMessage message = new OAuthMessage(POST, requestUrl, params);

    // Compute and check the hash of the body.
    MessageDigest md = MessageDigest.getInstance(SHA_1);
    byte[] hash = md.digest(jsonBody.getBytes(UTF_8));
    String encodedHash = new String(Base64.encodeBase64(hash, false), UTF_8);
    if (!encodedHash.equals(message.getParameter(OAUTH_BODY_HASH))) {
      throw new IllegalArgumentException("Body hash does not match. Expected: " + encodedHash
          + ", provided: " + message.getParameter(OAUTH_BODY_HASH));
    }

    // Construct validator arguments.
    OAuthConsumer consumer = new OAuthConsumer(null, consumerKey, consumerSecret, null);
    OAuthAccessor accessor = new OAuthAccessor(consumer);
    LOG.info("Signature base string: " + OAuthSignatureMethod.getBaseString(message));
    message.validateMessage(accessor, new SimpleOAuthValidator());
  }
View Full Code Here

      OAuthConsumer consumer = new OAuthConsumer(null, consumerKey, null, null);

      consumer.setProperty(RSA_SHA1.X509_CERTIFICATE, certificate);

      OAuthMessage message = new OAuthMessage(request.getMethod(),
          request.getRequestURL().toString(), getRequestParameters(request));

      OAuthAccessor accessor = new OAuthAccessor(consumer);

      SimpleOAuthValidator validator = new SimpleOAuthValidator();
View Full Code Here

    if (consumerKey == null || consumerSecret == null) {
      return null;
    }

    url = appendRequesterIdToQueryString(url);
    OAuthMessage message = new OAuthMessage(method, url, null,
        byteArrayToStream(body));

    for (Map.Entry<String, String> header : headers.entrySet()) {
      message.getHeaders().add(header);
    }

    OAuthConsumer consumer =
      new OAuthConsumer(null, consumerKey, consumerSecret, null);
    consumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.HMAC_SHA1);
View Full Code Here

      String url, Map<String, String> headers, byte[] body,
      Collection<? extends Entry> parameters) throws
      RequestException, IOException {
    OAuthAccessor accessor = getOAuthAccessor(accessToken.token,
        accessToken.secret);
    OAuthMessage message = new OAuthMessage(method, url, parameters,
        byteArrayToStream(body));

    for (Map.Entry<String, String> header : headers.entrySet()) {
      message.getHeaders().add(header);
    }

    return getHttpMessage(message, accessor, body, provider.getSignBodyHash());
  }
View Full Code Here

      parameters = parameterMap.entrySet();
    }

    OAuthAccessor accessor = getOAuthAccessor(oAuthToken,
        this.requestToken.secret);
    OAuthMessage message = getOAuthClient().invoke(accessor, "GET",
        provider.getAccessTokenUrl(), parameters);

    accessToken = new Token(message.getToken(),
        message.getParameter(OAuth.OAUTH_TOKEN_SECRET));
  }
View Full Code Here

    return String.format("OAuth realm=\"%s\"", realm);
  }

  public SecurityToken getSecurityTokenFromRequest(HttpServletRequest request)
    throws InvalidAuthenticationException {
    OAuthMessage message = OAuthServlet.getMessage(request, null);
    if (Strings.isNullOrEmpty(getParameter(message, OAuth.OAUTH_SIGNATURE))) {
      // Is not an oauth request
      return null;
    }
    String bodyHash = getParameter(message, OAuthConstants.OAUTH_BODY_HASH);
View Full Code Here

    }
   
    public static OAuthMessage getOAuthMessage(MessageContext mc,
                                               HttpServletRequest request,
                                               String[] requiredParams) throws Exception {
        OAuthMessage oAuthMessage = OAuthServlet.getMessage(request, request.getRequestURL().toString());
        OAuthUtils.addParametersIfNeeded(mc, request, oAuthMessage);
        oAuthMessage.requireParameters(requiredParams);
        return oAuthMessage;
    }
View Full Code Here

      return new HttpResponseBuilder()
          .setHttpStatusCode(rc)
          .setResponseString("some vague error")
          .create();
    }
    OAuthMessage msg = new OAuthMessage(null, null, null);
    msg.addParameter("oauth_problem", code);
    msg.addParameter("oauth_problem_advice", text);   
    return new HttpResponseBuilder()
        .setHttpStatusCode(rc)
        .addHeader("WWW-Authenticate", msg.getAuthorizationHeader("realm"))
        .create();
  }
View Full Code Here

TOP

Related Classes of net.oauth.OAuthMessage

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.