Ticket #4182: josm.diff

File josm.diff, 8.5 KB (added by michiel@…, 14 years ago)

fix for authentication of proxies

  • src/org/openstreetmap/josm/io/OsmConnection.java

     
    7070         * Set to true, when the autenticator tried the password once.
    7171         */
    7272        public boolean passwordtried = false;
     73        /**
     74         * Set to requestor type
     75         */
     76        public String requestorType;
    7377        /**
    7478         * Whether the user cancelled the password dialog
    7579         */
    7680        public boolean authCancelled = false;
    7781        @Override protected PasswordAuthentication getPasswordAuthentication() {
     82            requestorType=getRequestorType().name();
    7883            return credentialsManager.getPasswordAuthentication(this);
    7984        }
    8085    }
     
    153158        }
    154159        public PasswordAuthentication getPasswordAuthentication(OsmAuth caller) {
    155160            String username, password;
    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            }
    207266            caller.passwordtried = true;
    208267            return new PasswordAuthentication(username, password.toCharArray());
    209268        }
  • src/org/openstreetmap/josm/data/Preferences.java

     
    733733        if (getBoolean(ProxyPreferences.PROXY_ENABLE)) {
    734734            sysProp.put("proxySet", "true");
    735735            sysProp.put("http.proxyHost", get(ProxyPreferences.PROXY_HOST));
    736             sysProp.put("proxyPort", get(ProxyPreferences.PROXY_PORT));
     736            sysProp.put("http.proxyPort", get(ProxyPreferences.PROXY_PORT));
    737737            if (!getBoolean(ProxyPreferences.PROXY_ANONYMOUS)) {
    738                 sysProp.put("proxyUser", get(ProxyPreferences.PROXY_USER));
    739                 sysProp.put("proxyPassword", get(ProxyPreferences.PROXY_PASS));
     738                sysProp.put("http.proxyUser", get(ProxyPreferences.PROXY_USER));
     739                sysProp.put("http.proxyPassword", get(ProxyPreferences.PROXY_PASS));
    740740            }
    741741
    742742        }