Ignore:
Timestamp:
2010-06-26T21:09:24+02:00 (11 years ago)
Author:
bastiK
Message:

fixed #4259 - Authentication dialog appears several times while uploading a changeset

Location:
trunk/src/org/openstreetmap/josm/io
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/OsmConnection.java

    r2990 r3344  
    7373     *
    7474     * @param con the connection
    75      * @throws OsmTransferException thrown is something went wrong. Check for nested exceptions
     75     * @throws OsmTransferException thrown if something went wrong. Check for nested exceptions
    7676     */
    7777    protected void addBasicAuthorizationHeader(HttpURLConnection con) throws OsmTransferException {
  • trunk/src/org/openstreetmap/josm/io/auth/CredentialsManagerFactory.java

    r3083 r3344  
    1717     */
    1818    static public CredentialsManager getCredentialManager() {
    19         if (instance == null)
    20             return new JosmPreferencesCredentialManager();
     19        if (instance == null) {
     20            instance =  new JosmPreferencesCredentialManager();
     21        }
    2122        return instance;
    2223    }
  • trunk/src/org/openstreetmap/josm/io/auth/JosmPreferencesCredentialManager.java

    r3083 r3344  
    44import java.net.PasswordAuthentication;
    55import java.net.Authenticator.RequestorType;
     6import java.util.HashMap;
     7import java.util.Map;
    68
    79import org.openstreetmap.josm.Main;
     
    1719public class JosmPreferencesCredentialManager implements CredentialsManager {
    1820
     21    Map<RequestorType, PasswordAuthentication> memoryCredentialsCache = new HashMap<RequestorType, PasswordAuthentication>();
    1922    /**
    2023     * @see CredentialsManager#lookup(RequestorType)
     
    8083        CredentialsManagerResponse response = new CredentialsManagerResponse();
    8184
    82         if (noSuccessWithLastResponse|| username.equals("") || password.equals("")) {
     85        /*
     86         * Last request was successful and there was no credentials stored
     87         * in file. -> Try to recall credentials that have been entered
     88         * manually in this session.
     89         */
     90        if (!noSuccessWithLastResponse && credentials == null && memoryCredentialsCache.containsKey(requestorType)) {
     91            PasswordAuthentication pa = memoryCredentialsCache.get(requestorType);
     92            response.setUsername(pa.getUserName());
     93            response.setPassword(pa.getPassword());
     94            response.setCanceled(false);
     95        /*
     96         * Prompt the user for credentials. This happens the first time each
     97         * josm start if the user does not save the credentials to preference
     98         * file (username=="") and each time after authentication failed
     99         * (noSuccessWithLastResponse == true).
     100         */
     101        } else if (noSuccessWithLastResponse || username.equals("") || password.equals("")) {
    83102            CredentialDialog dialog = null;
    84103            switch(requestorType) {
     
    97116                        response.getPassword()
    98117                ));
     118            /*
     119             * User decides not to save credentials to file. Keep it
     120             * in memory so we don't have to ask over and over again.
     121             */
     122            } else {
     123                PasswordAuthentication pa = new PasswordAuthentication(dialog.getUsername(), dialog.getPassword());
     124                memoryCredentialsCache.put(requestorType, pa);
    99125            }
     126        /*
     127         * We got it from file.
     128         */
    100129        } else {
    101130            response.setUsername(username);
Note: See TracChangeset for help on using the changeset viewer.