Changeset 99 in josm for src/org/openstreetmap/josm/io/OsmConnection.java
- Timestamp:
- 2006-04-27T01:29:55+02:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/io/OsmConnection.java
r98 r99 8 8 9 9 import javax.swing.BoundedRangeModel; 10 import javax.swing.JCheckBox; 10 11 import javax.swing.JLabel; 11 12 import javax.swing.JOptionPane; … … 29 30 protected JLabel currentAction; 30 31 protected BoundedRangeModel progress; 31 32 32 33 private static OsmAuth authentication; 33 34 /** … … 38 39 Authenticator.setDefault(authentication = new OsmAuth()); 39 40 } 40 41 41 42 /** 42 * The authentication class handling the login requests. 43 */ 44 private static class OsmAuth extends Authenticator { 45 /** 46 * Set to true, when the autenticator tried the password once. 47 */ 48 boolean passwordtried = false; 49 /** 50 * Whether the user cancelled the password dialog 51 */ 52 boolean authCancelled = false; 53 54 @Override protected PasswordAuthentication getPasswordAuthentication() { 55 String username = Main.pref.get("osm-server.username"); 56 String password = Main.pref.get("osm-server.password"); 57 if (passwordtried || username.equals("") || password.equals("")) { 58 JPanel p = new JPanel(new GridBagLayout()); 59 p.add(new JLabel("Username"), GBC.std().insets(0,0,10,0)); 60 JTextField usernameField = new JTextField(username, 20); 61 p.add(usernameField, GBC.eol()); 62 p.add(new JLabel("Password"), GBC.std().insets(0,0,10,0)); 63 JPasswordField passwordField = new JPasswordField(password, 20); 64 p.add(passwordField, GBC.eol()); 65 JLabel warning = new JLabel("Warning: The password is transferred unencrypted."); 66 warning.setFont(warning.getFont().deriveFont(Font.ITALIC)); 67 p.add(warning, GBC.eol()); 68 int choice = JOptionPane.showConfirmDialog(Main.parent, p, "Enter Password", JOptionPane.OK_CANCEL_OPTION); 69 if (choice == JOptionPane.CANCEL_OPTION) { 70 authCancelled = true; 71 return null; 72 } 73 username = usernameField.getText(); 74 password = String.valueOf(passwordField.getPassword()); 75 if (username.equals("")) 76 return null; 77 } 78 passwordtried = true; 79 return new PasswordAuthentication(username, password.toCharArray()); 80 } 81 } 43 * The authentication class handling the login requests. 44 */ 45 private static class OsmAuth extends Authenticator { 46 /** 47 * Set to true, when the autenticator tried the password once. 48 */ 49 boolean passwordtried = false; 50 /** 51 * Whether the user cancelled the password dialog 52 */ 53 boolean authCancelled = false; 54 55 @Override protected PasswordAuthentication getPasswordAuthentication() { 56 String username = Main.pref.get("osm-server.username"); 57 String password = Main.pref.get("osm-server.password"); 58 if (passwordtried || username.equals("") || password.equals("")) { 59 JPanel p = new JPanel(new GridBagLayout()); 60 if (!username.equals("") && !password.equals("")) 61 p.add(new JLabel("Incorrect password or username."), GBC.eop()); 62 p.add(new JLabel("Username"), GBC.std().insets(0,0,10,0)); 63 JTextField usernameField = new JTextField(username, 20); 64 p.add(usernameField, GBC.eol()); 65 p.add(new JLabel("Password"), GBC.std().insets(0,0,10,0)); 66 JPasswordField passwordField = new JPasswordField(password, 20); 67 p.add(passwordField, GBC.eol()); 68 JLabel warning = new JLabel("Warning: The password is transferred unencrypted."); 69 warning.setFont(warning.getFont().deriveFont(Font.ITALIC)); 70 p.add(warning, GBC.eop()); 71 72 JCheckBox savePassword = new JCheckBox("Save user and password (unencrypted)", !username.equals("") && !password.equals("")); 73 p.add(savePassword, GBC.eop()); 74 75 int choice = JOptionPane.showConfirmDialog(Main.parent, p, "Enter Password", JOptionPane.OK_CANCEL_OPTION); 76 if (choice == JOptionPane.CANCEL_OPTION) { 77 authCancelled = true; 78 return null; 79 } 80 username = usernameField.getText(); 81 password = String.valueOf(passwordField.getPassword()); 82 if (savePassword.isSelected()) { 83 Main.pref.put("osm-server.username", username); 84 Main.pref.put("osm-server.password", password); 85 } 86 if (username.equals("")) 87 return null; 88 } 89 passwordtried = true; 90 return new PasswordAuthentication(username, password.toCharArray()); 91 } 92 } 82 93 83 94 /** … … 88 99 authentication.passwordtried = false; 89 100 } 90 101 91 102 /** 92 103 * @return Whether the connection was cancelled. … … 99 110 this.currentAction = currentAction; 100 111 this.progress = progress; 101 112 } 102 113 103 114 public void cancel() { 104 115 currentAction.setText("Aborting..."); 105 106 107 108 109 110 111 116 cancel = true; 117 if (activeConnection != null) { 118 activeConnection.setConnectTimeout(1); 119 activeConnection.setReadTimeout(1); 120 activeConnection.disconnect(); 121 } 122 } 112 123 }
Note:
See TracChangeset
for help on using the changeset viewer.