Changeset 19007 in josm


Ignore:
Timestamp:
2024-03-04T17:06:32+01:00 (2 months ago)
Author:
taylor.smock
Message:

OAuth2: Fix an issue where a valid URL would have no host

File:
1 edited

Legend:

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

    r18991 r19007  
    1717import java.beans.PropertyChangeListener;
    1818import java.net.URI;
     19import java.net.URISyntaxException;
    1920import java.util.Arrays;
    2021import java.util.Objects;
     
    318319            if (procedure == AuthorizationProcedure.MANUALLY) {
    319320                this.setEnabled(true);
    320             } else if (Utils.isValidUrl(apiUrl) && DomainValidator.getInstance().isValid(URI.create(apiUrl).getHost())) {
    321                 // We want to avoid trying to make connection with an invalid URL
    322                 final String currentApiUrl = apiUrl;
    323                 MainApplication.worker.execute(() -> {
    324                     final String clientId = OAuthParameters.createDefault(apiUrl, oAuthVersion).getClientId();
    325                     if (Objects.equals(apiUrl, currentApiUrl)) {
    326                         GuiHelper.runInEDT(() -> this.setEnabled(!Utils.isEmpty(clientId)));
    327                     }
    328                 });
     321            } else if (Utils.isValidUrl(apiUrl)) {
     322                final URI apiURI;
     323                try {
     324                    apiURI = new URI(apiUrl);
     325                } catch (URISyntaxException e) {
     326                    Logging.trace(e);
     327                    return;
     328                }
     329                if (DomainValidator.getInstance().isValid(apiURI.getHost())) {
     330                    // We want to avoid trying to make connection with an invalid URL
     331                    final String currentApiUrl = apiUrl;
     332                    MainApplication.worker.execute(() -> {
     333                        final String clientId = OAuthParameters.createDefault(apiUrl, oAuthVersion).getClientId();
     334                        if (Objects.equals(apiUrl, currentApiUrl)) {
     335                            GuiHelper.runInEDT(() -> this.setEnabled(!Utils.isEmpty(clientId)));
     336                        }
     337                    });
     338                }
    329339            }
    330340        }
Note: See TracChangeset for help on using the changeset viewer.