Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4386414

No call of java.net.Authenticator.getPasswordAuthentication() with Plug-In 1.3C

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.3.0
    • deploy
    • x86
    • windows_nt



      Name: yyT116575 Date: 11/06/2000


      Java(TM) Plug-In: Version 1.3.0-C
      Verwendung der JRE-Version 1.3.0 Java HotSpot(TM) Client VM


      I'm developing an Applet, which reads web pages with HttpURLConnection(). For
      authentication I've overwritten the method 'protected PasswordAuthentication
      getPasswordAuthentication()' of a subclass of java.net.Authenticator and
      registered a new instance by calling MyAuthenticator.setDefault(new
      MyAuthenticator()).

      When Plug-In 1.2.2 is installed (not depending of JRE 1.2.2 or 1.3),
      everytime the servers response is a 401, my own MyAuthenticator.
      getPasswordAuthentication()-Method is called.

      After changing to J2SE1.3 with Plug-In 1.3 my own method is not called any
      more (not depending of JRE 1.2.2 or 1.3)!!!

      I've made some print-outs in the class java.net.Authenticator of the rt.jar
      and it seems, the the method java.net.Authenticator.setDefault() is called
      automatically before the applet starts. So it is not possible to register an
      instance of my own Authenticator.

      I've made a copy of the java console in four different cases. The two with
      Plug-in 1.2.2 is working fine, the two with Plug-In 1.3 does not!

      Here it is:

      Successful Connections:
      -----------------------

      Java(TM) Plug-in: Version 1.2.2.p001
      Using JRE version 1.2.2
        User home directory = C:\WINNT\Profiles\fbreuer
        User has overriden browser's proxy settings.
      Proxy Configuration: Manual Configuration
           Proxy:
           Proxy Overrides:

      JAR cache disabled.
      <<<<< Applet starting >>>>>
      <<<FB<< URLConnect.URLConnect() >>>>>
      <<<FB>>> MyAuthenticator.MyAuthenticator() new instance created!
      <<<1.2.2>>> java.net.Authenticator.setDefault()
      <<<1.2.2>>> java.net.Authenticator.setDefault() New Authenticator registered!
      <<<FB<< URLConnect.fetchURL(String) >>>>>
      <<<1.2.2>>> java.net.HttpURLConnection()
      Opening http://pirobase.pironet.com/servlet/PB/menu/1046875/index.html no proxy
      Opening
      http://pirobase.pironet.com/servlet/PB/-s/1gsivqj1qwq2rt14yq4g2nqb7r91uorn4l/men
      u/1046875/index.html no proxy
      <<<1.2.2>>> java.net.Authenticator.requestPasswordAuthentication()
      <<<1.2.2>>> java.net.Authenticator.reset()
      <<<FB>>> MyAuthenticator.getPasswordAuthentication()
      <<<FB>>> MyAuthenticator.createLoginDialog()
      Opening
      http://pirobase.pironet.com/servlet/PB/-s/1gsivqj1qwq2rt14yq4g2nqb7r91uorn4l/men
      u/1046875/index.html no proxy
      <Info> Response: 200

      ---------------

      Java(TM) Plug-In: Version 1.2.2.p001
      Verwendung der JRE-Version 1.3.0
      Home-Verzeichnis des Benutzers = C:\WINNT\Profiles\fbreuer
      Proxy-Einstellungen des Browsers wurden vom Benutzer ?berschrieben.
      Proxy-Konfiguration:Manuelle Konfiguration
           Proxy:
           Proxy-?berschreibungen:

      JAR cache disabled.
      <<<<< Applet starting >>>>>
      <<<FB<< URLConnect.URLConnect() >>>>>
      <<<FB>>> MyAuthenticator.MyAuthenticator() new instance created!
      <<<1.3.0>>> java.net.Authenticator.setDefault()
      <<<1.3.0>>> java.net.Authenticator.setDefault() New Authenticator registered!
      <<<FB<< URLConnect.fetchURL(String) >>>>>
      <<<1.3.0>>> java.net.HttpURLConnection()
      Wird ge?ffnethttp://pirobase.pironet.com/servlet/PB/menu/1046875/index.html Kein
      Proxy
      Wird
      ge?ffnethttp://pirobase.pironet.com/servlet/PB/-s/1rkktab6d8rda1a18bvh1qazoag14b
      ystc/menu/1046875/index.html Kein Proxy
      <<<1.3.0>>> java.net.Authenticator.requestPasswordAuthentication()
      <<<1.3.0>>> java.net.Authenticator.reset()
      <<<FB>>> MyAuthenticator.getPasswordAuthentication()
      <<<FB>>> MyAuthenticator.createLoginDialog()
      Wird
      ge?ffnethttp://pirobase.pironet.com/servlet/PB/-s/1rkktab6d8rda1a18bvh1qazoag14b
      ystc/menu/1046875/index.html Kein Proxy
      <Info> Response: 200



      Unsuccessful Connections:
      -------------------------

      Java(TM) Plug-In: Version 1.3.0-C
      Verwendung der JRE-Version 1.2.2 Classic VM
      Home-Verzeichnis des Benutzers = C:\WINNT\Profiles\fbreuer
      Proxy-Einstellungen des Browsers wurden vom Benutzer ?berschrieben.
      Proxy-Konfiguration:Kein Proxy

      <<<1.2.2>>> java.net.Authenticator.setDefault()
      <<<1.2.2>>> java.net.Authenticator.setDefault() New Authenticator registered!
      JAR cache disabled.
      <<<<< Applet starting >>>>>
      <<<FB<< URLConnect.URLConnect() >>>>>
      <<<1.2.2>>> java.net.Authenticator.setDefault()
      <<<1.2.2>>> java.net.Authenticator.setDefault() Old Authenticator used!
      <<<FB<< URLConnect.fetchURL(String) >>>>>
      <<<1.2.2>>> java.net.HttpURLConnection()
      <<<1.2.2>>> java.net.Authenticator.requestPasswordAuthentication()
      <<<1.2.2>>> java.net.Authenticator.reset()
      <Info> Response: 200

      ---------------

      Java(TM) Plug-In: Version 1.3.0-C
      Verwendung der JRE-Version 1.3.0 Java HotSpot(TM) Client VM
      Home-Verzeichnis des Benutzers = C:\WINNT\Profiles\fbreuer
      Proxy-Einstellungen des Browsers wurden vom Benutzer ?berschrieben.
      Proxy-Konfiguration:Kein Proxy

      <<<1.3.0>>> java.net.Authenticator.setDefault()
      <<<1.3.0>>> java.net.Authenticator.setDefault() New Authenticator registered!
      JAR cache disabled.
      <<<<< Applet starting >>>>>
      <<<FB<< URLConnect.URLConnect() >>>>>
      <<<1.3.0>>> java.net.Authenticator.setDefault()
      <<<1.3.0>>> java.net.Authenticator.setDefault() Old Authenticator used!
      <<<FB<< URLConnect.fetchURL(String) >>>>>
      <<<1.3.0>>> java.net.HttpURLConnection()
      <<<1.3.0>>> java.net.Authenticator.requestPasswordAuthentication()
      <<<1.3.0>>> java.net.Authenticator.reset()
      <Info> Response: 200




      1. SOURCE CODE

      /**
       * ServerAuth.java
       *
       *
       * @author: Frank Breuer
       *
       * @version: 0.1
       *
       * Applet to make a brief connection to a web server to verify the
       * behaviour of registering the standard authenticator in J2SE1.3.
       *
       * history: 2000/09/22 created
       */


      import java.io.*;
      import java.net.*;
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;



      public class ServerAuth extends JApplet {
          public void init() {
              System.out.println("<<<<< Applet starting >>>>>");
              Container contentPane = getContentPane();
              contentPane.add(new URLConnect());
          }
      }


      class URLConnect extends JPanel {

          private MyAuthenticator myAuth = null;

      private JTextField tf = new JTextField();
      private JTextArea ta = new JTextArea();

      public URLConnect() {

      System.out.println("<<<FB<< URLConnect.URLConnect() >>>>>");

      // Install Authenticator
              myAuth = new MyAuthenticator();
      MyAuthenticator.setDefault(myAuth);

      // Setup screen
              setLayout(new BorderLayout());
      add(tf, BorderLayout.NORTH);
              tf.setBorder(BorderFactory.createTitledBorder(
                      BorderFactory.createEtchedBorder(), "URL"));
      ta.setEditable(false);
      add(ta, BorderLayout.CENTER);
      tf.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      String s = tf.getText();
      if (s.length() != 0)
      ta.setText(fetchURL(s));
      }
      });
              ta.setBorder(BorderFactory.createTitledBorder(
                      BorderFactory.createEtchedBorder(), "Responsecode"));

              setBorder(BorderFactory.createTitledBorder(
                      BorderFactory.createEtchedBorder(), "URLConnect"));
      }

      private String fetchURL(String urlString) {
      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);

      try {
      System.out.println("<<<FB<< URLConnect.fetchURL(String)>>>>>");

      URL url = new URL(urlString);
                  HttpURLConnection conn = (HttpURLConnection)url.openConnection();
      conn.setRequestMethod("GET");
      conn.setDoInput(true);
      conn.setFollowRedirects(true);
      conn.setAllowUserInteraction(false);
      conn.setUseCaches(false);
      conn.connect();
                  System.out.println("<Info> Response: " + conn.getResponseCode());
                  pw.println(conn.getResponseMessage());

      } catch(MalformedURLException e) {
      pw.println("Invalid URL");
      } catch(IOException e) {
      pw.println("Error reading URL");
      }
      return sw.toString();
      }
      }




      class MyAuthenticator extends Authenticator {

      private static String hostapplet;

      private static MyAuthenticator authenticator;
      private static PasswordAuthentication localAuth;

      private MyLoginDialog dialog;



          public MyAuthenticator() {
              System.out.println("<<<FB>>> MyAuthenticator.MyAuthenticator() " +
                      "new instance created!");
          }


      protected PasswordAuthentication getPasswordAuthentication() {

              System.out.println("<<<FB>>> MyAuthenticator." +
                      "getPasswordAuthentication()");
          MyAuthenticator.localAuth = createLoginDialog();
      return MyAuthenticator.localAuth;
      }


      private PasswordAuthentication createLoginDialog() {

              System.out.println("<<<FB>>> MyAuthenticator.createLoginDialog()");
              if (dialog == null)
                  dialog = new MyLoginDialog();
      dialog.show();
      return dialog.getAuth();
      }
      }




      class MyLoginDialog extends JDialog
      {
      private JPanel north, south;
      private JLabel nameLabel, passwordLabel, infoLabel;
      private JTextField nameTextField;
      private JPasswordField passwordField;
      private JButton loginButton, cancelButton;
      private String username;
      private char password[];
      private PasswordAuthentication privateAuth;



          public MyLoginDialog()
      {
      //
      // sets the title of the dialog field.
      //
      setModal(true);
      setTitle("Login");
      setSize(277, 215);

      //
      //
      // fill northern components
      //
      //

      north = new JPanel();
      north.setLayout(null);
      north.setPreferredSize(new Dimension(277, 165));



      //
      // creating labels
      //

              // Username
      nameLabel = new JLabel("Username:", JLabel.LEFT);
      nameLabel.setBounds(10, 60, 90, 20);
      north.add(nameLabel);

              // Password
      passwordLabel = new JLabel("Password:", JLabel.LEFT);
      passwordLabel.setBounds(10, 90, 90, 20);
      north.add(passwordLabel);



      //
      // creating textfields
      //
      nameTextField = new JTextField();
      nameTextField.setBounds(100, 60, 157, 20);
      north.add(nameTextField);

      passwordField = new JPasswordField();
      passwordField.setBounds(100, 90, 157, 20);
      north.add(passwordField);

      getContentPane().add(north,BorderLayout.CENTER);



      //
      //
      // fill southern components
      //
      //

      //
      // create JPanel for buttons
      //
      south = new JPanel();
      south.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 10));

      //
      // create buttons
      //

      // login
      loginButton = new JButton("Login");
              loginButton.addActionListener(new ActionListener()
                  {
                      public void actionPerformed(ActionEvent ae)
                      {
      char[] authArray;

      username = nameTextField.getText();
      nameTextField.setText("");
      password = passwordField.getPassword();
      passwordField.setText("");

      privateAuth = new PasswordAuthentication(username, password);

                          // Delete attributes for userID and password
                          username = "";
                          password = new String("").toCharArray();

                          nameTextField.requestFocus();
                          hide();
                      }
                  });
      south.add(loginButton);



      // cancel
      cancelButton = new JButton("Cancel");
              cancelButton.addActionListener(new ActionListener()
                  {
                      public void actionPerformed(ActionEvent ae)
                      {
      privateAuth = null;
        hide();
                     }
                  });
      south.add(cancelButton);


              getContentPane().add(south, BorderLayout.SOUTH);

      setDefaultCloseOperation(HIDE_ON_CLOSE);
      }


      /**
      * Returns the actual PasswordAuthentication,
      * which was generated from the login dialog.
      *
      * @return PasswordAuthentication - actual PasswordAuthentication.
      */
      public PasswordAuthentication getAuth()
      {
      return privateAuth;
      }
      }
      (Review ID: 109922)
      ======================================================================

            stanleyh Stanley Ho (Inactive)
            yyoungsunw Yung-ching Young (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: