Changeset 4245 in josm
- Timestamp:
- 2011-07-14T19:52:24+02:00 (12 years ago)
- 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 32 32 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 33 33 import org.openstreetmap.josm.io.DefaultProxySelector; 34 import org.openstreetmap.josm.io.auth.CredentialsManager Factory;34 import org.openstreetmap.josm.io.auth.CredentialsManager; 35 35 import org.openstreetmap.josm.io.auth.DefaultAuthenticator; 36 36 import org.openstreetmap.josm.io.remotecontrol.RemoteControl; … … 188 188 Main.pref.updateSystemProperties(); 189 189 190 DefaultAuthenticator.createInstance(CredentialsManager Factory.getCredentialManager());190 DefaultAuthenticator.createInstance(CredentialsManager.getInstance()); 191 191 Authenticator.setDefault(DefaultAuthenticator.getInstance()); 192 192 ProxySelector.setDefault(new DefaultProxySelector(ProxySelector.getDefault())); 193 OAuthAccessTokenHolder.getInstance().init(Main.pref, CredentialsManager Factory.getCredentialManager());193 OAuthAccessTokenHolder.getInstance().init(Main.pref, CredentialsManager.getInstance()); 194 194 195 195 // asking for help? show help and exit -
trunk/src/org/openstreetmap/josm/gui/oauth/FullyAutomaticAuthorizationUI.java
r4147 r4245 43 43 import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel; 44 44 import org.openstreetmap.josm.io.OsmTransferException; 45 import org.openstreetmap.josm.io.auth.CredentialsAgent; 46 import org.openstreetmap.josm.io.auth.CredentialsAgentException; 45 47 import org.openstreetmap.josm.io.auth.CredentialsManager; 46 import org.openstreetmap.josm.io.auth.CredentialsManagerException;47 import org.openstreetmap.josm.io.auth.CredentialsManagerFactory;48 48 import org.openstreetmap.josm.tools.ImageProvider; 49 49 import org.xml.sax.SAXException; … … 182 182 public void initFromPreferences(Preferences pref) { 183 183 super.initFromPreferences(pref); 184 Credentials Manager cm = CredentialsManagerFactory.getCredentialManager();184 CredentialsAgent cm = CredentialsManager.getInstance(); 185 185 try { 186 186 PasswordAuthentication pa = cm.lookup(RequestorType.SERVER); … … 192 192 tfPassword.setText(pa.getPassword() == null ? "" : String.valueOf(pa.getPassword())); 193 193 } 194 } catch(Credentials ManagerException e) {194 } catch(CredentialsAgentException e) { 195 195 e.printStackTrace(); 196 196 tfUserName.setText(""); -
trunk/src/org/openstreetmap/josm/gui/preferences/server/AuthenticationPreferencesPanel.java
r3530 r4245 20 20 import org.openstreetmap.josm.gui.help.HelpUtil; 21 21 import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel; 22 import org.openstreetmap.josm.io.auth.CredentialsManager Factory;22 import org.openstreetmap.josm.io.auth.CredentialsManager; 23 23 24 24 /** … … 124 124 pnlBasicAuthPreferences.saveToPreferences(); 125 125 OAuthAccessTokenHolder.getInstance().clear(); 126 OAuthAccessTokenHolder.getInstance().save(Main.pref, CredentialsManager Factory.getCredentialManager());126 OAuthAccessTokenHolder.getInstance().save(Main.pref, CredentialsManager.getInstance()); 127 127 } else if (authMethod.equals("oauth")) { 128 128 // clear the password in the preferences -
trunk/src/org/openstreetmap/josm/gui/preferences/server/BasicAuthenticationPreferencesPanel.java
r3530 r4245 20 20 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 21 21 import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator; 22 import org.openstreetmap.josm.io.auth.CredentialsAgent; 23 import org.openstreetmap.josm.io.auth.CredentialsAgentException; 22 24 import 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; 25 import org.openstreetmap.josm.io.auth.JosmPreferencesCredentialAgent; 26 26 27 27 /** … … 103 103 104 104 public void initFromPreferences() { 105 Credentials Manager cm = CredentialsManagerFactory.getCredentialManager();105 CredentialsAgent cm = CredentialsManager.getInstance(); 106 106 try { 107 107 PasswordAuthentication pa = cm.lookup(RequestorType.SERVER); … … 113 113 tfOsmPassword.setText(pa.getPassword() == null ? "" : String.valueOf(pa.getPassword())); 114 114 } 115 } catch(Credentials ManagerException e) {115 } catch(CredentialsAgentException e) { 116 116 e.printStackTrace(); 117 117 System.err.println(tr("Warning: failed to retrieve OSM credentials from credential manager.")); … … 123 123 124 124 public void saveToPreferences() { 125 Credentials Manager cm = CredentialsManagerFactory.getCredentialManager();125 CredentialsAgent cm = CredentialsManager.getInstance(); 126 126 try { 127 127 PasswordAuthentication pa = new PasswordAuthentication( … … 132 132 // always save the username to the preferences if it isn't already saved there 133 133 // by the credential manager 134 if (! (cm instanceof JosmPreferencesCredential Manager)) {134 if (! (cm instanceof JosmPreferencesCredentialAgent)) { 135 135 Main.pref.put("osm-server.username", tfOsmUserName.getText().trim()); 136 136 } 137 } catch(Credentials ManagerException e) {137 } catch(CredentialsAgentException e) { 138 138 e.printStackTrace(); 139 139 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 6 6 import org.openstreetmap.josm.data.Preferences; 7 7 import org.openstreetmap.josm.data.oauth.OAuthToken; 8 import org.openstreetmap.josm.io.auth.Credentials Manager;9 import org.openstreetmap.josm.io.auth.Credentials ManagerException;8 import org.openstreetmap.josm.io.auth.CredentialsAgent; 9 import org.openstreetmap.josm.io.auth.CredentialsAgentException; 10 10 import org.openstreetmap.josm.tools.CheckParameterUtil; 11 11 … … 136 136 * @throws IllegalArgumentException thrown if cm is null 137 137 */ 138 public void init(Preferences pref, Credentials Managercm) throws IllegalArgumentException {138 public void init(Preferences pref, CredentialsAgent cm) throws IllegalArgumentException { 139 139 CheckParameterUtil.ensureParameterNotNull(pref, "pref"); 140 140 CheckParameterUtil.ensureParameterNotNull(cm, "cm"); … … 142 142 try { 143 143 token = cm.lookupOAuthAccessToken(); 144 } catch(Credentials ManagerException e) {144 } catch(CredentialsAgentException e) { 145 145 e.printStackTrace(); 146 146 System.err.println(tr("Warning: Failed to retrieve OAuth Access Token from credential manager")); … … 163 163 * @throws IllegalArgumentException thrown if cm is null 164 164 */ 165 public void save(Preferences preferences, Credentials Managercm) throws IllegalArgumentException {165 public void save(Preferences preferences, CredentialsAgent cm) throws IllegalArgumentException { 166 166 CheckParameterUtil.ensureParameterNotNull(preferences, "preferences"); 167 167 CheckParameterUtil.ensureParameterNotNull(cm, "cm"); … … 173 173 cm.storeOAuthAccessToken(new OAuthToken(accessTokenKey, accessTokenSecret)); 174 174 } 175 } catch(Credentials ManagerException e){175 } catch(CredentialsAgentException e){ 176 176 e.printStackTrace(); 177 177 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 32 32 import org.openstreetmap.josm.gui.oauth.OAuthAuthorizationWizard; 33 33 import org.openstreetmap.josm.gui.oauth.TestAccessTokenTask; 34 import org.openstreetmap.josm.io.auth.CredentialsManager Factory;34 import org.openstreetmap.josm.io.auth.CredentialsManager; 35 35 import org.openstreetmap.josm.tools.ImageProvider; 36 36 … … 161 161 public void saveToPreferences() { 162 162 OAuthAccessTokenHolder.getInstance().setSaveToPreferences(cbSaveToPreferences.isSelected()); 163 OAuthAccessTokenHolder.getInstance().save(Main.pref, CredentialsManager Factory.getCredentialManager());163 OAuthAccessTokenHolder.getInstance().save(Main.pref, CredentialsManager.getInstance()); 164 164 pnlAdvancedProperties.getAdvancedParameters().saveToPreferences(Main.pref); 165 165 } -
trunk/src/org/openstreetmap/josm/gui/preferences/server/ProxyPreferencesPanel.java
r3530 r4245 31 31 import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel; 32 32 import org.openstreetmap.josm.io.DefaultProxySelector; 33 import org.openstreetmap.josm.io.auth.CredentialsAgent; 34 import org.openstreetmap.josm.io.auth.CredentialsAgentException; 33 35 import org.openstreetmap.josm.io.auth.CredentialsManager; 34 import org.openstreetmap.josm.io.auth.CredentialsManagerException;35 import org.openstreetmap.josm.io.auth.CredentialsManagerFactory;36 36 import org.openstreetmap.josm.tools.GBC; 37 37 … … 321 321 // save the proxy user and the proxy password to a credentials store managed by 322 322 // the credentials manager 323 Credentials Manager cm = CredentialsManagerFactory.getCredentialManager();323 CredentialsAgent cm = CredentialsManager.getInstance(); 324 324 try { 325 325 PasswordAuthentication pa = cm.lookup(RequestorType.PROXY); … … 331 331 tfProxyHttpPassword.setText(pa.getPassword() == null ? "" : String.valueOf(pa.getPassword())); 332 332 } 333 } catch(Credentials ManagerException e) {333 } catch(CredentialsAgentException e) { 334 334 e.printStackTrace(); 335 335 tfProxyHttpUser.setText(""); … … 395 395 } 396 396 397 Credentials Manager cm = CredentialsManagerFactory.getCredentialManager();397 CredentialsAgent cm = CredentialsManager.getInstance(); 398 398 try { 399 399 PasswordAuthentication pa = new PasswordAuthentication( … … 402 402 ); 403 403 cm.store(RequestorType.PROXY, pa); 404 } catch(Credentials ManagerException e) {404 } catch(CredentialsAgentException e) { 405 405 e.printStackTrace(); 406 406 } -
trunk/src/org/openstreetmap/josm/io/OsmConnection.java
r4191 r4245 18 18 import org.openstreetmap.josm.data.oauth.OAuthParameters; 19 19 import org.openstreetmap.josm.gui.preferences.server.OAuthAccessTokenHolder; 20 import org.openstreetmap.josm.io.auth.Credentials ManagerException;21 import org.openstreetmap.josm.io.auth.CredentialsManager Factory;22 import org.openstreetmap.josm.io.auth.Credentials ManagerResponse;20 import org.openstreetmap.josm.io.auth.CredentialsAgentException; 21 import org.openstreetmap.josm.io.auth.CredentialsManager; 22 import org.openstreetmap.josm.io.auth.CredentialsAgentResponse; 23 23 import org.openstreetmap.josm.tools.Base64; 24 24 … … 73 73 protected void addBasicAuthorizationHeader(HttpURLConnection con) throws OsmTransferException { 74 74 CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder(); 75 Credentials ManagerResponse response;75 CredentialsAgentResponse response; 76 76 String token; 77 77 try { 78 synchronized (CredentialsManager Factory.getCredentialManager()) {79 response = CredentialsManager Factory.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 */); 80 80 } 81 } catch (Credentials ManagerException e) {81 } catch (CredentialsAgentException e) { 82 82 throw new OsmTransferException(e); 83 83 } -
trunk/src/org/openstreetmap/josm/io/auth/CredentialsAgent.java
r4238 r4245 8 8 9 9 /** 10 * A Credential Managermanages two credentials:10 * A CredentialsAgent manages two credentials: 11 11 * <ul> 12 12 * <li>the credential for {@see RequestorType#SERVER} which is equal to the OSM API credentials … … 18 18 * In addition, it manages an OAuth Access Token for accessing the OSM server. 19 19 */ 20 public interface Credentials Manager{20 public interface CredentialsAgent { 21 21 22 22 /** … … 26 26 * for a proxy server 27 27 * @return the credentials 28 * @throws Credentials ManagerException thrown if a problem occurs in a implementation of this interface28 * @throws CredentialsAgentException thrown if a problem occurs in a implementation of this interface 29 29 */ 30 public PasswordAuthentication lookup(RequestorType requestorType) throws Credentials ManagerException;30 public PasswordAuthentication lookup(RequestorType requestorType) throws CredentialsAgentException; 31 31 32 32 /** … … 38 38 * @throws CredentialsManagerException thrown if a problem occurs in a implementation of this interface 39 39 */ 40 public void store(RequestorType requestorType, PasswordAuthentication credentials) throws Credentials ManagerException;40 public void store(RequestorType requestorType, PasswordAuthentication credentials) throws CredentialsAgentException; 41 41 42 42 /** … … 45 45 * for a proxy server 46 46 * @param noSuccessWithLastResponse true, if the last request with the supplied credentials failed; false otherwise. 47 * If true, implementations of this interface are advi ced promptuser for new credentials.48 * @throws Credentials ManagerException thrown if a problem occurs in a implementation of this interface47 * 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 49 49 50 50 */ 51 public Credentials ManagerResponse getCredentials(RequestorType requestorType, boolean noSuccessWithLastResponse) throws CredentialsManagerException;51 public CredentialsAgentResponse getCredentials(RequestorType requestorType, boolean noSuccessWithLastResponse) throws CredentialsAgentException; 52 52 53 53 /** 54 54 * Lookup the current OAuth Access Token to access the OSM server. Replies null, if no 55 * Access Token is currently managed by this Credential Manager.55 * Access Token is currently managed by this CredentialAgent. 56 56 * 57 57 * @return the current OAuth Access Token to access the OSM server. 58 * @throws Credentials ManagerException thrown if something goes wrong58 * @throws CredentialsAgentException thrown if something goes wrong 59 59 */ 60 public OAuthToken lookupOAuthAccessToken() throws Credentials ManagerException;60 public OAuthToken lookupOAuthAccessToken() throws CredentialsAgentException; 61 61 62 62 /** … … 64 64 * 65 65 * @param accessToken the access Token. null, to remove the Access Token. 66 * @throws Credentials ManagerException thrown if something goes wrong66 * @throws CredentialsAgentException thrown if something goes wrong 67 67 */ 68 public void storeOAuthAccessToken(OAuthToken accessToken) throws Credentials ManagerException;68 public void storeOAuthAccessToken(OAuthToken accessToken) throws CredentialsAgentException; 69 69 } -
trunk/src/org/openstreetmap/josm/io/auth/CredentialsAgentException.java
r4238 r4245 2 2 package org.openstreetmap.josm.io.auth; 3 3 4 public class Credentials ManagerException extends Exception {5 public Credentials ManagerException() {super();}6 public Credentials ManagerException(String message, Throwable cause) {super(message, cause);}7 public Credentials ManagerException(String message) {super(message);}8 public Credentials ManagerException(Throwable cause) {super(cause);}4 public 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);} 9 9 10 10 } -
trunk/src/org/openstreetmap/josm/io/auth/CredentialsAgentResponse.java
r4238 r4245 3 3 4 4 /** 5 * Credentials ManagerResponse 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)}. 6 6 * 7 7 * The response consists of the username and the password the requested credentials consists of. … … 10 10 * 11 11 */ 12 public class Credentials ManagerResponse {12 public class CredentialsAgentResponse { 13 13 private String username; 14 14 private char[] password; -
trunk/src/org/openstreetmap/josm/io/auth/CredentialsManager.java
r4238 r4245 3 3 4 4 /** 5 * CredentialManager Factory is a factory for the single credential managerused.5 * CredentialManager is a factory for the single credential agent used. 6 6 * 7 * Currently, it defaults to replying an instance of {@see JosmPreferencesCredential Manager}.7 * Currently, it defaults to replying an instance of {@see JosmPreferencesCredentialAgent}. 8 8 * 9 9 */ 10 public class CredentialsManager Factory{11 private static Credentials Managerinstance;10 public class CredentialsManager { 11 private static CredentialsAgent instance; 12 12 13 13 /** 14 * Replies the single credential managerused in JOSM14 * Replies the single credential agent used in JOSM 15 15 * 16 * @return the single credential managerused in JOSM16 * @return the single credential agent used in JOSM 17 17 */ 18 static public Credentials Manager getCredentialManager() {18 static public CredentialsAgent getInstance() { 19 19 if (instance == null) { 20 instance = new JosmPreferencesCredential Manager();20 instance = new JosmPreferencesCredentialAgent(); 21 21 } 22 22 return instance; -
trunk/src/org/openstreetmap/josm/io/auth/DefaultAuthenticator.java
r4191 r4245 22 22 } 23 23 24 public static void createInstance(Credentials ManagercredentialManager) {24 public static void createInstance(CredentialsAgent credentialManager) { 25 25 instance = new DefaultAuthenticator(credentialManager); 26 26 } 27 27 28 private Credentials Manager credentialManager;28 private CredentialsAgent credentialsAgent; 29 29 private final Map<RequestorType, Boolean> credentialsTried = new HashMap<RequestorType, Boolean>(); 30 30 private boolean enabled = true; … … 32 32 /** 33 33 * 34 * @param credential Managerthe credential manager34 * @param credentialsAgent the credential manager 35 35 */ 36 private DefaultAuthenticator(Credentials Manager credentialManager) {37 this.credential Manager = credentialManager;36 private DefaultAuthenticator(CredentialsAgent credentialsAgent) { 37 this.credentialsAgent = credentialsAgent; 38 38 } 39 39 … … 55 55 } 56 56 boolean tried = credentialsTried.get(getRequestorType()) != null; 57 Credentials ManagerResponse response = credentialManager.getCredentials(getRequestorType(), tried);57 CredentialsAgentResponse response = credentialsAgent.getCredentials(getRequestorType(), tried); 58 58 if (response == null || response.isCanceled()) 59 59 return null; 60 60 credentialsTried.put(getRequestorType(), true); 61 61 return new PasswordAuthentication(response.getUsername(), response.getPassword()); 62 } catch(Credentials ManagerException e) {62 } catch(CredentialsAgentException e) { 63 63 e.printStackTrace(); 64 64 return null; -
trunk/src/org/openstreetmap/josm/io/auth/JosmPreferencesCredentialAgent.java
r4238 r4245 13 13 14 14 /** 15 * This is the default credential managerin JOSM. It keeps username and password for both15 * This is the default credentials agent in JOSM. It keeps username and password for both 16 16 * the OSM API and an optional HTTP proxy in the JOSM preferences file. 17 17 * 18 18 */ 19 public class JosmPreferencesCredential Manager implements CredentialsManager{19 public class JosmPreferencesCredentialAgent implements CredentialsAgent { 20 20 21 21 Map<RequestorType, PasswordAuthentication> memoryCredentialsCache = new HashMap<RequestorType, PasswordAuthentication>(); 22 22 /** 23 * @see Credentials Manager#lookup(RequestorType)23 * @see CredentialsAgent#lookup(RequestorType) 24 24 */ 25 public PasswordAuthentication lookup(RequestorType requestorType) throws CredentialsManagerException{ 25 @Override 26 public PasswordAuthentication lookup(RequestorType requestorType) throws CredentialsAgentException{ 26 27 if (requestorType == null) 27 28 return null; … … 46 47 47 48 /** 48 * @see Credentials Manager#store(RequestorType, PasswordAuthentication)49 * @see CredentialsAgent#store(RequestorType, PasswordAuthentication) 49 50 */ 50 public void store(RequestorType requestorType, PasswordAuthentication credentials) throws CredentialsManagerException { 51 @Override 52 public void store(RequestorType requestorType, PasswordAuthentication credentials) throws CredentialsAgentException { 51 53 if (requestorType == null) 52 54 return; … … 72 74 73 75 /** 74 * @see Credentials Manager#getCredentials(RequestorType, boolean)76 * @see CredentialsAgent#getCredentials(RequestorType, boolean) 75 77 */ 76 public CredentialsManagerResponse getCredentials(RequestorType requestorType, boolean noSuccessWithLastResponse) throws CredentialsManagerException{ 78 @Override 79 public CredentialsAgentResponse getCredentials(RequestorType requestorType, boolean noSuccessWithLastResponse) throws CredentialsAgentException{ 77 80 if (requestorType == null) 78 81 return null; … … 81 84 String password = (credentials == null || credentials.getPassword() == null) ? "" : String.valueOf(credentials.getPassword()); 82 85 83 Credentials ManagerResponse response = new CredentialsManagerResponse();86 CredentialsAgentResponse response = new CredentialsAgentResponse(); 84 87 85 88 /* … … 142 145 * 143 146 * @return the current OAuth Access Token to access the OSM server. 144 * @throws Credentials ManagerException thrown if something goes wrong147 * @throws CredentialsAgentException thrown if something goes wrong 145 148 */ 146 public OAuthToken lookupOAuthAccessToken() throws CredentialsManagerException { 149 @Override 150 public OAuthToken lookupOAuthAccessToken() throws CredentialsAgentException { 147 151 String accessTokenKey = Main.pref.get("oauth.access-token.key", null); 148 152 String accessTokenSecret = Main.pref.get("oauth.access-token.secret", null); … … 156 160 * 157 161 * @param accessToken the access Token. null, to remove the Access Token. 158 * @throws Credentials ManagerException thrown if something goes wrong162 * @throws CredentialsAgentException thrown if something goes wrong 159 163 */ 160 public void storeOAuthAccessToken(OAuthToken accessToken) throws CredentialsManagerException { 164 @Override 165 public void storeOAuthAccessToken(OAuthToken accessToken) throws CredentialsAgentException { 161 166 if (accessToken == null) { 162 167 Main.pref.put("oauth.access-token.key", null);
Note: See TracChangeset
for help on using the changeset viewer.