Changeset 18651 in josm for trunk/src


Ignore:
Timestamp:
2023-02-08T22:22:05+01:00 (22 months ago)
Author:
taylor.smock
Message:

See #20768/r18650: Add OAuth 2.0 support

This fixes tests that don't have the HTTP factory set or have "http://invalid"
set as the OSM API url.

It also fixes 2 static analysis warnings.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/oauth/OAuthParameters.java

    r18650 r18651  
    100100        final String redirectUri;
    101101        final String baseUrl;
    102         if (apiUrl != null && !Config.getUrls().getDefaultOsmApiUrl().equals(apiUrl)) {
     102        if (apiUrl != null && !Config.getUrls().getDefaultOsmApiUrl().equals(apiUrl) && !"http://invalid".equals(apiUrl)) {
    103103            clientId = "";
    104104            clientSecret = "";
  • trunk/src/org/openstreetmap/josm/io/OsmConnection.java

    r18650 r18651  
    1111import java.util.Base64;
    1212import java.util.Objects;
     13import java.util.concurrent.CountDownLatch;
    1314import java.util.concurrent.TimeUnit;
    14 import java.util.concurrent.atomic.AtomicBoolean;
    1515import java.util.function.Consumer;
    1616
     
    214214            RemoteControl.start();
    215215        }
    216         AtomicBoolean done = new AtomicBoolean();
     216        CountDownLatch done = new CountDownLatch(1);
    217217        Consumer<IOAuthToken> consumer = authToken -> {
    218218                    if (!remoteControlIsRunning) {
     
    223223                    OAuthAccessTokenHolder.getInstance().setAccessToken(OsmApi.getOsmApi().getServerUrl(), authToken);
    224224                    OAuthAccessTokenHolder.getInstance().save(CredentialsManager.getInstance());
    225                     synchronized (done) {
    226                         done.set(true);
    227                         done.notifyAll();
    228                     }
     225                    done.countDown();
    229226                };
    230227        new OAuth20Authorization().authorize(oAuth20Parameters,
     
    235232            // Only wait at most 5 minutes
    236233            int counter = 0;
    237             while (!done.get() && counter < 5) {
     234            while (done.getCount() >= 0 && counter < 5) {
    238235                try {
    239                     done.wait(TimeUnit.MINUTES.toMillis(1));
     236                    if (done.await(1, TimeUnit.MINUTES)) {
     237                        break;
     238                    }
    240239                } catch (InterruptedException e) {
    241240                    Thread.currentThread().interrupt();
Note: See TracChangeset for help on using the changeset viewer.