Changeset 4263 in josm


Ignore:
Timestamp:
2011-07-25T00:48:51+02:00 (13 years ago)
Author:
bastiK
Message:

do not save username in preference file unconditionally - let the credentials manager handle it

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/JosmUserIdentityManager.java

    r4246 r4263  
    1010import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
    1111import org.openstreetmap.josm.data.osm.UserInfo;
     12import org.openstreetmap.josm.io.auth.CredentialsManager;
    1213import org.openstreetmap.josm.tools.CheckParameterUtil;
    1314
     
    168169     */
    169170    public void initFromPreferences() {
    170         String userName = Main.pref.get("osm-server.username");
     171        String userName = CredentialsManager.getInstance().getUsername();
    171172        if (isAnonymous()) {
    172173            if (userName != null && ! userName.trim().equals("")) {
  • trunk/src/org/openstreetmap/josm/gui/history/VersionInfoPanel.java

    r4191 r4263  
    2222import org.openstreetmap.josm.gui.JMultilineLabel;
    2323import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     24import org.openstreetmap.josm.io.auth.CredentialsManager;
    2425import org.openstreetmap.josm.tools.CheckParameterUtil;
    2526import org.openstreetmap.josm.tools.UrlLabel;
     
    147148            lblUser.setDescription(username);
    148149        } else {
    149             String user = Main.pref.get("osm-server.username");
     150            String user = CredentialsManager.getInstance().getUsername();
    150151            if (user == null) {
    151152                lblUser.setDescription(tr("anonymous"));
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/BasicAuthenticationPreferencesPanel.java

    r4249 r4263  
    119119            );
    120120            cm.store(RequestorType.SERVER, pa);
    121             // always save the username to the preferences if it isn't already saved there
    122             // by the credential manager
    123             if (! (cm instanceof JosmPreferencesCredentialAgent)) {
    124                 Main.pref.put("osm-server.username", tfOsmUserName.getText().trim());
    125             }
    126121        } catch(CredentialsAgentException e) {
    127122            e.printStackTrace();
  • trunk/src/org/openstreetmap/josm/io/GpxExporter.java

    r3083 r4263  
    3434import org.openstreetmap.josm.gui.layer.Layer;
    3535import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     36import org.openstreetmap.josm.io.auth.CredentialsManager;
    3637import org.openstreetmap.josm.tools.CheckParameterUtil;
    3738import org.openstreetmap.josm.tools.GBC;
     
    8485        JLabel emailLabel = new JLabel(tr("E-Mail"));
    8586        p.add(emailLabel, GBC.std().insets(10, 0, 5, 0));
    86         JTextField email = new JTextField(Main.pref.get("osm-server.username"));
     87        String user = CredentialsManager.getInstance().getUsername();
     88        JTextField email = new JTextField(user == null ? "" : user);
    8789        p.add(email, GBC.eol().fill(GBC.HORIZONTAL));
    8890        JLabel copyrightLabel = new JLabel(tr("Copyright (URL)"));
     
    232234                emailLabel.setEnabled(b);
    233235                authorName.setText(b ? Main.pref.get("lastAuthorName") : "");
    234                 email.setText(b ? Main.pref.get("osm-server.username") : "");
     236                String user = CredentialsManager.getInstance().getUsername();
     237                email.setText(b ? (user == null ? "" : user) : "");
    235238
    236239                boolean authorSet = authorName.getText().length() != 0;
  • trunk/src/org/openstreetmap/josm/io/auth/CredentialsManager.java

    r4249 r4263  
    77
    88import org.openstreetmap.josm.data.oauth.OAuthToken;
     9import org.openstreetmap.josm.gui.JosmUserIdentityManager;
     10import org.openstreetmap.josm.tools.Utils;
    911
    1012/**
     
    6365    }
    6466
     67    public String getUsername() {
     68        String username = null;
     69        try {
     70            PasswordAuthentication auth = lookup(RequestorType.SERVER);
     71            if (auth != null) {
     72                username = auth.getUserName();
     73            }
     74        } catch (CredentialsAgentException ex) {
     75            return null;
     76        }
     77        if (username == null) return null;
     78        username = username.trim();
     79        return Utils.equal(username, "") ? null : username;
     80    }
     81
    6582    @Override
    6683    public PasswordAuthentication lookup(RequestorType requestorType) throws CredentialsAgentException {
     
    7087    @Override
    7188    public void store(RequestorType requestorType, PasswordAuthentication credentials) throws CredentialsAgentException {
     89        if (requestorType == RequestorType.SERVER && credentials.getUserName() != null) {
     90            JosmUserIdentityManager.getInstance().setPartiallyIdentified(credentials.getUserName());
     91        }
    7292        delegate.store(requestorType, credentials);
    7393    }
  • trunk/src/org/openstreetmap/josm/tools/ExceptionUtil.java

    r4036 r4263  
    2727import org.openstreetmap.josm.io.OsmApiInitializationException;
    2828import org.openstreetmap.josm.io.OsmTransferException;
     29import org.openstreetmap.josm.io.auth.CredentialsManager;
    2930
    3031public class ExceptionUtil {
     
    115116                + "Please check the username and the password in the JOSM preferences."
    116117                + "</html>",
    117                 Main.pref.get("osm-server.username")
     118                CredentialsManager.getInstance().getUsername()
    118119        );
    119120    }
Note: See TracChangeset for help on using the changeset viewer.