Applet displays login dialog if basic authentication used

≡放荡痞女 提交于 2019-12-10 17:33:40

问题


I have a Java applet inserted on a webpage:

applet = '<embed'
    + ' type="application/x-java-applet;version=1.6"'
    + ' pluginspage = "http://www.java.com/en/download/"'
    + ' width="0" height="0"'
    + ' style="position: absolute"'
    + ' archive="/plugins/MyApplet.jar"'
    + ' code="MyTestApplet.class"'
    + '>'

appletContainer.innerHTML = applet;

The server is using Basic authentication. When Chrome or Safari (or better say JVM) requests the MyApplet.jar file the 'Authentication Required' dialog is displayed, that is very annoying.

I have found that Chrome/Safari (or JVM) does not attach the 'Authentication: Basic' header to GET request automatically for some reason.

Any idea how to force the Authentication: Basic header to be attached when requesting .jar file to avoid this extra login dialog?


回答1:


Actually, I think the problem might be that your applet is trying to open a connection back to the server, the server is protected by basic authentication. If so, you'd need to do something like this in your applet:

  // http://www.coderanch.com/how-to/java/AppletsFaq#authentication
  String authorization = Base64Coder.encode(username + ":" + password);
  connection.setRequestProperty("Authorization", "Basic " + authorization);

Otherwise, just move your .jar file to a directory on the server that allows anonymous read access.




回答2:


As I can see it, it is not an applet authentification as it is but a host/domain one just because the JVM (watch Oracle lable) itself is asking for login; perhaps it means that your html is trying to get the jar from a forbidden location or the path is being misstaking as an absolute one; but if it is an absolute one like the /plugins/MyApplet.jar so where is the domain root then? I am not pretty sure but have you tried to put down path like "archive="../plugins/MyApplet.jar" with double dots in its prefix?

And I just wondering is the "/plugins" folder a web one? If it is the problem may be much deeper than Java itself. It may be the domain inner web folders access policy (like a no sub folders access) or something which should be controlled by sys admin.

As a way about, try to put your jar into the same folder as its html file is. Maybe the domain security policy allows your client computer use the only one web folder only



来源:https://stackoverflow.com/questions/7395413/applet-displays-login-dialog-if-basic-authentication-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!