- Timestamp:
- 2011-12-21T23:12:59+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/io/CredentialDialog.java
r4645 r4690 42 42 public class CredentialDialog extends JDialog { 43 43 44 static public CredentialDialog getOsmApiCredentialDialog(String username, String password, String saveUsernameAndPasswordCheckboxText) {44 static public CredentialDialog getOsmApiCredentialDialog(String username, String password, String host, String saveUsernameAndPasswordCheckboxText) { 45 45 CredentialDialog dialog = new CredentialDialog(saveUsernameAndPasswordCheckboxText); 46 dialog.prepareForOsmApiCredentials(username, password); 46 if(OsmApi.getOsmApi().getHost().equals(host)) { 47 dialog.prepareForOsmApiCredentials(username, password); 48 } else { 49 dialog.prepareForOtherHostCredentials(username, password, host); 50 } 47 51 dialog.pack(); 48 52 return dialog; 49 53 } 50 54 51 static public CredentialDialog getHttpProxyCredentialDialog(String username, String password, String saveUsernameAndPasswordCheckboxText) {55 static public CredentialDialog getHttpProxyCredentialDialog(String username, String password, String host, String saveUsernameAndPasswordCheckboxText) { 52 56 CredentialDialog dialog = new CredentialDialog(saveUsernameAndPasswordCheckboxText); 53 57 dialog.prepareForProxyCredentials(username, password); … … 109 113 setTitle(tr("Enter credentials for OSM API")); 110 114 getContentPane().add(pnlCredentials = new OsmApiCredentialsPanel(this), BorderLayout.CENTER); 115 pnlCredentials.init(username, password); 116 validate(); 117 } 118 119 public void prepareForOtherHostCredentials(String username, String password, String host) { 120 setTitle(tr("Enter credentials for host")); 121 getContentPane().add(pnlCredentials = new OtherHostCredentialsPanel(this, host), BorderLayout.CENTER); 111 122 pnlCredentials.init(username, password); 112 123 validate(); … … 257 268 } 258 269 270 private static class OtherHostCredentialsPanel extends CredentialPanel { 271 272 String host; 273 274 @Override 275 protected void build() { 276 super.build(); 277 tfUserName.setToolTipText(tr("Please enter the user name of your account")); 278 tfPassword.setToolTipText(tr("Please enter the password of your account")); 279 lblHeading.setText( 280 "<html>" + tr("Authenticating at the host ''{0}'' failed. Please enter a valid username and a valid password.", 281 host) + "</html>"); 282 lblWarning.setText(tr("Warning: The password is transferred unencrypted.")); 283 } 284 285 public OtherHostCredentialsPanel(CredentialDialog owner, String host) { 286 super(owner); 287 this.host = host; 288 build(); 289 } 290 } 291 259 292 private static class HttpProxyCredentialsPanel extends CredentialPanel { 260 293 @Override -
trunk/src/org/openstreetmap/josm/gui/oauth/FullyAutomaticAuthorizationUI.java
r4253 r4690 42 42 import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator; 43 43 import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel; 44 import org.openstreetmap.josm.io.OsmApi; 44 45 import org.openstreetmap.josm.io.OsmTransferException; 45 46 import org.openstreetmap.josm.io.auth.CredentialsAgent; … … 184 185 CredentialsAgent cm = CredentialsManager.getInstance(); 185 186 try { 186 PasswordAuthentication pa = cm.lookup(RequestorType.SERVER );187 PasswordAuthentication pa = cm.lookup(RequestorType.SERVER, OsmApi.getOsmApi().getHost()); 187 188 if (pa == null) { 188 189 tfUserName.setText(""); -
trunk/src/org/openstreetmap/josm/gui/preferences/server/BasicAuthenticationPreferencesPanel.java
r4263 r4690 23 23 import org.openstreetmap.josm.io.auth.CredentialsManager; 24 24 import org.openstreetmap.josm.io.auth.JosmPreferencesCredentialAgent; 25 import org.openstreetmap.josm.io.OsmApi; 25 26 26 27 /** … … 94 95 decorationPanel.removeAll(); 95 96 decorationPanel.add(cm.getPreferencesDecorationPanel(), BorderLayout.CENTER); 96 PasswordAuthentication pa = cm.lookup(RequestorType.SERVER );97 PasswordAuthentication pa = cm.lookup(RequestorType.SERVER, OsmApi.getOsmApi().getHost()); 97 98 if (pa == null) { 98 99 tfOsmUserName.setText(""); … … 118 119 tfOsmPassword.getPassword() 119 120 ); 120 cm.store(RequestorType.SERVER, pa);121 cm.store(RequestorType.SERVER, OsmApi.getOsmApi().getHost(), pa); 121 122 } catch(CredentialsAgentException e) { 122 123 e.printStackTrace(); -
trunk/src/org/openstreetmap/josm/gui/preferences/server/ProxyPreferencesPanel.java
r4246 r4690 325 325 CredentialsAgent cm = CredentialsManager.getInstance(); 326 326 try { 327 PasswordAuthentication pa = cm.lookup(RequestorType.PROXY );327 PasswordAuthentication pa = cm.lookup(RequestorType.PROXY, tfProxyHttpHost.getText()); 328 328 if (pa == null) { 329 329 tfProxyHttpUser.setText(""); … … 404 404 tfProxyHttpPassword.getPassword() 405 405 ); 406 cm.store(RequestorType.PROXY, pa);406 cm.store(RequestorType.PROXY, tfProxyHttpHost.getText(), pa); 407 407 } catch(CredentialsAgentException e) { 408 408 e.printStackTrace(); -
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r4645 r4690 17 17 import java.net.ConnectException; 18 18 import java.net.HttpURLConnection; 19 import java.net.MalformedURLException; 19 20 import java.net.SocketTimeoutException; 20 21 import java.net.URL; … … 141 142 public String getVersion() { 142 143 return version; 144 } 145 146 public String getHost() { 147 String host = null; 148 try { 149 host = (new URL(serverUrl)).getHost(); 150 } catch (MalformedURLException e) { 151 } 152 return host; 143 153 } 144 154 -
trunk/src/org/openstreetmap/josm/io/OsmConnection.java
r4245 r4690 77 77 try { 78 78 synchronized (CredentialsManager.getInstance()) { 79 response = CredentialsManager.getInstance().getCredentials(RequestorType.SERVER, false /* don't know yet whether the credentials will succeed */); 79 response = CredentialsManager.getInstance().getCredentials(RequestorType.SERVER, 80 con.getURL().getHost(), false /* don't know yet whether the credentials will succeed */); 80 81 } 81 82 } catch (CredentialsAgentException e) { -
trunk/src/org/openstreetmap/josm/io/auth/AbstractCredentialsAgent.java
r4249 r4690 17 17 */ 18 18 @Override 19 public CredentialsAgentResponse getCredentials(RequestorType requestorType, boolean noSuccessWithLastResponse) throws CredentialsAgentException{19 public CredentialsAgentResponse getCredentials(RequestorType requestorType, String host, boolean noSuccessWithLastResponse) throws CredentialsAgentException{ 20 20 if (requestorType == null) 21 21 return null; 22 PasswordAuthentication credentials = lookup(requestorType );22 PasswordAuthentication credentials = lookup(requestorType, host); 23 23 String username = (credentials == null || credentials.getUserName() == null) ? "" : credentials.getUserName(); 24 24 String password = (credentials == null || credentials.getPassword() == null) ? "" : String.valueOf(credentials.getPassword()); … … 47 47 CredentialDialog dialog = null; 48 48 switch(requestorType) { 49 case SERVER: dialog = CredentialDialog.getOsmApiCredentialDialog(username, password, getSaveUsernameAndPasswordCheckboxText()); break;50 case PROXY: dialog = CredentialDialog.getHttpProxyCredentialDialog(username, password, getSaveUsernameAndPasswordCheckboxText()); break;49 case SERVER: dialog = CredentialDialog.getOsmApiCredentialDialog(username, password, host, getSaveUsernameAndPasswordCheckboxText()); break; 50 case PROXY: dialog = CredentialDialog.getHttpProxyCredentialDialog(username, password, host, getSaveUsernameAndPasswordCheckboxText()); break; 51 51 } 52 52 dialog.setVisible(true); … … 57 57 response.setPassword(dialog.getPassword()); 58 58 if (dialog.isSaveCredentials()) { 59 store(requestorType, new PasswordAuthentication(59 store(requestorType, host, new PasswordAuthentication( 60 60 response.getUsername(), 61 61 response.getPassword() -
trunk/src/org/openstreetmap/josm/io/auth/CredentialsAgent.java
r4249 r4690 29 29 * @throws CredentialsAgentException thrown if a problem occurs in a implementation of this interface 30 30 */ 31 PasswordAuthentication lookup(RequestorType requestorType ) throws CredentialsAgentException;31 PasswordAuthentication lookup(RequestorType requestorType, String host) throws CredentialsAgentException; 32 32 33 33 /** … … 39 39 * @throws CredentialsManagerException thrown if a problem occurs in a implementation of this interface 40 40 */ 41 void store(RequestorType requestorType, PasswordAuthentication credentials) throws CredentialsAgentException;41 void store(RequestorType requestorType, String host, PasswordAuthentication credentials) throws CredentialsAgentException; 42 42 43 43 /** … … 50 50 51 51 */ 52 CredentialsAgentResponse getCredentials(RequestorType requestorType, boolean noSuccessWithLastResponse) throws CredentialsAgentException;52 CredentialsAgentResponse getCredentials(RequestorType requestorType, String host, boolean noSuccessWithLastResponse) throws CredentialsAgentException; 53 53 54 54 /** -
trunk/src/org/openstreetmap/josm/io/auth/CredentialsManager.java
r4264 r4690 8 8 import org.openstreetmap.josm.data.oauth.OAuthToken; 9 9 import org.openstreetmap.josm.gui.JosmUserIdentityManager; 10 import org.openstreetmap.josm.io.OsmApi; 10 11 import org.openstreetmap.josm.tools.Utils; 11 12 … … 66 67 67 68 public String getUsername() { 69 return getUsername(OsmApi.getOsmApi().getHost()); 70 } 71 72 public String getUsername(String host) { 68 73 String username = null; 69 74 try { 70 PasswordAuthentication auth = lookup(RequestorType.SERVER );75 PasswordAuthentication auth = lookup(RequestorType.SERVER, host); 71 76 if (auth != null) { 72 77 username = auth.getUserName(); … … 81 86 82 87 @Override 83 public PasswordAuthentication lookup(RequestorType requestorType ) throws CredentialsAgentException {84 return delegate.lookup(requestorType );88 public PasswordAuthentication lookup(RequestorType requestorType, String host) throws CredentialsAgentException { 89 return delegate.lookup(requestorType, host); 85 90 } 86 91 87 92 @Override 88 public void store(RequestorType requestorType, PasswordAuthentication credentials) throws CredentialsAgentException { 89 if (requestorType == RequestorType.SERVER && credentials.getUserName() != null && !credentials.getUserName().trim().isEmpty()) { 90 JosmUserIdentityManager.getInstance().setPartiallyIdentified(credentials.getUserName()); 93 public void store(RequestorType requestorType, String host, PasswordAuthentication credentials) throws CredentialsAgentException { 94 if (requestorType == RequestorType.SERVER && OsmApi.getOsmApi().getHost().equals(host)) { 95 String username = credentials.getUserName(); 96 if(username != null && !username.trim().isEmpty()) { 97 JosmUserIdentityManager.getInstance().setPartiallyIdentified(username); 98 } 91 99 } 92 delegate.store(requestorType, credentials);100 delegate.store(requestorType, host, credentials); 93 101 } 94 102 95 103 @Override 96 public CredentialsAgentResponse getCredentials(RequestorType requestorType, boolean noSuccessWithLastResponse) throws CredentialsAgentException {97 return delegate.getCredentials(requestorType, noSuccessWithLastResponse);104 public CredentialsAgentResponse getCredentials(RequestorType requestorType, String host, boolean noSuccessWithLastResponse) throws CredentialsAgentException { 105 return delegate.getCredentials(requestorType, host, noSuccessWithLastResponse); 98 106 } 99 107 -
trunk/src/org/openstreetmap/josm/io/auth/DefaultAuthenticator.java
r4249 r4690 49 49 } 50 50 boolean tried = credentialsTried.get(getRequestorType()) != null; 51 CredentialsAgentResponse response = CredentialsManager.getInstance().getCredentials(getRequestorType(), tried);51 CredentialsAgentResponse response = CredentialsManager.getInstance().getCredentials(getRequestorType(), getRequestingHost(), tried); 52 52 if (response == null || response.isCanceled()) 53 53 return null; -
trunk/src/org/openstreetmap/josm/io/auth/JosmPreferencesCredentialAgent.java
r4249 r4690 14 14 import org.openstreetmap.josm.gui.preferences.server.ProxyPreferencesPanel; 15 15 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 16 import org.openstreetmap.josm.io.OsmApi; 16 17 17 18 /** … … 26 27 */ 27 28 @Override 28 public PasswordAuthentication lookup(RequestorType requestorType ) throws CredentialsAgentException{29 public PasswordAuthentication lookup(RequestorType requestorType, String host) throws CredentialsAgentException{ 29 30 if (requestorType == null) 30 31 return null; … … 33 34 switch(requestorType) { 34 35 case SERVER: 35 user = Main.pref.get("osm-server.username", null); 36 password = Main.pref.get("osm-server.password", null); 36 if(OsmApi.getOsmApi().getHost().equals(host)) { 37 user = Main.pref.get("osm-server.username", null); 38 password = Main.pref.get("osm-server.password", null); 39 } else { 40 user = null; 41 password = null; 42 } 37 43 if (user == null) 38 44 return null; … … 52 58 */ 53 59 @Override 54 public void store(RequestorType requestorType, PasswordAuthentication credentials) throws CredentialsAgentException {60 public void store(RequestorType requestorType, String host, PasswordAuthentication credentials) throws CredentialsAgentException { 55 61 if (requestorType == null) 56 62 return; 57 63 switch(requestorType) { 58 64 case SERVER: 59 Main.pref.put("osm-server.username", credentials.getUserName()); 60 if (credentials.getPassword() == null) { 61 Main.pref.put("osm-server.password", null); 62 } else { 63 Main.pref.put("osm-server.password", String.valueOf(credentials.getPassword())); 65 if(OsmApi.getOsmApi().getHost().equals(host)) { 66 Main.pref.put("osm-server.username", credentials.getUserName()); 67 if (credentials.getPassword() == null) { 68 Main.pref.put("osm-server.password", null); 69 } else { 70 Main.pref.put("osm-server.password", String.valueOf(credentials.getPassword())); 71 } 64 72 } 65 73 break;
Note:
See TracChangeset
for help on using the changeset viewer.