Skip to content

Commit

Permalink
See #22810: OSM OAuth 1.0a/Basic auth deprecation and removal
Browse files Browse the repository at this point in the history
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

git-svn-id: https://josm.openstreetmap.de/svn/trunk@18828 0c6e7542-c601-0410-84e7-c038aed88b3b
  • Loading branch information
taylor.smock committed Sep 15, 2023
1 parent 9b4aefa commit 1e89c0b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
import javax.swing.JPanel;
import javax.swing.JRadioButton;

import org.openstreetmap.josm.actions.ExpertToggleAction;
import org.openstreetmap.josm.data.UserIdentityManager;
import org.openstreetmap.josm.data.oauth.OAuthAccessTokenHolder;
import org.openstreetmap.josm.data.oauth.OAuthVersion;
import org.openstreetmap.josm.data.preferences.JosmUrls;
import org.openstreetmap.josm.gui.help.HelpUtil;
import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
import org.openstreetmap.josm.io.OsmApi;
Expand Down Expand Up @@ -49,6 +51,16 @@ public class AuthenticationPreferencesPanel extends VerticallyScrollablePanel im
/** the panel for the OAuth 2.0 authentication parameters */
private OAuthAuthenticationPreferencesPanel pnlOAuth20Preferences;

/** Used to determine which API we are using for disabling/enabling Basic Auth/OAuth 1.0a */
private String apiUrl = OsmApi.getOsmApi().getServerUrl();
/** ExpertToggleAction uses weak references; we don't want this listener to be garbage collected */
private final ExpertToggleAction.ExpertModeChangeListener expertModeChangeListener = isExpert -> {
final String authMethod = OsmApi.getAuthMethod();
final boolean defaultApi = JosmUrls.getInstance().getDefaultOsmApiUrl().equals(apiUrl);
rbBasicAuthentication.setEnabled(rbBasicAuthentication.isSelected() || "basic".equals(authMethod) || isExpert || !defaultApi);
rbOAuth.setEnabled(rbOAuth.isSelected() || "oauth".equals(authMethod) || isExpert || !defaultApi);
};

/**
* Constructs a new {@code AuthenticationPreferencesPanel}.
*/
Expand Down Expand Up @@ -109,8 +121,10 @@ protected final void build() {
pnlOAuthPreferences = new OAuthAuthenticationPreferencesPanel(OAuthVersion.OAuth10a);
pnlOAuth20Preferences = new OAuthAuthenticationPreferencesPanel(OAuthVersion.OAuth20);

rbBasicAuthentication.setSelected(true);
pnlAuthenticationParameters.add(pnlBasicAuthPreferences, BorderLayout.CENTER);
ExpertToggleAction.addExpertModeChangeListener(expertModeChangeListener, true);

rbOAuth20.setSelected(true);
pnlAuthenticationParameters.add(pnlOAuth20Preferences, BorderLayout.CENTER);
}

/**
Expand Down Expand Up @@ -177,6 +191,7 @@ public final void saveToPreferences() {
UserIdentityManager.getInstance().initFromOAuth();
}
}
ExpertToggleAction.removeExpertModeChangeListener(this.expertModeChangeListener);
}

/**
Expand Down Expand Up @@ -209,5 +224,12 @@ public void propertyChange(PropertyChangeEvent evt) {
if (pnlOAuthPreferences != null) {
pnlOAuthPreferences.propertyChange(evt);
}
if (pnlOAuth20Preferences != null) {
pnlOAuth20Preferences.propertyChange(evt);
}
if (OsmApiUrlInputPanel.API_URL_PROP.equals(evt.getPropertyName())) {
this.apiUrl = (String) evt.getNewValue();
this.expertModeChangeListener.expertChanged(ExpertToggleAction.isExpert());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.openstreetmap.josm.TestUtils;
import org.openstreetmap.josm.data.coor.ILatLon;
import org.openstreetmap.josm.data.coor.LatLon;
Expand Down

0 comments on commit 1e89c0b

Please sign in to comment.