Ignore:
Timestamp:
2024-02-21T21:26:18+01:00 (3 months ago)
Author:
taylor.smock
Message:

Fix #22810: OSM OAuth 1.0a/Basic auth deprecation and removal

As of 2024-02-15, something changed in the OSM server configuration. This broke
our OAuth 1.0a implementation (see #23475). As such, we are removing OAuth 1.0a
from JOSM now instead of when the OSM server removes support in June 2024.

For third-party OpenStreetMap servers, the Basic Authentication method has been
kept. However, they should be made aware that it may be removed if a non-trivial
bug occurs with it. We highly recommend that the third-party servers update to
the current OpenStreetMap website implementation (if only for their own security).

Failing that, the third-party server can implement RFC8414. As of this commit,
we currently use the authorization_endpoint and token_endpoint fields.
To check and see if their third-party server implements RFC8414, they can go
to <server host>/.well-known/oauth-authorization-server.

Prominent third-party OpenStreetMap servers may give us a client id for their
specific server. That client id may be added to the hard-coded client id list
at maintainer discretion. At a minimum, the server must be publicly
available and have a significant user base.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/AuthenticationPreferencesPanel.java

    r18828 r18991  
    3939    /** indicates whether we use basic authentication */
    4040    private final JRadioButton rbBasicAuthentication = new JRadioButton();
    41     /** indicates whether we use OAuth 1.0a as authentication scheme */
    42     private final JRadioButton rbOAuth = new JRadioButton();
    4341    /** indicates whether we use OAuth 2.0 as authentication scheme */
    4442    private final JRadioButton rbOAuth20 = new JRadioButton();
     
    4745    /** the panel for the basic authentication parameters */
    4846    private BasicAuthenticationPreferencesPanel pnlBasicAuthPreferences;
    49     /** the panel for the OAuth 1.0a authentication parameters */
    50     private OAuthAuthenticationPreferencesPanel pnlOAuthPreferences;
    5147    /** the panel for the OAuth 2.0 authentication parameters */
    5248    private OAuthAuthenticationPreferencesPanel pnlOAuth20Preferences;
     
    5955        final boolean defaultApi = JosmUrls.getInstance().getDefaultOsmApiUrl().equals(apiUrl);
    6056        rbBasicAuthentication.setEnabled(rbBasicAuthentication.isSelected() || "basic".equals(authMethod) || isExpert || !defaultApi);
    61         rbOAuth.setEnabled(rbOAuth.isSelected() || "oauth".equals(authMethod) || isExpert || !defaultApi);
    6257    };
    6358
     
    8580        rbBasicAuthentication.setToolTipText(tr("Select to use HTTP basic authentication with your OSM username and password"));
    8681        rbBasicAuthentication.addItemListener(authChangeListener);
    87 
    88         //-- radio button for OAuth 1.0a
    89         buttonPanel.add(rbOAuth);
    90         rbOAuth.setText(tr("Use OAuth {0}", "1.0a"));
    91         rbOAuth.setToolTipText(tr("Select to use OAuth {0} as authentication mechanism", "1.0a"));
    92         rbOAuth.addItemListener(authChangeListener);
    93 
    9482        //-- radio button for OAuth 2.0
    9583        buttonPanel.add(rbOAuth20);
     84        rbOAuth20.setSelected(true); // This must before adding the listener; otherwise, saveToPreferences is called prior to initFromPreferences
    9685        rbOAuth20.setText(tr("Use OAuth {0}", "2.0"));
    9786        rbOAuth20.setToolTipText(tr("Select to use OAuth {0} as authentication mechanism", "2.0"));
     
    10291        ButtonGroup bg = new ButtonGroup();
    10392        bg.add(rbBasicAuthentication);
    104         bg.add(rbOAuth);
    10593        bg.add(rbOAuth20);
    10694
     
    119107        //-- the two panels for authentication parameters
    120108        pnlBasicAuthPreferences = new BasicAuthenticationPreferencesPanel();
    121         pnlOAuthPreferences = new OAuthAuthenticationPreferencesPanel(OAuthVersion.OAuth10a);
    122109        pnlOAuth20Preferences = new OAuthAuthenticationPreferencesPanel(OAuthVersion.OAuth20);
    123110
    124111        ExpertToggleAction.addExpertModeChangeListener(expertModeChangeListener, true);
    125112
    126         rbOAuth20.setSelected(true);
    127113        pnlAuthenticationParameters.add(pnlOAuth20Preferences, BorderLayout.CENTER);
    128114    }
     
    133119    public final void initFromPreferences() {
    134120        final String authMethod = OsmApi.getAuthMethod();
    135         switch (authMethod) {
    136             case "basic":
    137                 rbBasicAuthentication.setSelected(true);
    138                 break;
    139             case "oauth":
    140                 rbOAuth.setSelected(true);
    141                 break;
    142             case "oauth20":
    143                 rbOAuth20.setSelected(true);
    144                 break;
    145             default:
    146                 Logging.warn(tr("Unsupported value in preference ''{0}'', got ''{1}''. Using authentication method ''Basic Authentication''.",
    147                         "osm-server.auth-method", authMethod));
    148                 rbBasicAuthentication.setSelected(true);
     121        if ("basic".equals(authMethod)) {
     122            rbBasicAuthentication.setSelected(true);
     123        } else if ("oauth20".equals(authMethod)) {
     124            rbOAuth20.setSelected(true);
     125        } else {
     126            Logging.warn(
     127                    tr("Unsupported value in preference ''{0}'', got ''{1}''. Using authentication method ''OAuth 2.0 Authentication''.",
     128                            "osm-server.auth-method", authMethod));
     129            rbOAuth20.setSelected(true);
    149130        }
    150131        pnlBasicAuthPreferences.initFromPreferences();
    151         pnlOAuthPreferences.initFromPreferences();
    152132        pnlOAuth20Preferences.initFromPreferences();
    153133    }
     
    161141        if (rbBasicAuthentication.isSelected()) {
    162142            authMethod = "basic";
    163         } else if (rbOAuth.isSelected()) {
    164             authMethod = "oauth";
    165143        } else if (rbOAuth20.isSelected()) {
    166144            authMethod = "oauth20";
     
    174152            OAuthAccessTokenHolder.getInstance().clear();
    175153            OAuthAccessTokenHolder.getInstance().save(CredentialsManager.getInstance());
    176         } else if ("oauth".equals(authMethod)) {
     154        } else if ("oauth20".equals(authMethod)) {
     155            // oauth20
    177156            // clear the password in the preferences
    178157            pnlBasicAuthPreferences.clearPassword();
    179             pnlBasicAuthPreferences.saveToPreferences();
    180             pnlOAuthPreferences.saveToPreferences();
    181         } else { // oauth20
    182             // clear the password in the preferences
    183             pnlBasicAuthPreferences.clearPassword();
    184             pnlBasicAuthPreferences.saveToPreferences();
    185158            pnlOAuth20Preferences.saveToPreferences();
    186159        }
     
    188161            if ("basic".equals(authMethod)) {
    189162                UserIdentityManager.getInstance().initFromPreferences();
     163            } else if (OsmApi.isUsingOAuthAndOAuthSetUp(OsmApi.getOsmApi())) {
     164                UserIdentityManager.getInstance().initFromOAuth();
    190165            } else {
    191                 UserIdentityManager.getInstance().initFromOAuth();
     166                UserIdentityManager.getInstance().setAnonymous();
    192167            }
    193168        }
     
    205180                pnlAuthenticationParameters.add(pnlBasicAuthPreferences, BorderLayout.CENTER);
    206181                pnlBasicAuthPreferences.revalidate();
    207             } else if (rbOAuth.isSelected()) {
    208                 pnlAuthenticationParameters.add(pnlOAuthPreferences, BorderLayout.CENTER);
    209                 pnlOAuthPreferences.saveToPreferences();
    210                 pnlOAuthPreferences.initFromPreferences();
    211                 pnlOAuthPreferences.revalidate();
    212182            } else if (rbOAuth20.isSelected()) {
    213183                pnlAuthenticationParameters.add(pnlOAuth20Preferences, BorderLayout.CENTER);
     
    222192    @Override
    223193    public void propertyChange(PropertyChangeEvent evt) {
    224         if (pnlOAuthPreferences != null) {
    225             pnlOAuthPreferences.propertyChange(evt);
    226         }
    227194        if (pnlOAuth20Preferences != null) {
    228195            pnlOAuth20Preferences.propertyChange(evt);
Note: See TracChangeset for help on using the changeset viewer.