- Timestamp:
- 2017-09-11T01:54:52+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r12808 r12821 97 97 import org.openstreetmap.josm.gui.bugreport.BugReportDialog; 98 98 import org.openstreetmap.josm.gui.download.DownloadDialog; 99 import org.openstreetmap.josm.gui.io.CredentialDialog; 99 100 import org.openstreetmap.josm.gui.io.CustomConfigurator.XMLCommandProcessor; 100 101 import org.openstreetmap.josm.gui.io.SaveLayersDialog; … … 132 133 import org.openstreetmap.josm.io.OsmTransferCanceledException; 133 134 import org.openstreetmap.josm.io.OsmTransferException; 135 import org.openstreetmap.josm.io.auth.AbstractCredentialsAgent; 134 136 import org.openstreetmap.josm.io.auth.CredentialsManager; 135 137 import org.openstreetmap.josm.io.auth.DefaultAuthenticator; … … 1089 1091 static void setupCallbacks() { 1090 1092 OsmConnection.setOAuthAccessTokenFetcher(OAuthAuthorizationWizard::obtainAccessToken); 1093 AbstractCredentialsAgent.setCredentialsProvider(CredentialDialog::promptCredentials); 1091 1094 MessageNotifier.setNotifierCallback(MainApplication::notifyNewMessages); 1092 1095 DeleteCommand.setDeletionCallback(DeleteAction.defaultDeletionCallback); -
trunk/src/org/openstreetmap/josm/gui/io/CredentialDialog.java
r12805 r12821 18 18 import java.awt.event.WindowAdapter; 19 19 import java.awt.event.WindowEvent; 20 import java.net.Authenticator.RequestorType; 20 21 import java.util.Objects; 21 22 … … 32 33 import org.openstreetmap.josm.gui.help.ContextSensitiveHelpAction; 33 34 import org.openstreetmap.josm.gui.help.HelpUtil; 35 import org.openstreetmap.josm.gui.util.GuiHelper; 34 36 import org.openstreetmap.josm.gui.util.WindowGeometry; 35 37 import org.openstreetmap.josm.gui.widgets.JMultilineLabel; … … 38 40 import org.openstreetmap.josm.io.DefaultProxySelector; 39 41 import org.openstreetmap.josm.io.OsmApi; 42 import org.openstreetmap.josm.io.auth.AbstractCredentialsAgent; 43 import org.openstreetmap.josm.io.auth.CredentialsAgentResponse; 40 44 import org.openstreetmap.josm.tools.ImageProvider; 41 45 import org.openstreetmap.josm.tools.InputMapUtils; … … 68 72 dialog.pack(); 69 73 return dialog; 74 } 75 76 /** 77 * Prompts the user (in the EDT) for credentials and fills the given response with what has been entered. 78 * @param requestorType type of the entity requesting authentication 79 * @param agent the credentials agent requesting credentials 80 * @param response authentication response to fill 81 * @param username the known username, if any. Likely to be empty 82 * @param password the known password, if any. Likely to be empty 83 * @param host the host against authentication will be performed 84 * @since 12821 85 */ 86 public static void promptCredentials(RequestorType requestorType, AbstractCredentialsAgent agent, CredentialsAgentResponse response, 87 String username, String password, String host) { 88 GuiHelper.runInEDTAndWait(() -> { 89 CredentialDialog dialog; 90 if (requestorType.equals(RequestorType.PROXY)) 91 dialog = getHttpProxyCredentialDialog( 92 username, password, host, agent.getSaveUsernameAndPasswordCheckboxText()); 93 else 94 dialog = getOsmApiCredentialDialog( 95 username, password, host, agent.getSaveUsernameAndPasswordCheckboxText()); 96 dialog.setVisible(true); 97 response.setCanceled(dialog.isCanceled()); 98 if (dialog.isCanceled()) 99 return; 100 response.setUsername(dialog.getUsername()); 101 response.setPassword(dialog.getPassword()); 102 response.setSaveCredentials(dialog.isSaveCredentials()); 103 }); 70 104 } 71 105 -
trunk/src/org/openstreetmap/josm/io/auth/AbstractCredentialsAgent.java
r12646 r12821 2 2 package org.openstreetmap.josm.io.auth; 3 3 4 import java.awt.GraphicsEnvironment;5 4 import java.net.Authenticator.RequestorType; 6 5 import java.net.PasswordAuthentication; 7 6 import java.util.EnumMap; 8 7 import java.util.Map; 8 import java.util.Objects; 9 9 10 import org.openstreetmap.josm.gui.io.CredentialDialog; 11 import org.openstreetmap.josm.gui.util.GuiHelper; 10 import org.openstreetmap.josm.tools.Logging; 12 11 13 12 /** 14 13 * Partial implementation of the {@link CredentialsAgent} interface. 15 14 * <p> 16 * Provides a memory cache for the credentials and means to query the information 17 * from the user.15 * Provides a memory cache for the credentials and means to query the information from the user. 16 * @since 4246 18 17 */ 19 18 public abstract class AbstractCredentialsAgent implements CredentialsAgent { 19 20 /** 21 * Synchronous credentials provider. Called if no credentials are cached. Can be used for user login prompt. 22 * @since 12821 23 */ 24 @FunctionalInterface 25 public interface CredentialsProvider { 26 /** 27 * Fills the given response with appropriate user credentials. 28 * @param requestorType type of the entity requesting authentication 29 * @param agent the credentials agent requesting credentials 30 * @param response authentication response to fill 31 * @param username the known username, if any. Likely to be empty 32 * @param password the known password, if any. Likely to be empty 33 * @param host the host against authentication will be performed 34 */ 35 void provideCredentials(RequestorType requestorType, AbstractCredentialsAgent agent, CredentialsAgentResponse response, 36 String username, String password, String host); 37 } 38 39 private static CredentialsProvider credentialsProvider = (a, b, c, d, e, f) -> Logging.error("Credentials provider has not been set"); 40 41 /** 42 * Sets the global credentials provider. 43 * @param provider credentials provider. Called if no credentials are cached. Can be used for user login prompt 44 */ 45 public static void setCredentialsProvider(CredentialsProvider provider) { 46 credentialsProvider = Objects.requireNonNull(provider, "provider"); 47 } 20 48 21 49 protected Map<RequestorType, PasswordAuthentication> memoryCredentialsCache = new EnumMap<>(RequestorType.class); … … 51 79 */ 52 80 } else if (noSuccessWithLastResponse || username.isEmpty() || password.isEmpty()) { 53 if (!GraphicsEnvironment.isHeadless()) { 54 GuiHelper.runInEDTAndWait(() -> { 55 CredentialDialog dialog; 56 if (requestorType.equals(RequestorType.PROXY)) 57 dialog = CredentialDialog.getHttpProxyCredentialDialog( 58 username, password, host, getSaveUsernameAndPasswordCheckboxText()); 59 else 60 dialog = CredentialDialog.getOsmApiCredentialDialog( 61 username, password, host, getSaveUsernameAndPasswordCheckboxText()); 62 dialog.setVisible(true); 63 response.setCanceled(dialog.isCanceled()); 64 if (dialog.isCanceled()) 65 return; 66 response.setUsername(dialog.getUsername()); 67 response.setPassword(dialog.getPassword()); 68 response.setSaveCredentials(dialog.isSaveCredentials()); 69 }); 70 } 81 credentialsProvider.provideCredentials(requestorType, this, response, username, password, host); 71 82 if (response.isCanceled() || response.getUsername() == null || response.getPassword() == null) { 72 83 return response;
Note:
See TracChangeset
for help on using the changeset viewer.