Changeset 5422 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2012-08-11T17:37:00+02:00 (12 years ago)
Author:
Don-vip
Message:

see #7943 - Introduce OsmApi.DEFAULT_API_URL, better handling of change of API URL in OAuth management, javadoc improvements

Location:
trunk/src/org/openstreetmap/josm
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AbstractInfoAction.java

    r5360 r5422  
    1818import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec;
    1919import org.openstreetmap.josm.gui.help.HelpUtil;
     20import org.openstreetmap.josm.io.OsmApi;
    2021import org.openstreetmap.josm.tools.ImageProvider;
    2122import org.openstreetmap.josm.tools.OpenBrowser;
     
    3839     */
    3940    static public String getBaseBrowseUrl() {
    40         String baseUrl = Main.pref.get("osm-server.url", "http://api.openstreetmap.org/api");
     41        String baseUrl = Main.pref.get("osm-server.url", OsmApi.DEFAULT_API_URL);
    4142        Pattern pattern = Pattern.compile("/api/?$");
    4243        String ret =  pattern.matcher(baseUrl).replaceAll("/browse");
     
    5758     */
    5859    static public String getBaseUserUrl() {
    59         String baseUrl = Main.pref.get("osm-server.url", "http://api.openstreetmap.org/api");
     60        String baseUrl = Main.pref.get("osm-server.url", OsmApi.DEFAULT_API_URL);
    6061        Pattern pattern = Pattern.compile("/api/?$");
    6162        String ret =  pattern.matcher(baseUrl).replaceAll("/user");
  • trunk/src/org/openstreetmap/josm/data/oauth/OAuthParameters.java

    r5266 r5422  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.oauth;
     3
     4import java.net.MalformedURLException;
     5import java.net.URL;
    36
    47import oauth.signpost.OAuthConsumer;
     
    811
    912import org.openstreetmap.josm.data.Preferences;
     13import org.openstreetmap.josm.io.OsmApi;
    1014import org.openstreetmap.josm.tools.CheckParameterUtil;
    1115
    1216/**
    1317 * This class manages a set of OAuth parameters.
    14  *
     18 * @since 2747
    1519 */
    1620public class OAuthParameters {
    1721
     22    /**
     23     * The default JOSM OAuth consumer key.
     24     */
    1825    static public final String DEFAULT_JOSM_CONSUMER_KEY = "AdCRxTpvnbmfV8aPqrTLyA";
     26    /**
     27     * The default JOSM OAuth consumer secret.
     28     */
    1929    static public final String DEFAULT_JOSM_CONSUMER_SECRET = "XmYOiGY9hApytcBC3xCec3e28QBqOWz5g6DSb5UpE";
     30    /**
     31     * The default OSM OAuth request token URL.
     32     */
    2033    static public final String DEFAULT_REQUEST_TOKEN_URL = "http://www.openstreetmap.org/oauth/request_token";
     34    /**
     35     * The default OSM OAuth access token URL.
     36     */
    2137    static public final String DEFAULT_ACCESS_TOKEN_URL = "http://www.openstreetmap.org/oauth/access_token";
     38    /**
     39     * The default OSM OAuth authorize URL.
     40     */
    2241    static public final String DEFAULT_AUTHORISE_URL = "http://www.openstreetmap.org/oauth/authorize";
    2342
     
    2544    /**
    2645     * Replies a set of default parameters for a consumer accessing the standard OSM server
    27      * at http://api.openstreetmap.org/api
     46     * at {@link OsmApi#DEFAULT_API_URL}.
    2847     *
    2948     * @return a set of default parameters
    3049     */
    3150    static public OAuthParameters createDefault() {
     51        return createDefault(null);
     52    }
     53
     54    /**
     55     * Replies a set of default parameters for a consumer accessing an OSM server
     56     * at the given API url. URL parameters are only set if the URL equals {@link OsmApi#DEFAULT_API_URL}
     57     * or references the domain "dev.openstreetmap.org", otherwise they may be <code>null</code>.
     58     *
     59     * @param apiUrl The API URL for which the OAuth default parameters are created. If null or empty, the default OSM API url is used.
     60     * @return a set of default parameters for the given {@code apiUrl}
     61     * @since 5422
     62     */
     63    static public OAuthParameters createDefault(String apiUrl) {
    3264        OAuthParameters parameters = new OAuthParameters();
    3365        parameters.setConsumerKey(DEFAULT_JOSM_CONSUMER_KEY);
    3466        parameters.setConsumerSecret(DEFAULT_JOSM_CONSUMER_SECRET);
    35         parameters.setRequestTokenUrl(DEFAULT_REQUEST_TOKEN_URL);
    36         parameters.setAccessTokenUrl(DEFAULT_ACCESS_TOKEN_URL);
    37         parameters.setAuthoriseUrl(DEFAULT_AUTHORISE_URL);
     67        if (apiUrl == null || apiUrl.isEmpty() || apiUrl.equals(OsmApi.DEFAULT_API_URL)) {
     68            parameters.setRequestTokenUrl(DEFAULT_REQUEST_TOKEN_URL);
     69            parameters.setAccessTokenUrl(DEFAULT_ACCESS_TOKEN_URL);
     70            parameters.setAuthoriseUrl(DEFAULT_AUTHORISE_URL);
     71        } else {
     72            try {
     73                String host = new URL(apiUrl).getHost();
     74                if (host.endsWith("dev.openstreetmap.org")) {
     75                    parameters.setRequestTokenUrl(DEFAULT_REQUEST_TOKEN_URL.replace("www.openstreetmap.org", host));
     76                    parameters.setAccessTokenUrl(DEFAULT_ACCESS_TOKEN_URL.replace("www.openstreetmap.org", host));
     77                    parameters.setAuthoriseUrl(DEFAULT_AUTHORISE_URL.replace("www.openstreetmap.org", host));
     78                }
     79            } catch (MalformedURLException e) {
     80                // Ignored
     81            }
     82        }
    3883        return parameters;
    3984    }
     
    4893        boolean useDefault = pref.getBoolean("oauth.settings.use-default", true );
    4994        if (useDefault)
    50             return createDefault();
     95            return createDefault(pref.get("osm-server.url"));
    5196        OAuthParameters parameters = new OAuthParameters();
    5297        parameters.setConsumerKey(pref.get("oauth.settings.consumer-key", ""));
     
    78123    private String authoriseUrl;
    79124
     125    /**
     126     * Constructs a new, unitialized, {@code OAuthParameters}.
     127     *
     128     * @see #createDefault
     129     * @see #createFromPreferences
     130     */
    80131    public OAuthParameters() {
    81132    }
     
    96147    }
    97148
     149    /**
     150     * Gets the consumer key.
     151     * @return The consumer key
     152     */
    98153    public String getConsumerKey() {
    99154        return consumerKey;
    100155    }
     156   
     157    /**
     158     * Sets the consumer key.
     159     * @param consumerKey The consumer key
     160     */
    101161    public void setConsumerKey(String consumerKey) {
    102162        this.consumerKey = consumerKey;
    103163    }
     164   
     165    /**
     166     * Gets the consumer secret.
     167     * @return The consumer secret
     168     */
    104169    public String getConsumerSecret() {
    105170        return consumerSecret;
    106171    }
     172   
     173    /**
     174     * Sets the consumer secret.
     175     * @param consumerSecret The consumer secret
     176     */
    107177    public void setConsumerSecret(String consumerSecret) {
    108178        this.consumerSecret = consumerSecret;
    109179    }
     180   
     181    /**
     182     * Gets the request token URL.
     183     * @return The request token URL
     184     */
    110185    public String getRequestTokenUrl() {
    111186        return requestTokenUrl;
    112187    }
     188   
     189    /**
     190     * Sets the request token URL.
     191     * @param requestTokenUrl the request token URL
     192     */
    113193    public void setRequestTokenUrl(String requestTokenUrl) {
    114194        this.requestTokenUrl = requestTokenUrl;
    115195    }
     196   
     197    /**
     198     * Gets the access token URL.
     199     * @return The access token URL
     200     */
    116201    public String getAccessTokenUrl() {
    117202        return accessTokenUrl;
    118203    }
     204   
     205    /**
     206     * Sets the access token URL.
     207     * @param accessTokenUrl The access token URL
     208     */
    119209    public void setAccessTokenUrl(String accessTokenUrl) {
    120210        this.accessTokenUrl = accessTokenUrl;
    121211    }
     212   
     213    /**
     214     * Gets the authorise URL.
     215     * @return The authorise URL
     216     */
    122217    public String getAuthoriseUrl() {
    123218        return authoriseUrl;
    124219    }
     220   
     221    /**
     222     * Sets the authorise URL.
     223     * @param authoriseUrl The authorise URL
     224     */
    125225    public void setAuthoriseUrl(String authoriseUrl) {
    126226        this.authoriseUrl = authoriseUrl;
     
    128228
    129229    /**
    130      * Builds an {@link OAuthConsumer} based on these parameters
     230     * Builds an {@link OAuthConsumer} based on these parameters.
    131231     *
    132232     * @return the consumer
    133233     */
    134234    public OAuthConsumer buildConsumer() {
    135         OAuthConsumer consumer = new DefaultOAuthConsumer(consumerKey, consumerSecret);
    136         return consumer;
     235        return new DefaultOAuthConsumer(consumerKey, consumerSecret);
    137236    }
    138237
     
    142241     * @param consumer the consumer. Must not be null.
    143242     * @return the provider
    144      * @throws IllegalArgumentException thrown if consumer is null
     243     * @throws IllegalArgumentException if consumer is null
    145244     */
    146245    public OAuthProvider buildProvider(OAuthConsumer consumer) throws IllegalArgumentException {
     
    153252    }
    154253
     254    /**
     255     * Saves these OAuth parameters to the given {@code Preferences}.
     256     * @param pref The Preferences into which are saved these OAuth parameters with the prefix "oauth.settings"
     257     */
    155258    public void saveToPreferences(Preferences pref) {
    156         if (this.equals(createDefault())) {
     259        if (this.equals(createDefault(pref.get("osm-server.url")))) {
    157260            pref.put("oauth.settings.use-default", true );
    158261            clearPreferences(pref);
  • trunk/src/org/openstreetmap/josm/gui/oauth/AbstractAuthorizationUI.java

    r5266 r5422  
    1111 * This is the abstract base class for the three authorisation UIs.
    1212 *
    13  *
     13 * @since 2746
    1414 */
    15 public abstract class AbstractAuthorizationUI extends VerticallyScrollablePanel{
     15public abstract class AbstractAuthorizationUI extends VerticallyScrollablePanel {
    1616    /**
    1717     * The property name for the Access Token property
     
    2020
    2121    private String apiUrl;
    22     private AdvancedOAuthPropertiesPanel pnlAdvancedProperties;
     22    private final AdvancedOAuthPropertiesPanel pnlAdvancedProperties;
    2323    private OAuthToken accessToken;
    2424
     
    2727    }
    2828
    29     public AbstractAuthorizationUI() {
     29    /**
     30     * Constructs a new {@code AbstractAuthorizationUI} for the given API URL.
     31     * @param apiUrl The OSM API URL
     32     * @since 5422
     33     */
     34    public AbstractAuthorizationUI(String apiUrl) {
    3035        pnlAdvancedProperties = new AdvancedOAuthPropertiesPanel();
     36        setApiUrl(apiUrl);
    3137    }
    3238
     
    4955    public void setApiUrl(String apiUrl) {
    5056        this.apiUrl = apiUrl;
     57        this.pnlAdvancedProperties.setApiUrl(apiUrl);
    5158    }
    5259
  • trunk/src/org/openstreetmap/josm/gui/oauth/AdvancedOAuthPropertiesPanel.java

    r3530 r5422  
    2727import org.openstreetmap.josm.tools.ImageProvider;
    2828
     29/**
     30 * Panel allowing the user to setup advanced OAuth parameters:
     31 * <li>Consumer key</li>
     32 * <li>Consumer secret</li>
     33 * <li>Request token URL</li>
     34 * <li>Access token URL</li>
     35 * <li>Authorize URL</li>
     36 *
     37 * @see OAuthParameters
     38 * @since 2746
     39 */
    2940public class AdvancedOAuthPropertiesPanel extends VerticallyScrollablePanel {
    3041
     
    3647    private JTextField tfAuthoriseURL;
    3748    private UseDefaultItemListener ilUseDefault;
     49    private String apiUrl;
    3850
    3951    protected void build() {
     
    110122
    111123    protected boolean hasCustomSettings() {
     124        OAuthParameters params = OAuthParameters.createDefault(apiUrl);
    112125        return
    113         ! tfConsumerKey.getText().equals( OAuthParameters.DEFAULT_JOSM_CONSUMER_KEY)
    114         || ! tfConsumerSecret.getText().equals( OAuthParameters.DEFAULT_JOSM_CONSUMER_SECRET)
    115         || ! tfRequestTokenURL.getText().equals( OAuthParameters.DEFAULT_REQUEST_TOKEN_URL)
    116         || ! tfAccessTokenURL.getText().equals( OAuthParameters.DEFAULT_ACCESS_TOKEN_URL)
    117         || ! tfAuthoriseURL.getText().equals( OAuthParameters.DEFAULT_AUTHORISE_URL);
     126           ! tfConsumerKey.getText().equals(params.getConsumerKey())
     127        || ! tfConsumerSecret.getText().equals(params.getConsumerSecret())
     128        || ! tfRequestTokenURL.getText().equals(params.getRequestTokenUrl())
     129        || ! tfAccessTokenURL.getText().equals(params.getAccessTokenUrl())
     130        || ! tfAuthoriseURL.getText().equals(params.getAuthoriseUrl());
    118131    }
    119132
     
    152165    protected void resetToDefaultSettings() {
    153166        cbUseDefaults.setSelected(true);
    154         tfConsumerKey.setText( OAuthParameters.DEFAULT_JOSM_CONSUMER_KEY);
    155         tfConsumerSecret.setText( OAuthParameters.DEFAULT_JOSM_CONSUMER_SECRET);
    156         tfRequestTokenURL.setText(OAuthParameters.DEFAULT_REQUEST_TOKEN_URL);
    157         tfAccessTokenURL.setText(OAuthParameters.DEFAULT_ACCESS_TOKEN_URL);
    158         tfAuthoriseURL.setText(OAuthParameters.DEFAULT_AUTHORISE_URL);
     167        OAuthParameters params = OAuthParameters.createDefault(apiUrl);
     168        tfConsumerKey.setText(params.getConsumerKey());
     169        tfConsumerSecret.setText(params.getConsumerSecret());
     170        tfRequestTokenURL.setText(params.getRequestTokenUrl());
     171        tfAccessTokenURL.setText(params.getAccessTokenUrl());
     172        tfAuthoriseURL.setText(params.getAuthoriseUrl());
    159173
    160174        setChildComponentsEnabled(false);
     
    176190    public OAuthParameters getAdvancedParameters() {
    177191        if (cbUseDefaults.isSelected())
    178             return OAuthParameters.createDefault();
     192            return OAuthParameters.createDefault(apiUrl);
    179193        OAuthParameters parameters = new OAuthParameters();
    180194        parameters.setConsumerKey(tfConsumerKey.getText());
     
    194208    public void setAdvancedParameters(OAuthParameters parameters) throws IllegalArgumentException{
    195209        CheckParameterUtil.ensureParameterNotNull(parameters, "parameters");
    196         if (parameters.equals(OAuthParameters.createDefault())) {
     210        if (parameters.equals(OAuthParameters.createDefault(apiUrl))) {
    197211            cbUseDefaults.setSelected(true);
    198212            setChildComponentsEnabled(false);
     
    208222    }
    209223
     224    /**
     225     * Constructs a new {@code AdvancedOAuthPropertiesPanel}.
     226     */
    210227    public AdvancedOAuthPropertiesPanel() {
    211228        build();
     
    218235     * @throws IllegalArgumentException thrown if pref is null
    219236     */
    220     public void initFromPreferences(Preferences pref) throws IllegalArgumentException{
     237    public void initFromPreferences(Preferences pref) throws IllegalArgumentException {
    221238        CheckParameterUtil.ensureParameterNotNull(pref, "pref");
     239        setApiUrl(pref.get("osm-server-url"));
    222240        boolean useDefault = pref.getBoolean("oauth.settings.use-default", true);
    223241        ilUseDefault.setEnabled(false);
     
    265283        public void itemStateChanged(ItemEvent e) {
    266284            if (!enabled) return;
    267             switch(e.getStateChange()) {
     285            switch (e.getStateChange()) {
    268286            case ItemEvent.SELECTED:
    269287                if (hasCustomSettings()) {
     
    285303        }
    286304    }
     305
     306    /**
     307     * Sets the URL of the OSM API for which this panel is currently displaying OAuth properties.
     308     *
     309     * @param apiUrl the api URL
     310     * @since 5422
     311     */
     312    public void setApiUrl(String apiUrl) {
     313        this.apiUrl = apiUrl;
     314        if (cbUseDefaults.isSelected()) {
     315            resetToDefaultSettings();
     316        }
     317    }
    287318}
  • trunk/src/org/openstreetmap/josm/gui/oauth/FullyAutomaticAuthorizationUI.java

    r4690 r5422  
    5454 * automatic process.
    5555 *
     56 * @since 2746
    5657 */
    5758public class FullyAutomaticAuthorizationUI extends AbstractAuthorizationUI {
     
    306307    }
    307308
    308     public FullyAutomaticAuthorizationUI() {
     309    /**
     310     * Constructs a new {@code FullyAutomaticAuthorizationUI} for the given API URL.
     311     * @param apiUrl The OSM API URL
     312     * @since 5422
     313     */
     314    public FullyAutomaticAuthorizationUI(String apiUrl) {
     315        super(apiUrl);
    309316        build();
    310317    }
  • trunk/src/org/openstreetmap/josm/gui/oauth/ManualAuthorizationUI.java

    r4457 r5422  
    3333import org.openstreetmap.josm.tools.ImageProvider;
    3434
     35/**
     36 * This is an UI which supports a JOSM user to get an OAuth Access Token in a fully
     37 * manual process.
     38 *
     39 * @since 2746
     40 */
    3541public class ManualAuthorizationUI extends AbstractAuthorizationUI{
    3642
     
    5460        gc.gridwidth = 2;
    5561        gc.insets = new Insets(0,0,5,0);
    56         pnlMessage= new HtmlPanel();
     62        pnlMessage = new HtmlPanel();
    5763        pnlMessage.setText("<html><body>"
    5864                + tr("Please enter an OAuth Access Token which is authorized to access the OSM server "
     
    137143    public void setApiUrl(String apiUrl) {
    138144        super.setApiUrl(apiUrl);
    139         pnlMessage.setText(tr("<html><body>"
    140                 + "Please enter an OAuth Access Token which is authorized to access the OSM server "
    141                 + "''{0}''."
    142                 + "</body></html>",
    143                 getApiUrl()
    144         ));
     145        if (pnlMessage != null) {
     146            pnlMessage.setText(tr("<html><body>"
     147                    + "Please enter an OAuth Access Token which is authorized to access the OSM server "
     148                    + "''{0}''."
     149                    + "</body></html>",
     150                    getApiUrl()
     151            ));
     152        }
    145153    }
    146154
     
    152160    }
    153161
    154     public ManualAuthorizationUI() {
     162    /**
     163     * Constructs a new {@code ManualAuthorizationUI} for the given API URL.
     164     * @param apiUrl The OSM API URL
     165     * @since 5422
     166     */
     167    public ManualAuthorizationUI(String apiUrl) {
     168        super(apiUrl);
    155169        build();
    156170    }
  • trunk/src/org/openstreetmap/josm/gui/oauth/OAuthAuthorizationWizard.java

    r4310 r5422  
    3737
    3838import org.openstreetmap.josm.Main;
     39import org.openstreetmap.josm.data.CustomConfigurator;
     40import org.openstreetmap.josm.data.Preferences;
    3941import org.openstreetmap.josm.data.oauth.OAuthParameters;
    4042import org.openstreetmap.josm.data.oauth.OAuthToken;
     
    5658    private HtmlPanel pnlMessage;
    5759    private boolean canceled;
    58     private String apiUrl;
     60    private final String apiUrl;
    5961
    6062    private AuthorizationProcedureComboBox cbAuthorisationProcedure;
     
    163165        getContentPane().add(buildHeaderInfoPanel(), BorderLayout.NORTH);
    164166
    165         pnlFullyAutomaticAuthorisationUI = new FullyAutomaticAuthorizationUI();
    166         pnlFullyAutomaticAuthorisationUI.setApiUrl(apiUrl);
    167 
    168         pnlSemiAutomaticAuthorisationUI = new SemiAutomaticAuthorizationUI();
    169         pnlSemiAutomaticAuthorisationUI.setApiUrl(apiUrl);
    170 
    171         pnlManualAuthorisationUI = new ManualAuthorizationUI();
    172         pnlManualAuthorisationUI.setApiUrl(apiUrl);
     167        setTitle(tr("Get an Access Token for ''{0}''", apiUrl));
     168
     169        pnlFullyAutomaticAuthorisationUI = new FullyAutomaticAuthorizationUI(apiUrl);
     170        pnlSemiAutomaticAuthorisationUI = new SemiAutomaticAuthorizationUI(apiUrl);
     171        pnlManualAuthorisationUI = new ManualAuthorizationUI(apiUrl);
    173172
    174173        spAuthorisationProcedureUI = new JScrollPane(new JPanel());
     
    208207     */
    209208    public OAuthAuthorizationWizard(String apiUrl) throws IllegalArgumentException {
    210         super(JOptionPane.getFrameForComponent(Main.parent), ModalityType.DOCUMENT_MODAL);
    211         CheckParameterUtil.ensureParameterNotNull(apiUrl, "apiUrl");
    212         build();
    213         setApiUrl(apiUrl);
     209        this(Main.parent, apiUrl);
    214210    }
    215211
     
    224220        super(JOptionPane.getFrameForComponent(parent), ModalityType.DOCUMENT_MODAL);
    225221        CheckParameterUtil.ensureParameterNotNull(apiUrl, "apiUrl");
     222        this.apiUrl = apiUrl;
    226223        build();
    227         setApiUrl(apiUrl);
    228     }
    229 
    230     /**
    231      * Sets the API URL for the API for which this wizard is generating
    232      * an Access Token.
    233      *
    234      * @param apiUrl the API URL. Must not be null.
    235      * @throws IllegalArgumentException thrown if apiUrl is null
    236      */
    237     public void setApiUrl(String apiUrl) throws IllegalArgumentException{
    238         CheckParameterUtil.ensureParameterNotNull(apiUrl, "apiUrl");
    239         this.apiUrl = apiUrl;
    240         setTitle(tr("Get an Access Token for ''{0}''", apiUrl));
    241         if (pnlFullyAutomaticAuthorisationUI != null) {
    242             pnlFullyAutomaticAuthorisationUI.setApiUrl(apiUrl);
    243         }
    244         if (pnlSemiAutomaticAuthorisationUI != null) {
    245             pnlSemiAutomaticAuthorisationUI.setApiUrl(apiUrl);
    246         }
    247         if (pnlManualAuthorisationUI != null) {
    248             pnlManualAuthorisationUI.setApiUrl(apiUrl);
    249         }
    250224    }
    251225
     
    302276     */
    303277    public void initFromPreferences() {
    304         pnlFullyAutomaticAuthorisationUI.initFromPreferences(Main.pref);
    305         pnlSemiAutomaticAuthorisationUI.initFromPreferences(Main.pref);
    306         pnlManualAuthorisationUI.initFromPreferences(Main.pref);
     278        // Copy current JOSM preferences to update API url with the one used in this wizard
     279        Preferences copyPref = CustomConfigurator.clonePreferences(Main.pref);
     280        copyPref.put("osm-server-url", apiUrl);
     281        pnlFullyAutomaticAuthorisationUI.initFromPreferences(copyPref);
     282        pnlSemiAutomaticAuthorisationUI.initFromPreferences(copyPref);
     283        pnlManualAuthorisationUI.initFromPreferences(copyPref);
    307284    }
    308285
     
    388365        public void hyperlinkUpdate(HyperlinkEvent e) {
    389366            if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
    390                 String url = e.getDescription();
    391                 OpenBrowser.displayUrl(url);
     367                OpenBrowser.displayUrl(e.getDescription());
    392368            }
    393369        }
  • trunk/src/org/openstreetmap/josm/gui/oauth/OsmOAuthAuthorizationClient.java

    r5266 r5422  
    3939import org.openstreetmap.josm.tools.CheckParameterUtil;
    4040
     41/**
     42 * An OAuth 1.0 authorization client.
     43 * @since 2746
     44 */
    4145public class OsmOAuthAuthorizationClient {
    42     private OAuthParameters oauthProviderParameters;
    43     private OAuthConsumer consumer;
    44     private OAuthProvider provider;
     46    private final OAuthParameters oauthProviderParameters;
     47    private final OAuthConsumer consumer;
     48    private final OAuthProvider provider;
    4549    private boolean canceled;
    4650    private HttpURLConnection connection;
     
    5761     */
    5862    public OsmOAuthAuthorizationClient() {
    59         oauthProviderParameters = OAuthParameters.createDefault();
     63        oauthProviderParameters = OAuthParameters.createDefault(Main.pref.get("osm-server.url"));
    6064        consumer = oauthProviderParameters.buildConsumer();
    6165        provider = oauthProviderParameters.buildProvider(consumer);
     
    6670     *
    6771     * @param parameters the OAuth parameters. Must not be null.
    68      * @throws IllegalArgumentException thrown if parameters is null
     72     * @throws IllegalArgumentException if parameters is null
    6973     */
    7074    public OsmOAuthAuthorizationClient(OAuthParameters parameters) throws IllegalArgumentException {
     
    8185     * @param parameters the OAuth parameters. Must not be null.
    8286     * @param requestToken the request token. Must not be null.
    83      * @throws IllegalArgumentException thrown if parameters is null
    84      * @throws IllegalArgumentException thrown if requestToken is null
     87     * @throws IllegalArgumentException if parameters is null
     88     * @throws IllegalArgumentException if requestToken is null
    8589     */
    8690    public OsmOAuthAuthorizationClient(OAuthParameters parameters, OAuthToken requestToken) throws IllegalArgumentException {
     
    9296    }
    9397
     98    /**
     99     * Cancels the current OAuth operation.
     100     */
    94101    public void cancel() {
    95102        DefaultOAuthProvider p  = (DefaultOAuthProvider)provider;
     
    127134     * @param monitor a progress monitor. Defaults to {@link NullProgressMonitor#INSTANCE} if null
    128135     * @return the OAuth Request Token
    129      * @throws OsmOAuthAuthorizationException thrown if something goes wrong when retrieving the request token
     136     * @throws OsmOAuthAuthorizationException if something goes wrong when retrieving the request token
     137     * @throws OsmTransferCanceledException if the user canceled the request
    130138     */
    131139    public OAuthToken getRequestToken(ProgressMonitor monitor) throws OsmOAuthAuthorizationException, OsmTransferCanceledException {
     
    159167     * @param monitor a progress monitor. Defaults to {@link NullProgressMonitor#INSTANCE} if null
    160168     * @return the OAuth Access Token
    161      * @throws OsmOAuthAuthorizationException thrown if something goes wrong when retrieving the request token
     169     * @throws OsmOAuthAuthorizationException if something goes wrong when retrieving the request token
     170     * @throws OsmTransferCanceledException if the user canceled the request
    162171     * @see #getRequestToken(ProgressMonitor)
    163172     */
     
    273282     *
    274283     * @return the OSM login URL
    275      * @throws OsmOAuthAuthorizationException thrown if something went wrong, in particular if the
     284     * @throws OsmOAuthAuthorizationException if something went wrong, in particular if the
    276285     * URLs are malformed
    277286     */
     
    290299     *
    291300     * @return the OSM logout URL
    292      * @throws OsmOAuthAuthorizationException thrown if something went wrong, in particular if the
     301     * @throws OsmOAuthAuthorizationException if something went wrong, in particular if the
    293302     * URLs are malformed
    294303     */
     
    308317     *
    309318     * @return the session ID structure
    310      * @throws OsmOAuthAuthorizationException thrown if something went wrong
     319     * @throws OsmOAuthAuthorizationException if something went wrong
    311320     */
    312321    protected SessionId fetchOsmWebsiteSessionId() throws OsmOAuthAuthorizationException {
     
    340349     * a hidden parameter.
    341350     *
    342      * @throws OsmOAuthAuthorizationException thrown if something went wrong
     351     * @throws OsmOAuthAuthorizationException if something went wrong
    343352     */
    344353    protected void fetchOAuthToken(SessionId sessionId, OAuthToken requestToken) throws OsmOAuthAuthorizationException {
     
    526535     * @param privileges the set of privileges. Must not be null.
    527536     * @param monitor a progress monitor. Defaults to {@link NullProgressMonitor#INSTANCE} if null
    528      * @throws IllegalArgumentException thrown if requestToken is null
    529      * @throws IllegalArgumentException thrown if osmUserName is null
    530      * @throws IllegalArgumentException thrown if osmPassword is null
    531      * @throws IllegalArgumentException thrown if privileges is null
    532      * @throws OsmOAuthAuthorizationException thrown if the authorisation fails
    533      * @throws OsmTransferCanceledException thrown if the task is canceled by the user
     537     * @throws IllegalArgumentException if requestToken is null
     538     * @throws IllegalArgumentException if osmUserName is null
     539     * @throws IllegalArgumentException if osmPassword is null
     540     * @throws IllegalArgumentException if privileges is null
     541     * @throws OsmOAuthAuthorizationException if the authorisation fails
     542     * @throws OsmTransferCanceledException if the task is canceled by the user
    534543     */
    535544    public void authorise(OAuthToken requestToken, String osmUserName, String osmPassword, OsmPrivileges privileges, ProgressMonitor monitor) throws IllegalArgumentException, OsmOAuthAuthorizationException, OsmTransferCanceledException{
  • trunk/src/org/openstreetmap/josm/gui/oauth/SemiAutomaticAuthorizationUI.java

    r3530 r5422  
    3737 * In contrast to the fully-automatic procedure the user is dispatched to an
    3838 * external browser for login and authorisation.
     39 *
     40 * @since 2746
    3941 */
    4042public class SemiAutomaticAuthorizationUI extends AbstractAuthorizationUI {
     
    5860    }
    5961
    60     public SemiAutomaticAuthorizationUI() {
     62    /**
     63     * Constructs a new {@code SemiAutomaticAuthorizationUI} for the given API URL.
     64     * @param apiUrl The OSM API URL
     65     * @since 5422
     66     */
     67    public SemiAutomaticAuthorizationUI(String apiUrl) {
     68        super(apiUrl);
    6169        build();
    6270    }
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/OAuthAuthenticationPreferencesPanel.java

    r5266 r5422  
    4040 * user already has an Access Token.
    4141 *
    42  * For initial authorisation see {@link OAuthAuthorisationWizard}.
     42 * For initial authorisation see {@link OAuthAuthorizationWizard}.
    4343 *
    4444 */
     
    145145    }
    146146
     147    /**
     148     * Sets the URL of the OSM API for which this panel is currently displaying OAuth properties.
     149     *
     150     * @param apiUrl the api URL
     151     */
    147152    public void setApiUrl(String apiUrl) {
    148153        this.apiUrl = apiUrl;
     154        pnlAdvancedProperties.setApiUrl(apiUrl);
    149155    }
    150156
     
    372378        if (! evt.getPropertyName().equals(OsmApiUrlInputPanel.API_URL_PROP))
    373379            return;
    374         apiUrl = (String)evt.getNewValue();
     380        setApiUrl((String)evt.getNewValue());
    375381    }
    376382}
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/OsmApiUrlInputPanel.java

    r4246 r5422  
    3838    static public final String API_URL_PROP = OsmApiUrlInputPanel.class.getName() + ".apiUrl";
    3939
    40     static public final String defaulturl = "http://api.openstreetmap.org/api";
    4140    private JLabel lblValid;
    4241    private JLabel lblApiUrl;
     
    6160        gc.gridx = 1;
    6261        gc.weightx = 1.0;
    63         JLabel lbl = new JLabel(tr("<html>Use the default OSM server URL (<strong>{0}</strong>)</html>", defaulturl));
     62        JLabel lbl = new JLabel(tr("<html>Use the default OSM server URL (<strong>{0}</strong>)</html>", OsmApi.DEFAULT_API_URL));
    6463        lbl.setFont(lbl.getFont().deriveFont(Font.PLAIN));
    6564        pnl.add(lbl, gc);
     
    122121        if (url == null) {
    123122            cbUseDefaultServerUrl.setSelected(true);
    124             firePropertyChange(API_URL_PROP, null, defaulturl);
    125         } else if (url.trim().equals(defaulturl)) {
     123            firePropertyChange(API_URL_PROP, null, OsmApi.DEFAULT_API_URL);
     124        } else if (url.trim().equals(OsmApi.DEFAULT_API_URL)) {
    126125            cbUseDefaultServerUrl.setSelected(true);
    127             firePropertyChange(API_URL_PROP, null, defaulturl);
     126            firePropertyChange(API_URL_PROP, null, OsmApi.DEFAULT_API_URL);
    128127        } else {
    129128            cbUseDefaultServerUrl.setSelected(false);
     
    140139        if (cbUseDefaultServerUrl.isSelected()) {
    141140            Main.pref.put("osm-server.url", null);
    142         } else if (tfOsmServerUrl.getText().trim().equals(defaulturl)) {
     141        } else if (tfOsmServerUrl.getText().trim().equals(OsmApi.DEFAULT_API_URL)) {
    143142            Main.pref.put("osm-server.url", null);
    144143        } else {
     
    264263            case ItemEvent.SELECTED:
    265264                setApiUrlInputEnabled(false);
    266                 firePropertyChange(API_URL_PROP, null, defaulturl);
     265                firePropertyChange(API_URL_PROP, null, OsmApi.DEFAULT_API_URL);
    267266                break;
    268267            case ItemEvent.DESELECTED:
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r5386 r5422  
    6161     * <a href="http://wiki.openstreetmap.org/wiki/API_usage_policy#Technical_Usage_Requirements">
    6262     * OSM API usage policy.</a>
     63     * @since 5386
    6364     */
    6465    static public final int MAX_DOWNLOAD_THREADS = 2;
     66   
     67    /**
     68     * Default URL of the standard OSM API.
     69     * @since 5422
     70     */
     71    static public final String DEFAULT_API_URL = "http://api.openstreetmap.org/api";
    6572
    6673    // The collection of instantiated OSM APIs
     
    9299     */
    93100    static public OsmApi getOsmApi() {
    94         String serverUrl = Main.pref.get("osm-server.url", "http://api.openstreetmap.org/api");
     101        String serverUrl = Main.pref.get("osm-server.url", DEFAULT_API_URL);
    95102        if (serverUrl == null)
    96103            throw new IllegalStateException(tr("Preference ''{0}'' missing. Cannot initialize OsmApi.", "osm-server.url"));
  • trunk/src/org/openstreetmap/josm/tools/ExceptionUtil.java

    r5321 r5422  
    5252                "<html>Failed to initialize communication with the OSM server {0}.<br>"
    5353                + "Check the server URL in your preferences and your internet connection.", Main.pref.get(
    54                         "osm-server.url", "http://api.openstreetmap.org/api"));
     54                        "osm-server.url", OsmApi.DEFAULT_API_URL));
    5555        return msg;
    5656    }
     
    7070                + "Please open the Preferences Dialog and generate or enter an Access Token."
    7171                + "</html>",
    72                 Main.pref.get("osm-server.url", "http://api.openstreetmap.org/api")
     72                Main.pref.get("osm-server.url", OsmApi.DEFAULT_API_URL)
    7373        );
    7474        return msg;
Note: See TracChangeset for help on using the changeset viewer.