Changeset 5439 in josm


Ignore:
Timestamp:
2012-08-13T01:18:23+02:00 (12 years ago)
Author:
Don-vip
Message:

Adapt OAuth user identification mechanism so it is no longer reserved to changeset dialog and that it is only asked again when necessary

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 edited

Legend:

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

    r5434 r5439  
    5959        if (instance == null) {
    6060            instance = new JosmUserIdentityManager();
    61             instance.initFromPreferences();
     61            if (Main.pref.get("osm-server.auth-method").equals("oauth")) {
     62                try {
     63                    instance.initFromOAuth(Main.parent);
     64                } catch (Throwable t) {
     65                    t.printStackTrace();
     66                    // Fall back to preferences if OAuth identification fails for any reason
     67                    instance.initFromPreferences();
     68                }
     69            } else {
     70                instance.initFromPreferences();
     71            }
    6272            Main.pref.addPreferenceChangeListener(instance);
    6373        }
     
    6777    private String userName;
    6878    private UserInfo userInfo;
     79    private boolean accessTokenKeyChanged;
     80    private boolean accessTokenSecretChanged;
    6981
    7082    private JosmUserIdentityManager() {
     
    183195            }
    184196        } else {
    185             if (!userName.equals(this.userName)) {
     197            if (userName != null && !userName.equals(this.userName)) {
    186198                setPartiallyIdentified(userName);
    187199            } else {
     
    238250            }
    239251            return;
    240         }
    241 
    242         if (evt.getKey().equals("osm-server.url")) {
     252           
     253        } else if (evt.getKey().equals("osm-server.url")) {
    243254            if (!(evt.getNewValue() instanceof StringSetting)) return;
    244255            String newValue = ((StringSetting) evt.getNewValue()).getValue();
     
    248259                setPartiallyIdentified(getUserName());
    249260            }
     261           
     262        } else if (evt.getKey().equals("oauth.access-token.key")) {
     263            accessTokenKeyChanged = true;
     264           
     265        } else if (evt.getKey().equals("oauth.access-token.secret")) {
     266            accessTokenSecretChanged = true;
     267        }
     268       
     269        if (accessTokenKeyChanged && accessTokenSecretChanged) {
     270            accessTokenKeyChanged = false;
     271            accessTokenSecretChanged = false;
     272            if (Main.pref.get("osm-server.auth-method").equals("oauth")) {
     273                try {
     274                    instance.initFromOAuth(Main.parent);
     275                } catch (Throwable t) {
     276                    t.printStackTrace();
     277                }
     278            }
    250279        }
    251280    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManager.java

    r5434 r5439  
    532532        public void actionPerformed(ActionEvent arg0) {
    533533            JosmUserIdentityManager im = JosmUserIdentityManager.getInstance();
    534             if (Main.pref.get("osm-server.auth-method").equals("oauth")) {
    535                 im.initFromOAuth(ChangesetCacheManager.this);
    536             } else {
    537                 im.initFromPreferences();
    538                 if (im.isAnonymous()) {
    539                     alertAnonymousUser();
    540                     return;
    541                 }
     534            if (im.isAnonymous()) {
     535                alertAnonymousUser();
     536                return;
    542537            }
    543538            ChangesetQuery query = new ChangesetQuery();
Note: See TracChangeset for help on using the changeset viewer.