当前位置: 首页>>代码示例>>Java>>正文


Java OAuthMessage.addParameter方法代码示例

本文整理汇总了Java中net.oauth.OAuthMessage.addParameter方法的典型用法代码示例。如果您正苦于以下问题:Java OAuthMessage.addParameter方法的具体用法?Java OAuthMessage.addParameter怎么用?Java OAuthMessage.addParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.oauth.OAuthMessage的用法示例。


在下文中一共展示了OAuthMessage.addParameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createLaunchParameters

import net.oauth.OAuthMessage; //导入方法依赖的package包/类
private OAuthMessage createLaunchParameters(String consumerKey, String secret, String url, String bodyHash)
{
	final String nonce = UUID.randomUUID().toString();
	final String timestamp = Long.toString(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()));

	final OAuthMessage message = new OAuthMessage(OAuthMessage.POST, url, null);
	message.addParameter(OAuth.OAUTH_CONSUMER_KEY, consumerKey);
	message.addParameter(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.HMAC_SHA1);
	message.addParameter(OAuth.OAUTH_NONCE, nonce);
	message.addParameter(OAuth.OAUTH_TIMESTAMP, timestamp);
	message.addParameter("oauth_body_hash", bodyHash);

	final OAuthConsumer consumer = new OAuthConsumer(null, consumerKey, secret, null);
	final OAuthAccessor accessor = new OAuthAccessor(consumer);
	try
	{
		message.sign(accessor);
		return message;
	}
	catch( Exception e )
	{
		throw new RuntimeException(e);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:25,代码来源:LtiServiceImpl.java

示例2: getOAuthURL

import net.oauth.OAuthMessage; //导入方法依赖的package包/类
/** 
        * getOAuthURL - Form a GET request signed by OAuth
 * @param method
 * @param url
 * @param oauth_consumer_key
 * @param oauth_consumer_secret
 * @param signature
 */
public static String getOAuthURL(String method, String url, 
	String oauth_consumer_key, String oauth_secret, String signature)
{
	OAuthMessage om = new OAuthMessage(method, url, null);
	om.addParameter(OAuth.OAUTH_CONSUMER_KEY, oauth_consumer_key);
	if ( signature == null ) signature = OAuth.HMAC_SHA1;
	om.addParameter(OAuth.OAUTH_SIGNATURE_METHOD, signature);
	om.addParameter(OAuth.OAUTH_VERSION, "1.0");
	om.addParameter(OAuth.OAUTH_TIMESTAMP, new Long((new Date().getTime()) / 1000).toString());
	om.addParameter(OAuth.OAUTH_NONCE, UUID.randomUUID().toString());

	OAuthConsumer oc = new OAuthConsumer(null, oauth_consumer_key, oauth_secret, null);
	try {
	    OAuthSignatureMethod osm = OAuthSignatureMethod.newMethod(signature, new OAuthAccessor(oc));
	    osm.sign(om);
	    url = OAuth.addParameters(url, om.getParameters());
	    return url;
	} catch (Exception e) {
		log.error(e.getMessage(), e);
		return null;
	}
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:31,代码来源:BasicLTIUtil.java

示例3: prepareRequestMessage

import net.oauth.OAuthMessage; //导入方法依赖的package包/类
private static OAuthMessage prepareRequestMessage(OAuthConsumer consumer,
                                                 String httpMethod,
                                                 URL url,
                                                 String signatureMethod) {
    OAuthMessage message = new OAuthMessage(httpMethod,
                                          url.toString(),
                                          new ArrayList<OAuth.Parameter>());
    message.addParameter(OAuth.OAUTH_SIGNATURE_METHOD, signatureMethod);
    message.addParameter(OAuth.OAUTH_VERSION, OAuth.VERSION_1_0);
    message.addParameter(OAuth.OAUTH_CONSUMER_KEY, consumer.consumerKey );
    long currentTime = System.currentTimeMillis() / 1000l;
    message.addParameter(OAuth.OAUTH_TIMESTAMP,
                         Long.toString(currentTime, 10));
    byte[] nonce = new byte[8];
    random.nextBytes(nonce);
    BigInteger nonceInt = new BigInteger(1, nonce);
    message.addParameter(OAuth.OAUTH_NONCE,
                         nonceInt.toString(10));
    return message;
}
 
开发者ID:groovenauts,项目名称:jmeter_oauth_plugin,代码行数:21,代码来源:RSA_SHA1SignatureTest.java

示例4: getRequestURL

import net.oauth.OAuthMessage; //导入方法依赖的package包/类
private String getRequestURL(String consumerKey, String consumerSecret) throws Exception {
 OAuthMessage message = new OAuthMessage("GET", RequestURL, Collections.<Map.Entry>emptyList());
 OAuthConsumer consumer = new OAuthConsumer("http://callback.net", consumerKey, consumerSecret, null);
 OAuthAccessor accessor = new OAuthAccessor(consumer);
 message.addParameter(OAuth.OAUTH_CALLBACK, consumer.callbackURL);
 message.addRequiredParameters(accessor);
 return OAuth.addParameters(message.URL, message.getParameters());
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:9,代码来源:OAuthTest.java

示例5: getAccessURL

import net.oauth.OAuthMessage; //导入方法依赖的package包/类
private String getAccessURL(String consumerKey, String consumerSecret, String requestKey, String requestSecret, String verifier) throws Exception {
 OAuthMessage message = new OAuthMessage("GET", AccessURL, Collections.<Map.Entry>emptyList());
 OAuthConsumer consumer = new OAuthConsumer("http://callback.net", consumerKey, consumerSecret, null);
 OAuthAccessor accessor = new OAuthAccessor(consumer);
 accessor.requestToken = requestKey;
 accessor.tokenSecret = requestSecret;
 message.addParameter(OAuthUtils.OAUTH_VERIFIER_PARAM, verifier);
 message.addParameter(OAuth.OAUTH_TOKEN, requestKey);
 message.addRequiredParameters(accessor);
 return OAuth.addParameters(message.URL, message.getParameters());
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:12,代码来源:OAuthTest.java

示例6: getProtectedURL

import net.oauth.OAuthMessage; //导入方法依赖的package包/类
private String getProtectedURL(String url, String consumerKey, String consumerSecret, String accessKey, String accessSecret) throws Exception {
 OAuthMessage message = new OAuthMessage("GET", ProtectedURL+url, Collections.<Map.Entry>emptyList());
 OAuthConsumer consumer = new OAuthConsumer("http://callback.net", consumerKey, consumerSecret, null);
 OAuthAccessor accessor = new OAuthAccessor(consumer);
 accessor.accessToken = accessKey;
 accessor.tokenSecret = accessSecret;
 message.addParameter(OAuth.OAUTH_TOKEN, accessKey);
 message.addRequiredParameters(accessor);
 return OAuth.addParameters(message.URL, message.getParameters());
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:11,代码来源:OAuthTest.java

示例7: getRequestURL

import net.oauth.OAuthMessage; //导入方法依赖的package包/类
private String getRequestURL(String consumerKey, String consumerSecret, 
                             String callbackURI, String scope, String permission) throws Exception {
 OAuthMessage message = new OAuthMessage("GET", RequestTokenURL, Collections.<Map.Entry>emptyList());
 OAuthConsumer consumer = new OAuthConsumer(callbackURI, consumerKey, consumerSecret, null);
 OAuthAccessor accessor = new OAuthAccessor(consumer);
 message.addParameter(OAuth.OAUTH_CALLBACK, consumer.callbackURL);
 message.addParameter("xoauth_scope", scope);
 message.addParameter("xoauth_permission", permission);
 message.addRequiredParameters(accessor);
 return OAuth.addParameters(message.URL, message.getParameters());
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:12,代码来源:ConsumerResource.java

示例8: getAccessURL

import net.oauth.OAuthMessage; //导入方法依赖的package包/类
private String getAccessURL(String consumerKey, String consumerSecret, String requestKey, String requestSecret, String verifier) throws Exception {
 OAuthMessage message = new OAuthMessage("GET", AccessTokenURL, Collections.<Map.Entry>emptyList());
 OAuthConsumer consumer = new OAuthConsumer("http://callback.net", consumerKey, consumerSecret, null);
 OAuthAccessor accessor = new OAuthAccessor(consumer);
 accessor.requestToken = requestKey;
 accessor.tokenSecret = requestSecret;
 message.addParameter(OAuthUtils.OAUTH_VERIFIER_PARAM, verifier);
 message.addParameter(OAuth.OAUTH_TOKEN, requestKey);
 message.addRequiredParameters(accessor);
 return OAuth.addParameters(message.URL, message.getParameters());
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:12,代码来源:ConsumerResource.java

示例9: getEndUserURL

import net.oauth.OAuthMessage; //导入方法依赖的package包/类
private String getEndUserURL(String url, String consumerKey, String consumerSecret, String accessKey, String accessSecret) throws Exception {
 OAuthMessage message = new OAuthMessage("GET", endUserScope + url, Collections.<Map.Entry>emptyList());
 OAuthConsumer consumer = new OAuthConsumer("http://callback.net", consumerKey, consumerSecret, null);
 OAuthAccessor accessor = new OAuthAccessor(consumer);
 accessor.accessToken = accessKey;
 accessor.tokenSecret = accessSecret;
 message.addParameter(OAuth.OAUTH_TOKEN, accessKey);
 message.addRequiredParameters(accessor);
 return OAuth.addParameters(message.URL, message.getParameters());
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:11,代码来源:ConsumerResource.java

示例10: createOAuthUrlString

import net.oauth.OAuthMessage; //导入方法依赖的package包/类
/**
 * Creates a URL that contains the necessary OAuth query parameters for the
 * given JSON string.
 *
 * The required OAuth parameters are:
 * <ul>
 * <li>oauth_body_hash</li>
 * <li>oauth_consumer_key</li>
 * <li>oauth_signature_method</li>
 * <li>oauth_timestamp</li>
 * <li>oauth_nonce</li>
 * <li>oauth_version</li>
 * <li>oauth_signature</li>
 * </ul>
 *
 * @param method the HTTP method.
 * @param jsonBody the JSON string to construct the URL from.
 * @param rpcServerUrl the URL of the handler that services the JSON-RPC
 *        request.
 * @param accessor the OAuth accessor used to create the signed string.
 * @return a URL for the given JSON string, and the required OAuth parameters.
 */
public static String createOAuthUrlString(String method,
    String jsonBody, String rpcServerUrl, OAuthAccessor accessor, List<SimpleEntry<String, String>> params)
    throws IOException, URISyntaxException, OAuthException {
  OAuthMessage message =
      new OAuthMessage(method, rpcServerUrl, params);

  if (jsonBody != null) {
    // Compute the hash of the body.
    byte[] rawBody = jsonBody.getBytes(UTF_8);
    byte[] hash = DigestUtils.sha(rawBody);
    byte[] encodedHash = Base64.encodeBase64(hash);
    message.addParameter(OAUTH_BODY_HASH, new String(encodedHash, UTF_8));
  }

  // Add other parameters.

  message.addRequiredParameters(accessor);
  if (LOG.isLoggable(Level.FINE)) {
    LOG.fine("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));
      connector = '&';
    }
  }
  return sb.toString();
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:58,代码来源:WaveService.java

示例11: createOAuthUrlString

import net.oauth.OAuthMessage; //导入方法依赖的package包/类
/**
 * Creates a URL that contains the necessary OAuth query parameters for the
 * given JSON string.
 *
 * The required OAuth parameters are:
 * <ul>
 * <li>oauth_body_hash</li>
 * <li>oauth_consumer_key</li>
 * <li>oauth_signature_method</li>
 * <li>oauth_timestamp</li>
 * <li>oauth_nonce</li>
 * <li>oauth_version</li>
 * <li>oauth_signature</li>
 * </ul>
 *
 * @param jsonBody the JSON string to construct the URL from.
 * @param rpcServerUrl the URL of the handler that services the JSON-RPC
 *        request.
 * @param accessor the OAuth accessor used to create the signed string.
 * @return a URL for the given JSON string, and the required OAuth parameters.
 */
public static String createOAuthUrlString(
    String jsonBody, String rpcServerUrl, OAuthAccessor accessor)
    throws IOException, URISyntaxException, OAuthException {
  OAuthMessage message =
      new OAuthMessage(POST, rpcServerUrl, Collections.<SimpleEntry<String, String>>emptyList());

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

  // Add other parameters.

  message.addRequiredParameters(accessor);
  if (LOG.isLoggable(Level.FINE)) {
    LOG.fine("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));
      connector = '&';
    }
  }
  return sb.toString();
}
 
开发者ID:apache,项目名称:incubator-wave,代码行数:55,代码来源:WaveService.java

示例12: getSecurityTokenFromRequest

import net.oauth.OAuthMessage; //导入方法依赖的package包/类
public SecurityToken getSecurityTokenFromRequest(HttpServletRequest request)
    throws InvalidAuthenticationException {
  OAuthMessage message = OAuthServlet.getMessage(request, null);
  if (StringUtils.isEmpty(getParameter(message, OAuth.OAUTH_SIGNATURE))) {
    // Is not an oauth request
    return null;
  }
  String bodyHash = getParameter(message, OAuthConstants.OAUTH_BODY_HASH);
  if (!StringUtils.isEmpty(bodyHash)) {
    verifyBodyHash(request, bodyHash);
  }
  try {
    return verifyMessage(message);
  } catch (OAuthProblemException oauthException) {
    // Legacy body signing is intended for backwards compatability with opensocial clients
    // that assumed they could use the raw request body as a pseudo query param to get
    // body signing. This assumption was born out of the limitations of the OAuth 1.0 spec which
    // states that request bodies are only signed if they are form-encoded. This lead many clients
    // to force a content type of application/x-www-form-urlencoded for xml/json bodies and then
    // hope that receiver decoding of the body didnt have encoding issues. This didn't work out
    // to well so now these clients are required to specify the correct content type. This code
    // lets clients which sign using the old technique to work if they specify the correct content
    // type. This support is deprecated and should be removed later.
    if (allowLegacyBodySigning &&
        (StringUtils.isEmpty(request.getContentType())  ||
        !request.getContentType().contains(OAuth.FORM_ENCODED))) {
      try {
        message.addParameter(readBodyString(request), "");
        return verifyMessage(message);
      } catch (OAuthProblemException ioe) {
        // ignore, let original exception be thrown
      } catch (IOException e) {
        // also ignore;
      }
    }
    throw new InvalidAuthenticationException("OAuth Authentication Failure", oauthException);
  }
}
 
开发者ID:inevo,项目名称:shindig-1.1-BETA5-incubating,代码行数:39,代码来源:OAuthAuthenticationHandler.java

示例13: makeOAuthProblemReport

import net.oauth.OAuthMessage; //导入方法依赖的package包/类
private HttpResponse makeOAuthProblemReport(String code, String text, int rc) throws IOException {
  if (vagueErrors) {
    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();
}
 
开发者ID:inevo,项目名称:shindig-1.1-BETA5-incubating,代码行数:16,代码来源:FakeOAuthServiceProvider.java

示例14: getOauthSignatureParams

import net.oauth.OAuthMessage; //导入方法依赖的package包/类
@Override
public List<Entry<String, String>> getOauthSignatureParams(String consumerKey, String secret, String urlStr,
	Map<String, String[]> formParams)
{
	String nonce = UUID.randomUUID().toString();
	String timestamp = Long.toString(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()));
	// OAuth likes the Map.Entry interface, so copy into a Collection of a
	// local implementation thereof. Note that this is a flat list.
	List<Parameter> postParams = null;

	if( !Check.isEmpty(formParams) )
	{
		postParams = new ArrayList<Parameter>(formParams.size());
		for( Entry<String, String[]> entry : formParams.entrySet() )
		{
			String key = entry.getKey();
			String[] formParamEntry = entry.getValue();
			// cater for multiple values for the same key
			if( formParamEntry.length > 0 )
			{
				for( int i = 0; i < formParamEntry.length; ++i )
				{
					Parameter erp = new Parameter(entry.getKey(), formParamEntry[i]);
					postParams.add(erp);
				}
			}
			else
			{
				// key with no value
				postParams.add(new Parameter(key, null));
			}
		}
	}

	OAuthMessage message = new OAuthMessage(OAuthMessage.POST, urlStr, postParams);
	// Parameters needed for a signature
	message.addParameter(OAuth.OAUTH_CONSUMER_KEY, consumerKey);
	message.addParameter(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.HMAC_SHA1);
	message.addParameter(OAuth.OAUTH_NONCE, nonce);
	message.addParameter(OAuth.OAUTH_TIMESTAMP, timestamp);
	message.addParameter(OAuth.OAUTH_VERSION, OAuth.VERSION_1_0);
	message.addParameter(OAuth.OAUTH_CALLBACK, "about:blank");

	// Sign the request
	OAuthConsumer consumer = new OAuthConsumer("about:blank", consumerKey, secret, null);
	OAuthAccessor accessor = new OAuthAccessor(consumer);
	try
	{
		message.sign(accessor);
		// send oauth parameters back including signature
		return message.getParameters();
	}
	catch( Exception e )
	{
		throw new RuntimeException(e);
	}

}
 
开发者ID:equella,项目名称:Equella,代码行数:59,代码来源:ExternalToolsServiceImpl.java

示例15: sign

import net.oauth.OAuthMessage; //导入方法依赖的package包/类
/** Add a signature to the message. 
 * @throws URISyntaxException 
 * @throws IOException */
public void sign(OAuthMessage message)
throws OAuthException, IOException, URISyntaxException {
    message.addParameter(new OAuth.Parameter("oauth_signature",
            getSignature(message)));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:OAuthSignatureMethod.java


注:本文中的net.oauth.OAuthMessage.addParameter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。