Ignore:
Timestamp:
2009-01-12T11:19:54+13:00 (15 years ago)
Author:
kjdon
Message:

updated the rtl-gli branch with files from trunk. Result of a merge 14807:18318

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gli/branches/rtl-gli/src/org/greenstone/gatherer/GAuthenticator.java

    r14567 r18363  
    4242import java.util.*;
    4343import javax.swing.*;
     44
     45
    4446import org.greenstone.gatherer.gui.GLIButton;
     47
    4548
    4649/** Provides a graphic authenticator for network password requests.
     
    6568    /** The default size of this dialog. */
    6669    static final private Dimension SIZE = new Dimension(470,160);
    67 
     70   
     71    /** For Wget downloads, we want to avoid the second automatic request for proxy authentication
     72     * But the settings for that specific case will otherwise interfere with how this GAuthenticator
     73     * is to function in the usual situation. For this reason, we use two modes.*/
     74    static final public int REGULAR = 0;
     75    static final public int DOWNLOAD = 1;
     76    static private int operationMode = REGULAR;
     77
     78    public static void setMode(int mode) {
     79    operationMode = mode;
     80    }
     81   
    6882    /** Constructor. */
    6983    public GAuthenticator() {
     
    7589     * @see org.greenstone.gatherer.GAuthenticator.RequestFocusListener
    7690     */
    77     protected PasswordAuthentication getPasswordAuthentication() {
     91    protected PasswordAuthentication getPasswordAuthentication(String username_str, String password_str) {
     92    if(operationMode == DOWNLOAD) { // special handling of proxy authentication popup for Wget downloads
     93       
     94        // Don't prompt if the details were already saved for the same host and port. This is necessary
     95        // when running wget because wget requires proxy authentication. And without the following, the
     96        // regular proxy authentication would also popup a dialog requesting the same information.
     97       
     98        String key = getRequestingHost() + ":" + getRequestingPort();
     99        String value = (String)authentications.get(key);
     100       
     101        if(value != null) { // authentication for this host and port was already stored
     102        // Arguments may be null. If so, retrieve them from the stored value
     103        if(username_str == null) {
     104            username_str = value.substring(0, value.indexOf("@"));
     105        }
     106        if(password_str == null) {
     107            password_str = value.substring(value.indexOf("@") + 1);
     108        }
     109        operationMode = REGULAR; // reset the state of the Authenticator to normal mode
     110        return new PasswordAuthentication(username_str, password_str.toCharArray());
     111        }
     112    }
     113   
    78114    // Component definition.
    79115    dialog = new JDialog (Gatherer.g_man, Dictionary.get("GAuthenticator.Title"), true);
     
    82118    JPanel content_pane = (JPanel) dialog.getContentPane();
    83119    JLabel title_label = new JLabel(getMessageString());
     120
    84121    JPanel user_panel = new JPanel();
    85122    JLabel username_label = new JLabel(Dictionary.get("GAuthenticator.Username"));
    86123    JTextField username = new JTextField();
    87124    username.setToolTipText(Dictionary.get("GAuthenticator.Username_Tooltip"));
     125    if (username_str != null) {
     126        username.setText(username_str);
     127    }
     128
    88129    JPanel password_panel = new JPanel();
    89130    JLabel password_label = new JLabel(Dictionary.get("GAuthenticator.Password"));
     
    91132    password.setEchoChar('*');
    92133    password.setToolTipText(Dictionary.get("GAuthenticator.Password_Tooltip"));
     134    if (password_str != null) {
     135        password.setText(password_str);
     136    }
     137
    93138    JPanel button_panel = new JPanel();
    94139    ok_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip"));
     
    134179    }
    135180
     181    protected PasswordAuthentication getPasswordAuthentication() {
     182    return getPasswordAuthentication(null,null);
     183    }
    136184
    137185    /** This is defined so it can be overridden by subclasses (getRequestingPrompt is final). */
Note: See TracChangeset for help on using the changeset viewer.