Changeset 12821 in josm for trunk/src/org/openstreetmap/josm/io/auth/AbstractCredentialsAgent.java
- Timestamp:
- 2017-09-11T01:54:52+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.