Ignore:
Timestamp:
2010-01-06T20:35:56+01:00 (14 years ago)
Author:
Gubaer
Message:

new: JOSM now supports OAuth

See also online help for server preferences and new OAuth Authorisation Wizard

File:
1 edited

Legend:

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

    r2711 r2748  
    66
    77import org.openstreetmap.josm.Main;
     8import org.openstreetmap.josm.data.oauth.OAuthToken;
    89import org.openstreetmap.josm.gui.io.CredentialDialog;
    9 import org.openstreetmap.josm.gui.preferences.ProxyPreferences;
     10import org.openstreetmap.josm.gui.preferences.server.ProxyPreferencesPanel;
    1011
    1112/**
     
    3233            return new PasswordAuthentication(user, password == null ? new char[0] : password.toCharArray());
    3334        case PROXY:
    34             user = Main.pref.get(ProxyPreferences.PROXY_USER, null);
    35             password = Main.pref.get(ProxyPreferences.PROXY_PASS, null);
     35            user = Main.pref.get(ProxyPreferencesPanel.PROXY_USER, null);
     36            password = Main.pref.get(ProxyPreferencesPanel.PROXY_PASS, null);
    3637            if (user == null)
    3738                return null;
     
    5758            break;
    5859        case PROXY:
    59             Main.pref.put("proxy.username", credentials.getUserName());
     60            Main.pref.put(ProxyPreferencesPanel.PROXY_USER, credentials.getUserName());
    6061            if (credentials.getPassword() == null) {
    61                 Main.pref.put("proxy.password", null);
     62                Main.pref.put(ProxyPreferencesPanel.PROXY_PASS, null);
    6263            } else {
    63                 Main.pref.put("proxy.password", String.valueOf(credentials.getPassword()));
     64                Main.pref.put(ProxyPreferencesPanel.PROXY_PASS, String.valueOf(credentials.getPassword()));
    6465            }
    6566            break;
     
    104105        return response;
    105106    }
     107
     108
     109    /**
     110     * Lookup the current OAuth Access Token to access the OSM server. Replies null, if no
     111     * Access Token is currently managed by this CredentialManager.
     112     *
     113     * @return the current OAuth Access Token to access the OSM server.
     114     * @throws CredentialsManagerException thrown if something goes wrong
     115     */
     116    public OAuthToken lookupOAuthAccessToken() throws CredentialsManagerException {
     117        String accessTokenKey = Main.pref.get("oauth.access-token.key", null);
     118        String accessTokenSecret = Main.pref.get("oauth.access-token.secret", null);
     119        if (accessTokenKey == null && accessTokenSecret == null)
     120            return null;
     121        return new OAuthToken(accessTokenKey, accessTokenSecret);
     122    }
     123
     124    /**
     125     * Stores the OAuth Access Token <code>accessToken</code>.
     126     *
     127     * @param accessToken the access Token. null, to remove the Access Token.
     128     * @throws CredentialsManagerException thrown if something goes wrong
     129     */
     130    public void storeOAuthAccessToken(OAuthToken accessToken) throws CredentialsManagerException {
     131        if (accessToken == null) {
     132            Main.pref.put("oauth.access-token.key", null);
     133            Main.pref.put("oauth.access-token.secret", null);
     134        } else {
     135            Main.pref.put("oauth.access-token.key", accessToken.getKey());
     136            Main.pref.put("oauth.access-token.secret", accessToken.getSecret());
     137        }
     138    }
    106139}
Note: See TracChangeset for help on using the changeset viewer.