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


Java CommonsHttpOAuthConsumer.sign方法代码示例

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


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

示例1: sign

import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //导入方法依赖的package包/类
@Override
public HttpRequest sign(HttpRequest request, String key, String secret) throws LtiSigningException {
    CommonsHttpOAuthConsumer signer = new CommonsHttpOAuthConsumer(key, secret);
    try {
        String body = getRequestBody(request);
        String bodyHash = new String(Base64.encodeBase64(md.digest(body.getBytes())));

        HttpParameters params = new HttpParameters();
        params.put("oauth_body_hash", URLEncoder.encode(bodyHash, "UTF-8"));
        signer.setAdditionalParameters(params);

        signer.sign(request);
    } catch (OAuthMessageSignerException|OAuthExpectationFailedException|OAuthCommunicationException|IOException e) {
        throw new LtiSigningException("Exception encountered while singing Lti request...", e);
    }
    return request;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:LtiOauthSigner.java

示例2: buildReplaceResult

import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //导入方法依赖的package包/类
public static HttpPost buildReplaceResult(String url, String key, String secret, String sourcedid, String score, String resultData, Boolean isUrl) throws IOException, OAuthException, GeneralSecurityException {
	String dataXml = "";
	if (resultData != null) {
		String format = isUrl ? resultDataUrl : resultDataText;
		dataXml = String.format(format, StringEscapeUtils.escapeXml(resultData));
	}
	//*LAMS* the following line was added by LAMS and also messageIdentifier was added to the line after it
	String messageIdentifier = UUID.randomUUID().toString();
	String xml = String.format(replaceResultMessage, messageIdentifier, StringEscapeUtils.escapeXml(sourcedid),
			StringEscapeUtils.escapeXml(score), dataXml);

	HttpParameters parameters = new HttpParameters();
	String hash = getBodyHash(xml);
	parameters.put("oauth_body_hash", URLEncoder.encode(hash, "UTF-8"));

	CommonsHttpOAuthConsumer signer = new CommonsHttpOAuthConsumer(key, secret);
	HttpPost request = new HttpPost(url);
	request.setHeader("Content-Type", "application/xml");
	request.setEntity(new StringEntity(xml, "UTF-8"));
	signer.setAdditionalParameters(parameters);
	signer.sign(request);
	return request;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:IMSPOXRequest.java

示例3: getServiceOAuthSigner

import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //导入方法依赖的package包/类
private OAuthSigner getServiceOAuthSigner() throws Exception {
    String password = keyStorePassword(instanceConfig.getRoutesHost(), instanceConfig.getRoutesPort());
    File oauthKeystoreFile = new File("./certs/oauthKeystore");
    RSAKeyPairGenerator generator = new RSAKeyPairGenerator();
    String consumerKey = instanceConfig.getInstanceKey();
    String consumerSecret = generator.getPrivateKey(consumerKey, password, oauthKeystoreFile);

    String token = consumerKey;
    String tokenSecret = consumerSecret;

    return (request) -> {
        CommonsHttpOAuthConsumer oAuthConsumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);
        oAuthConsumer.setMessageSigner(new RsaSha1MessageSigner());
        oAuthConsumer.setTokenWithSecret(token, tokenSecret);
        return oAuthConsumer.sign(request);
    };
}
 
开发者ID:jivesoftware,项目名称:routing-bird,代码行数:18,代码来源:Deployable.java

示例4: buildReplaceResult

import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //导入方法依赖的package包/类
public static HttpPost buildReplaceResult(String url, String key, String secret, String sourcedid,
	String score, String resultData, Boolean isUrl, String messageId) throws IOException, OAuthException, GeneralSecurityException
{
	String dataXml = "";
	if (resultData != null) {
		String format = isUrl ? resultDataUrl : resultDataText;
		dataXml = String.format(format, StringEscapeUtils.escapeXml(resultData));
	}

	String messageIdentifier = StringUtils.isBlank(messageId) ? String.valueOf(new Date().getTime()) : messageId;
	String xml = String.format(ReplaceResultMessageTemplate,
		StringEscapeUtils.escapeXml(messageIdentifier),
		StringEscapeUtils.escapeXml(sourcedid),
		StringEscapeUtils.escapeXml(score),
		dataXml);

	HttpParameters parameters = new HttpParameters();
	String hash = getBodyHash(xml);
	parameters.put("oauth_body_hash", URLEncoder.encode(hash, "UTF-8"));

	CommonsHttpOAuthConsumer signer = new CommonsHttpOAuthConsumer(key, secret);
	HttpPost request = new HttpPost(url);
	request.setHeader("Content-Type", "application/xml");
	request.setEntity(new StringEntity(xml, "UTF-8"));
	signer.setAdditionalParameters(parameters);
	signer.sign(request);
	return request;
}
 
开发者ID:IMSGlobal,项目名称:basiclti-util-java,代码行数:29,代码来源:IMSPOXRequest.java

示例5: syncClient

import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //导入方法依赖的package包/类
private MiruSyncClient syncClient(MiruSyncSenderConfig config) throws Exception {
    if (config.loopback) {
        return syncReceiver;
    } else {
        String consumerKey = StringUtils.trimToNull(config.oAuthConsumerKey);
        String consumerSecret = StringUtils.trimToNull(config.oAuthConsumerSecret);
        String consumerMethod = StringUtils.trimToNull(config.oAuthConsumerMethod);
        if (consumerKey == null || consumerSecret == null || consumerMethod == null) {
            throw new IllegalStateException("OAuth consumer has not been configured");
        }

        consumerMethod = consumerMethod.toLowerCase();
        if (!consumerMethod.equals("hmac") && !consumerMethod.equals("rsa")) {
            throw new IllegalStateException("OAuth consumer method must be one of HMAC or RSA");
        }

        String scheme = config.senderScheme;
        String host = config.senderHost;
        int port = config.senderPort;

        boolean sslEnable = scheme.equals("https");
        OAuthSigner authSigner = (request) -> {
            CommonsHttpOAuthConsumer oAuthConsumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);
            oAuthConsumer.setMessageSigner(new HmacSha1MessageSigner());
            oAuthConsumer.setTokenWithSecret(consumerKey, consumerSecret);
            return oAuthConsumer.sign(request);
        };
        HttpClient httpClient = HttpRequestHelperUtils.buildHttpClient(sslEnable,
            config.allowSelfSignedCerts,
            authSigner,
            host,
            port,
            syncConfig.getSyncSenderSocketTimeout());

        return new HttpMiruSyncClient(httpClient,
            mapper,
            "/api/sync/v1/write/activities",
            "/api/sync/v1/register/schema");
    }
}
 
开发者ID:jivesoftware,项目名称:miru,代码行数:41,代码来源:MiruSyncSenders.java

示例6: getSignedRequest

import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //导入方法依赖的package包/类
/**
 * Signs an HTTP post request for cases where OAuth 1.0 posts are
 * required instead of GET.
 *
 * @param unsignedUrl     - The unsigned URL
 * @param clientId        - The external provider assigned client id
 * @param clientSecret    - The external provider assigned client secret
 * @param token           - The access token
 * @param tokenSecret     - The 'secret' parameter to be used (Note: token secret != client secret)
 * @param oAuthParameters - Any additional parameters
 * @return The request to be signed and sent to external data provider.
 */
public static HttpRequestBase getSignedRequest(HttpMethod method,
                                               String unsignedUrl,
                                               String clientId,
                                               String clientSecret,
                                               String token,
                                               String tokenSecret,
                                               Map<String, String> oAuthParameters) throws ShimException {

    URL requestUrl = buildSignedUrl(unsignedUrl, clientId, clientSecret, token, tokenSecret, oAuthParameters);
    String[] signedParams = requestUrl.toString().split("\\?")[1].split("&");

    HttpRequestBase postRequest = method == HttpMethod.GET ?
        new HttpGet(unsignedUrl) : new HttpPost(unsignedUrl);
    String oauthHeader = "";
    for (String signedParam : signedParams) {
        String[] parts = signedParam.split("=");
        oauthHeader += parts[0] + "=\"" + parts[1] + "\",";
    }
    oauthHeader = "OAuth " + oauthHeader.substring(0, oauthHeader.length() - 1);
    postRequest.setHeader("Authorization", oauthHeader);
    CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(clientId, clientSecret);
    consumer.setSendEmptyTokens(false);
    if (token != null) {
        consumer.setTokenWithSecret(token, tokenSecret);
    }
    try {
        consumer.sign(postRequest);
        return postRequest;
    } catch (
        OAuthMessageSignerException
            | OAuthExpectationFailedException
            | OAuthCommunicationException e) {
        e.printStackTrace();
        throw new ShimException("Could not sign POST request, cannot continue");
    }
}
 
开发者ID:openmhealth,项目名称:shimmer,代码行数:49,代码来源:OAuth1Utils.java

示例7: signRequest

import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //导入方法依赖的package包/类
private void signRequest(HttpUriRequest request)
		throws OAuthMessageSignerException,
		OAuthExpectationFailedException, OAuthCommunicationException {
	CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(
			consumerKey, consumerSecret);
	consumer.setTokenWithSecret(accessToken.getToken(),
			accessToken.getTokenSecret());
	consumer.sign(request);
}
 
开发者ID:fsiu,项目名称:dw2020,代码行数:10,代码来源:PxApi.java

示例8: signRequest

import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //导入方法依赖的package包/类
private boolean signRequest(HttpUriRequest request) {
    try {
        CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(
                consumerKey, consumerSecret);
        consumer.setTokenWithSecret(accessToken.getToken(),
                accessToken.getTokenSecret());
        consumer.sign(request);
        return true;
    } catch (Exception e) {
        Log.e(TAG, "Error trying to sign the request.", e);
        return false;
    }
}
 
开发者ID:marc-ashman,项目名称:500px,代码行数:14,代码来源:CustomPxApi.java

示例9: amzaSyncClient

import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //导入方法依赖的package包/类
private AmzaSyncClient amzaSyncClient(AmzaSyncSenderConfig config) throws Exception {
    if (config.loopback) {
        return syncReceiver;
    } else {
        String consumerKey = StringUtils.trimToNull(config.oAuthConsumerKey);
        String consumerSecret = StringUtils.trimToNull(config.oAuthConsumerSecret);
        String consumerMethod = StringUtils.trimToNull(config.oAuthConsumerMethod);
        if (consumerKey == null || consumerSecret == null || consumerMethod == null) {
            throw new IllegalStateException("OAuth consumer has not been configured");
        }

        consumerMethod = consumerMethod.toLowerCase();
        if (!consumerMethod.equals("hmac") && !consumerMethod.equals("rsa")) {
            throw new IllegalStateException("OAuth consumer method must be one of HMAC or RSA");
        }

        String scheme = config.senderScheme;
        String host = config.senderHost;
        int port = config.senderPort;

        OAuthSigner authSigner = (request) -> {
            CommonsHttpOAuthConsumer oAuthConsumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);
            oAuthConsumer.setMessageSigner(new HmacSha1MessageSigner());
            oAuthConsumer.setTokenWithSecret(consumerKey, consumerSecret);
            return oAuthConsumer.sign(request);
        };

        HttpClient httpClient = HttpRequestHelperUtils.buildHttpClient(scheme.equals("https"),
            config.allowSelfSignedCerts,
            authSigner,
            host,
            port,
            syncConfig.getSyncSenderSocketTimeout());

        return new HttpAmzaSyncClient(httpClient,
            mapper,
            "/api/sync/v1/commit/rows",
            "/api/sync/v1/ensure/partition");
    }
}
 
开发者ID:jivesoftware,项目名称:amza,代码行数:41,代码来源:AmzaSyncSenders.java


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