Changeset 4245 in josm for trunk/src


Ignore:
Timestamp:
2011-07-14T19:52:24+02:00 (13 years ago)
Author:
bastiK
Message:

some renames to simplify further development

Location:
trunk/src/org/openstreetmap/josm
Files:
9 edited
1 copied
4 moved

Legend:

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

    r4139 r4245  
    3232import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    3333import org.openstreetmap.josm.io.DefaultProxySelector;
    34 import org.openstreetmap.josm.io.auth.CredentialsManagerFactory;
     34import org.openstreetmap.josm.io.auth.CredentialsManager;
    3535import org.openstreetmap.josm.io.auth.DefaultAuthenticator;
    3636import org.openstreetmap.josm.io.remotecontrol.RemoteControl;
     
    188188        Main.pref.updateSystemProperties();
    189189
    190         DefaultAuthenticator.createInstance(CredentialsManagerFactory.getCredentialManager());
     190        DefaultAuthenticator.createInstance(CredentialsManager.getInstance());
    191191        Authenticator.setDefault(DefaultAuthenticator.getInstance());
    192192        ProxySelector.setDefault(new DefaultProxySelector(ProxySelector.getDefault()));
    193         OAuthAccessTokenHolder.getInstance().init(Main.pref, CredentialsManagerFactory.getCredentialManager());
     193        OAuthAccessTokenHolder.getInstance().init(Main.pref, CredentialsManager.getInstance());
    194194
    195195        // asking for help? show help and exit
  • trunk/src/org/openstreetmap/josm/gui/oauth/FullyAutomaticAuthorizationUI.java

    r4147 r4245  
    4343import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
    4444import org.openstreetmap.josm.io.OsmTransferException;
     45import org.openstreetmap.josm.io.auth.CredentialsAgent;
     46import org.openstreetmap.josm.io.auth.CredentialsAgentException;
    4547import org.openstreetmap.josm.io.auth.CredentialsManager;
    46 import org.openstreetmap.josm.io.auth.CredentialsManagerException;
    47 import org.openstreetmap.josm.io.auth.CredentialsManagerFactory;
    4848import org.openstreetmap.josm.tools.ImageProvider;
    4949import org.xml.sax.SAXException;
     
    182182    public void initFromPreferences(Preferences pref) {
    183183        super.initFromPreferences(pref);
    184         CredentialsManager cm = CredentialsManagerFactory.getCredentialManager();
     184        CredentialsAgent cm = CredentialsManager.getInstance();
    185185        try {
    186186            PasswordAuthentication pa = cm.lookup(RequestorType.SERVER);
     
    192192                tfPassword.setText(pa.getPassword() == null ? "" : String.valueOf(pa.getPassword()));
    193193            }
    194         } catch(CredentialsManagerException e) {
     194        } catch(CredentialsAgentException e) {
    195195            e.printStackTrace();
    196196            tfUserName.setText("");
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/AuthenticationPreferencesPanel.java

    r3530 r4245  
    2020import org.openstreetmap.josm.gui.help.HelpUtil;
    2121import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
    22 import org.openstreetmap.josm.io.auth.CredentialsManagerFactory;
     22import org.openstreetmap.josm.io.auth.CredentialsManager;
    2323
    2424/**
     
    124124            pnlBasicAuthPreferences.saveToPreferences();
    125125            OAuthAccessTokenHolder.getInstance().clear();
    126             OAuthAccessTokenHolder.getInstance().save(Main.pref, CredentialsManagerFactory.getCredentialManager());
     126            OAuthAccessTokenHolder.getInstance().save(Main.pref, CredentialsManager.getInstance());
    127127        } else if (authMethod.equals("oauth")) {
    128128            // clear the password in the preferences
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/BasicAuthenticationPreferencesPanel.java

    r3530 r4245  
    2020import org.openstreetmap.josm.gui.widgets.HtmlPanel;
    2121import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator;
     22import org.openstreetmap.josm.io.auth.CredentialsAgent;
     23import org.openstreetmap.josm.io.auth.CredentialsAgentException;
    2224import org.openstreetmap.josm.io.auth.CredentialsManager;
    23 import org.openstreetmap.josm.io.auth.CredentialsManagerException;
    24 import org.openstreetmap.josm.io.auth.CredentialsManagerFactory;
    25 import org.openstreetmap.josm.io.auth.JosmPreferencesCredentialManager;
     25import org.openstreetmap.josm.io.auth.JosmPreferencesCredentialAgent;
    2626
    2727/**
     
    103103
    104104    public void initFromPreferences() {
    105         CredentialsManager cm = CredentialsManagerFactory.getCredentialManager();
     105        CredentialsAgent cm = CredentialsManager.getInstance();
    106106        try {
    107107            PasswordAuthentication pa = cm.lookup(RequestorType.SERVER);
     
    113113                tfOsmPassword.setText(pa.getPassword() == null ? "" : String.valueOf(pa.getPassword()));
    114114            }
    115         } catch(CredentialsManagerException e) {
     115        } catch(CredentialsAgentException e) {
    116116            e.printStackTrace();
    117117            System.err.println(tr("Warning: failed to retrieve OSM credentials from credential manager."));
     
    123123
    124124    public void saveToPreferences() {
    125         CredentialsManager cm = CredentialsManagerFactory.getCredentialManager();
     125        CredentialsAgent cm = CredentialsManager.getInstance();
    126126        try {
    127127            PasswordAuthentication pa = new PasswordAuthentication(
     
    132132            // always save the username to the preferences if it isn't already saved there
    133133            // by the credential manager
    134             if (! (cm instanceof JosmPreferencesCredentialManager)) {
     134            if (! (cm instanceof JosmPreferencesCredentialAgent)) {
    135135                Main.pref.put("osm-server.username", tfOsmUserName.getText().trim());
    136136            }
    137         } catch(CredentialsManagerException e) {
     137        } catch(CredentialsAgentException e) {
    138138            e.printStackTrace();
    139139            System.err.println(tr("Warning: failed to save OSM credentials to credential manager."));
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/OAuthAccessTokenHolder.java

    r4191 r4245  
    66import org.openstreetmap.josm.data.Preferences;
    77import org.openstreetmap.josm.data.oauth.OAuthToken;
    8 import org.openstreetmap.josm.io.auth.CredentialsManager;
    9 import org.openstreetmap.josm.io.auth.CredentialsManagerException;
     8import org.openstreetmap.josm.io.auth.CredentialsAgent;
     9import org.openstreetmap.josm.io.auth.CredentialsAgentException;
    1010import org.openstreetmap.josm.tools.CheckParameterUtil;
    1111
     
    136136     * @throws IllegalArgumentException thrown if cm is null
    137137     */
    138     public void init(Preferences pref, CredentialsManager cm) throws IllegalArgumentException {
     138    public void init(Preferences pref, CredentialsAgent cm) throws IllegalArgumentException {
    139139        CheckParameterUtil.ensureParameterNotNull(pref, "pref");
    140140        CheckParameterUtil.ensureParameterNotNull(cm, "cm");
     
    142142        try {
    143143            token = cm.lookupOAuthAccessToken();
    144         } catch(CredentialsManagerException e) {
     144        } catch(CredentialsAgentException e) {
    145145            e.printStackTrace();
    146146            System.err.println(tr("Warning: Failed to retrieve OAuth Access Token from credential manager"));
     
    163163     * @throws IllegalArgumentException thrown if cm is null
    164164     */
    165     public void save(Preferences preferences, CredentialsManager cm) throws IllegalArgumentException {
     165    public void save(Preferences preferences, CredentialsAgent cm) throws IllegalArgumentException {
    166166        CheckParameterUtil.ensureParameterNotNull(preferences, "preferences");
    167167        CheckParameterUtil.ensureParameterNotNull(cm, "cm");
     
    173173                cm.storeOAuthAccessToken(new OAuthToken(accessTokenKey, accessTokenSecret));
    174174            }
    175         } catch(CredentialsManagerException e){
     175        } catch(CredentialsAgentException e){
    176176            e.printStackTrace();
    177177            System.err.println(tr("Warning: Failed to store OAuth Access Token to credentials manager"));
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/OAuthAuthenticationPreferencesPanel.java

    r4191 r4245  
    3232import org.openstreetmap.josm.gui.oauth.OAuthAuthorizationWizard;
    3333import org.openstreetmap.josm.gui.oauth.TestAccessTokenTask;
    34 import org.openstreetmap.josm.io.auth.CredentialsManagerFactory;
     34import org.openstreetmap.josm.io.auth.CredentialsManager;
    3535import org.openstreetmap.josm.tools.ImageProvider;
    3636
     
    161161    public void saveToPreferences() {
    162162        OAuthAccessTokenHolder.getInstance().setSaveToPreferences(cbSaveToPreferences.isSelected());
    163         OAuthAccessTokenHolder.getInstance().save(Main.pref, CredentialsManagerFactory.getCredentialManager());
     163        OAuthAccessTokenHolder.getInstance().save(Main.pref, CredentialsManager.getInstance());
    164164        pnlAdvancedProperties.getAdvancedParameters().saveToPreferences(Main.pref);
    165165    }
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/ProxyPreferencesPanel.java

    r3530 r4245  
    3131import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
    3232import org.openstreetmap.josm.io.DefaultProxySelector;
     33import org.openstreetmap.josm.io.auth.CredentialsAgent;
     34import org.openstreetmap.josm.io.auth.CredentialsAgentException;
    3335import org.openstreetmap.josm.io.auth.CredentialsManager;
    34 import org.openstreetmap.josm.io.auth.CredentialsManagerException;
    35 import org.openstreetmap.josm.io.auth.CredentialsManagerFactory;
    3636import org.openstreetmap.josm.tools.GBC;
    3737
     
    321321        // save the proxy user and the proxy password to a credentials store managed by
    322322        // the credentials manager
    323         CredentialsManager cm = CredentialsManagerFactory.getCredentialManager();
     323        CredentialsAgent cm = CredentialsManager.getInstance();
    324324        try {
    325325            PasswordAuthentication pa = cm.lookup(RequestorType.PROXY);
     
    331331                tfProxyHttpPassword.setText(pa.getPassword() == null ? "" : String.valueOf(pa.getPassword()));
    332332            }
    333         } catch(CredentialsManagerException e) {
     333        } catch(CredentialsAgentException e) {
    334334            e.printStackTrace();
    335335            tfProxyHttpUser.setText("");
     
    395395        }
    396396
    397         CredentialsManager cm = CredentialsManagerFactory.getCredentialManager();
     397        CredentialsAgent cm = CredentialsManager.getInstance();
    398398        try {
    399399            PasswordAuthentication pa = new PasswordAuthentication(
     
    402402            );
    403403            cm.store(RequestorType.PROXY, pa);
    404         } catch(CredentialsManagerException e) {
     404        } catch(CredentialsAgentException e) {
    405405            e.printStackTrace();
    406406        }
  • trunk/src/org/openstreetmap/josm/io/OsmConnection.java

    r4191 r4245  
    1818import org.openstreetmap.josm.data.oauth.OAuthParameters;
    1919import org.openstreetmap.josm.gui.preferences.server.OAuthAccessTokenHolder;
    20 import org.openstreetmap.josm.io.auth.CredentialsManagerException;
    21 import org.openstreetmap.josm.io.auth.CredentialsManagerFactory;
    22 import org.openstreetmap.josm.io.auth.CredentialsManagerResponse;
     20import org.openstreetmap.josm.io.auth.CredentialsAgentException;
     21import org.openstreetmap.josm.io.auth.CredentialsManager;
     22import org.openstreetmap.josm.io.auth.CredentialsAgentResponse;
    2323import org.openstreetmap.josm.tools.Base64;
    2424
     
    7373    protected void addBasicAuthorizationHeader(HttpURLConnection con) throws OsmTransferException {
    7474        CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
    75         CredentialsManagerResponse response;
     75        CredentialsAgentResponse response;
    7676        String token;
    7777        try {
    78             synchronized (CredentialsManagerFactory.getCredentialManager()) {
    79                 response = CredentialsManagerFactory.getCredentialManager().getCredentials(RequestorType.SERVER, false /* don't know yet whether the credentials will succeed */);
     78            synchronized (CredentialsManager.getInstance()) {
     79                response = CredentialsManager.getInstance().getCredentials(RequestorType.SERVER, false /* don't know yet whether the credentials will succeed */);
    8080            }
    81         } catch (CredentialsManagerException e) {
     81        } catch (CredentialsAgentException e) {
    8282            throw new OsmTransferException(e);
    8383        }
  • trunk/src/org/openstreetmap/josm/io/auth/CredentialsAgent.java

    r4238 r4245  
    88
    99/**
    10  * A CredentialManager manages two credentials:
     10 * A CredentialsAgent manages two credentials:
    1111 * <ul>
    1212 *   <li>the credential for {@see RequestorType#SERVER} which is equal to the OSM API credentials
     
    1818 *  In addition, it manages an OAuth Access Token for accessing the OSM server.
    1919 */
    20 public interface CredentialsManager {
     20public interface CredentialsAgent {
    2121
    2222    /**
     
    2626     * for a proxy server
    2727     * @return the credentials
    28      * @throws CredentialsManagerException thrown if a problem occurs in a implementation of this interface
     28     * @throws CredentialsAgentException thrown if a problem occurs in a implementation of this interface
    2929     */
    30     public PasswordAuthentication lookup(RequestorType requestorType) throws CredentialsManagerException;
     30    public PasswordAuthentication lookup(RequestorType requestorType) throws CredentialsAgentException;
    3131
    3232    /**
     
    3838     * @throws CredentialsManagerException thrown if a problem occurs in a implementation of this interface
    3939     */
    40     public void store(RequestorType requestorType, PasswordAuthentication credentials) throws CredentialsManagerException;
     40    public void store(RequestorType requestorType, PasswordAuthentication credentials) throws CredentialsAgentException;
    4141
    4242    /**
     
    4545     * for a proxy server
    4646     * @param noSuccessWithLastResponse true, if the last request with the supplied credentials failed; false otherwise.
    47      * If true, implementations of this interface are adviced prompt user for new credentials.
    48      * @throws CredentialsManagerException thrown if a problem occurs in a implementation of this interface
     47     * If true, implementations of this interface are advised to prompt the user for new credentials.
     48     * @throws CredentialsAgentException thrown if a problem occurs in a implementation of this interface
    4949
    5050     */
    51     public CredentialsManagerResponse getCredentials(RequestorType requestorType, boolean noSuccessWithLastResponse) throws CredentialsManagerException;
     51    public CredentialsAgentResponse getCredentials(RequestorType requestorType, boolean noSuccessWithLastResponse) throws CredentialsAgentException;
    5252
    5353    /**
    5454     * Lookup the current OAuth Access Token to access the OSM server. Replies null, if no
    55      * Access Token is currently managed by this CredentialManager.
     55     * Access Token is currently managed by this CredentialAgent.
    5656     *
    5757     * @return the current OAuth Access Token to access the OSM server.
    58      * @throws CredentialsManagerException thrown if something goes wrong
     58     * @throws CredentialsAgentException thrown if something goes wrong
    5959     */
    60     public OAuthToken lookupOAuthAccessToken() throws CredentialsManagerException;
     60    public OAuthToken lookupOAuthAccessToken() throws CredentialsAgentException;
    6161
    6262    /**
     
    6464     *
    6565     * @param accessToken the access Token. null, to remove the Access Token.
    66      * @throws CredentialsManagerException thrown if something goes wrong
     66     * @throws CredentialsAgentException thrown if something goes wrong
    6767     */
    68     public void storeOAuthAccessToken(OAuthToken accessToken) throws CredentialsManagerException;
     68    public void storeOAuthAccessToken(OAuthToken accessToken) throws CredentialsAgentException;
    6969}
  • trunk/src/org/openstreetmap/josm/io/auth/CredentialsAgentException.java

    r4238 r4245  
    22package org.openstreetmap.josm.io.auth;
    33
    4 public class CredentialsManagerException extends Exception {
    5     public CredentialsManagerException() {super();}
    6     public CredentialsManagerException(String message, Throwable cause) {super(message, cause);}
    7     public CredentialsManagerException(String message) {super(message);}
    8     public CredentialsManagerException(Throwable cause) {super(cause);}
     4public class CredentialsAgentException extends Exception {
     5    public CredentialsAgentException() {super();}
     6    public CredentialsAgentException(String message, Throwable cause) {super(message, cause);}
     7    public CredentialsAgentException(String message) {super(message);}
     8    public CredentialsAgentException(Throwable cause) {super(cause);}
    99
    1010}
  • trunk/src/org/openstreetmap/josm/io/auth/CredentialsAgentResponse.java

    r4238 r4245  
    33
    44/**
    5  * CredentialsManagerResponse represents the response from {@see CredentialsManager#getCredentials(java.net.Authenticator.RequestorType, boolean)}.
     5 * CredentialsAgentResponse represents the response from {@see CredentialsAgent#getCredentials(java.net.Authenticator.RequestorType, boolean)}.
    66 *
    77 * The response consists of the username and the password the requested credentials consists of.
     
    1010 *
    1111 */
    12 public class CredentialsManagerResponse {
     12public class CredentialsAgentResponse {
    1313    private String username;
    1414    private char[] password;
  • trunk/src/org/openstreetmap/josm/io/auth/CredentialsManager.java

    r4238 r4245  
    33
    44/**
    5  * CredentialManagerFactory is a factory for the single credential manager used.
     5 * CredentialManager is a factory for the single credential agent used.
    66 *
    7  * Currently, it defaults to replying an instance of {@see JosmPreferencesCredentialManager}.
     7 * Currently, it defaults to replying an instance of {@see JosmPreferencesCredentialAgent}.
    88 *
    99 */
    10 public class CredentialsManagerFactory {
    11     private static CredentialsManager instance;
     10public class CredentialsManager {
     11    private static CredentialsAgent instance;
    1212
    1313    /**
    14      * Replies the single credential manager used in JOSM
     14     * Replies the single credential agent used in JOSM
    1515     *
    16      * @return the single credential manager used in JOSM
     16     * @return the single credential agent used in JOSM
    1717     */
    18     static public CredentialsManager getCredentialManager() {
     18    static public CredentialsAgent getInstance() {
    1919        if (instance == null) {
    20             instance =  new JosmPreferencesCredentialManager();
     20            instance =  new JosmPreferencesCredentialAgent();
    2121        }
    2222        return instance;
  • trunk/src/org/openstreetmap/josm/io/auth/DefaultAuthenticator.java

    r4191 r4245  
    2222    }
    2323
    24     public static void createInstance(CredentialsManager credentialManager) {
     24    public static void createInstance(CredentialsAgent credentialManager) {
    2525        instance = new DefaultAuthenticator(credentialManager);
    2626    }
    2727
    28     private CredentialsManager credentialManager;
     28    private CredentialsAgent credentialsAgent;
    2929    private final Map<RequestorType, Boolean> credentialsTried = new HashMap<RequestorType, Boolean>();
    3030    private boolean enabled = true;
     
    3232    /**
    3333     *
    34      * @param credentialManager the credential manager
     34     * @param credentialsAgent the credential manager
    3535     */
    36     private DefaultAuthenticator(CredentialsManager credentialManager) {
    37         this.credentialManager = credentialManager;
     36    private DefaultAuthenticator(CredentialsAgent credentialsAgent) {
     37        this.credentialsAgent = credentialsAgent;
    3838    }
    3939
     
    5555            }
    5656            boolean tried = credentialsTried.get(getRequestorType()) != null;
    57             CredentialsManagerResponse response = credentialManager.getCredentials(getRequestorType(), tried);
     57            CredentialsAgentResponse response = credentialsAgent.getCredentials(getRequestorType(), tried);
    5858            if (response == null || response.isCanceled())
    5959                return null;
    6060            credentialsTried.put(getRequestorType(), true);
    6161            return new PasswordAuthentication(response.getUsername(), response.getPassword());
    62         } catch(CredentialsManagerException e) {
     62        } catch(CredentialsAgentException e) {
    6363            e.printStackTrace();
    6464            return null;
  • trunk/src/org/openstreetmap/josm/io/auth/JosmPreferencesCredentialAgent.java

    r4238 r4245  
    1313
    1414/**
    15  * This is the default credential manager in JOSM. It keeps username and password for both
     15 * This is the default credentials agent in JOSM. It keeps username and password for both
    1616 * the OSM API and an optional HTTP proxy in the JOSM preferences file.
    1717 *
    1818 */
    19 public class JosmPreferencesCredentialManager implements CredentialsManager {
     19public class JosmPreferencesCredentialAgent implements CredentialsAgent {
    2020
    2121    Map<RequestorType, PasswordAuthentication> memoryCredentialsCache = new HashMap<RequestorType, PasswordAuthentication>();
    2222    /**
    23      * @see CredentialsManager#lookup(RequestorType)
     23     * @see CredentialsAgent#lookup(RequestorType)
    2424     */
    25     public PasswordAuthentication lookup(RequestorType requestorType) throws CredentialsManagerException{
     25    @Override
     26    public PasswordAuthentication lookup(RequestorType requestorType) throws CredentialsAgentException{
    2627        if (requestorType == null)
    2728            return null;
     
    4647
    4748    /**
    48      * @see CredentialsManager#store(RequestorType, PasswordAuthentication)
     49     * @see CredentialsAgent#store(RequestorType, PasswordAuthentication)
    4950     */
    50     public void store(RequestorType requestorType, PasswordAuthentication credentials) throws CredentialsManagerException {
     51    @Override
     52    public void store(RequestorType requestorType, PasswordAuthentication credentials) throws CredentialsAgentException {
    5153        if (requestorType == null)
    5254            return;
     
    7274
    7375    /**
    74      * @see CredentialsManager#getCredentials(RequestorType, boolean)
     76     * @see CredentialsAgent#getCredentials(RequestorType, boolean)
    7577     */
    76     public CredentialsManagerResponse getCredentials(RequestorType requestorType, boolean noSuccessWithLastResponse) throws CredentialsManagerException{
     78    @Override
     79    public CredentialsAgentResponse getCredentials(RequestorType requestorType, boolean noSuccessWithLastResponse) throws CredentialsAgentException{
    7780        if (requestorType == null)
    7881            return null;
     
    8184        String password = (credentials == null || credentials.getPassword() == null) ? "" : String.valueOf(credentials.getPassword());
    8285
    83         CredentialsManagerResponse response = new CredentialsManagerResponse();
     86        CredentialsAgentResponse response = new CredentialsAgentResponse();
    8487
    8588        /*
     
    142145     *
    143146     * @return the current OAuth Access Token to access the OSM server.
    144      * @throws CredentialsManagerException thrown if something goes wrong
     147     * @throws CredentialsAgentException thrown if something goes wrong
    145148     */
    146     public OAuthToken lookupOAuthAccessToken() throws CredentialsManagerException {
     149    @Override
     150    public OAuthToken lookupOAuthAccessToken() throws CredentialsAgentException {
    147151        String accessTokenKey = Main.pref.get("oauth.access-token.key", null);
    148152        String accessTokenSecret = Main.pref.get("oauth.access-token.secret", null);
     
    156160     *
    157161     * @param accessToken the access Token. null, to remove the Access Token.
    158      * @throws CredentialsManagerException thrown if something goes wrong
     162     * @throws CredentialsAgentException thrown if something goes wrong
    159163     */
    160     public void storeOAuthAccessToken(OAuthToken accessToken) throws CredentialsManagerException {
     164    @Override
     165    public void storeOAuthAccessToken(OAuthToken accessToken) throws CredentialsAgentException {
    161166        if (accessToken == null) {
    162167            Main.pref.put("oauth.access-token.key", null);
Note: See TracChangeset for help on using the changeset viewer.