Changeset 10831 in josm


Ignore:
Timestamp:
2016-08-18T00:21:03+02:00 (8 years ago)
Author:
Don-vip
Message:

see #13232 - cleanup OAuth signpost code:

  • remove classes unused by JOSM
  • add missing @Override annotations
Location:
trunk/src/oauth/signpost
Files:
5 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/oauth/signpost/AbstractOAuthConsumer.java

    r6849 r10831  
    5555    // these are the params which will be passed to the message signer
    5656    private HttpParameters requestParameters;
    57    
     57
    5858    private boolean sendEmptyTokens;
    59    
     59
    6060    final private Random random = new Random(System.nanoTime());
    6161
     
    6767    }
    6868
     69    @Override
    6970    public void setMessageSigner(OAuthMessageSigner messageSigner) {
    7071        this.messageSigner = messageSigner;
     
    7273    }
    7374
     75    @Override
    7476    public void setSigningStrategy(SigningStrategy signingStrategy) {
    7577        this.signingStrategy = signingStrategy;
    7678    }
    7779
     80    @Override
    7881    public void setAdditionalParameters(HttpParameters additionalParameters) {
    7982        this.additionalParameters = additionalParameters;
    8083    }
    8184
     85    @Override
    8286    public synchronized HttpRequest sign(HttpRequest request) throws OAuthMessageSignerException,
    8387            OAuthExpectationFailedException, OAuthCommunicationException {
     
    116120    }
    117121
     122    @Override
    118123    public synchronized HttpRequest sign(Object request) throws OAuthMessageSignerException,
    119124            OAuthExpectationFailedException, OAuthCommunicationException {
     
    121126    }
    122127
     128    @Override
    123129    public synchronized String sign(String url) throws OAuthMessageSignerException,
    124130            OAuthExpectationFailedException, OAuthCommunicationException {
     
    147153    protected abstract HttpRequest wrap(Object request);
    148154
     155    @Override
    149156    public void setTokenWithSecret(String token, String tokenSecret) {
    150157        this.token = token;
     
    152159    }
    153160
     161    @Override
    154162    public String getToken() {
    155163        return token;
    156164    }
    157165
     166    @Override
    158167    public String getTokenSecret() {
    159168        return messageSigner.getTokenSecret();
    160169    }
    161170
     171    @Override
    162172    public String getConsumerKey() {
    163173        return this.consumerKey;
    164174    }
    165175
     176    @Override
    166177    public String getConsumerSecret() {
    167178        return this.consumerSecret;
     
    207218    }
    208219
     220    @Override
    209221    public HttpParameters getRequestParameters() {
    210222        return requestParameters;
    211223    }
    212224
     225    @Override
    213226    public void setSendEmptyTokens(boolean enable) {
    214227        this.sendEmptyTokens = enable;
  • trunk/src/oauth/signpost/AbstractOAuthProvider.java

    r9227 r10831  
    5959    }
    6060
     61    @Override
    6162    public synchronized String retrieveRequestToken(OAuthConsumer consumer, String callbackUrl,
    6263            String... customOAuthParams) throws OAuthMessageSignerException,
     
    9091    }
    9192
     93    @Override
    9294    public synchronized void retrieveAccessToken(OAuthConsumer consumer, String oauthVerifier,
    9395            String... customOAuthParams) throws OAuthMessageSignerException,
     
    291293    }
    292294
     295    @Override
    293296    public HttpParameters getResponseParameters() {
    294297        return responseParameters;
     
    308311    }
    309312
     313    @Override
    310314    public void setResponseParameters(HttpParameters parameters) {
    311315        this.responseParameters = parameters;
    312316    }
    313317
     318    @Override
    314319    public void setOAuth10a(boolean isOAuth10aProvider) {
    315320        this.isOAuth10a = isOAuth10aProvider;
    316321    }
    317322
     323    @Override
    318324    public boolean isOAuth10a() {
    319325        return isOAuth10a;
    320326    }
    321327
     328    @Override
    322329    public String getRequestTokenEndpointUrl() {
    323330        return this.requestTokenEndpointUrl;
    324331    }
    325332
     333    @Override
    326334    public String getAccessTokenEndpointUrl() {
    327335        return this.accessTokenEndpointUrl;
    328336    }
    329337
     338    @Override
    330339    public String getAuthorizationWebsiteUrl() {
    331340        return this.authorizationWebsiteUrl;
    332341    }
    333342
     343    @Override
    334344    public void setRequestHeader(String header, String value) {
    335345        defaultHeaders.put(header, value);
    336346    }
    337347
     348    @Override
    338349    public Map<String, String> getRequestHeaders() {
    339350        return defaultHeaders;
    340351    }
    341352
     353    @Override
    342354    public void setListener(OAuthProviderListener listener) {
    343355        this.listener = listener;
    344356    }
    345357
     358    @Override
    346359    public void removeListener(OAuthProviderListener listener) {
    347360        this.listener = null;
  • trunk/src/oauth/signpost/OAuthConsumer.java

    r6849 r10831  
    2525import oauth.signpost.signature.HmacSha1MessageSigner;
    2626import oauth.signpost.signature.OAuthMessageSigner;
    27 import oauth.signpost.signature.PlainTextMessageSigner;
    2827import oauth.signpost.signature.QueryStringSigningStrategy;
    2928import oauth.signpost.signature.SigningStrategy;
     
    3837 * HTTP messages are signed as follows:
    3938 * <p>
    40  * 
     39 *
    4140 * <pre>
    4241 * // exchange the arguments with the actual token/secret pair
    4342 * OAuthConsumer consumer = new DefaultOAuthConsumer(&quot;1234&quot;, &quot;5678&quot;);
    44  * 
     43 *
    4544 * URL url = new URL(&quot;http://example.com/protected.xml&quot;);
    4645 * HttpURLConnection request = (HttpURLConnection) url.openConnection();
    47  * 
     46 *
    4847 * consumer.sign(request);
    49  * 
     48 *
    5049 * request.connect();
    5150 * </pre>
    52  * 
     51 *
    5352 * </p>
    5453 * </p>
    55  * 
     54 *
    5655 * @author Matthias Kaeppler
    5756 */
     
    6160     * Sets the message signer that should be used to generate the OAuth
    6261     * signature.
    63      * 
     62     *
    6463     * @param messageSigner
    6564     *        the signer
    6665     * @see HmacSha1MessageSigner
    67      * @see PlainTextMessageSigner
    6866     */
    6967    public void setMessageSigner(OAuthMessageSigner messageSigner);
     
    7977     * as-is. <b>BE CAREFUL WITH THIS METHOD! Your service provider may decide
    8078     * to ignore any non-standard OAuth params when computing the signature.</b>
    81      * 
     79     *
    8280     * @param additionalParameters
    8381     *        the parameters
     
    8886     * Defines which strategy should be used to write a signature to an HTTP
    8987     * request.
    90      * 
     88     *
    9189     * @param signingStrategy
    9290     *        the strategy
     
    102100     * {@link OAuthProvider#retrieveRequestToken}, try setting this to true.
    103101     * </p>
    104      * 
     102     *
    105103     * @param enable
    106104     *        true or false
     
    112110     * required OAuth parameters) to it. Where these parameters are written
    113111     * depends on the current {@link SigningStrategy}.
    114      * 
     112     *
    115113     * @param request
    116114     *        the request to sign
     
    132130     * implementation must ensure that only those request types are passed which
    133131     * it supports.
    134      * 
     132     *
    135133     * @param request
    136134     *        the request to sign
     
    152150     * request that is being sent.
    153151     * </p>
    154      * 
     152     *
    155153     * @param url
    156154     *        the input URL. May have query parameters.
     
    166164    /**
    167165     * Sets the OAuth token and token secret used for message signing.
    168      * 
     166     *
    169167     * @param token
    170168     *        the token
     
    189187     * is the exact set of parameters that were used for creating the message
    190188     * signature.
    191      * 
     189     *
    192190     * @return the request parameters used for message signing
    193191     */
  • trunk/src/oauth/signpost/OAuthProvider.java

    r6849 r10831  
    1414import java.util.Map;
    1515
    16 import oauth.signpost.basic.DefaultOAuthConsumer;
    17 import oauth.signpost.basic.DefaultOAuthProvider;
    1816import oauth.signpost.exception.OAuthCommunicationException;
    1917import oauth.signpost.exception.OAuthExpectationFailedException;
     
    3533 * resource authorization, e.g.:
    3634 * </p>
    37  * 
     35 *
    3836 * <pre>
    3937 * OAuthProvider provider = new DefaultOAuthProvider(&quot;http://twitter.com/oauth/request_token&quot;,
     
    4947 * </p>
    5048 * <p>
    51  * 
     49 *
    5250 * <pre>
    5351 * String url = provider.retrieveRequestToken(consumer, &quot;http://www.example.com/callback&quot;);
    5452 * </pre>
    55  * 
     53 *
    5654 * </p>
    5755 * <p>
     
    6462 * </p>
    6563 * <p>
    66  * 
     64 *
    6765 * <pre>
    6866 * provider.retrieveAccessToken(consumer, nullOrVerifierCode);
    6967 * </pre>
    70  * 
     68 *
    7169 * </p>
    7270 * <p>
     
    7876 * The consumer used during token handshakes is now ready for signing.
    7977 * </p>
    80  *
    81  * @see DefaultOAuthProvider
    82  * @see DefaultOAuthConsumer
     78 *
    8379 * @see OAuthProviderListener
    8480 */
     
    9591     * unauthorized request token and token secret set.
    9692     * </p>
    97      * 
     93     *
    9894     * @param consumer
    9995     *        the {@link OAuthConsumer} that should be used to sign the request
     
    143139     * access token and token secret set.
    144140     * </p>
    145      * 
     141     *
    146142     * @param consumer
    147143     *        the {@link OAuthConsumer} that should be used to sign the request
     
    187183     * parameters contained in the server response. It's the caller's
    188184     * responsibility that any OAuth parameters be removed beforehand.
    189      * 
     185     *
    190186     * @param parameters
    191187     *        the map of query parameters served by the service provider in the
     
    198194     * which are sent to retrieve tokens. @deprecated THIS METHOD HAS BEEN
    199195     * DEPRECATED. Use {@link OAuthProviderListener} to customize requests.
    200      * 
     196     *
    201197     * @param header
    202198     *        The header name (e.g. 'WWW-Authenticate')
  • trunk/src/oauth/signpost/basic/UrlStringRequestAdapter.java

    r4231 r10831  
    1616    }
    1717
     18    @Override
    1819    public String getMethod() {
    1920        return "GET";
    2021    }
    2122
     23    @Override
    2224    public String getRequestUrl() {
    2325        return url;
    2426    }
    2527
     28    @Override
    2629    public void setRequestUrl(String url) {
    2730        this.url = url;
    2831    }
    2932
     33    @Override
    3034    public void setHeader(String name, String value) {
    3135    }
    3236
     37    @Override
    3338    public String getHeader(String name) {
    3439        return null;
    3540    }
    3641
     42    @Override
    3743    public Map<String, String> getAllHeaders() {
    3844        return Collections.emptyMap();
    3945    }
    4046
     47    @Override
    4148    public InputStream getMessagePayload() throws IOException {
    4249        return null;
    4350    }
    4451
     52    @Override
    4553    public String getContentType() {
    4654        return null;
    4755    }
    4856
     57    @Override
    4958    public Object unwrap() {
    5059        return url;
  • trunk/src/oauth/signpost/http/HttpParameters.java

    r6849 r10831  
    3030 * A multi-map of HTTP request parameters. Each key references a
    3131 * {@link SortedSet} of parameters collected from the request during message
    32  * signing. Parameter values are sorted as per {@linkplain http
    33  * ://oauth.net/core/1.0a/#anchor13}. Every key/value pair will be
    34  * percent-encoded upon insertion. This class has special semantics tailored to
    35  * being useful for message signing; it's not a general purpose collection class
    36  * to handle request parameters.
    37  *
     32 * signing. Parameter values are sorted as per {@linkplain http://oauth.net/core/1.0a/#anchor13}.
     33 * Every key/value pair will be percent-encoded upon insertion.
     34 * This class has special semantics tailored to being useful for message signing;
     35 * it's not a general purpose collection class to handle request parameters.
     36 *
    3837 * @author Matthias Kaeppler
    3938 */
     
    4140public class HttpParameters implements Map<String, SortedSet<String>>, Serializable {
    4241
    43     private TreeMap<String, SortedSet<String>> wrappedMap = new TreeMap<String, SortedSet<String>>();
    44 
     42    private TreeMap<String, SortedSet<String>> wrappedMap = new TreeMap<>();
     43
     44    @Override
    4545    public SortedSet<String> put(String key, SortedSet<String> value) {
    4646        return wrappedMap.put(key, value);
     
    6262     * Convenience method to add a single value for the parameter specified by
    6363     * 'key'.
    64      * 
     64     *
    6565     * @param key
    6666     *        the parameter name
     
    7676     * Convenience method to add a single value for the parameter specified by
    7777     * 'key'.
    78      * 
     78     *
    7979     * @param key
    8080     *        the parameter name
     
    9191         SortedSet<String> values = wrappedMap.get(key);
    9292         if (values == null) {
    93              values = new TreeSet<String>();
     93             values = new TreeSet<>();
    9494             wrappedMap.put( key, values);
    9595         }
     
    105105     * Convenience method to allow for storing null values. {@link #put} doesn't
    106106     * allow null values, because that would be ambiguous.
    107      * 
     107     *
    108108     * @param key
    109109     *        the parameter name
     
    116116    }
    117117
     118    @Override
    118119    public void putAll(Map<? extends String, ? extends SortedSet<String>> m) {
    119120        wrappedMap.putAll(m);
     
    138139    /**
    139140     * Convenience method to merge a Map<String, List<String>>.
    140      * 
     141     *
    141142     * @param m
    142143     *        the map
     
    146147            SortedSet<String> vals = get(key);
    147148            if (vals == null) {
    148                 vals = new TreeSet<String>();
     149                vals = new TreeSet<>();
    149150                put(key, vals);
    150151            }
     
    153154    }
    154155
     156    @Override
    155157    public SortedSet<String> get(Object key) {
    156158        return wrappedMap.get(key);
     
    159161    /**
    160162     * Convenience method for {@link #getFirst(key, false)}.
    161      * 
     163     *
    162164     * @param key
    163165     *        the parameter name (must be percent encoded if it contains unsafe
     
    176178     * (that's because upon storing values in this map, keys get
    177179     * percent-encoded).
    178      * 
     180     *
    179181     * @param key
    180182     *        the parameter name (must be percent encoded if it contains unsafe
     
    196198     * Concatenates all values for the given key to a list of key/value pairs
    197199     * suitable for use in a URL query string.
    198      * 
     200     *
    199201     * @param key
    200202     *        the parameter name
     
    208210     * Concatenates all values for the given key to a list of key/value pairs
    209211     * suitable for use in a URL query string.
    210      * 
     212     *
    211213     * @param key
    212214     *        the parameter name
     
    237239        return sb.toString();
    238240    }
    239    
     241
    240242    public String getAsHeaderElement(String key) {
    241243        String value = getFirst(key);
     
    246248    }
    247249
     250    @Override
    248251    public boolean containsKey(Object key) {
    249252        return wrappedMap.containsKey(key);
    250253    }
    251254
     255    @Override
    252256    public boolean containsValue(Object value) {
    253257        for (Set<String> values : wrappedMap.values()) {
     
    259263    }
    260264
     265    @Override
    261266    public int size() {
    262267        int count = 0;
     
    267272    }
    268273
     274    @Override
    269275    public boolean isEmpty() {
    270276        return wrappedMap.isEmpty();
    271277    }
    272278
     279    @Override
    273280    public void clear() {
    274281        wrappedMap.clear();
    275282    }
    276283
     284    @Override
    277285    public SortedSet<String> remove(Object key) {
    278286        return wrappedMap.remove(key);
    279287    }
    280288
     289    @Override
    281290    public Set<String> keySet() {
    282291        return wrappedMap.keySet();
    283292    }
    284293
     294    @Override
    285295    public Collection<SortedSet<String>> values() {
    286296        return wrappedMap.values();
    287297    }
    288298
     299    @Override
    289300    public Set<Entry<String, SortedSet<String>>> entrySet() {
    290301        return wrappedMap.entrySet();
  • trunk/src/oauth/signpost/http/HttpRequest.java

    r4231 r10831  
    66
    77import oauth.signpost.OAuthConsumer;
    8 import oauth.signpost.basic.HttpURLConnectionRequestAdapter;
    98
    109/**
     
    1413 * currently supported, you'll have to write an adapter which implements this
    1514 * interface and a custom {@link OAuthConsumer} which performs the wrapping.
    16  *
    17  * @see HttpURLConnectionRequestAdapter
     15 *
    1816 * @author Matthias Kaeppler
    1917 */
     
    3836    /**
    3937     * Returns the wrapped request object, in case you must work directly on it.
    40      * 
     38     *
    4139     * @return the wrapped request object
    4240     */
  • trunk/src/oauth/signpost/signature/AuthorizationHeaderSigningStrategy.java

    r6849 r10831  
    99/**
    1010 * Writes to the HTTP Authorization header field.
    11  * 
     11 *
    1212 * @author Matthias Kaeppler
    1313 */
     
    1616    private static final long serialVersionUID = 1L;
    1717
     18    @Override
    1819    public String writeSignature(String signature, HttpRequest request,
    1920            HttpParameters requestParameters) {
  • trunk/src/oauth/signpost/signature/QueryStringSigningStrategy.java

    r6849 r10831  
    1313 * the URL once the request has been instantiated, so there is no way to append
    1414 * parameters to it.
    15  * 
     15 *
    1616 * @author Matthias Kaeppler
    1717 */
     
    2020    private static final long serialVersionUID = 1L;
    2121
     22    @Override
    2223    public String writeSignature(String signature, HttpRequest request,
    2324            HttpParameters requestParameters) {
Note: See TracChangeset for help on using the changeset viewer.