Index: trunk/src/oauth/signpost/AbstractOAuthConsumer.java
===================================================================
--- trunk/src/oauth/signpost/AbstractOAuthConsumer.java (revision 10746)
+++ trunk/src/oauth/signpost/AbstractOAuthConsumer.java (revision 10831)
@@ -55,7 +55,7 @@
// these are the params which will be passed to the message signer
private HttpParameters requestParameters;
-
+
private boolean sendEmptyTokens;
-
+
final private Random random = new Random(System.nanoTime());
@@ -67,4 +67,5 @@
}
+ @Override
public void setMessageSigner(OAuthMessageSigner messageSigner) {
this.messageSigner = messageSigner;
@@ -72,12 +73,15 @@
}
+ @Override
public void setSigningStrategy(SigningStrategy signingStrategy) {
this.signingStrategy = signingStrategy;
}
+ @Override
public void setAdditionalParameters(HttpParameters additionalParameters) {
this.additionalParameters = additionalParameters;
}
+ @Override
public synchronized HttpRequest sign(HttpRequest request) throws OAuthMessageSignerException,
OAuthExpectationFailedException, OAuthCommunicationException {
@@ -116,4 +120,5 @@
}
+ @Override
public synchronized HttpRequest sign(Object request) throws OAuthMessageSignerException,
OAuthExpectationFailedException, OAuthCommunicationException {
@@ -121,4 +126,5 @@
}
+ @Override
public synchronized String sign(String url) throws OAuthMessageSignerException,
OAuthExpectationFailedException, OAuthCommunicationException {
@@ -147,4 +153,5 @@
protected abstract HttpRequest wrap(Object request);
+ @Override
public void setTokenWithSecret(String token, String tokenSecret) {
this.token = token;
@@ -152,16 +159,20 @@
}
+ @Override
public String getToken() {
return token;
}
+ @Override
public String getTokenSecret() {
return messageSigner.getTokenSecret();
}
+ @Override
public String getConsumerKey() {
return this.consumerKey;
}
+ @Override
public String getConsumerSecret() {
return this.consumerSecret;
@@ -207,8 +218,10 @@
}
+ @Override
public HttpParameters getRequestParameters() {
return requestParameters;
}
+ @Override
public void setSendEmptyTokens(boolean enable) {
this.sendEmptyTokens = enable;
Index: trunk/src/oauth/signpost/AbstractOAuthProvider.java
===================================================================
--- trunk/src/oauth/signpost/AbstractOAuthProvider.java (revision 10746)
+++ trunk/src/oauth/signpost/AbstractOAuthProvider.java (revision 10831)
@@ -59,4 +59,5 @@
}
+ @Override
public synchronized String retrieveRequestToken(OAuthConsumer consumer, String callbackUrl,
String... customOAuthParams) throws OAuthMessageSignerException,
@@ -90,4 +91,5 @@
}
+ @Override
public synchronized void retrieveAccessToken(OAuthConsumer consumer, String oauthVerifier,
String... customOAuthParams) throws OAuthMessageSignerException,
@@ -291,4 +293,5 @@
}
+ @Override
public HttpParameters getResponseParameters() {
return responseParameters;
@@ -308,40 +311,50 @@
}
+ @Override
public void setResponseParameters(HttpParameters parameters) {
this.responseParameters = parameters;
}
+ @Override
public void setOAuth10a(boolean isOAuth10aProvider) {
this.isOAuth10a = isOAuth10aProvider;
}
+ @Override
public boolean isOAuth10a() {
return isOAuth10a;
}
+ @Override
public String getRequestTokenEndpointUrl() {
return this.requestTokenEndpointUrl;
}
+ @Override
public String getAccessTokenEndpointUrl() {
return this.accessTokenEndpointUrl;
}
+ @Override
public String getAuthorizationWebsiteUrl() {
return this.authorizationWebsiteUrl;
}
+ @Override
public void setRequestHeader(String header, String value) {
defaultHeaders.put(header, value);
}
+ @Override
public Map
- *
+ *
*
* // exchange the arguments with the actual token/secret pair
* OAuthConsumer consumer = new DefaultOAuthConsumer("1234", "5678");
- *
+ *
* URL url = new URL("http://example.com/protected.xml");
* HttpURLConnection request = (HttpURLConnection) url.openConnection();
- *
+ *
* consumer.sign(request);
- *
+ *
* request.connect();
*
- *
+ *
*
* OAuthProvider provider = new DefaultOAuthProvider("http://twitter.com/oauth/request_token", @@ -49,9 +47,9 @@ * *- * + * *
* String url = provider.retrieveRequestToken(consumer, "http://www.example.com/callback"); *- * + * * *@@ -64,9 +62,9 @@ *
*- * + * *
* provider.retrieveAccessToken(consumer, nullOrVerifierCode); *- * + * * *@@ -78,7 +76,5 @@ * The consumer used during token handshakes is now ready for signing. *
- * - * @see DefaultOAuthProvider - * @see DefaultOAuthConsumer + * * @see OAuthProviderListener */ @@ -95,5 +91,5 @@ * unauthorized request token and token secret set. * - * + * * @param consumer * the {@link OAuthConsumer} that should be used to sign the request @@ -143,5 +139,5 @@ * access token and token secret set. * - * + * * @param consumer * the {@link OAuthConsumer} that should be used to sign the request @@ -187,5 +183,5 @@ * parameters contained in the server response. It's the caller's * responsibility that any OAuth parameters be removed beforehand. - * + * * @param parameters * the map of query parameters served by the service provider in the @@ -198,5 +194,5 @@ * which are sent to retrieve tokens. @deprecated THIS METHOD HAS BEEN * DEPRECATED. Use {@link OAuthProviderListener} to customize requests. - * + * * @param header * The header name (e.g. 'WWW-Authenticate') Index: trunk/src/oauth/signpost/basic/DefaultOAuthConsumer.java =================================================================== --- trunk/src/oauth/signpost/basic/DefaultOAuthConsumer.java (revision 10746) +++ (revision ) @@ -1,45 +1,0 @@ -/* Copyright (c) 2009 Matthias Kaeppler - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package oauth.signpost.basic; - -import java.net.HttpURLConnection; - -import oauth.signpost.AbstractOAuthConsumer; -import oauth.signpost.http.HttpRequest; - -/** - * The default implementation for an OAuth consumer. Only supports signing - * {@link java.net.HttpURLConnection} type requests. - * - * @author Matthias Kaeppler - */ -public class DefaultOAuthConsumer extends AbstractOAuthConsumer { - - private static final long serialVersionUID = 1L; - - public DefaultOAuthConsumer(String consumerKey, String consumerSecret) { - super(consumerKey, consumerSecret); - } - - @Override - protected HttpRequest wrap(Object request) { - if (!(request instanceof HttpURLConnection)) { - throw new IllegalArgumentException( - "The default consumer expects requests of type java.net.HttpURLConnection"); - } - return new HttpURLConnectionRequestAdapter((HttpURLConnection) request); - } - -} Index: trunk/src/oauth/signpost/basic/DefaultOAuthProvider.java =================================================================== --- trunk/src/oauth/signpost/basic/DefaultOAuthProvider.java (revision 10746) +++ (revision ) @@ -1,59 +1,0 @@ -/* - * Copyright (c) 2009 Matthias Kaeppler Licensed under the Apache License, - * Version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law - * or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the specific language - * governing permissions and limitations under the License. - */ -package oauth.signpost.basic; - -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; - -import oauth.signpost.AbstractOAuthProvider; -import oauth.signpost.http.HttpRequest; -import oauth.signpost.http.HttpResponse; - -/** - * This default implementation uses {@link java.net.HttpURLConnection} type GET - * requests to receive tokens from a service provider. - * - * @author Matthias Kaeppler - */ -public class DefaultOAuthProvider extends AbstractOAuthProvider { - - private static final long serialVersionUID = 1L; - - public DefaultOAuthProvider(String requestTokenEndpointUrl, String accessTokenEndpointUrl, - String authorizationWebsiteUrl) { - super(requestTokenEndpointUrl, accessTokenEndpointUrl, authorizationWebsiteUrl); - } - - protected HttpRequest createRequest(String endpointUrl) throws MalformedURLException, - IOException { - HttpURLConnection connection = (HttpURLConnection) new URL(endpointUrl).openConnection(); - connection.setRequestMethod("POST"); - connection.setAllowUserInteraction(false); - connection.setRequestProperty("Content-Length", "0"); - return new HttpURLConnectionRequestAdapter(connection); - } - - protected HttpResponse sendRequest(HttpRequest request) throws IOException { - HttpURLConnection connection = (HttpURLConnection) request.unwrap(); - connection.connect(); - return new HttpURLConnectionResponseAdapter(connection); - } - - @Override - protected void closeConnection(HttpRequest request, HttpResponse response) { - HttpURLConnection connection = (HttpURLConnection) request.unwrap(); - if (connection != null) { - connection.disconnect(); - } - } -} Index: trunk/src/oauth/signpost/basic/HttpURLConnectionRequestAdapter.java =================================================================== --- trunk/src/oauth/signpost/basic/HttpURLConnectionRequestAdapter.java (revision 10746) +++ (revision ) @@ -1,63 +1,0 @@ -package oauth.signpost.basic; - -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import oauth.signpost.http.HttpRequest; - -public class HttpURLConnectionRequestAdapter implements HttpRequest { - - protected HttpURLConnection connection; - - public HttpURLConnectionRequestAdapter(HttpURLConnection connection) { - this.connection = connection; - } - - public String getMethod() { - return connection.getRequestMethod(); - } - - public String getRequestUrl() { - return connection.getURL().toExternalForm(); - } - - public void setRequestUrl(String url) { - // can't do - } - - public void setHeader(String name, String value) { - connection.setRequestProperty(name, value); - } - - public String getHeader(String name) { - return connection.getRequestProperty(name); - } - - public MapgetAllHeaders() { - Map > origHeaders = connection.getRequestProperties(); - Map headers = new HashMap (origHeaders.size()); - for (String name : origHeaders.keySet()) { - List values = origHeaders.get(name); - if (!values.isEmpty()) { - headers.put(name, values.get(0)); - } - } - return headers; - } - - public InputStream getMessagePayload() throws IOException { - return null; - } - - public String getContentType() { - return connection.getRequestProperty("Content-Type"); - } - - public HttpURLConnection unwrap() { - return connection; - } -} Index: trunk/src/oauth/signpost/basic/HttpURLConnectionResponseAdapter.java =================================================================== --- trunk/src/oauth/signpost/basic/HttpURLConnectionResponseAdapter.java (revision 10746) +++ (revision ) @@ -1,36 +1,0 @@ -package oauth.signpost.basic; - -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; - -import oauth.signpost.http.HttpResponse; - -public class HttpURLConnectionResponseAdapter implements HttpResponse { - - private HttpURLConnection connection; - - public HttpURLConnectionResponseAdapter(HttpURLConnection connection) { - this.connection = connection; - } - - public InputStream getContent() throws IOException { - try { - return connection.getInputStream(); - } catch (IOException e) { - return connection.getErrorStream(); - } - } - - public int getStatusCode() throws IOException { - return connection.getResponseCode(); - } - - public String getReasonPhrase() throws Exception { - return connection.getResponseMessage(); - } - - public Object unwrap() { - return connection; - } -} Index: trunk/src/oauth/signpost/basic/UrlStringRequestAdapter.java =================================================================== --- trunk/src/oauth/signpost/basic/UrlStringRequestAdapter.java (revision 10746) +++ trunk/src/oauth/signpost/basic/UrlStringRequestAdapter.java (revision 10831) @@ -16,35 +16,44 @@ } + @Override public String getMethod() { return "GET"; } + @Override public String getRequestUrl() { return url; } + @Override public void setRequestUrl(String url) { this.url = url; } + @Override public void setHeader(String name, String value) { } + @Override public String getHeader(String name) { return null; } + @Override public Map getAllHeaders() { return Collections.emptyMap(); } + @Override public InputStream getMessagePayload() throws IOException { return null; } + @Override public String getContentType() { return null; } + @Override public Object unwrap() { return url; Index: trunk/src/oauth/signpost/http/HttpParameters.java =================================================================== --- trunk/src/oauth/signpost/http/HttpParameters.java (revision 10746) +++ trunk/src/oauth/signpost/http/HttpParameters.java (revision 10831) @@ -30,10 +30,9 @@ * A multi-map of HTTP request parameters. Each key references a * {@link SortedSet} of parameters collected from the request during message - * signing. Parameter values are sorted as per {@linkplain http - * ://oauth.net/core/1.0a/#anchor13}. Every key/value pair will be - * percent-encoded upon insertion. This class has special semantics tailored to - * being useful for message signing; it's not a general purpose collection class - * to handle request parameters. - * + * signing. Parameter values are sorted as per {@linkplain http://oauth.net/core/1.0a/#anchor13}. + * Every key/value pair will be percent-encoded upon insertion. + * This class has special semantics tailored to being useful for message signing; + * it's not a general purpose collection class to handle request parameters. + * * @author Matthias Kaeppler */ @@ -41,6 +40,7 @@ public class HttpParameters implements Map >, Serializable { - private TreeMap > wrappedMap = new TreeMap >(); - + private TreeMap > wrappedMap = new TreeMap<>(); + + @Override public SortedSet put(String key, SortedSet value) { return wrappedMap.put(key, value); @@ -62,5 +62,5 @@ * Convenience method to add a single value for the parameter specified by * 'key'. - * + * * @param key * the parameter name @@ -76,5 +76,5 @@ * Convenience method to add a single value for the parameter specified by * 'key'. - * + * * @param key * the parameter name @@ -91,5 +91,5 @@ SortedSet values = wrappedMap.get(key); if (values == null) { - values = new TreeSet (); + values = new TreeSet<>(); wrappedMap.put( key, values); } @@ -105,5 +105,5 @@ * Convenience method to allow for storing null values. {@link #put} doesn't * allow null values, because that would be ambiguous. - * + * * @param key * the parameter name @@ -116,4 +116,5 @@ } + @Override public void putAll(Map extends String, ? extends SortedSet > m) { wrappedMap.putAll(m); @@ -138,5 +139,5 @@ /** * Convenience method to merge a Map >. - * + * * @param m * the map @@ -146,5 +147,5 @@ SortedSet vals = get(key); if (vals == null) { - vals = new TreeSet (); + vals = new TreeSet<>(); put(key, vals); } @@ -153,4 +154,5 @@ } + @Override public SortedSet get(Object key) { return wrappedMap.get(key); @@ -159,5 +161,5 @@ /** * Convenience method for {@link #getFirst(key, false)}. - * + * * @param key * the parameter name (must be percent encoded if it contains unsafe @@ -176,5 +178,5 @@ * (that's because upon storing values in this map, keys get * percent-encoded). - * + * * @param key * the parameter name (must be percent encoded if it contains unsafe @@ -196,5 +198,5 @@ * Concatenates all values for the given key to a list of key/value pairs * suitable for use in a URL query string. - * + * * @param key * the parameter name @@ -208,5 +210,5 @@ * Concatenates all values for the given key to a list of key/value pairs * suitable for use in a URL query string. - * + * * @param key * the parameter name @@ -237,5 +239,5 @@ return sb.toString(); } - + public String getAsHeaderElement(String key) { String value = getFirst(key); @@ -246,8 +248,10 @@ } + @Override public boolean containsKey(Object key) { return wrappedMap.containsKey(key); } + @Override public boolean containsValue(Object value) { for (Set values : wrappedMap.values()) { @@ -259,4 +263,5 @@ } + @Override public int size() { int count = 0; @@ -267,24 +272,30 @@ } + @Override public boolean isEmpty() { return wrappedMap.isEmpty(); } + @Override public void clear() { wrappedMap.clear(); } + @Override public SortedSet remove(Object key) { return wrappedMap.remove(key); } + @Override public Set keySet() { return wrappedMap.keySet(); } + @Override public Collection > values() { return wrappedMap.values(); } + @Override public Set >> entrySet() { return wrappedMap.entrySet(); Index: trunk/src/oauth/signpost/http/HttpRequest.java =================================================================== --- trunk/src/oauth/signpost/http/HttpRequest.java (revision 10746) +++ trunk/src/oauth/signpost/http/HttpRequest.java (revision 10831) @@ -6,5 +6,4 @@ import oauth.signpost.OAuthConsumer; -import oauth.signpost.basic.HttpURLConnectionRequestAdapter; /** @@ -14,6 +13,5 @@ * currently supported, you'll have to write an adapter which implements this * interface and a custom {@link OAuthConsumer} which performs the wrapping. - * - * @see HttpURLConnectionRequestAdapter + * * @author Matthias Kaeppler */ @@ -38,5 +36,5 @@ /** * Returns the wrapped request object, in case you must work directly on it. - * + * * @return the wrapped request object */ Index: trunk/src/oauth/signpost/signature/AuthorizationHeaderSigningStrategy.java =================================================================== --- trunk/src/oauth/signpost/signature/AuthorizationHeaderSigningStrategy.java (revision 10746) +++ trunk/src/oauth/signpost/signature/AuthorizationHeaderSigningStrategy.java (revision 10831) @@ -9,5 +9,5 @@ /** * Writes to the HTTP Authorization header field. - * + * * @author Matthias Kaeppler */ @@ -16,4 +16,5 @@ private static final long serialVersionUID = 1L; + @Override public String writeSignature(String signature, HttpRequest request, HttpParameters requestParameters) { Index: trunk/src/oauth/signpost/signature/PlainTextMessageSigner.java =================================================================== --- trunk/src/oauth/signpost/signature/PlainTextMessageSigner.java (revision 10746) +++ (revision ) @@ -1,36 +1,0 @@ -/* Copyright (c) 2009 Matthias Kaeppler - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package oauth.signpost.signature; - -import oauth.signpost.OAuth; -import oauth.signpost.exception.OAuthMessageSignerException; -import oauth.signpost.http.HttpRequest; -import oauth.signpost.http.HttpParameters; - -@SuppressWarnings("serial") -public class PlainTextMessageSigner extends OAuthMessageSigner { - - @Override - public String getSignatureMethod() { - return "PLAINTEXT"; - } - - @Override - public String sign(HttpRequest request, HttpParameters requestParams) - throws OAuthMessageSignerException { - return OAuth.percentEncode(getConsumerSecret()) + '&' - + OAuth.percentEncode(getTokenSecret()); - } -} Index: trunk/src/oauth/signpost/signature/QueryStringSigningStrategy.java =================================================================== --- trunk/src/oauth/signpost/signature/QueryStringSigningStrategy.java (revision 10746) +++ trunk/src/oauth/signpost/signature/QueryStringSigningStrategy.java (revision 10831) @@ -13,5 +13,5 @@ * the URL once the request has been instantiated, so there is no way to append * parameters to it. - * + * * @author Matthias Kaeppler */ @@ -20,4 +20,5 @@ private static final long serialVersionUID = 1L; + @Override public String writeSignature(String signature, HttpRequest request, HttpParameters requestParameters) {