Changeset 18828 in josm for trunk/src


Ignore:
Timestamp:
2023-09-15T15:57:24+02:00 (14 months ago)
Author:
taylor.smock
Message:

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

This prevents users from using Basic Authentication or OAuth 1.0a unless one of the following is true:

  • They were previously using the authentication method
  • They have enabled Expert Mode
  • They are not using the default OSM API
File:
1 edited

Legend:

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

    r18764 r18828  
    1818import javax.swing.JRadioButton;
    1919
     20import org.openstreetmap.josm.actions.ExpertToggleAction;
    2021import org.openstreetmap.josm.data.UserIdentityManager;
    2122import org.openstreetmap.josm.data.oauth.OAuthAccessTokenHolder;
    2223import org.openstreetmap.josm.data.oauth.OAuthVersion;
     24import org.openstreetmap.josm.data.preferences.JosmUrls;
    2325import org.openstreetmap.josm.gui.help.HelpUtil;
    2426import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
     
    5052    private OAuthAuthenticationPreferencesPanel pnlOAuth20Preferences;
    5153
     54    /** Used to determine which API we are using for disabling/enabling Basic Auth/OAuth 1.0a */
     55    private String apiUrl = OsmApi.getOsmApi().getServerUrl();
     56    /** ExpertToggleAction uses weak references; we don't want this listener to be garbage collected */
     57    private final ExpertToggleAction.ExpertModeChangeListener expertModeChangeListener = isExpert -> {
     58        final String authMethod = OsmApi.getAuthMethod();
     59        final boolean defaultApi = JosmUrls.getInstance().getDefaultOsmApiUrl().equals(apiUrl);
     60        rbBasicAuthentication.setEnabled(rbBasicAuthentication.isSelected() || "basic".equals(authMethod) || isExpert || !defaultApi);
     61        rbOAuth.setEnabled(rbOAuth.isSelected() || "oauth".equals(authMethod) || isExpert || !defaultApi);
     62    };
     63
    5264    /**
    5365     * Constructs a new {@code AuthenticationPreferencesPanel}.
     
    110122        pnlOAuth20Preferences = new OAuthAuthenticationPreferencesPanel(OAuthVersion.OAuth20);
    111123
    112         rbBasicAuthentication.setSelected(true);
    113         pnlAuthenticationParameters.add(pnlBasicAuthPreferences, BorderLayout.CENTER);
     124        ExpertToggleAction.addExpertModeChangeListener(expertModeChangeListener, true);
     125
     126        rbOAuth20.setSelected(true);
     127        pnlAuthenticationParameters.add(pnlOAuth20Preferences, BorderLayout.CENTER);
    114128    }
    115129
     
    178192            }
    179193        }
     194        ExpertToggleAction.removeExpertModeChangeListener(this.expertModeChangeListener);
    180195    }
    181196
     
    210225            pnlOAuthPreferences.propertyChange(evt);
    211226        }
     227        if (pnlOAuth20Preferences != null) {
     228            pnlOAuth20Preferences.propertyChange(evt);
     229        }
     230        if (OsmApiUrlInputPanel.API_URL_PROP.equals(evt.getPropertyName())) {
     231            this.apiUrl = (String) evt.getNewValue();
     232            this.expertModeChangeListener.expertChanged(ExpertToggleAction.isExpert());
     233        }
    212234    }
    213235}
Note: See TracChangeset for help on using the changeset viewer.