當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。