Forum Stats

  • 3,814,696 Users
  • 2,258,899 Discussions
  • 7,892,808 Comments

Discussions

How can I pass the userId and pasword to proxy while opening the URLConnect

843811
843811 Member Posts: 49,851
First I was having problem on how can I send a userid and password for proxy authentication while trying to connect to a servlet from a applet, finally I figured out that I need to add Authenticator as
Authenticator.setDefault(new MyAuthenticator());
and everything started working fine but only from a java application not from a applet. In applet when I try to add a Authenticator I get exception that cannot add defualt Authenticator. Please someone help how can I add Authenticator in a applet? I dont think for adding a defualt autheticator I need to get my applet signed. Please comment.
Thanks,
Mandeep

Comments

  • 843811
    843811 Member Posts: 49,851
    Hi Mandeep,

    You can set up a policytool entry for
    java.net.NetPermission on the target setDefaultAuthenticator.

    Authenticator.setDefault will generate a NetPermission
    error if you do not do this:
    java.security.AccessControlException: access denied
    (java.net.NetPermission setDefaultAuthenticator)

    I have done this and I get past the problem above.
    However I still get prompted for a login dialog by the
    applet even though I have overridden the
    getPasswordAuthentication method. Any ideas on
    this ????


    Paul
  • 843811
    843811 Member Posts: 49,851
    Can u tell me please how can I add
    java.net.NetPermission on the target setDefaultAuthenticator.
    And by the way for sending the password I tried the following code which doesn't use Authenticator and it worked. U can use it what Iam doin is iam using my own base64encoder instead of jdk's which was giving problems to me. U can try with jdk base64encoder and if u get any problems let me know I'll send u my version of the encoder.
    If u r using any images in ur applet and getting the images by using getImage() method then probably while getting the image applet is prompting for user and password.
    URLConnection con = url.openConnection();
    String authString = "userid:passsword";
    String auth = "Basic " + new sun.misc.BASE64Encoder().encode(authString.getBytes());
    //String auth = "Basic " + new MyBase64Converter().encode(authString.getBytes());
    con.setRequestProperty("Proxy-Authorization", auth);
  • 843811
    843811 Member Posts: 49,851
    Hi,
    ?Can u tell me please how can I add
    java.net.NetPermission on the target >setDefaultAuthenticator.
    This is done on the client machine. Launch policytool
    from the command line.

    There should be an entry "Codebase : <ALL>".
    Select and edit this entry.
    Click "Add Permission". A permissions window will pop up to allow addition of entry.
    Select "NetPermission" from the 1st dropdown.
    Select "setDefaultAuthenticator" from the 2nd dropdown.
    Click "OK". That's it.

    This has to be done on each client machine accessing the applet.

    I'll get back to you if I have any problems with the authentication problem I'm having.

    Bye,
    Paul
This discussion has been closed.