本文整理汇总了Java中net.oauth.OAuthMessage.getParameters方法的典型用法代码示例。如果您正苦于以下问题:Java OAuthMessage.getParameters方法的具体用法?Java OAuthMessage.getParameters怎么用?Java OAuthMessage.getParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.oauth.OAuthMessage
的用法示例。
在下文中一共展示了OAuthMessage.getParameters方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBaseString
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
public static String getBaseString(OAuthMessage message)
throws IOException, URISyntaxException {
List<Map.Entry<String, String>> parameters;
String url = message.URL;
int q = url.indexOf('?');
if (q < 0) {
parameters = message.getParameters();
} else {
// Combine the URL query string with the other parameters:
parameters = new ArrayList<Map.Entry<String, String>>();
parameters.addAll(OAuth.decodeForm(message.URL.substring(q + 1)));
parameters.addAll(message.getParameters());
url = url.substring(0, q);
}
return OAuth.percentEncode(message.method.toUpperCase()) + '&'
+ OAuth.percentEncode(normalizeUrl(url)) + '&'
+ OAuth.percentEncode(normalizeParameters(parameters));
}
示例2: signParameters
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
@Override
public Map<String, String> signParameters(Map<String, String> parameters, String key, String secret, String url, String method) throws LtiSigningException {
OAuthMessage oam = new OAuthMessage(method, url, parameters.entrySet());
OAuthConsumer cons = new OAuthConsumer(null, key, secret, null);
OAuthAccessor acc = new OAuthAccessor(cons);
try {
oam.addRequiredParameters(acc);
Map<String, String> signedParameters = new HashMap<>();
for(Map.Entry<String, String> param : oam.getParameters()){
signedParameters.put(param.getKey(), param.getValue());
}
return signedParameters;
} catch (OAuthException |IOException |URISyntaxException e) {
throw new LtiSigningException("Error signing LTI request.", e);
}
}
示例3: 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();
}
示例4: buildResponse
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
/**
* Builds an XOAUTH SASL client response.
*
* @param userEmail The email address of the user, for example
* "[email protected]".
* @param protocol The XoauthProtocol for which to generate an authentication
* string.
* @param tokenAndTokenSecret The OAuth token and token_secret.
* @param consumer The OAuth consumer that is trying to authenticate.
*
* @return A byte array containing the auth string suitable for being returned
* from {@code SaslClient.evaluateChallenge}. It needs to be base64-encoded
* before actually being sent over the network.
*/
public byte[] buildResponse(String userEmail,
XoauthProtocol protocol,
String oauthToken,
String oauthTokenSecret,
OAuthConsumer consumer)
throws IOException, OAuthException, URISyntaxException {
OAuthAccessor accessor = new OAuthAccessor(consumer);
accessor.tokenSecret = oauthTokenSecret;
Map<String, String> parameters = new HashMap<String, String>();
parameters.put(OAuth.OAUTH_SIGNATURE_METHOD, "HMAC-SHA1");
parameters.put(OAuth.OAUTH_TOKEN, oauthToken);
String url = String.format("https://mail.google.com/mail/b/%s/%s/",
userEmail,
protocol.getName());
OAuthMessage message = new OAuthMessage(
"GET",
url,
parameters.entrySet());
message.addRequiredParameters(accessor);
StringBuilder authString = new StringBuilder();
authString.append("GET ");
authString.append(url);
authString.append(" ");
int i = 0;
for (Map.Entry<String, String> entry : message.getParameters()) {
if (i++ > 0) {
authString.append(",");
}
authString.append(OAuth.percentEncode(entry.getKey()));
authString.append("=\"");
authString.append(OAuth.percentEncode(entry.getValue()));
authString.append("\"");
}
return authString.toString().getBytes();
}
示例5: 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();
}
示例6: selectOAuthParams
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
private static List<Map.Entry<String, String>> selectOAuthParams(OAuthMessage message)
throws IOException {
List<Map.Entry<String, String>> result = Lists.newArrayList();
for (Map.Entry<String, String> param : message.getParameters()) {
if (isContainerInjectedParameter(param.getKey())) {
result.add(param);
}
}
return result;
}
示例7: getParameters
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
public static List<Entry<String, String>> getParameters(OAuthMessage message) {
try {
return message.getParameters();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例8: 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);
}
}
示例9: doGet
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws IOException {
response.setHeader("Cache-Control", "no-cache");
final OAuthMessage msg = OAuthServlet.getMessage(request, null);
// System.out.print(Thread.currentThread().getName() + " " + msg.method + " ...");
// System.out.flush();
response.setCharacterEncoding(msg.getBodyEncoding());
final ServletOutputStream out = response.getOutputStream();
out.print(msg.method + "\n");
out.print(OAuthSignatureMethod.normalizeParameters(msg.getParameters())
+ "\n");
if ("true".equalsIgnoreCase(msg.getParameter("echoHeader"))) {
{
URL url = new URL(msg.URL);
String path = url.getPath();
String queryString = request.getQueryString();
if (queryString != null) {
path += ("?" + queryString);
}
out.println(msg.method + " " + path);
}
for (Enumeration<String> names = request.getHeaderNames(); names
.hasMoreElements();) {
final String name = names.nextElement();
for (Enumeration<String> values = request.getHeaders(name); values
.hasMoreElements();) {
final String value = values.nextElement();
out.println(name + ": " + value);
}
}
out.println();
}
if ("true".equalsIgnoreCase(msg.getParameter("echoParameters"))) {
final List<Map.Entry<String, String>> parameters = msg
.getParameters();
for (Map.Entry<String, String> parameter : parameters) {
out.println(parameter.getKey() + ": " + parameter.getValue());
}
out.println();
}
final String echoData = msg.getParameter("echoData");
if (echoData != null) {
int n = Integer.parseInt(echoData);
for (; n > 0; n -= (DATA.length + 1)) {
int len = Math.min(n - 1, DATA.length);
out.write(DATA, 0, len);
out.write('\n');
}
out.write('\n');
}
if (!"false".equalsIgnoreCase(msg.getParameter("echoBody"))) {
out.print(request.getHeader("Content-Length") + "\n");
InputStream in = msg.getBodyAsStream();
byte[] body = readAll(in);
out.write(body);
}
// out.close();
// System.out.println("... done");
}
示例10: sign
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
public FakeHttpServletRequest sign(String consumerKey, String consumerSecret, String requestor,
String token, String tokenSecret, OAuthParamLocation paramLocationEnum,
BodySigning bodySigning)
throws Exception {
FakeHttpServletRequest request = new FakeHttpServletRequest(url);
List<OAuth.Parameter> oauthParams = Lists.newArrayList();
UriBuilder target = new UriBuilder(Uri.parse(url));
String query = target.getQuery();
target.setQuery(null);
oauthParams.addAll(OAuth.decodeForm(query));
if (body != null) {
if (OAuth.isFormEncoded(contentType)) {
oauthParams.addAll(OAuth.decodeForm(body));
} else if (bodySigning == BodySigning.LEGACY) {
oauthParams.add(new OAuth.Parameter(body, ""));
} else if (bodySigning == BodySigning.HASH) {
oauthParams.add(
new OAuth.Parameter(OAuthConstants.OAUTH_BODY_HASH,
new String(Base64.encodeBase64(DigestUtils.sha(body.getBytes())), "UTF-8")));
}
}
oauthParams.add(new OAuth.Parameter(OAuth.OAUTH_CONSUMER_KEY, consumerKey));
oauthParams.add(new OAuth.Parameter("xoauth_requestor_id", requestor));
OAuthConsumer consumer = new OAuthConsumer(null,consumerKey,consumerSecret, null);
OAuthAccessor accessor = new OAuthAccessor(consumer);
if (!StringUtils.isEmpty(token)) {
accessor.accessToken = token;
accessor.tokenSecret = tokenSecret;
}
OAuthMessage message = accessor.newRequestMessage(method, target.toString(), oauthParams);
List<Map.Entry<String, String>> entryList = selectOAuthParams(message);
switch (paramLocationEnum) {
case AUTH_HEADER:
request.setHeader("Authorization", getAuthorizationHeader(entryList));
break;
case POST_BODY:
if (!OAuth.isFormEncoded(contentType)) {
throw new RuntimeException(
"OAuth param location can only be post_body if post body is of " +
"type x-www-form-urlencoded");
}
// All message params should be added if oauth params are added to body
for (Map.Entry<String, String> param : message.getParameters()) {
request.setParameter(param.getKey(), true, param.getValue());
}
String oauthData = OAuth.formEncode(message.getParameters());
request.setPostData(CharsetUtil.getUtf8Bytes(oauthData));
break;
case URI_QUERY:
request.setQueryString(Uri.parse(OAuth.addParameters(url, entryList)).getQuery());
break;
}
if (body != null && paramLocationEnum != OAuthParamLocation.POST_BODY) {
request.setContentType(contentType);
request.setPostData(body, "UTF-8");
if (contentType.contains(OAuth.FORM_ENCODED)) {
List<OAuth.Parameter> bodyParams = OAuth.decodeForm(body);
for (OAuth.Parameter bodyParam : bodyParams) {
request.setParameter(bodyParam.getKey(), bodyParam.getValue());
}
}
}
request.setMethod(method);
return request;
}