Changeset 5692 in josm
- Timestamp:
- 2013-01-30T02:25:13+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/io/auth
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/auth/AbstractCredentialsAgent.java
r4826 r5692 8 8 9 9 import org.openstreetmap.josm.gui.io.CredentialDialog; 10 import org.openstreetmap.josm.gui.util.GuiHelper; 10 11 11 12 abstract public class AbstractCredentialsAgent implements CredentialsAgent { … … 14 15 15 16 /** 16 * @see CredentialsAgent#getCredentials(RequestorType, boolean)17 * @see CredentialsAgent#getCredentials(RequestorType, String, boolean) 17 18 */ 18 19 @Override 19 public CredentialsAgentResponse getCredentials( RequestorType requestorType,String host, boolean noSuccessWithLastResponse) throws CredentialsAgentException{20 public CredentialsAgentResponse getCredentials(final RequestorType requestorType, final String host, boolean noSuccessWithLastResponse) throws CredentialsAgentException{ 20 21 if (requestorType == null) 21 22 return null; 22 23 PasswordAuthentication credentials = lookup(requestorType, host); 23 String username = (credentials == null || credentials.getUserName() == null) ? "" : credentials.getUserName();24 String password = (credentials == null || credentials.getPassword() == null) ? "" : String.valueOf(credentials.getPassword());24 final String username = (credentials == null || credentials.getUserName() == null) ? "" : credentials.getUserName(); 25 final String password = (credentials == null || credentials.getPassword() == null) ? "" : String.valueOf(credentials.getPassword()); 25 26 26 CredentialsAgentResponse response = new CredentialsAgentResponse();27 final CredentialsAgentResponse response = new CredentialsAgentResponse(); 27 28 28 29 /* … … 45 46 */ 46 47 } else if (noSuccessWithLastResponse || username.equals("") || password.equals("")) { 47 CredentialDialog dialog = null; 48 switch(requestorType) { 49 case SERVER: dialog = CredentialDialog.getOsmApiCredentialDialog(username, password, host, getSaveUsernameAndPasswordCheckboxText()); break; 50 case PROXY: dialog = CredentialDialog.getHttpProxyCredentialDialog(username, password, host, getSaveUsernameAndPasswordCheckboxText()); break; 48 GuiHelper.runInEDTAndWait(new Runnable() { 49 @Override 50 public void run() { 51 CredentialDialog dialog = null; 52 switch(requestorType) { 53 case SERVER: dialog = CredentialDialog.getOsmApiCredentialDialog(username, password, host, getSaveUsernameAndPasswordCheckboxText()); break; 54 case PROXY: dialog = CredentialDialog.getHttpProxyCredentialDialog(username, password, host, getSaveUsernameAndPasswordCheckboxText()); break; 55 } 56 dialog.setVisible(true); 57 response.setCanceled(dialog.isCanceled()); 58 if (dialog.isCanceled()) 59 return; 60 response.setUsername(dialog.getUsername()); 61 response.setPassword(dialog.getPassword()); 62 response.setSaveCredentials(dialog.isSaveCredentials()); 63 } 64 }); 65 if (response.isCanceled()) { 66 return response; 51 67 } 52 dialog.setVisible(true); 53 response.setCanceled(dialog.isCanceled()); 54 if (dialog.isCanceled()) 55 return response; 56 response.setUsername(dialog.getUsername()); 57 response.setPassword(dialog.getPassword()); 58 if (dialog.isSaveCredentials()) { 68 if (response.isSaveCredentials()) { 59 69 store(requestorType, host, new PasswordAuthentication( 60 70 response.getUsername(), … … 66 76 */ 67 77 } else { 68 PasswordAuthentication pa = new PasswordAuthentication( dialog.getUsername(), dialog.getPassword());78 PasswordAuthentication pa = new PasswordAuthentication(response.getUsername(), response.getPassword()); 69 79 memoryCredentialsCache.put(requestorType, pa); 70 80 } -
trunk/src/org/openstreetmap/josm/io/auth/CredentialsAgentResponse.java
r5266 r5692 3 3 4 4 /** 5 * CredentialsAgentResponse represents the response from {@link CredentialsAgent#getCredentials(java.net.Authenticator.RequestorType, boolean)}.5 * CredentialsAgentResponse represents the response from {@link CredentialsAgent#getCredentials(java.net.Authenticator.RequestorType, String, boolean)}. 6 6 * 7 7 * The response consists of the username and the password the requested credentials consists of. 8 8 * In addition, it provides information whether authentication was canceled by the user, i.e. 9 9 * because he or she canceled a username/password dialog (see {@link #isCanceled()}. 10 * It also provides information whether authentication should be saved. 10 11 * 11 12 */ … … 14 15 private char[] password; 15 16 private boolean canceled; 17 private boolean saveCredentials; 18 /** 19 * Replies the user name 20 * @return The user name 21 */ 16 22 public String getUsername() { 17 23 return username; 18 24 } 25 /** 26 * Sets the user name 27 * @param username The user name 28 */ 19 29 public void setUsername(String username) { 20 30 this.username = username; 21 31 } 32 /** 33 * Replies the password 34 * @return The password in plain text 35 */ 22 36 public char[] getPassword() { 23 37 return password; 24 38 } 39 /** 40 * Sets the password 41 * @param password The password in plain text 42 */ 25 43 public void setPassword(char[] password) { 26 44 this.password = password; 27 45 } 46 /** 47 * Determines if authentication request has been canceled by user 48 * @return true if authentication request has been canceled by user, false otherwise 49 */ 28 50 public boolean isCanceled() { 29 51 return canceled; 30 52 } 53 /** 54 * Sets the cancelation status (authentication request canceled by user) 55 * @param canceled the cancelation status (authentication request canceled by user) 56 */ 31 57 public void setCanceled(boolean canceled) { 32 58 this.canceled = canceled; 33 59 } 60 /** 61 * Determines if authentication credentials should be saved 62 * @return true if authentication credentials should be saved, false otherwise 63 */ 64 public boolean isSaveCredentials() { 65 return saveCredentials; 66 } 67 /** 68 * Sets the saving status (authentication credentials to save) 69 * @param saveCredentials the saving status (authentication credentials to save) 70 */ 71 public void setSaveCredentials(boolean saveCredentials) { 72 this.saveCredentials = saveCredentials; 73 } 34 74 }
Note:
See TracChangeset
for help on using the changeset viewer.