开发者

Bypassing built-in browser authentication when making HTTP calls from embedded Applet

开发者 https://www.devze.com 2022-12-22 03:55 出处:网络
I have a simple web page with an embedded Java applet. The applet makes HTTP calls to different A开发者_高级运维xis
  • I have a simple web page with an embedded Java applet.
  • The applet makes HTTP calls to different A开发者_高级运维xis Cameras who all share the same authentication (e.g. username, password).
  • I am passing the user name and password to the Java code upon launch of the applet - no problem.
  • When I run from within NetBeans with the applet viewer, I get full access to the cameras and see streaming video - exactly as advertised.
  • The problem begins when I open the HTML page in a web browser (Firefox).
  • Even though my code handles authentication:

    URL u = new URL(useMJPGStream ? mjpgURL : jpgURL);
    huc = (HttpURLConnection) u.openConnection();
    
    
    String base64authorization = 
        securityMan.getAlias(this.securityAlias).getBase64authorization();
    // if authorization is required set up the connection with the encoded 
    // authorization-information
    if(base64authorization != null)
    {
        huc.setDoInput(true);
        huc.setRequestProperty("Authorization",base64authorization);
        huc.connect();
    }
    
    InputStream is = huc.getInputStream();
    connected = true;
    BufferedInputStream bis = new BufferedInputStream(is);
    dis= new DataInputStream(bis);
    
  • The browser still brings up an authentication pop-up and requests the username and password for each camera separately!
  • To make things worse, the images displayed from the camera are frozen and old (from last night).
  • How can I bypass the browser's authentication?


Fixed

I added the following lines:

huc.setDoOuput(true);
huc.setUseCaches(false);

after the

huc.setDoInput(true);

line.


When running in the browser base64authorization not null, correct?

I'm not really sure what getBase64authorization is supposed to return, but I'm fairly certain when you call huc.setRequestProperty("Authorization", **autorization value**) it's looking for a HTTP Basic authentication value. Meaning **authorization value** needs to be in the format Basic **base 64 encoding of username:password** as described here.

Maybe you just need to add the Basic (note the trailing space) string to your property.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号