Changeset 12803 in josm
- Timestamp:
- 2017-09-09T16:45:41+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r12796 r12803 107 107 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 108 108 import org.openstreetmap.josm.gui.layer.TMSLayer; 109 import org.openstreetmap.josm.gui.oauth.OAuthAuthorizationWizard; 109 110 import org.openstreetmap.josm.gui.preferences.ToolbarPreferences; 110 111 import org.openstreetmap.josm.gui.preferences.display.LafPreference; … … 126 127 import org.openstreetmap.josm.io.OsmApi; 127 128 import org.openstreetmap.josm.io.OsmApiInitializationException; 129 import org.openstreetmap.josm.io.OsmConnection; 128 130 import org.openstreetmap.josm.io.OsmTransferCanceledException; 129 131 import org.openstreetmap.josm.io.OsmTransferException; … … 1070 1072 1071 1073 static void setupCallbacks() { 1074 OsmConnection.setOAuthAccessTokenFetcher(OAuthAuthorizationWizard::obtainAccessToken); 1072 1075 MessageNotifier.setNotifierCallback(MainApplication::notifyNewMessages); 1073 1076 DeleteCommand.setDeletionCallback(DeleteAction.defaultDeletionCallback); -
trunk/src/org/openstreetmap/josm/gui/oauth/OAuthAuthorizationWizard.java
r12686 r12803 21 21 import java.beans.PropertyChangeEvent; 22 22 import java.beans.PropertyChangeListener; 23 import java.lang.reflect.InvocationTargetException; 24 import java.net.URL; 23 25 import java.util.concurrent.Executor; 26 import java.util.concurrent.FutureTask; 24 27 25 28 import javax.swing.AbstractAction; … … 30 33 import javax.swing.JPanel; 31 34 import javax.swing.JScrollPane; 35 import javax.swing.SwingUtilities; 32 36 import javax.swing.UIManager; 33 37 import javax.swing.event.HyperlinkEvent; … … 51 55 import org.openstreetmap.josm.tools.OpenBrowser; 52 56 import org.openstreetmap.josm.tools.UserCancelException; 57 import org.openstreetmap.josm.tools.Utils; 53 58 54 59 /** … … 333 338 } 334 339 340 /** 341 * Obtains an OAuth access token for the connection. Afterwards, the token is accessible via {@link OAuthAccessTokenHolder}. 342 * @param serverUrl the URL to OSM server 343 * @throws InterruptedException if we're interrupted while waiting for the event dispatching thread to finish OAuth authorization task 344 * @throws InvocationTargetException if an exception is thrown while running OAuth authorization task 345 * @since 12803 346 */ 347 public static void obtainAccessToken(final URL serverUrl) throws InvocationTargetException, InterruptedException { 348 final Runnable authTask = new FutureTask<>(() -> { 349 // Concerning Utils.newDirectExecutor: Main worker cannot be used since this connection is already 350 // executed via main worker. The OAuth connections would block otherwise. 351 final OAuthAuthorizationWizard wizard = new OAuthAuthorizationWizard( 352 Main.parent, serverUrl.toExternalForm(), Utils.newDirectExecutor()); 353 wizard.showDialog(); 354 return wizard; 355 }); 356 // exception handling differs from implementation at GuiHelper.runInEDTAndWait() 357 if (SwingUtilities.isEventDispatchThread()) { 358 authTask.run(); 359 } else { 360 SwingUtilities.invokeAndWait(authTask); 361 } 362 } 363 335 364 class AuthorisationProcedureChangeListener implements ItemListener { 336 365 @Override -
trunk/src/org/openstreetmap/josm/io/OsmConnection.java
r12686 r12803 11 11 import java.util.Base64; 12 12 import java.util.Objects; 13 import java.util.concurrent.FutureTask;14 15 import javax.swing.SwingUtilities;16 13 17 14 import org.openstreetmap.josm.Main; 18 15 import org.openstreetmap.josm.data.oauth.OAuthAccessTokenHolder; 19 16 import org.openstreetmap.josm.data.oauth.OAuthParameters; 20 import org.openstreetmap.josm.gui.oauth.OAuthAuthorizationWizard;21 17 import org.openstreetmap.josm.io.auth.CredentialsAgentException; 22 18 import org.openstreetmap.josm.io.auth.CredentialsAgentResponse; 23 19 import org.openstreetmap.josm.io.auth.CredentialsManager; 24 20 import org.openstreetmap.josm.tools.HttpClient; 21 import org.openstreetmap.josm.tools.JosmRuntimeException; 25 22 import org.openstreetmap.josm.tools.Logging; 26 import org.openstreetmap.josm.tools.Utils;27 23 28 24 import oauth.signpost.OAuthConsumer; … … 39 35 protected HttpClient activeConnection; 40 36 protected OAuthParameters oauthParameters; 37 38 /** 39 * Retrieves OAuth access token. 40 * @since 12803 41 */ 42 public interface OAuthAccessTokenFetcher { 43 /** 44 * Obtains an OAuth access token for the connection. Afterwards, the token is accessible via {@link OAuthAccessTokenHolder}. 45 * @param serverUrl the URL to OSM server 46 * @throws InterruptedException if we're interrupted while waiting for the event dispatching thread to finish OAuth authorization task 47 * @throws InvocationTargetException if an exception is thrown while running OAuth authorization task 48 */ 49 void obtainAccessToken(URL serverUrl) throws InvocationTargetException, InterruptedException; 50 } 51 52 static OAuthAccessTokenFetcher fetcher = u -> { 53 throw new JosmRuntimeException("OsmConnection.setOAuthAccessTokenFetcher() has not been called"); 54 }; 55 56 /** 57 * Sets the OAuth access token fetcher. 58 * @param tokenFetcher new OAuth access token fetcher. Cannot be null 59 * @since 12803 60 */ 61 public static void setOAuthAccessTokenFetcher(OAuthAccessTokenFetcher tokenFetcher) { 62 fetcher = Objects.requireNonNull(tokenFetcher, "tokenFetcher"); 63 } 41 64 42 65 /** … … 110 133 111 134 /** 112 * Obtains an OAuth access token for the connection. Afterwards, the token is accessible via {@link OAuthAccessTokenHolder}. 135 * Obtains an OAuth access token for the connection. 136 * Afterwards, the token is accessible via {@link OAuthAccessTokenHolder} / {@link CredentialsManager}. 113 137 * @param connection connection for which the access token should be obtained 114 * @throws MissingOAuthAccessTokenException if the process cannot be complete csuccessfully138 * @throws MissingOAuthAccessTokenException if the process cannot be completed successfully 115 139 */ 116 140 protected void obtainAccessToken(final HttpClient connection) throws MissingOAuthAccessTokenException { … … 120 144 throw new MissingOAuthAccessTokenException(); 121 145 } 122 final Runnable authTask = new FutureTask<>(() -> { 123 // Concerning Utils.newDirectExecutor: Main worker cannot be used since this connection is already 124 // executed via main worker. The OAuth connections would block otherwise. 125 final OAuthAuthorizationWizard wizard = new OAuthAuthorizationWizard( 126 Main.parent, apiUrl.toExternalForm(), Utils.newDirectExecutor()); 127 wizard.showDialog(); 128 OAuthAccessTokenHolder.getInstance().setSaveToPreferences(true); 129 OAuthAccessTokenHolder.getInstance().save(Main.pref, CredentialsManager.getInstance()); 130 return wizard; 131 }); 132 // exception handling differs from implementation at GuiHelper.runInEDTAndWait() 133 if (SwingUtilities.isEventDispatchThread()) { 134 authTask.run(); 135 } else { 136 SwingUtilities.invokeAndWait(authTask); 137 } 146 fetcher.obtainAccessToken(apiUrl); 147 OAuthAccessTokenHolder.getInstance().setSaveToPreferences(true); 148 OAuthAccessTokenHolder.getInstance().save(Main.pref, CredentialsManager.getInstance()); 138 149 } catch (MalformedURLException | InterruptedException | InvocationTargetException e) { 139 150 throw new MissingOAuthAccessTokenException(e); -
trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java
r12796 r12803 7 7 import java.util.HashMap; 8 8 import java.util.Map; 9 import java.util.Objects; 9 10 import java.util.function.Supplier; 10 11 … … 211 212 */ 212 213 public static void setMapSizeSupplier(Supplier<Dimension> mapSizeSupplier) { 213 mapSize = mapSizeSupplier;214 mapSize = Objects.requireNonNull(mapSizeSupplier, "mapSizeSupplier"); 214 215 } 215 216
Note:
See TracChangeset
for help on using the changeset viewer.