Index: /trunk/src/org/openstreetmap/josm/gui/MainApplication.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/MainApplication.java	(revision 4244)
+++ /trunk/src/org/openstreetmap/josm/gui/MainApplication.java	(revision 4245)
@@ -32,5 +32,5 @@
 import org.openstreetmap.josm.gui.progress.ProgressMonitor;
 import org.openstreetmap.josm.io.DefaultProxySelector;
-import org.openstreetmap.josm.io.auth.CredentialsManagerFactory;
+import org.openstreetmap.josm.io.auth.CredentialsManager;
 import org.openstreetmap.josm.io.auth.DefaultAuthenticator;
 import org.openstreetmap.josm.io.remotecontrol.RemoteControl;
@@ -188,8 +188,8 @@
         Main.pref.updateSystemProperties();
 
-        DefaultAuthenticator.createInstance(CredentialsManagerFactory.getCredentialManager());
+        DefaultAuthenticator.createInstance(CredentialsManager.getInstance());
         Authenticator.setDefault(DefaultAuthenticator.getInstance());
         ProxySelector.setDefault(new DefaultProxySelector(ProxySelector.getDefault()));
-        OAuthAccessTokenHolder.getInstance().init(Main.pref, CredentialsManagerFactory.getCredentialManager());
+        OAuthAccessTokenHolder.getInstance().init(Main.pref, CredentialsManager.getInstance());
 
         // asking for help? show help and exit
Index: /trunk/src/org/openstreetmap/josm/gui/oauth/FullyAutomaticAuthorizationUI.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/oauth/FullyAutomaticAuthorizationUI.java	(revision 4244)
+++ /trunk/src/org/openstreetmap/josm/gui/oauth/FullyAutomaticAuthorizationUI.java	(revision 4245)
@@ -43,7 +43,7 @@
 import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
 import org.openstreetmap.josm.io.OsmTransferException;
+import org.openstreetmap.josm.io.auth.CredentialsAgent;
+import org.openstreetmap.josm.io.auth.CredentialsAgentException;
 import org.openstreetmap.josm.io.auth.CredentialsManager;
-import org.openstreetmap.josm.io.auth.CredentialsManagerException;
-import org.openstreetmap.josm.io.auth.CredentialsManagerFactory;
 import org.openstreetmap.josm.tools.ImageProvider;
 import org.xml.sax.SAXException;
@@ -182,5 +182,5 @@
     public void initFromPreferences(Preferences pref) {
         super.initFromPreferences(pref);
-        CredentialsManager cm = CredentialsManagerFactory.getCredentialManager();
+        CredentialsAgent cm = CredentialsManager.getInstance();
         try {
             PasswordAuthentication pa = cm.lookup(RequestorType.SERVER);
@@ -192,5 +192,5 @@
                 tfPassword.setText(pa.getPassword() == null ? "" : String.valueOf(pa.getPassword()));
             }
-        } catch(CredentialsManagerException e) {
+        } catch(CredentialsAgentException e) {
             e.printStackTrace();
             tfUserName.setText("");
Index: /trunk/src/org/openstreetmap/josm/gui/preferences/server/AuthenticationPreferencesPanel.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/preferences/server/AuthenticationPreferencesPanel.java	(revision 4244)
+++ /trunk/src/org/openstreetmap/josm/gui/preferences/server/AuthenticationPreferencesPanel.java	(revision 4245)
@@ -20,5 +20,5 @@
 import org.openstreetmap.josm.gui.help.HelpUtil;
 import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
-import org.openstreetmap.josm.io.auth.CredentialsManagerFactory;
+import org.openstreetmap.josm.io.auth.CredentialsManager;
 
 /**
@@ -124,5 +124,5 @@
             pnlBasicAuthPreferences.saveToPreferences();
             OAuthAccessTokenHolder.getInstance().clear();
-            OAuthAccessTokenHolder.getInstance().save(Main.pref, CredentialsManagerFactory.getCredentialManager());
+            OAuthAccessTokenHolder.getInstance().save(Main.pref, CredentialsManager.getInstance());
         } else if (authMethod.equals("oauth")) {
             // clear the password in the preferences
Index: /trunk/src/org/openstreetmap/josm/gui/preferences/server/BasicAuthenticationPreferencesPanel.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/preferences/server/BasicAuthenticationPreferencesPanel.java	(revision 4244)
+++ /trunk/src/org/openstreetmap/josm/gui/preferences/server/BasicAuthenticationPreferencesPanel.java	(revision 4245)
@@ -20,8 +20,8 @@
 import org.openstreetmap.josm.gui.widgets.HtmlPanel;
 import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator;
+import org.openstreetmap.josm.io.auth.CredentialsAgent;
+import org.openstreetmap.josm.io.auth.CredentialsAgentException;
 import org.openstreetmap.josm.io.auth.CredentialsManager;
-import org.openstreetmap.josm.io.auth.CredentialsManagerException;
-import org.openstreetmap.josm.io.auth.CredentialsManagerFactory;
-import org.openstreetmap.josm.io.auth.JosmPreferencesCredentialManager;
+import org.openstreetmap.josm.io.auth.JosmPreferencesCredentialAgent;
 
 /**
@@ -103,5 +103,5 @@
 
     public void initFromPreferences() {
-        CredentialsManager cm = CredentialsManagerFactory.getCredentialManager();
+        CredentialsAgent cm = CredentialsManager.getInstance();
         try {
             PasswordAuthentication pa = cm.lookup(RequestorType.SERVER);
@@ -113,5 +113,5 @@
                 tfOsmPassword.setText(pa.getPassword() == null ? "" : String.valueOf(pa.getPassword()));
             }
-        } catch(CredentialsManagerException e) {
+        } catch(CredentialsAgentException e) {
             e.printStackTrace();
             System.err.println(tr("Warning: failed to retrieve OSM credentials from credential manager."));
@@ -123,5 +123,5 @@
 
     public void saveToPreferences() {
-        CredentialsManager cm = CredentialsManagerFactory.getCredentialManager();
+        CredentialsAgent cm = CredentialsManager.getInstance();
         try {
             PasswordAuthentication pa = new PasswordAuthentication(
@@ -132,8 +132,8 @@
             // always save the username to the preferences if it isn't already saved there
             // by the credential manager
-            if (! (cm instanceof JosmPreferencesCredentialManager)) {
+            if (! (cm instanceof JosmPreferencesCredentialAgent)) {
                 Main.pref.put("osm-server.username", tfOsmUserName.getText().trim());
             }
-        } catch(CredentialsManagerException e) {
+        } catch(CredentialsAgentException e) {
             e.printStackTrace();
             System.err.println(tr("Warning: failed to save OSM credentials to credential manager."));
Index: /trunk/src/org/openstreetmap/josm/gui/preferences/server/OAuthAccessTokenHolder.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/preferences/server/OAuthAccessTokenHolder.java	(revision 4244)
+++ /trunk/src/org/openstreetmap/josm/gui/preferences/server/OAuthAccessTokenHolder.java	(revision 4245)
@@ -6,6 +6,6 @@
 import org.openstreetmap.josm.data.Preferences;
 import org.openstreetmap.josm.data.oauth.OAuthToken;
-import org.openstreetmap.josm.io.auth.CredentialsManager;
-import org.openstreetmap.josm.io.auth.CredentialsManagerException;
+import org.openstreetmap.josm.io.auth.CredentialsAgent;
+import org.openstreetmap.josm.io.auth.CredentialsAgentException;
 import org.openstreetmap.josm.tools.CheckParameterUtil;
 
@@ -136,5 +136,5 @@
      * @throws IllegalArgumentException thrown if cm is null
      */
-    public void init(Preferences pref, CredentialsManager cm) throws IllegalArgumentException {
+    public void init(Preferences pref, CredentialsAgent cm) throws IllegalArgumentException {
         CheckParameterUtil.ensureParameterNotNull(pref, "pref");
         CheckParameterUtil.ensureParameterNotNull(cm, "cm");
@@ -142,5 +142,5 @@
         try {
             token = cm.lookupOAuthAccessToken();
-        } catch(CredentialsManagerException e) {
+        } catch(CredentialsAgentException e) {
             e.printStackTrace();
             System.err.println(tr("Warning: Failed to retrieve OAuth Access Token from credential manager"));
@@ -163,5 +163,5 @@
      * @throws IllegalArgumentException thrown if cm is null
      */
-    public void save(Preferences preferences, CredentialsManager cm) throws IllegalArgumentException {
+    public void save(Preferences preferences, CredentialsAgent cm) throws IllegalArgumentException {
         CheckParameterUtil.ensureParameterNotNull(preferences, "preferences");
         CheckParameterUtil.ensureParameterNotNull(cm, "cm");
@@ -173,5 +173,5 @@
                 cm.storeOAuthAccessToken(new OAuthToken(accessTokenKey, accessTokenSecret));
             }
-        } catch(CredentialsManagerException e){
+        } catch(CredentialsAgentException e){
             e.printStackTrace();
             System.err.println(tr("Warning: Failed to store OAuth Access Token to credentials manager"));
Index: /trunk/src/org/openstreetmap/josm/gui/preferences/server/OAuthAuthenticationPreferencesPanel.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/preferences/server/OAuthAuthenticationPreferencesPanel.java	(revision 4244)
+++ /trunk/src/org/openstreetmap/josm/gui/preferences/server/OAuthAuthenticationPreferencesPanel.java	(revision 4245)
@@ -32,5 +32,5 @@
 import org.openstreetmap.josm.gui.oauth.OAuthAuthorizationWizard;
 import org.openstreetmap.josm.gui.oauth.TestAccessTokenTask;
-import org.openstreetmap.josm.io.auth.CredentialsManagerFactory;
+import org.openstreetmap.josm.io.auth.CredentialsManager;
 import org.openstreetmap.josm.tools.ImageProvider;
 
@@ -161,5 +161,5 @@
     public void saveToPreferences() {
         OAuthAccessTokenHolder.getInstance().setSaveToPreferences(cbSaveToPreferences.isSelected());
-        OAuthAccessTokenHolder.getInstance().save(Main.pref, CredentialsManagerFactory.getCredentialManager());
+        OAuthAccessTokenHolder.getInstance().save(Main.pref, CredentialsManager.getInstance());
         pnlAdvancedProperties.getAdvancedParameters().saveToPreferences(Main.pref);
     }
Index: /trunk/src/org/openstreetmap/josm/gui/preferences/server/ProxyPreferencesPanel.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/preferences/server/ProxyPreferencesPanel.java	(revision 4244)
+++ /trunk/src/org/openstreetmap/josm/gui/preferences/server/ProxyPreferencesPanel.java	(revision 4245)
@@ -31,7 +31,7 @@
 import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
 import org.openstreetmap.josm.io.DefaultProxySelector;
+import org.openstreetmap.josm.io.auth.CredentialsAgent;
+import org.openstreetmap.josm.io.auth.CredentialsAgentException;
 import org.openstreetmap.josm.io.auth.CredentialsManager;
-import org.openstreetmap.josm.io.auth.CredentialsManagerException;
-import org.openstreetmap.josm.io.auth.CredentialsManagerFactory;
 import org.openstreetmap.josm.tools.GBC;
 
@@ -321,5 +321,5 @@
         // save the proxy user and the proxy password to a credentials store managed by
         // the credentials manager
-        CredentialsManager cm = CredentialsManagerFactory.getCredentialManager();
+        CredentialsAgent cm = CredentialsManager.getInstance();
         try {
             PasswordAuthentication pa = cm.lookup(RequestorType.PROXY);
@@ -331,5 +331,5 @@
                 tfProxyHttpPassword.setText(pa.getPassword() == null ? "" : String.valueOf(pa.getPassword()));
             }
-        } catch(CredentialsManagerException e) {
+        } catch(CredentialsAgentException e) {
             e.printStackTrace();
             tfProxyHttpUser.setText("");
@@ -395,5 +395,5 @@
         }
 
-        CredentialsManager cm = CredentialsManagerFactory.getCredentialManager();
+        CredentialsAgent cm = CredentialsManager.getInstance();
         try {
             PasswordAuthentication pa = new PasswordAuthentication(
@@ -402,5 +402,5 @@
             );
             cm.store(RequestorType.PROXY, pa);
-        } catch(CredentialsManagerException e) {
+        } catch(CredentialsAgentException e) {
             e.printStackTrace();
         }
Index: /trunk/src/org/openstreetmap/josm/io/OsmConnection.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/OsmConnection.java	(revision 4244)
+++ /trunk/src/org/openstreetmap/josm/io/OsmConnection.java	(revision 4245)
@@ -18,7 +18,7 @@
 import org.openstreetmap.josm.data.oauth.OAuthParameters;
 import org.openstreetmap.josm.gui.preferences.server.OAuthAccessTokenHolder;
-import org.openstreetmap.josm.io.auth.CredentialsManagerException;
-import org.openstreetmap.josm.io.auth.CredentialsManagerFactory;
-import org.openstreetmap.josm.io.auth.CredentialsManagerResponse;
+import org.openstreetmap.josm.io.auth.CredentialsAgentException;
+import org.openstreetmap.josm.io.auth.CredentialsManager;
+import org.openstreetmap.josm.io.auth.CredentialsAgentResponse;
 import org.openstreetmap.josm.tools.Base64;
 
@@ -73,11 +73,11 @@
     protected void addBasicAuthorizationHeader(HttpURLConnection con) throws OsmTransferException {
         CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
-        CredentialsManagerResponse response;
+        CredentialsAgentResponse response;
         String token;
         try {
-            synchronized (CredentialsManagerFactory.getCredentialManager()) {
-                response = CredentialsManagerFactory.getCredentialManager().getCredentials(RequestorType.SERVER, false /* don't know yet whether the credentials will succeed */);
+            synchronized (CredentialsManager.getInstance()) {
+                response = CredentialsManager.getInstance().getCredentials(RequestorType.SERVER, false /* don't know yet whether the credentials will succeed */);
             }
-        } catch (CredentialsManagerException e) {
+        } catch (CredentialsAgentException e) {
             throw new OsmTransferException(e);
         }
Index: /trunk/src/org/openstreetmap/josm/io/auth/CredentialsAgent.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/auth/CredentialsAgent.java	(revision 4245)
+++ /trunk/src/org/openstreetmap/josm/io/auth/CredentialsAgent.java	(revision 4245)
@@ -0,0 +1,69 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.io.auth;
+
+import java.net.PasswordAuthentication;
+import java.net.Authenticator.RequestorType;
+
+import org.openstreetmap.josm.data.oauth.OAuthToken;
+
+/**
+ * A CredentialsAgent manages two credentials:
+ * <ul>
+ *   <li>the credential for {@see RequestorType#SERVER} which is equal to the OSM API credentials
+ *   in JOSM</li>
+ *   <li>the credential for {@see RequestorType#PROXY} which is equal to the credentials for an
+ *   optional HTTP proxy server a user may use</li>
+ *  </ul>
+ *
+ *  In addition, it manages an OAuth Access Token for accessing the OSM server.
+ */
+public interface CredentialsAgent {
+
+    /**
+     * Looks up the credentials for a given type.
+     *
+     * @param the type of service. {@see RequestorType#SERVER} for the OSM API server, {@see RequestorType#PROXY}
+     * for a proxy server
+     * @return the credentials
+     * @throws CredentialsAgentException thrown if a problem occurs in a implementation of this interface
+     */
+    public PasswordAuthentication lookup(RequestorType requestorType) throws CredentialsAgentException;
+
+    /**
+     * Saves the credentials in <code>credentials</code> for the given service type.
+     *
+     * @param the type of service. {@see RequestorType#SERVER} for the OSM API server, {@see RequestorType#PROXY}
+     * for a proxy server
+     * @param credentials the credentials
+     * @throws CredentialsManagerException thrown if a problem occurs in a implementation of this interface
+     */
+    public void store(RequestorType requestorType, PasswordAuthentication credentials) throws CredentialsAgentException;
+
+    /**
+     *
+     * @param requestorType  the type of service. {@see RequestorType#SERVER} for the OSM API server, {@see RequestorType#PROXY}
+     * for a proxy server
+     * @param noSuccessWithLastResponse true, if the last request with the supplied credentials failed; false otherwise.
+     * If true, implementations of this interface are advised to prompt the user for new credentials.
+     * @throws CredentialsAgentException thrown if a problem occurs in a implementation of this interface
+
+     */
+    public CredentialsAgentResponse getCredentials(RequestorType requestorType, boolean noSuccessWithLastResponse) throws CredentialsAgentException;
+
+    /**
+     * Lookup the current OAuth Access Token to access the OSM server. Replies null, if no
+     * Access Token is currently managed by this CredentialAgent.
+     *
+     * @return the current OAuth Access Token to access the OSM server.
+     * @throws CredentialsAgentException thrown if something goes wrong
+     */
+    public OAuthToken lookupOAuthAccessToken() throws CredentialsAgentException;
+
+    /**
+     * Stores the OAuth Access Token <code>accessToken</code>.
+     *
+     * @param accessToken the access Token. null, to remove the Access Token.
+     * @throws CredentialsAgentException thrown if something goes wrong
+     */
+    public void storeOAuthAccessToken(OAuthToken accessToken) throws CredentialsAgentException;
+}
Index: /trunk/src/org/openstreetmap/josm/io/auth/CredentialsAgentException.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/auth/CredentialsAgentException.java	(revision 4245)
+++ /trunk/src/org/openstreetmap/josm/io/auth/CredentialsAgentException.java	(revision 4245)
@@ -0,0 +1,10 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.io.auth;
+
+public class CredentialsAgentException extends Exception {
+    public CredentialsAgentException() {super();}
+    public CredentialsAgentException(String message, Throwable cause) {super(message, cause);}
+    public CredentialsAgentException(String message) {super(message);}
+    public CredentialsAgentException(Throwable cause) {super(cause);}
+
+}
Index: /trunk/src/org/openstreetmap/josm/io/auth/CredentialsAgentResponse.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/auth/CredentialsAgentResponse.java	(revision 4245)
+++ /trunk/src/org/openstreetmap/josm/io/auth/CredentialsAgentResponse.java	(revision 4245)
@@ -0,0 +1,34 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.io.auth;
+
+/**
+ * CredentialsAgentResponse represents the response from {@see CredentialsAgent#getCredentials(java.net.Authenticator.RequestorType, boolean)}.
+ *
+ * The response consists of the username and the password the requested credentials consists of.
+ * In addition, it provides information whether authentication was canceled by the user, i.e.
+ * because he or she canceled a username/password dialog (see {@see #isCanceled()}.
+ *
+ */
+public class CredentialsAgentResponse {
+    private String username;
+    private char[] password;
+    private boolean canceled;
+    public String getUsername() {
+        return username;
+    }
+    public void setUsername(String username) {
+        this.username = username;
+    }
+    public char[] getPassword() {
+        return password;
+    }
+    public void setPassword(char[] password) {
+        this.password = password;
+    }
+    public boolean isCanceled() {
+        return canceled;
+    }
+    public void setCanceled(boolean cancelled) {
+        this.canceled = cancelled;
+    }
+}
Index: /trunk/src/org/openstreetmap/josm/io/auth/CredentialsManager.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/auth/CredentialsManager.java	(revision 4244)
+++ /trunk/src/org/openstreetmap/josm/io/auth/CredentialsManager.java	(revision 4245)
@@ -2,68 +2,23 @@
 package org.openstreetmap.josm.io.auth;
 
-import java.net.PasswordAuthentication;
-import java.net.Authenticator.RequestorType;
-
-import org.openstreetmap.josm.data.oauth.OAuthToken;
-
 /**
- * A CredentialManager manages two credentials:
- * <ul>
- *   <li>the credential for {@see RequestorType#SERVER} which is equal to the OSM API credentials
- *   in JOSM</li>
- *   <li>the credential for {@see RequestorType#PROXY} which is equal to the credentials for an
- *   optional HTTP proxy server a user may use</li>
- *  </ul>
+ * CredentialManager is a factory for the single credential agent used.
  *
- *  In addition, it manages an OAuth Access Token for accessing the OSM server.
+ * Currently, it defaults to replying an instance of {@see JosmPreferencesCredentialAgent}.
+ *
  */
-public interface CredentialsManager {
+public class CredentialsManager {
+    private static CredentialsAgent instance;
 
     /**
-     * Looks up the credentials for a given type.
+     * Replies the single credential agent used in JOSM
      *
-     * @param the type of service. {@see RequestorType#SERVER} for the OSM API server, {@see RequestorType#PROXY}
-     * for a proxy server
-     * @return the credentials
-     * @throws CredentialsManagerException thrown if a problem occurs in a implementation of this interface
+     * @return the single credential agent used in JOSM
      */
-    public PasswordAuthentication lookup(RequestorType requestorType) throws CredentialsManagerException;
-
-    /**
-     * Saves the credentials in <code>credentials</code> for the given service type.
-     *
-     * @param the type of service. {@see RequestorType#SERVER} for the OSM API server, {@see RequestorType#PROXY}
-     * for a proxy server
-     * @param credentials the credentials
-     * @throws CredentialsManagerException thrown if a problem occurs in a implementation of this interface
-     */
-    public void store(RequestorType requestorType, PasswordAuthentication credentials) throws CredentialsManagerException;
-
-    /**
-     *
-     * @param requestorType  the type of service. {@see RequestorType#SERVER} for the OSM API server, {@see RequestorType#PROXY}
-     * for a proxy server
-     * @param noSuccessWithLastResponse true, if the last request with the supplied credentials failed; false otherwise.
-     * If true, implementations of this interface are adviced prompt user for new credentials.
-     * @throws CredentialsManagerException thrown if a problem occurs in a implementation of this interface
-
-     */
-    public CredentialsManagerResponse getCredentials(RequestorType requestorType, boolean noSuccessWithLastResponse) throws CredentialsManagerException;
-
-    /**
-     * Lookup the current OAuth Access Token to access the OSM server. Replies null, if no
-     * Access Token is currently managed by this CredentialManager.
-     *
-     * @return the current OAuth Access Token to access the OSM server.
-     * @throws CredentialsManagerException thrown if something goes wrong
-     */
-    public OAuthToken lookupOAuthAccessToken() throws CredentialsManagerException;
-
-    /**
-     * Stores the OAuth Access Token <code>accessToken</code>.
-     *
-     * @param accessToken the access Token. null, to remove the Access Token.
-     * @throws CredentialsManagerException thrown if something goes wrong
-     */
-    public void storeOAuthAccessToken(OAuthToken accessToken) throws CredentialsManagerException;
+    static public CredentialsAgent getInstance() {
+        if (instance == null) {
+            instance =  new JosmPreferencesCredentialAgent();
+        }
+        return instance;
+    }
 }
Index: unk/src/org/openstreetmap/josm/io/auth/CredentialsManagerException.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/auth/CredentialsManagerException.java	(revision 4244)
+++ 	(revision )
@@ -1,10 +1,0 @@
-// License: GPL. For details, see LICENSE file.
-package org.openstreetmap.josm.io.auth;
-
-public class CredentialsManagerException extends Exception {
-    public CredentialsManagerException() {super();}
-    public CredentialsManagerException(String message, Throwable cause) {super(message, cause);}
-    public CredentialsManagerException(String message) {super(message);}
-    public CredentialsManagerException(Throwable cause) {super(cause);}
-
-}
Index: unk/src/org/openstreetmap/josm/io/auth/CredentialsManagerFactory.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/auth/CredentialsManagerFactory.java	(revision 4244)
+++ 	(revision )
@@ -1,24 +1,0 @@
-// License: GPL. For details, see LICENSE file.
-package org.openstreetmap.josm.io.auth;
-
-/**
- * CredentialManagerFactory is a factory for the single credential manager used.
- *
- * Currently, it defaults to replying an instance of {@see JosmPreferencesCredentialManager}.
- *
- */
-public class CredentialsManagerFactory {
-    private static CredentialsManager instance;
-
-    /**
-     * Replies the single credential manager used in JOSM
-     *
-     * @return the single credential manager used in JOSM
-     */
-    static public CredentialsManager getCredentialManager() {
-        if (instance == null) {
-            instance =  new JosmPreferencesCredentialManager();
-        }
-        return instance;
-    }
-}
Index: unk/src/org/openstreetmap/josm/io/auth/CredentialsManagerResponse.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/auth/CredentialsManagerResponse.java	(revision 4244)
+++ 	(revision )
@@ -1,34 +1,0 @@
-// License: GPL. For details, see LICENSE file.
-package org.openstreetmap.josm.io.auth;
-
-/**
- * CredentialsManagerResponse represents the response from {@see CredentialsManager#getCredentials(java.net.Authenticator.RequestorType, boolean)}.
- *
- * The response consists of the username and the password the requested credentials consists of.
- * In addition, it provides information whether authentication was canceled by the user, i.e.
- * because he or she canceled a username/password dialog (see {@see #isCanceled()}.
- *
- */
-public class CredentialsManagerResponse {
-    private String username;
-    private char[] password;
-    private boolean canceled;
-    public String getUsername() {
-        return username;
-    }
-    public void setUsername(String username) {
-        this.username = username;
-    }
-    public char[] getPassword() {
-        return password;
-    }
-    public void setPassword(char[] password) {
-        this.password = password;
-    }
-    public boolean isCanceled() {
-        return canceled;
-    }
-    public void setCanceled(boolean cancelled) {
-        this.canceled = cancelled;
-    }
-}
Index: /trunk/src/org/openstreetmap/josm/io/auth/DefaultAuthenticator.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/auth/DefaultAuthenticator.java	(revision 4244)
+++ /trunk/src/org/openstreetmap/josm/io/auth/DefaultAuthenticator.java	(revision 4245)
@@ -22,9 +22,9 @@
     }
 
-    public static void createInstance(CredentialsManager credentialManager) {
+    public static void createInstance(CredentialsAgent credentialManager) {
         instance = new DefaultAuthenticator(credentialManager);
     }
 
-    private CredentialsManager credentialManager;
+    private CredentialsAgent credentialsAgent;
     private final Map<RequestorType, Boolean> credentialsTried = new HashMap<RequestorType, Boolean>();
     private boolean enabled = true;
@@ -32,8 +32,8 @@
     /**
      *
-     * @param credentialManager the credential manager
+     * @param credentialsAgent the credential manager
      */
-    private DefaultAuthenticator(CredentialsManager credentialManager) {
-        this.credentialManager = credentialManager;
+    private DefaultAuthenticator(CredentialsAgent credentialsAgent) {
+        this.credentialsAgent = credentialsAgent;
     }
 
@@ -55,10 +55,10 @@
             }
             boolean tried = credentialsTried.get(getRequestorType()) != null;
-            CredentialsManagerResponse response = credentialManager.getCredentials(getRequestorType(), tried);
+            CredentialsAgentResponse response = credentialsAgent.getCredentials(getRequestorType(), tried);
             if (response == null || response.isCanceled())
                 return null;
             credentialsTried.put(getRequestorType(), true);
             return new PasswordAuthentication(response.getUsername(), response.getPassword());
-        } catch(CredentialsManagerException e) {
+        } catch(CredentialsAgentException e) {
             e.printStackTrace();
             return null;
Index: /trunk/src/org/openstreetmap/josm/io/auth/JosmPreferencesCredentialAgent.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/auth/JosmPreferencesCredentialAgent.java	(revision 4245)
+++ /trunk/src/org/openstreetmap/josm/io/auth/JosmPreferencesCredentialAgent.java	(revision 4245)
@@ -0,0 +1,174 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.io.auth;
+
+import java.net.PasswordAuthentication;
+import java.net.Authenticator.RequestorType;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.oauth.OAuthToken;
+import org.openstreetmap.josm.gui.io.CredentialDialog;
+import org.openstreetmap.josm.gui.preferences.server.ProxyPreferencesPanel;
+
+/**
+ * This is the default credentials agent in JOSM. It keeps username and password for both
+ * the OSM API and an optional HTTP proxy in the JOSM preferences file.
+ *
+ */
+public class JosmPreferencesCredentialAgent implements CredentialsAgent {
+
+    Map<RequestorType, PasswordAuthentication> memoryCredentialsCache = new HashMap<RequestorType, PasswordAuthentication>();
+    /**
+     * @see CredentialsAgent#lookup(RequestorType)
+     */
+    @Override
+    public PasswordAuthentication lookup(RequestorType requestorType) throws CredentialsAgentException{
+        if (requestorType == null)
+            return null;
+        String user;
+        String password;
+        switch(requestorType) {
+        case SERVER:
+            user = Main.pref.get("osm-server.username", null);
+            password = Main.pref.get("osm-server.password", null);
+            if (user == null)
+                return null;
+            return new PasswordAuthentication(user, password == null ? new char[0] : password.toCharArray());
+        case PROXY:
+            user = Main.pref.get(ProxyPreferencesPanel.PROXY_USER, null);
+            password = Main.pref.get(ProxyPreferencesPanel.PROXY_PASS, null);
+            if (user == null)
+                return null;
+            return new PasswordAuthentication(user, password == null ? new char[0] : password.toCharArray());
+        }
+        return null;
+    }
+
+    /**
+     * @see CredentialsAgent#store(RequestorType, PasswordAuthentication)
+     */
+    @Override
+    public void store(RequestorType requestorType, PasswordAuthentication credentials) throws CredentialsAgentException {
+        if (requestorType == null)
+            return;
+        switch(requestorType) {
+        case SERVER:
+            Main.pref.put("osm-server.username", credentials.getUserName());
+            if (credentials.getPassword() == null) {
+                Main.pref.put("osm-server.password", null);
+            } else {
+                Main.pref.put("osm-server.password", String.valueOf(credentials.getPassword()));
+            }
+            break;
+        case PROXY:
+            Main.pref.put(ProxyPreferencesPanel.PROXY_USER, credentials.getUserName());
+            if (credentials.getPassword() == null) {
+                Main.pref.put(ProxyPreferencesPanel.PROXY_PASS, null);
+            } else {
+                Main.pref.put(ProxyPreferencesPanel.PROXY_PASS, String.valueOf(credentials.getPassword()));
+            }
+            break;
+        }
+    }
+
+    /**
+     * @see CredentialsAgent#getCredentials(RequestorType, boolean)
+     */
+    @Override
+    public CredentialsAgentResponse getCredentials(RequestorType requestorType, boolean noSuccessWithLastResponse) throws CredentialsAgentException{
+        if (requestorType == null)
+            return null;
+        PasswordAuthentication credentials =  lookup(requestorType);
+        String username = (credentials == null || credentials.getUserName() == null) ? "" : credentials.getUserName();
+        String password = (credentials == null || credentials.getPassword() == null) ? "" : String.valueOf(credentials.getPassword());
+
+        CredentialsAgentResponse response = new CredentialsAgentResponse();
+
+        /*
+         * Last request was successful and there was no credentials stored
+         * in file (or only the username is stored).
+         * -> Try to recall credentials that have been entered
+         * manually in this session.
+         */
+        if (!noSuccessWithLastResponse && memoryCredentialsCache.containsKey(requestorType) &&
+                (credentials == null || credentials.getPassword() == null || credentials.getPassword().length == 0)) {
+            PasswordAuthentication pa = memoryCredentialsCache.get(requestorType);
+            response.setUsername(pa.getUserName());
+            response.setPassword(pa.getPassword());
+            response.setCanceled(false);
+        /*
+         * Prompt the user for credentials. This happens the first time each
+         * josm start if the user does not save the credentials to preference
+         * file (username=="") and each time after authentication failed
+         * (noSuccessWithLastResponse == true).
+         */
+        } else if (noSuccessWithLastResponse || username.equals("") || password.equals("")) {
+            CredentialDialog dialog = null;
+            switch(requestorType) {
+            case SERVER: dialog = CredentialDialog.getOsmApiCredentialDialog(username, password); break;
+            case PROXY: dialog = CredentialDialog.getHttpProxyCredentialDialog(username, password); break;
+            }
+            dialog.setVisible(true);
+            response.setCanceled(dialog.isCanceled());
+            if (dialog.isCanceled())
+                return response;
+            response.setUsername(dialog.getUsername());
+            response.setPassword(dialog.getPassword());
+            if (dialog.isSaveCredentials()) {
+                store(requestorType, new PasswordAuthentication(
+                        response.getUsername(),
+                        response.getPassword()
+                ));
+            /*
+             * User decides not to save credentials to file. Keep it
+             * in memory so we don't have to ask over and over again.
+             */
+            } else {
+                PasswordAuthentication pa = new PasswordAuthentication(dialog.getUsername(), dialog.getPassword());
+                memoryCredentialsCache.put(requestorType, pa);
+            }
+        /*
+         * We got it from file.
+         */
+        } else {
+            response.setUsername(username);
+            response.setPassword(password.toCharArray());
+            response.setCanceled(false);
+        }
+        return response;
+    }
+
+    /**
+     * Lookup the current OAuth Access Token to access the OSM server. Replies null, if no
+     * Access Token is currently managed by this CredentialManager.
+     *
+     * @return the current OAuth Access Token to access the OSM server.
+     * @throws CredentialsAgentException thrown if something goes wrong
+     */
+    @Override
+    public OAuthToken lookupOAuthAccessToken() throws CredentialsAgentException {
+        String accessTokenKey = Main.pref.get("oauth.access-token.key", null);
+        String accessTokenSecret = Main.pref.get("oauth.access-token.secret", null);
+        if (accessTokenKey == null && accessTokenSecret == null)
+            return null;
+        return new OAuthToken(accessTokenKey, accessTokenSecret);
+    }
+
+    /**
+     * Stores the OAuth Access Token <code>accessToken</code>.
+     *
+     * @param accessToken the access Token. null, to remove the Access Token.
+     * @throws CredentialsAgentException thrown if something goes wrong
+     */
+    @Override
+    public void storeOAuthAccessToken(OAuthToken accessToken) throws CredentialsAgentException {
+        if (accessToken == null) {
+            Main.pref.put("oauth.access-token.key", null);
+            Main.pref.put("oauth.access-token.secret", null);
+        } else {
+            Main.pref.put("oauth.access-token.key", accessToken.getKey());
+            Main.pref.put("oauth.access-token.secret", accessToken.getSecret());
+        }
+    }
+}
Index: unk/src/org/openstreetmap/josm/io/auth/JosmPreferencesCredentialManager.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/auth/JosmPreferencesCredentialManager.java	(revision 4244)
+++ 	(revision )
@@ -1,169 +1,0 @@
-// License: GPL. For details, see LICENSE file.
-package org.openstreetmap.josm.io.auth;
-
-import java.net.PasswordAuthentication;
-import java.net.Authenticator.RequestorType;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.data.oauth.OAuthToken;
-import org.openstreetmap.josm.gui.io.CredentialDialog;
-import org.openstreetmap.josm.gui.preferences.server.ProxyPreferencesPanel;
-
-/**
- * This is the default credential manager in JOSM. It keeps username and password for both
- * the OSM API and an optional HTTP proxy in the JOSM preferences file.
- *
- */
-public class JosmPreferencesCredentialManager implements CredentialsManager {
-
-    Map<RequestorType, PasswordAuthentication> memoryCredentialsCache = new HashMap<RequestorType, PasswordAuthentication>();
-    /**
-     * @see CredentialsManager#lookup(RequestorType)
-     */
-    public PasswordAuthentication lookup(RequestorType requestorType) throws CredentialsManagerException{
-        if (requestorType == null)
-            return null;
-        String user;
-        String password;
-        switch(requestorType) {
-        case SERVER:
-            user = Main.pref.get("osm-server.username", null);
-            password = Main.pref.get("osm-server.password", null);
-            if (user == null)
-                return null;
-            return new PasswordAuthentication(user, password == null ? new char[0] : password.toCharArray());
-        case PROXY:
-            user = Main.pref.get(ProxyPreferencesPanel.PROXY_USER, null);
-            password = Main.pref.get(ProxyPreferencesPanel.PROXY_PASS, null);
-            if (user == null)
-                return null;
-            return new PasswordAuthentication(user, password == null ? new char[0] : password.toCharArray());
-        }
-        return null;
-    }
-
-    /**
-     * @see CredentialsManager#store(RequestorType, PasswordAuthentication)
-     */
-    public void store(RequestorType requestorType, PasswordAuthentication credentials) throws CredentialsManagerException {
-        if (requestorType == null)
-            return;
-        switch(requestorType) {
-        case SERVER:
-            Main.pref.put("osm-server.username", credentials.getUserName());
-            if (credentials.getPassword() == null) {
-                Main.pref.put("osm-server.password", null);
-            } else {
-                Main.pref.put("osm-server.password", String.valueOf(credentials.getPassword()));
-            }
-            break;
-        case PROXY:
-            Main.pref.put(ProxyPreferencesPanel.PROXY_USER, credentials.getUserName());
-            if (credentials.getPassword() == null) {
-                Main.pref.put(ProxyPreferencesPanel.PROXY_PASS, null);
-            } else {
-                Main.pref.put(ProxyPreferencesPanel.PROXY_PASS, String.valueOf(credentials.getPassword()));
-            }
-            break;
-        }
-    }
-
-    /**
-     * @see CredentialsManager#getCredentials(RequestorType, boolean)
-     */
-    public CredentialsManagerResponse getCredentials(RequestorType requestorType, boolean noSuccessWithLastResponse) throws CredentialsManagerException{
-        if (requestorType == null)
-            return null;
-        PasswordAuthentication credentials =  lookup(requestorType);
-        String username = (credentials == null || credentials.getUserName() == null) ? "" : credentials.getUserName();
-        String password = (credentials == null || credentials.getPassword() == null) ? "" : String.valueOf(credentials.getPassword());
-
-        CredentialsManagerResponse response = new CredentialsManagerResponse();
-
-        /*
-         * Last request was successful and there was no credentials stored
-         * in file (or only the username is stored).
-         * -> Try to recall credentials that have been entered
-         * manually in this session.
-         */
-        if (!noSuccessWithLastResponse && memoryCredentialsCache.containsKey(requestorType) &&
-                (credentials == null || credentials.getPassword() == null || credentials.getPassword().length == 0)) {
-            PasswordAuthentication pa = memoryCredentialsCache.get(requestorType);
-            response.setUsername(pa.getUserName());
-            response.setPassword(pa.getPassword());
-            response.setCanceled(false);
-        /*
-         * Prompt the user for credentials. This happens the first time each
-         * josm start if the user does not save the credentials to preference
-         * file (username=="") and each time after authentication failed
-         * (noSuccessWithLastResponse == true).
-         */
-        } else if (noSuccessWithLastResponse || username.equals("") || password.equals("")) {
-            CredentialDialog dialog = null;
-            switch(requestorType) {
-            case SERVER: dialog = CredentialDialog.getOsmApiCredentialDialog(username, password); break;
-            case PROXY: dialog = CredentialDialog.getHttpProxyCredentialDialog(username, password); break;
-            }
-            dialog.setVisible(true);
-            response.setCanceled(dialog.isCanceled());
-            if (dialog.isCanceled())
-                return response;
-            response.setUsername(dialog.getUsername());
-            response.setPassword(dialog.getPassword());
-            if (dialog.isSaveCredentials()) {
-                store(requestorType, new PasswordAuthentication(
-                        response.getUsername(),
-                        response.getPassword()
-                ));
-            /*
-             * User decides not to save credentials to file. Keep it
-             * in memory so we don't have to ask over and over again.
-             */
-            } else {
-                PasswordAuthentication pa = new PasswordAuthentication(dialog.getUsername(), dialog.getPassword());
-                memoryCredentialsCache.put(requestorType, pa);
-            }
-        /*
-         * We got it from file.
-         */
-        } else {
-            response.setUsername(username);
-            response.setPassword(password.toCharArray());
-            response.setCanceled(false);
-        }
-        return response;
-    }
-
-    /**
-     * Lookup the current OAuth Access Token to access the OSM server. Replies null, if no
-     * Access Token is currently managed by this CredentialManager.
-     *
-     * @return the current OAuth Access Token to access the OSM server.
-     * @throws CredentialsManagerException thrown if something goes wrong
-     */
-    public OAuthToken lookupOAuthAccessToken() throws CredentialsManagerException {
-        String accessTokenKey = Main.pref.get("oauth.access-token.key", null);
-        String accessTokenSecret = Main.pref.get("oauth.access-token.secret", null);
-        if (accessTokenKey == null && accessTokenSecret == null)
-            return null;
-        return new OAuthToken(accessTokenKey, accessTokenSecret);
-    }
-
-    /**
-     * Stores the OAuth Access Token <code>accessToken</code>.
-     *
-     * @param accessToken the access Token. null, to remove the Access Token.
-     * @throws CredentialsManagerException thrown if something goes wrong
-     */
-    public void storeOAuthAccessToken(OAuthToken accessToken) throws CredentialsManagerException {
-        if (accessToken == null) {
-            Main.pref.put("oauth.access-token.key", null);
-            Main.pref.put("oauth.access-token.secret", null);
-        } else {
-            Main.pref.put("oauth.access-token.key", accessToken.getKey());
-            Main.pref.put("oauth.access-token.secret", accessToken.getSecret());
-        }
-    }
-}
