| 156 | | try { |
| 157 | | username = lookup(Key.USERNAME); |
| 158 | | } catch (CMException e) { |
| 159 | | username = ""; |
| 160 | | } |
| 161 | | try { |
| 162 | | password = lookup(Key.PASSWORD); |
| 163 | | } catch (CMException e) { |
| 164 | | password = ""; |
| 165 | | } |
| 166 | | if (caller.passwordtried || username.equals("") || password.equals("")) { |
| 167 | | JPanel p = new JPanel(new GridBagLayout()); |
| 168 | | if (!username.equals("") && !password.equals("")) { |
| 169 | | p.add(new JLabel(tr("Incorrect password or username.")), GBC.eop()); |
| 170 | | } |
| 171 | | p.add(new JLabel(tr("Username")), GBC.std().insets(0,0,10,0)); |
| 172 | | JTextField usernameField = new JTextField(username, 20); |
| 173 | | p.add(usernameField, GBC.eol()); |
| 174 | | p.add(new JLabel(tr("Password")), GBC.std().insets(0,0,10,0)); |
| 175 | | JPasswordField passwordField = new JPasswordField(password, 20); |
| 176 | | p.add(passwordField, GBC.eol()); |
| 177 | | JLabel warning = new JLabel(tr("Warning: The password is transferred unencrypted.")); |
| 178 | | warning.setFont(warning.getFont().deriveFont(Font.ITALIC)); |
| 179 | | p.add(warning, GBC.eop()); |
| 180 | | |
| 181 | | JCheckBox savePassword = new JCheckBox(tr("Save user and password (unencrypted)"), |
| 182 | | !username.equals("") && !password.equals("")); |
| 183 | | p.add(savePassword, GBC.eop()); |
| 184 | | |
| 185 | | ExtendedDialog dialog = new ExtendedDialog( |
| 186 | | Main.parent, |
| 187 | | tr("Enter Password"), |
| 188 | | new String[] {tr("Login"), tr("Cancel")} |
| 189 | | ); |
| 190 | | dialog.setContent(p); |
| 191 | | dialog.setButtonIcons( new String[] {"ok.png", "cancel.png"}); |
| 192 | | dialog.showDialog(); |
| 193 | | |
| 194 | | if (dialog.getValue() != 1) { |
| 195 | | caller.authCancelled = true; |
| 196 | | return null; |
| 197 | | } |
| 198 | | username = usernameField.getText(); |
| 199 | | password = String.valueOf(passwordField.getPassword()); |
| 200 | | if (savePassword.isSelected()) { |
| 201 | | store(Key.USERNAME, username); |
| 202 | | store(Key.PASSWORD, password); |
| 203 | | } |
| 204 | | if (username.equals("")) |
| 205 | | return null; |
| 206 | | } |
| | 161 | if (caller.requestorType.equals("PROXY")) { |
| | 162 | try { |
| | 163 | username = System.getProperties().getProperty("http.proxyUser"); |
| | 164 | } catch (Exception e) { |
| | 165 | username = ""; |
| | 166 | } |
| | 167 | try { |
| | 168 | password = System.getProperties().getProperty("http.proxyPassword"); |
| | 169 | } catch (Exception e) { |
| | 170 | password = ""; |
| | 171 | } |
| | 172 | if (caller.passwordtried || username.equals("") || password.equals("")) { |
| | 173 | JPanel p = new JPanel(new GridBagLayout()); |
| | 174 | if (!username.equals("") && !password.equals("")) { |
| | 175 | p.add(new JLabel(tr("Incorrect password or username for proxy.")), GBC.eop()); |
| | 176 | } |
| | 177 | p.add(new JLabel(tr("Username")), GBC.std().insets(0,0,10,0)); |
| | 178 | JTextField usernameField = new JTextField(username, 20); |
| | 179 | p.add(usernameField, GBC.eol()); |
| | 180 | p.add(new JLabel(tr("Password")), GBC.std().insets(0,0,10,0)); |
| | 181 | JPasswordField passwordField = new JPasswordField(password, 20); |
| | 182 | p.add(passwordField, GBC.eol()); |
| | 183 | JLabel warning = new JLabel(tr("Warning: The password is transferred unencrypted.")); |
| | 184 | warning.setFont(warning.getFont().deriveFont(Font.ITALIC)); |
| | 185 | p.add(warning, GBC.eop()); |
| | 186 | |
| | 187 | JCheckBox savePassword = new JCheckBox(tr("Save user and password (unencrypted)"), |
| | 188 | !username.equals("") && !password.equals("")); |
| | 189 | p.add(savePassword, GBC.eop()); |
| | 190 | |
| | 191 | ExtendedDialog dialog = new ExtendedDialog( |
| | 192 | Main.parent, |
| | 193 | tr("Enter Password"), |
| | 194 | new String[] {tr("Login"), tr("Cancel")} |
| | 195 | ); |
| | 196 | dialog.setContent(p); |
| | 197 | dialog.setButtonIcons( new String[] {"ok.png", "cancel.png"}); |
| | 198 | dialog.showDialog(); |
| | 199 | |
| | 200 | if (dialog.getValue() != 1) { |
| | 201 | caller.authCancelled = true; |
| | 202 | return null; |
| | 203 | } |
| | 204 | username = usernameField.getText(); |
| | 205 | password = String.valueOf(passwordField.getPassword()); |
| | 206 | if (savePassword.isSelected()) { |
| | 207 | System.getProperties().setProperty("http.proxyUser", username); |
| | 208 | System.getProperties().setProperty("http.proxyPassword", password); |
| | 209 | } |
| | 210 | if (username.equals("")) |
| | 211 | return null; |
| | 212 | } |
| | 213 | } else { |
| | 214 | try { |
| | 215 | username = lookup(Key.USERNAME); |
| | 216 | } catch (CMException e) { |
| | 217 | username = ""; |
| | 218 | } |
| | 219 | try { |
| | 220 | password = lookup(Key.PASSWORD); |
| | 221 | } catch (CMException e) { |
| | 222 | password = ""; |
| | 223 | } |
| | 224 | if (caller.passwordtried || username.equals("") || password.equals("")) { |
| | 225 | JPanel p = new JPanel(new GridBagLayout()); |
| | 226 | if (!username.equals("") && !password.equals("")) { |
| | 227 | p.add(new JLabel(tr("Incorrect password or username for OSM server.")), GBC.eop()); |
| | 228 | } |
| | 229 | p.add(new JLabel(tr("Username")), GBC.std().insets(0,0,10,0)); |
| | 230 | JTextField usernameField = new JTextField(username, 20); |
| | 231 | p.add(usernameField, GBC.eol()); |
| | 232 | p.add(new JLabel(tr("Password")), GBC.std().insets(0,0,10,0)); |
| | 233 | JPasswordField passwordField = new JPasswordField(password, 20); |
| | 234 | p.add(passwordField, GBC.eol()); |
| | 235 | JLabel warning = new JLabel(tr("Warning: The password is transferred unencrypted.")); |
| | 236 | warning.setFont(warning.getFont().deriveFont(Font.ITALIC)); |
| | 237 | p.add(warning, GBC.eop()); |
| | 238 | |
| | 239 | JCheckBox savePassword = new JCheckBox(tr("Save user and password (unencrypted)"), |
| | 240 | !username.equals("") && !password.equals("")); |
| | 241 | p.add(savePassword, GBC.eop()); |
| | 242 | |
| | 243 | ExtendedDialog dialog = new ExtendedDialog( |
| | 244 | Main.parent, |
| | 245 | tr("Enter Password"), |
| | 246 | new String[] {tr("Login"), tr("Cancel")} |
| | 247 | ); |
| | 248 | dialog.setContent(p); |
| | 249 | dialog.setButtonIcons( new String[] {"ok.png", "cancel.png"}); |
| | 250 | dialog.showDialog(); |
| | 251 | |
| | 252 | if (dialog.getValue() != 1) { |
| | 253 | caller.authCancelled = true; |
| | 254 | return null; |
| | 255 | } |
| | 256 | username = usernameField.getText(); |
| | 257 | password = String.valueOf(passwordField.getPassword()); |
| | 258 | if (savePassword.isSelected()) { |
| | 259 | store(Key.USERNAME, username); |
| | 260 | store(Key.PASSWORD, password); |
| | 261 | } |
| | 262 | if (username.equals("")) |
| | 263 | return null; |
| | 264 | } |
| | 265 | } |