Skip to content

Commit 87a45a5

Browse files
author
taylor.smock
committed
Fix #23707: Remove basic auth for openstreetmap.org
This does the following: * On startup, if the current API is set to the default OSM API url, `osm-server.{auth-method|username|password}` are set to `null`, clearing them from the saved preferences.xml file. * In preferences, if the OSM API is set to the default OSM API url, the basic auth radio button is disabled (if it is not currently selected or the current auth method). This is done since some users contribute to both OSM and some other project, which may still support basic authentication. git-svn-id: https://josm.openstreetmap.de/svn/trunk@19095 0c6e7542-c601-0410-84e7-c038aed88b3b
1 parent 86e4d77 commit 87a45a5

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/org/openstreetmap/josm/data/Preferences.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@
3737

3838
import org.openstreetmap.josm.data.preferences.ColorInfo;
3939
import org.openstreetmap.josm.data.preferences.JosmBaseDirectories;
40+
import org.openstreetmap.josm.data.preferences.JosmUrls;
4041
import org.openstreetmap.josm.data.preferences.NamedColorProperty;
4142
import org.openstreetmap.josm.data.preferences.PreferencesReader;
4243
import org.openstreetmap.josm.data.preferences.PreferencesWriter;
4344
import org.openstreetmap.josm.gui.MainApplication;
4445
import org.openstreetmap.josm.io.NetworkManager;
46+
import org.openstreetmap.josm.io.OsmApi;
4547
import org.openstreetmap.josm.spi.preferences.AbstractPreferences;
4648
import org.openstreetmap.josm.spi.preferences.Config;
4749
import org.openstreetmap.josm.spi.preferences.DefaultPreferenceChangeEvent;
@@ -910,6 +912,12 @@ private void removeAndUpdateObsolete(int loadedVersion) {
910912
}
911913
modifiedDefault = false;
912914
}
915+
// As of June 1st, 2024, the OSM.org instance no longer allows basic authentication.
916+
if (JosmUrls.getInstance().getDefaultOsmApiUrl().equals(OsmApi.getOsmApi().getServerUrl()) && "basic".equals(OsmApi.getAuthMethod())) {
917+
put("osm-server.auth-method", null);
918+
put("osm-server.username", null);
919+
put("osm-server.password", null);
920+
}
913921
}
914922

915923
/**

src/org/openstreetmap/josm/gui/preferences/server/AuthenticationPreferencesPanel.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import javax.swing.JPanel;
1818
import javax.swing.JRadioButton;
1919

20-
import org.openstreetmap.josm.actions.ExpertToggleAction;
2120
import org.openstreetmap.josm.data.UserIdentityManager;
2221
import org.openstreetmap.josm.data.oauth.OAuthAccessTokenHolder;
2322
import org.openstreetmap.josm.data.oauth.OAuthVersion;
@@ -47,15 +46,6 @@ public class AuthenticationPreferencesPanel extends VerticallyScrollablePanel im
4746
/** the panel for the OAuth 2.0 authentication parameters */
4847
private OAuthAuthenticationPreferencesPanel pnlOAuth20Preferences;
4948

50-
/** Used to determine which API we are using for disabling/enabling Basic Auth/OAuth 1.0a */
51-
private String apiUrl = OsmApi.getOsmApi().getServerUrl();
52-
/** ExpertToggleAction uses weak references; we don't want this listener to be garbage collected */
53-
private final ExpertToggleAction.ExpertModeChangeListener expertModeChangeListener = isExpert -> {
54-
final String authMethod = OsmApi.getAuthMethod();
55-
final boolean defaultApi = JosmUrls.getInstance().getDefaultOsmApiUrl().equals(apiUrl);
56-
rbBasicAuthentication.setEnabled(rbBasicAuthentication.isSelected() || "basic".equals(authMethod) || isExpert || !defaultApi);
57-
};
58-
5949
/**
6050
* Constructs a new {@code AuthenticationPreferencesPanel}.
6151
*/
@@ -108,9 +98,8 @@ protected final void build() {
10898
pnlBasicAuthPreferences = new BasicAuthenticationPreferencesPanel();
10999
pnlOAuth20Preferences = new OAuthAuthenticationPreferencesPanel(OAuthVersion.OAuth20);
110100

111-
ExpertToggleAction.addExpertModeChangeListener(expertModeChangeListener, true);
112-
113101
pnlAuthenticationParameters.add(pnlOAuth20Preferences, BorderLayout.CENTER);
102+
this.updateAcceptableAuthenticationMethods(OsmApi.getOsmApi().getServerUrl());
114103
}
115104

116105
/**
@@ -166,7 +155,6 @@ public final void saveToPreferences() {
166155
UserIdentityManager.getInstance().setAnonymous();
167156
}
168157
}
169-
ExpertToggleAction.removeExpertModeChangeListener(this.expertModeChangeListener);
170158
}
171159

172160
/**
@@ -195,8 +183,18 @@ public void propertyChange(PropertyChangeEvent evt) {
195183
pnlOAuth20Preferences.propertyChange(evt);
196184
}
197185
if (OsmApiUrlInputPanel.API_URL_PROP.equals(evt.getPropertyName())) {
198-
this.apiUrl = (String) evt.getNewValue();
199-
this.expertModeChangeListener.expertChanged(ExpertToggleAction.isExpert());
186+
this.updateAcceptableAuthenticationMethods((String) evt.getNewValue());
200187
}
201188
}
189+
190+
/**
191+
* Update the acceptable authentications methods
192+
* @param apiUrl The API url to check
193+
*/
194+
private void updateAcceptableAuthenticationMethods(String apiUrl) {
195+
final String authMethod = OsmApi.getAuthMethod();
196+
final boolean defaultApi = JosmUrls.getInstance().getDefaultOsmApiUrl().equals(apiUrl);
197+
rbBasicAuthentication.setEnabled(rbBasicAuthentication.isSelected() || "basic".equals(authMethod) || !defaultApi);
198+
}
199+
202200
}

0 commit comments

Comments
 (0)