Changeset 16422 in josm for trunk


Ignore:
Timestamp:
2020-05-16T16:38:31+02:00 (5 years ago)
Author:
simon04
Message:

fix #18820, see #13872 - Make OAuth signing of all API requests configurable

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

Legend:

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

    r14977 r16422  
    3434import org.openstreetmap.josm.io.OsmApi;
    3535import org.openstreetmap.josm.io.auth.CredentialsManager;
     36import org.openstreetmap.josm.tools.GBC;
    3637import org.openstreetmap.josm.tools.ImageProvider;
    3738import org.openstreetmap.josm.tools.Logging;
     
    4748 */
    4849public class OAuthAuthenticationPreferencesPanel extends JPanel implements PropertyChangeListener {
    49     private final JCheckBox cbShowAdvancedParameters = new JCheckBox();
     50    private final JCheckBox cbUseForAllRequests = new JCheckBox();
     51    private final JCheckBox cbShowAdvancedParameters = new JCheckBox(tr("Display Advanced OAuth Parameters"));
    5052    private final JCheckBox cbSaveToPreferences = new JCheckBox(tr("Save to preferences"));
    5153    private final JPanel pnlAuthorisationMessage = new JPanel(new BorderLayout());
     
    7072    protected JPanel buildAdvancedPropertiesPanel() {
    7173        JPanel pnl = new JPanel(new GridBagLayout());
    72         GridBagConstraints gc = new GridBagConstraints();
    73 
    74         gc.anchor = GridBagConstraints.NORTHWEST;
    75         gc.fill = GridBagConstraints.HORIZONTAL;
    76         gc.weightx = 0.0;
    77         gc.insets = new Insets(0, 0, 0, 3);
    78         pnl.add(cbShowAdvancedParameters, gc);
     74
     75        cbUseForAllRequests.setText(tr("Use OAuth for all requests to {0}", OsmApi.getOsmApi().getServerUrl()));
     76        cbUseForAllRequests.setToolTipText(tr("For user-based bandwith limit instead of IP-based one"));
     77        pnl.add(cbUseForAllRequests, GBC.eol().fill(GBC.HORIZONTAL));
     78
     79        pnl.add(cbShowAdvancedParameters, GBC.eol().fill(GBC.HORIZONTAL));
    7980        cbShowAdvancedParameters.setSelected(false);
    8081        cbShowAdvancedParameters.addItemListener(
     
    8283        );
    8384
    84         gc.gridx = 1;
    85         gc.weightx = 1.0;
    86         JMultilineLabel lbl = new JMultilineLabel(tr("Display Advanced OAuth Parameters"));
    87         lbl.setFont(lbl.getFont().deriveFont(Font.PLAIN));
    88         pnl.add(lbl, gc);
    89 
    90         gc.gridy = 1;
    91         gc.gridx = 1;
    92         gc.insets = new Insets(3, 0, 3, 0);
    93         gc.fill = GridBagConstraints.BOTH;
    94         gc.weightx = 1.0;
    95         gc.weighty = 1.0;
    96         pnl.add(pnlAdvancedProperties, gc);
     85        pnl.add(pnlAdvancedProperties, GBC.eol().fill(GBC.HORIZONTAL).insets(0, 3, 0, 0));
    9786        pnlAdvancedProperties.initialize(OsmApi.getOsmApi().getServerUrl());
    9887        pnlAdvancedProperties.setBorder(
     
    153142    public void initFromPreferences() {
    154143        setApiUrl(OsmApi.getOsmApi().getServerUrl().trim());
     144        cbUseForAllRequests.setSelected(OsmApi.USE_OAUTH_FOR_ALL_REQUESTS.get());
    155145        refreshView();
    156146    }
     
    162152        OAuthAccessTokenHolder.getInstance().setSaveToPreferences(cbSaveToPreferences.isSelected());
    163153        OAuthAccessTokenHolder.getInstance().save(CredentialsManager.getInstance());
     154        OsmApi.USE_OAUTH_FOR_ALL_REQUESTS.put(cbUseForAllRequests.isSelected());
    164155        pnlAdvancedProperties.rememberPreferences();
    165156    }
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r15969 r16422  
    3131import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3232import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     33import org.openstreetmap.josm.data.preferences.BooleanProperty;
    3334import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    3435import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     
    6970     */
    7071    public static final int MAX_DOWNLOAD_THREADS = 2;
     72
     73    /**
     74     * Defines whether all OSM API requests should be signed with an OAuth token (user-based bandwith limit instead of IP-based one)
     75     */
     76    public static final BooleanProperty USE_OAUTH_FOR_ALL_REQUESTS = new BooleanProperty("oauth.use-for-all-requests", true);
    7177
    7278    // The collection of instantiated OSM APIs
  • trunk/src/org/openstreetmap/josm/io/OsmServerReader.java

    r15969 r16422  
    5050    public OsmServerReader() {
    5151        try {
    52             doAuthenticate = OsmApi.isUsingOAuth() && CredentialsManager.getInstance().lookupOAuthAccessToken() != null;
     52            doAuthenticate = OsmApi.isUsingOAuth()
     53                    && CredentialsManager.getInstance().lookupOAuthAccessToken() != null
     54                    && OsmApi.USE_OAUTH_FOR_ALL_REQUESTS.get();
    5355        } catch (CredentialsAgentException e) {
    5456            Logging.warn(e);
Note: See TracChangeset for help on using the changeset viewer.