Relaxed check to allow 'scope' parameter

This commit is contained in:
Pablo Fernandez committed 2010-10-20 17:06:03 -03:00
1 parent 5d86982421
commit 50b54fbfb6
1 file changed
+28 -3
@@ -2,18 +2,38 @@ package org.scribe.model;
import java.util.*; import java.util.*;
/**
* The representation of an OAuth HttpRequest.
*
* Adds OAuth-related functionality to the {@link Request}
*
* @author Pablo Fernandez
*/
public class OAuthRequest extends Request public class OAuthRequest extends Request
{ {
private static final String OAUTH_PREFIX = "oauth_"; private static final String OAUTH_PREFIX = "oauth_";
private Map<String, String> oauthParameters; private Map<String, String> oauthParameters;
/**
* Default constructor.
*
* @param verb Http verb/method
* @param url resource URL
*/
public OAuthRequest(Verb verb, String url) public OAuthRequest(Verb verb, String url)
{ {
super(verb, url); super(verb, url);
this.oauthParameters = new HashMap<String, String>(); this.oauthParameters = new HashMap<String, String>();
} }
/**
* Adds an OAuth parameter.
*
* @param key name of the parameter
* @param value value of the parameter
*
* @throws IllegalArgumentException if the parameter is not an OAuth parameter
*/
public void addOAuthParameter(String key, String value) public void addOAuthParameter(String key, String value)
{ {
oauthParameters.put(checkKey(key), value); oauthParameters.put(checkKey(key), value);
@@ -21,15 +41,20 @@ public class OAuthRequest extends Request
private String checkKey(String key) private String checkKey(String key)
{ {
if (!key.startsWith(OAUTH_PREFIX)) if (!key.startsWith(OAUTH_PREFIX) || key.equals(OAuthConstants.SCOPE))
{ {
throw new IllegalArgumentException(String.format("OAuth parameters must start with '%s'", OAUTH_PREFIX)); throw new IllegalArgumentException(String.format("OAuth parameters must either be %s or start with '%s'", OAuthConstants.SCOPE, OAUTH_PREFIX));
} else } else
{ {
return key; return key;
} }
} }
/**
* Returns the {@link Map} containing the key-value pair of parameters.
*
* @return parameters as map
*/
public Map<String, String> getOauthParameters() public Map<String, String> getOauthParameters()
{ {
return oauthParameters; return oauthParameters;