[英]JAVA Applet Loading Issue
我们已经在JAVA中开发了一个applet,主要用于从密钥库访问数字证书。
小程序在大多数情况下都可以正常工作,但是在某些安全的银行网络中,小程序的行为变得不可预测。
我们正在HTML中使用applet标记来访问applet。
我的第一个问题是我们是否需要为此使用JNLP进行部署?
其次,我过去编写了一个测试应用程序,当时我只是简单地调用一种applet方法,该方法就是加载所有证书的公共详细信息并将其打印在控制台上。 它曾经可以正常工作。
以下是相同的代码。
小程序方法
public void init() {
printMessageToConsole("Applet Initialized Version : " + appletVersion);
browserName = "Internet Explorer";
try {
String osName = System.getProperty("os.name");
printMessageToConsole("Operating system name =>" + osName);
} catch (Exception e) {
printMessageToConsole("Error in Get OS Init.");
e.printStackTrace();
}
}
public List<String> getCertificateAllDetails() throws NoSuchFieldException,
SecurityException, IllegalArgumentException,
IllegalAccessException, NoSuchMethodException,
InvocationTargetException {
printMessageToConsole("Get All Certificate Details");
String certString = "";
int count =0;
String pubKey = "";
KeyStore browserKeyStore = null;
String certDetails = "";
browserKeyStore = initializeBrowserKeyStore();
List<String> resultValues = new ArrayList<String>();
String aliasnew = null;
printMessageToConsole(browserName);
if (browserKeyStore != null) {
printMessageToConsole("INSIDE IE CERTIFICATE READING");
Field spiField = KeyStore.class.getDeclaredField("keyStoreSpi");
spiField.setAccessible(true);
KeyStoreSpi spi = (KeyStoreSpi) spiField.get(browserKeyStore);
Field entriesField = spi.getClass().getSuperclass().getDeclaredField("entries");
entriesField.setAccessible(true);
@SuppressWarnings("rawtypes")
Collection entries = (Collection) entriesField.get(spi);
resultValues.add("Total Certificates in Browser : " + entries.size() + "<br><br><br>");
printMessageToConsole("Total Certificates in Browser : " + entries.size());
for (Object entry : entries) {
aliasnew = (String) invokeGetter(entry, "getAlias");
PrivateKey privateKey = (PrivateKey) invokeGetter(entry,"getPrivateKey");
X509Certificate[] certificateChain = (X509Certificate[]) invokeGetter(entry, "getCertificateChain");
for (X509Certificate current : certificateChain) {
certString = "";
if (certDetails != null && getkeyUsage(current.getKeyUsage()) != "") {
count ++;
pubKey = this.bASE64Encoder.encode(current.getPublicKey().getEncoded());
certDetails = getX509CertificateDetails(current);
Map<String, String> valueMap = new HashMap<String, String>();
valueMap = getMetadata(certDetails);
certString += "====================== Certificate Details for Certificate No : " + count + "======================<br>";
certString += "Alias : " + aliasnew + " <br>";
certString += "Name : "+ valueMap.get(CERT_DETAILS.NAME) + " <br>";
certString += "Key Usage : " + getkeyUsage(current.getKeyUsage()) + "<br>";
certString += "CNName : "+ valueMap.get(CERT_DETAILS.CN_NAME) + "<br>";
printMessageToConsole(certString);
resultValues.add(certString);
break;
} else {
printMessageToConsole("Cert Details is NULL");
}
}
}
}
else {
printMessageToConsole("Keystore is NULL");
}
return resultValues;
}
HTML页面
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<SCRIPT LANGUAGE="JavaScript">
function getAllCertificates()
{
document.write("Certificate Reading Started.")
var certificates = document.securityApplet.getCertificateAllDetails();
document.write(certificates);
}
</SCRIPT>
<body>
<div>Digital Certificate Test Application</div>
<script src="http://www.java.com/js/deployJava.js"></script>
<applet name="securityApplet" code="SecurityApplet.class"
archive="securityApplet.jar" width="0" height="0" MAYSCRIPT="true"
scriptable="true" > </applet>
<button type="button" onclick="getAllCertificates()">Load Certificates!</button>
</body>
我最近打开了此页面,现在在我的本地网络中,该小程序已正确初始化,但是单击该按钮后它无法再调用任何东西。
加载页面时的控制台输出。
Applet Initialized Version : 30
Operating system name =>Windows 7
basic: Applet initialized
basic: Starting applet
basic: completed perf rollup
basic: Applet made visible
basic: Applet started
basic: Told clients applet is started
一切正常,直到上面加载
当我单击“加载证书”按钮时,以下是控制台日志,然后什么也没有发生。 而且在安全网络中,最后两行甚至都不到。
basic: Starting applet teardown
basic: Finished applet teardown
basic: Removed progress listener: sun.plugin.util.ProgressMonitorAdapter@1b9bbe8
plugin2manager.parentwindowDispose
以下是控制台输出,它在循环中进入。
期待在同一答案。 提前致谢。
我发现了问题。 这里没有JNLP可以做。 唯一的问题是我已经完成了document.write,这正在阻塞并且需要处理applet。 我已经从HTML删除了document.write,并且在跟随HTML的情况下,代码完全可以正常工作。
<html>
<head>
<title> Digital Certificate Test Application </title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<script src="http://www.java.com/js/deployJava.js"></script>
<applet name="securityApplet" code="SecurityApplet.class"
archive="securityApplet.jar" width="0" height="0" MAYSCRIPT="true"
scriptable="true" > </applet>
<SCRIPT LANGUAGE="JavaScript">
function getAllCertificates()
{
alert("Certificate Reading Started");
var certificates = document.securityApplet.getCertificateAllDetails();
document.getElementById("displaymessage").innerHTML = certificates;
}
</SCRIPT>
<body>
<div>Digital Certificate Test Application</div>
<div id="displaymessage">
</div>
<button type="button" onclick="getAllCertificates()">Load Certificates!</button>
</body>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.