Changeset 3344 in josm for trunk


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

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

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

Legend:

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

    r3194 r3344  
    719719    }
    720720    synchronized public void removeFromCollection(String key, String value) {
    721         List<String> a = new ArrayList<String>(getCollection(key, null));
     721        List<String> a = new ArrayList<String>(getCollection(key, Collections.<String>emptyList()));
    722722        a.remove(value);
    723723        putCollection(key, a);
  • trunk/src/org/openstreetmap/josm/gui/io/UploadStrategy.java

    r3083 r3344  
    6464     */
    6565    public static UploadStrategy getFromPreferences() {
    66         String v = Main.pref.get("osm-server.upload-strategy");
     66        String v = Main.pref.get("osm-server.upload-strategy", null);
    6767        if (v == null) {
    6868            // legacy support. Until 12/2009 we had osm-server.atomic-upload only.
     
    7070            // When the preferences are saved the next time, "osm-server.upload-strategy"
    7171            // will be inserted.
    72             v = Main.pref.get("osm-server.atomic-upload");
     72            v = Main.pref.get("osm-server.atomic-upload", null);
    7373            if (v != null) {
    7474                Main.pref.removeFromCollection("osm-server.atomic-upload", v);
     75            } else {
     76                v = "";
    7577            }
    7678            v = v.trim().toLowerCase();
  • 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.