Detect java version using deployJava.js ,pops up java upgrade menu - java

I have a need to know the java version installed on client machine, have come up with the solution here
How to write JavaScript function to check JRE version
When I tried, got with the answer:
console.log(deployJava.getJREs());
But at the address bar, pop up menu is displayed like this
How to hide this?.
If this can not be achieved, please suggest any other idea to implement, as this can not be used,if this popup is not suppressed

I am pretty sure from recent experiments that there is no way to suppress it. For the script to detect the plug-in versions, it must invoke the plug-in itself.
After those experiments I worked to create a script that could detect a variety of things out about the Java plug-in without invoking the plug-in itself. They relied on examining the mime-types info.
This still shows a warning in IE if opened from the local file-system. But I hope it will be more forgiving if loaded from the internet. Please report back.
But note this is what it reports for IE when the 'allow scripts' check is OK'd.
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Java Information - Non Deployment Toolkit Script</title>
<meta name='author' content='Andrew Thompson'>
<meta name='description' content='Non Deployment Toolkit Script'>
<script src='mimetypes.js'></script>
<style type='text/css'>
.true {
background-color: #6F6;
}
.false {
background-color: #FB0;
}
.undefined {
background-color: #FF0;
}
.datum {
font-family: monospace;
}
td {
padding: 4px;
}
</style>
</head>
<body>
<h1>Java on this PC</h1>
<h2>Overview</h2>
<p>This page endeavors to ascertain the installation, availability
& version of the Java installed on the client PC.
More importantly, it attempts to discover the information <b>without
invoking the Java Plug-In</b> itself.
The last part is what makes it different
to the Deployment Toolkit Script supplied by Oracle.
</p>
<script type='text/javascript'>
document.write("<h2>Browser Info.</h2>");
document.write(getBrowserInfo());
document.write("<h2>Basic Info.</h2>");
document.write("<table border='1'>");
document.write(get3CellRow('<b>Enabled</b>', isJava(), 'Java is enabled (1.1+) - IE info. (short of ActiveX) stops here'));
document.write(get3CellRow('<b>Version</b>', getVersion(), 'Maximum version reliably <em>known</em> to be available'));
if (isIE()) {
document.write(get3CellRow('<b>MSIE</b>', getIEVersion(), 'Maximum version reliably known to be available in IE, tested using ActiveX'));
}
document.write(get3CellRow('<b>JWS</b>', isJWS(), 'Java Web Start available (1.4.2+)'));
document.write(get3CellRow('<b>Plug-In 2</b>', isPlugin2(), 'Plug-In 2 available (1.6.0_10+)'));
document.write("</table>");
if (plugins.length>0) {
document.write("<h2>Navigator Plug-Ins</h2>");
document.write("<table border='1'>");
document.write("<tr><th>Name</th><th>Version</th><th>File Name</th><th>Description</th></tr>");
for (var ii=0; ii<plugins.length; ii++) {
var t = plugins[ii].name;
if (t.indexOf("Java")>-1) {
document.write("<tr>");
document.write("<td>" + plugins[ii].name + "</td>");
document.write(getDataStyledCell(plugins[ii].version));
document.write("<td>" + plugins[ii].filename + "</td>");
document.write("<td>" + plugins[ii].description + "</td>");
document.write("</tr>");
}
}
document.write("</table>");
}
if (mimes.length>0) {
document.write("<h2>Navigator Mime-Types</h2>");
document.write("<table border='1'>");
document.write("<tr><th>Mime</th><th>Description</th><th>Types</th></tr>");
for (var ii=0; ii<mimes.length; ii++) {
var t = mimes[ii].type;
if (t.indexOf("java")>0 &&
((t.indexOf("jpi")>0 || t.indexOf("deploy")>0 || t.indexOf("jnlp")>0 || t.indexOf("vm")>0) ||
mimes[ii].description.length>0)
) {
document.write("<tr>");
document.write("<td>" + mimes[ii].type + "</td>");
document.write("<td>" + mimes[ii].description + "</td>");
document.write("<td>" + mimes[ii].suffixes + "</td>");
document.write("</tr>");
}
}
document.write("</table>");
}
</script>
<hr>
<h2>Description</h2>
<p>In order (if available) the information is:
<ul>
<li><b>Browser info. Table:</b> Not strictly related to Java - the
information in the other tables is determined without
further reference to any information shown in this table (except for the <code>appName</code> used for
identifying IE).
OTOH it is an helpful guide
as to what we should be <em>expecting</em>
from the other information. E.G. IE
will not show the Plug-In or Mime Type tables. <em>Only</em>
FF displays the plug-in version numbers.
</li>
<li><b>Basic info. Table</b>
<ul>
<li><b>Enabled</b>: Java is known to this browser and enabled, according to JavaScript <code>navigator.javaEnabled()</code>.</li>
<li><b>Version</b>: The maximum Java version known to be supported in this browser/PC.
It is set to <code>1.1</code> if the previous check is <code>true</code>, since the MSVM
was the first Java version the public could get in a browser, and the MSVM
implemented Java 1.1. Goes on to check
<code>application/x-java-applet;jpi-version</code>
in the mime types if available
(i.e. typically browsers that are <em>not</em> IE).
</li>
<li><b>MSIE</b> (IE Only): The maximum Java version known to be supported by this instance of Internet Explorer
as determined using ActiveX. It runs from 1.4.2, 1.5.0.. through 1.9.0.
</li>
<li><b>JWS</b>:
Inferred from a comparison of the version to the Sun JRE in which
it was co-bundled.</li>
<li><b>Plug-In 2</b>:
Inferred from a comparison of the version to the Sun JRE in which
it was introduced.</li>
</ul>
</li>
<li><b>Navigator Object Tables:</b>
<em>The rest of the info. is gleaned from the <code>navigator</code> object.
IE does not include this information.</em>
<ul>
<li><b>Plug-Ins</b>: More details of the Java related plugins.
Filtered for <code>Java</code> in the <code>name</code>.
A <code>description</code> showing "Next Generation Java Plug-in" or <code>name</code>
"Java Deployment Toolkit" should be 1.6.0_10+.</li>
<li><b>Mime-Types</b>: More information on the Java related Mime-Types.
Filtered in <code>mime</code> field for <code>'java'</code> + <code>('jpi'||'vm'||'deploy')</code>
or a non-empty <code>description</code>.
The value <code>java-deployment-toolkit</code> in the <code>mime</code>
is a good indicator of 1.6.0_10+.
</li>
</ul>
</li>
</ul>
</body>
</html>
mimetypes.js
// As a version string, this might be '1.4.2_31'.
// I.E. it is not a 'number' but a 'string' and therefore must be treated as a string.
var highestVersion = 'undefined';
var mimes = window.navigator.mimeTypes;
var plugins = window.navigator.plugins;
function isJava() {
return (
typeof(navigator.javaEnabled) !== 'undefined' &&
navigator.javaEnabled());
}
function getVersion() {
var version = 0;
if (isJava()) {
version = 1.1;
}
for (var ii=0; ii<mimes.length; ii++) {
var t = mimes[ii].type;
if (t.indexOf("java")>0 &&
t.indexOf("jpi")>0 &&
t.indexOf("applet")>0
) {
var parts = t.split("=");
version = parts[parts.length-1];
}
}
if (highestVersion=='undefined') highestVersion = version;
return version;
}
function isJWS() {
var ver = highestVersion;
var className = false;
if (ver>'1.0') {
className = undefined;
}
if (ver>'1.4.2') {
className = true;
}
return className;
}
function isPlugin2() {
var ver = highestVersion;
var className = false;
if (ver>'1.0') {
className = undefined;
}
if (ver>'1.6.0_10') {
className = true;
}
return className;
}
var versionFamily = [
'1.9.0', '1.8.0', '1.7.0',
'1.6.0', '1.5.0', '1.4.2'
];
function getIEVersion() {
for (var i=0; i<versionFamily.length; i++) {
if (testUsingActiveX(versionFamily[i])) {
return versionFamily[i];
}
}
return false;
}
if (isIE() && getVersion()=='1.1') {
highestVersion = getIEVersion();
}
function isIE() {
return navigator.appName=='Microsoft Internet Explorer';
}
function testUsingActiveX(version) {
var objectName = 'JavaWebStart.isInstalled.' + version + '.0';
// we need the typeof check here for this to run on FF/Chrome
// the check needs to be in place here - cannot even pass ActiveXObject
// as arg to another function
if (typeof ActiveXObject == 'undefined' || !ActiveXObject) {
alert('[testUsingActiveX()] Browser claims to be IE, but no ActiveXObject object?');
return false;
}
try {
return (new ActiveXObject(objectName) != null);
} catch (exception) {
return false;
}
}
function get3CellRow(cell1, cell2, cell3) {
var s = "" +
"<tr>" +
"<td class='" +
getClassName(cell1) +
"'>" +
cell1 +
"</td>" +
getDataStyledCell(cell2) +
"<td class='" +
getClassName(cell3) +
"'>" +
cell3 +
"</td>" +
"</tr>" +
"";
return s;
}
function getDataStyledCell(value) {
var s = "<td class='datum " +
getClassName(value) +
"'>" +
value +
"</td>";
return s;
}
function getClassName(val) {
var className = undefined;
if (
(val) ||
(!val) ||
(val!=="undefined")
) {
className = val;
}
return className;
}
function getBrowserInfo() {
var s = "";
var props = [
'appCodeName','appName','appVersion',
'userAgent',
'platform','cookieEnabled'
];
s += "<table border='1'>";
for (var i=0; i<props.length; i++) {
s+= "<tr>";
s+= "<td><b>";
s+= props[i];
s+= "</b></td>";
s+= "<td>";
s+= navigator[props[i]];
s+= "</td>";
s+= "</tr>";
}
s += "</table>";
return s;
}
Please note (be warned) this script was written by me, a Java programmer. Java programmers are typically the absolute worst people on the planet for writing JS, since we foolishly tend to presume. "It's JavaScript, how hard can it be?".
To write really good JavaScript is indeed an art.
Even worse, this was experimental code that was 'hacked out' with the intention of improving it later, but the project was abandoned and 'later' never arrived.
Caveat emptor.

Related

How to create Websocket Java SE client?

My problem is that not since a Websocket creates client in Java SE to be able to connect to the Websocket HTML5 server.
Ningun example I dress in Internet they me have worked.
Code in HTML5
<script type="text/javascript">
var mysocket = new WebSocket("ws://localhost:8080");
mysocket.onopen = function (evt){
escribir("Websocket abierto");
};
mysocket.onmessage = function (evt){
escribir("RECIBIDO: " + evt.data);
};
mysocket.onclose = function (evt){
escribir("Websocket cerrado");
};
mysocket.onerror = function (evt) {
escribir("ERROR: " + evt.data);
}
function escribir(texto){
valor = document.getElementById("caja").value;
document.getElementById("caja").value = valor + texto + "\n";
}
function enviar(texto) {
mysocket.send(texto);
escribir("ENVIADO: " + texto);
}
function desconectar(){
mysocket.close();
}
</script>
I have tried Jetty and it me has not worked.
Do you help me please?
In java there are some options, if you aren't interested in secure websocket server, then this link can help you. There are enough examples.
PD: You can try Jetty, using some dependencies needed for websocket.

How can I find out java version with javascript but without deployJava.js?

This is a quasi follow-up of
Detect version of Java using JavaScript
I have the restriction that the javascript should not initialize the java plugin (also not use deployJava, which in turn uses the plugin) for security reasons.
Also an applet should not be used.
How else can I detect java version?
Here is some primitive script I cobbled together from the only answer on the linked thread that comes close to being useful and does not use the Deployment Toolkit Script.
The current attempt is good with browsers that support the mimeTypes & plugins of the navigator object. For IE it uses ActiveX (which can detect JRE family).
javainfo.js
// As a version string, this might be '1.4.2_31'.
// I.E. it is not a 'number' but a 'string' and therefore must be treated as a string.
var highestVersion = 'undefined';
// not available in IE, but all other known desktop browsers
var mimes = window.navigator.mimeTypes;
// not available in IE, but all other known desktop browsers
var plugins = window.navigator.plugins;
function isJava() {
return (
typeof(navigator.javaEnabled) !== 'undefined' &&
navigator.javaEnabled());
}
function getVersion() {
var version = 0;
if (isJava()) {
version = 1.1;
}
for (var ii=0; ii<mimes.length; ii++) {
var t = mimes[ii].type;
if (t.indexOf("java")>0 &&
t.indexOf("jpi")>0 &&
t.indexOf("applet")>0
) {
var parts = t.split("=");
version = parts[parts.length-1];
}
}
if (highestVersion=='undefined') highestVersion = version;
return version;
}
function isJWS() {
var ver = highestVersion;
var className = false;
if (ver>'1.0') {
className = undefined;
}
if (ver>'1.4.2') {
className = true;
}
return className;
}
function isPlugin2() {
var ver = highestVersion;
var className = false;
if (ver>'1.0') {
className = undefined;
}
if (ver>'1.6.0_10') {
className = true;
}
return className;
}
function getIEVersion() {
if (testUsingActiveX('1.9.0')) {
return '1.9.0';
} else if (testUsingActiveX('1.8.0')) {
return '1.8.0';
} else if (testUsingActiveX('1.7.0')) {
return '1.7.0';
} else if (testUsingActiveX('1.6.0')) {
return '1.6.0';
} else if (testUsingActiveX('1.5.0')) {
return '1.5.0';
} else if (testUsingActiveX('1.4.2')) {
return '1.4.2';
}
return false;
}
if (supportsActiveX() && getVersion()=='1.1') {
highestVersion = getIEVersion();
}
/** This checks directly for the support for ActiveX.
Internet Explorer 11 completely dropped support for ActiveX. */
function supportsActiveX() {
return typeof window.ActiveXObject != 'undefined';
}
/*
A fragile way to determine either 'IE' or 'ActiveX support'.
function isIE() {
// return navigator.appName=='Microsoft Internet Explorer';
// return navigator.appVersion.indexOf(".NET CLR")>0
return supportsActiveX();
}
*/
function testUsingActiveX(version) {
var objectName = 'JavaWebStart.isInstalled.' + version + '.0';
// we need the typeof check here for this to run on FF/Chrome
// the check needs to be in place here - cannot even pass ActiveXObject
// as arg to another function
if (typeof ActiveXObject == 'undefined' || !ActiveXObject) {
alert('[testUsingActiveX()] Browser claims to be IE, but no ActiveXObject object?');
return false;
}
try {
return (new ActiveXObject(objectName) != null);
} catch (exception) {
return false;
}
}
function get3CellRow(cell1, cell2, cell3) {
var s = "" +
"<tr>" +
"<td class='" +
getClassName(cell1) +
"'>" +
cell1 +
"</td>" +
getDataStyledCell(cell2) +
"<td class='" +
getClassName(cell3) +
"'>" +
cell3 +
"</td>" +
"</tr>" +
"";
return s;
}
function getDataStyledCell(value) {
var s = "<td class='datum " +
getClassName(value) +
"'>" +
value +
"</td>";
return s;
}
function getClassName(val) {
var className = undefined;
if (
(val) ||
(!val) ||
(val!=="undefined")
) {
className = val;
}
return className;
}
function getBrowserInfo() {
var s = "";
var props = [
'appCodeName','appName','appVersion',
'userAgent',
'platform','cookieEnabled'
];
s += "<table border='1'>";
for (var i=0; i<props.length; i++) {
s+= "<tr>";
s+= "<td><b>";
s+= props[i];
s+= "</b></td>";
s+= "<td>";
s+= navigator[props[i]];
s+= "</td>";
s+= "</tr>";
}
s += "</table>";
return s;
}
This is typical HTML I use to view the resulting information.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Java Information - Non Deployment Toolkit Script</title>
<meta name='author' content='Andrew Thompson'>
<meta name='description' content='Non Deployment Toolkit Script'>
<script src='javainfo.js'></script>
<style type='text/css'>
.true {
background-color: #6F6;
}
.false {
background-color: #FB0;
}
.undefined {
background-color: #FF0;
}
.datum {
font-family: monospace;
}
td {
padding: 4px;
}
</style>
</head>
<body>
<h1>Java on this PC</h1>
<h2>Overview</h2>
<p>This page endeavors to ascertain the installation, availability
& version of the Java installed on the client PC.
More importantly, it attempts to discover the information <b>without
invoking the Java Plug-In</b> itself.
The last part is what makes it different
to the Deployment Toolkit Script supplied by Oracle.
</p>
<script type='text/javascript'>
document.write("<h2>Browser Info.</h2>");
document.write(getBrowserInfo());
document.write("<h2>Basic Info.</h2>");
document.write("<table border='1'>");
document.write(get3CellRow('<b>Enabled</b>', isJava(), 'Java is enabled (1.1+) - IE info. (short of ActiveX) stops here'));
document.write(get3CellRow('<b>Version</b>', getVersion(), 'Maximum version reliably <em>known</em> to be available'));
if (supportsActiveX()) {
document.write(get3CellRow('<b>MSIE</b>', getIEVersion(), 'Maximum version reliably known to be available in IE, tested using ActiveX'));
}
document.write(get3CellRow('<b>JWS</b>', isJWS(), 'Java Web Start available (1.4.2+)'));
document.write(get3CellRow('<b>Plug-In 2</b>', isPlugin2(), 'Plug-In 2 available (1.6.0_10+)'));
document.write("</table>");
if (plugins.length>0) {
document.write("<h2>Navigator Plug-Ins</h2>");
document.write("<table border='1'>");
document.write("<tr><th>Name</th><th>Version</th><th>File Name</th><th>Description</th></tr>");
for (var ii=0; ii<plugins.length; ii++) {
var t = plugins[ii].name;
if (t.indexOf("Java")>-1) {
document.write("<tr>");
document.write("<td>" + plugins[ii].name + "</td>");
document.write(getDataStyledCell(plugins[ii].version));
document.write("<td>" + plugins[ii].filename + "</td>");
document.write("<td>" + plugins[ii].description + "</td>");
document.write("</tr>");
}
}
document.write("</table>");
}
if (mimes.length>0) {
document.write("<h2>Navigator Mime-Types</h2>");
document.write("<table border='1'>");
document.write("<tr><th>Mime</th><th>Description</th><th>Types</th></tr>");
for (var ii=0; ii<mimes.length; ii++) {
var t = mimes[ii].type;
if (t.indexOf("java")>0 &&
((t.indexOf("jpi")>0 || t.indexOf("deploy")>0 || t.indexOf("vm")>0) ||
mimes[ii].description.length>0)
) {
document.write("<tr>");
document.write("<td>" + mimes[ii].type + "</td>");
document.write("<td>" + mimes[ii].description + "</td>");
document.write("<td>" + mimes[ii].suffixes + "</td>");
document.write("</tr>");
}
}
document.write("</table>");
}
</script>
<hr>
<h2>Description</h2>
<p>In order (if available) the information is:
<ul>
<li><b>Browser info. Table:</b> Not strictly related to Java - the
information in the other tables is determined without
further reference to any information shown in this table (except for the <code>appName</code> used for
identifying IE).
OTOH it is an helpful guide
as to what we should be <em>expecting</em>
from the other information. E.G. IE
will not show the Plug-In or Mime Type tables. <em>Only</em>
FF displays the plug-in version numbers.
</li>
<li><b>Basic info. Table</b>
<ul>
<li><b>Enabled</b>: Java is known to this browser and enabled, according to JavaScript <code>navigator.javaEnabled()</code>.</li>
<li><b>Version</b>: The maximum Java version known to be supported in this browser/PC.
It is set to <code>1.1</code> if the previous check is <code>true</code>, since the MSVM
was the first Java version the public could get in a browser, and the MSVM
implemented Java 1.1. Goes on to check
<code>application/x-java-applet;jpi-version</code>
in the mime types if available
(i.e. typically browsers that are <em>not</em> IE).
</li>
<li><b>MSIE</b> (IE Only): The maximum Java version known to be supported by this instance of Internet Explorer
as determined using ActiveX. It runs from 1.4.2, 1.5.0.. through 1.9.0.
</li>
<li><b>JWS</b>:
Inferred from a comparison of the version to the Sun JRE in which
it was co-bundled or introduced.</li>
<li><b>Plug-In 2</b>:
Inferred from a comparison of the version to the Sun JRE in which
it was co-bundled or introduced.</li>
</ul>
</li>
<li><b>Navigator Object Tables:</b>
<em>The rest of the info. is gleaned from the <code>navigator</code> object.
IE does not include this information.</em>
<ul>
<li><b>Plug-Ins</b>: More details of the Java related plugins.
Filtered for <code>Java</code> in the <code>name</code>.
A <code>description</code> showing "Next Generation Java Plug-in" or <code>name</code>
"Java Deployment Toolkit" should be 1.6.0_10+.</li>
<li><b>Mime-Types</b>: More information on the Java related Mime-Types.
Filtered in <code>mime</code> field for <code>'java'</code> + <code>('jpi'||'vm'||'deploy')</code>
or a non-empty <code>description</code>.
The value <code>java-deployment-toolkit</code> in the <code>mime</code>
is a good indicator of 1.6.0_10+.
</li>
</ul>
</li>
</ul>
</body>
</html>
Output
FireFox
Browser Info.
appCodeName Mozilla
appName Netscape
appVersion 5.0 (Windows)
userAgent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0
platform Win32
cookieEnabled true
Basic Info.
Enabled true Java is enabled (1.1+) - IE info. stops here
Version 1.7.0_25 Maximum version reliably known to be available
JWS true Java Web Start available (1.4.2+)
Plug-In 2 true Plug-In 2 available (1.6.0_10+)
Navigator Plug-Ins
Name Version File Name Description
Java(TM) Platform SE 7 U25 10.25.2.17 npjp2.dll Next Generation Java Plug-in 10.25.2 for Mozilla browsers
Java Deployment Toolkit 7.0.250.17 10.25.2.17 npdeployJava1.dll NPRuntime Script Plug-in Library for Java(TM) Deploy
Navigator Mime-Types
Mime Description Types
application/x-java-applet Java Applet
application/x-java-bean JavaBeans
application/x-java-vm
application/x-java-applet;jpi-version=1.7.0_25
application/x-java-bean;jpi-version=1.7.0_25
application/x-java-vm-npruntime
application/x-java-applet;deploy=10.25.2
application/java-deployment-toolkit
Chrome
Browser Info.
appCodeName Mozilla
appName Netscape
appVersion 5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36
userAgent Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36
platform Win32
cookieEnabled true
Basic Info.
Enabled true Java is enabled (1.1+) - IE info. stops here
Version 1.7.0_25 Maximum version reliably known to be available
JWS true Java Web Start available (1.4.2+)
Plug-In 2 true Plug-In 2 available (1.6.0_10+)
Navigator Plug-Ins
Name Version File Name Description
Java(TM) Platform SE 7 U25 undefined npjp2.dll Next Generation Java Plug-in 10.25.2 for Mozilla browsers
Java Deployment Toolkit 7.0.250.17 undefined npDeployJava1.dll NPRuntime Script Plug-in Library for Java(TM) Deploy
Navigator Mime-Types
Mime Description Types
application/x-java-applet Java Applet
application/x-java-bean JavaBeans
application/x-java-vm
application/x-java-applet;jpi-version=1.7.0_25
application/x-java-bean;jpi-version=1.7.0_25
application/x-java-vm-npruntime
application/x-java-applet;deploy=10.25.2
application/java-deployment-toolkit
(Note: Navigator Mime-Types trimmed from the image since it was the same info. as FF.)
Internet Explorer
Browser Info.
appCodeName Mozilla
appName Microsoft Internet Explorer
appVersion 5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; AskTbORJ/5.15.25.36191)
userAgent Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; AskTbORJ/5.15.25.36191)
platform Win32
cookieEnabled true
Basic Info.
Enabled true Java is enabled (1.1+) - IE info. (short of ActiveX) stops here
Version 1.1 Maximum version reliably known to be available
MSIE 1.7.0 Maximum version reliably known to be available in IE, tested using ActiveX
JWS true Java Web Start available (1.4.2+)
Plug-In 2 true Plug-In 2 available (1.6.0_10+)
Internet Explorer 11+
Internet Explorer 11 has dropped support for ActiveX so this is how it might appear.
On the bright side, if this is Internet Explorer 11+ and it has Java Enabled, it will have installed Java 1.7.0 at the minimum. Java has been defaulting to auto-update since around Java 1.6. So this browser would logically (at least by default options) have the latest JRE version.

JAVA Applet Loading Issue

We have developed an applet in JAVA which is mainly used for accessing Digital Certificate from keystore.
The applet works fine in most of the cases, but in some secure networks of banks the applet behaviour becomes unpredictable.
We are using applet tag in HTML to access applet.
My first question is do we need to deploy using JNLP for this?
Secondly, I prepared one test application in past where by I was simply calling one method of applet, which was loading all the certificate public details and printing it on console. It used to work perfectly ok.
Following is the code for the same.
Applet Method
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 Page
<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>
I recently opened up this page and now in my local network the applet is getting initialised properly but then it is unable to call anything further on click of button.
Console Output on loading of page.
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
Everything is ok till above on loading
When I click on Load Certificate Button, following is the console log and then nothing happens. And in the secured network the last two line even does not come.
basic: Starting applet teardown
basic: Finished applet teardown
basic: Removed progress listener: sun.plugin.util.ProgressMonitorAdapter#1b9bbe8
plugin2manager.parentwindowDispose
Following is the console output, where it goes in loop.
Looking forward for an answer on the same. Thanks in Advance.
I have found out the problem.
There is nothing to do JNLP here.
The only problem is I have done document.write which is blocking and getting applet to dispose.
I have removed the document.write from HTML and with following HTML the code works completely ok.
<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>

DJ Native Swing javascript command problems

Using DJ Native Swing it is possible to show a web page within a java application. When you do this it is also possible to communicate from the browser to the java runtime environment using the "command" protocol. The documentation has a code snippet which demonstrates it's usage:
function sendCommand( command ){
var s = 'command://' + encodeURIComponent( command );
for( var i = 1; i < arguments.length; s+= '&' + encodeURIComponent( arguments[i++] ) );
window.location = s;
}
As it looks here it seems to be a regular GET request to an url using the command protocol instead of http. Although when I create and image, script tag or just and ajax get request there is no response and the breakpoint in the java runtime isn't triggered.
I don't want to set the window.location because I don't want to navigate away from the page I am currently at. Using the link to navigate to a command url does work though but it also navigates away from the current page. The page uses OpenLayers and dojo. (I have also tried dojo.io.script)
After some work I have found a neat way to communicate with the java runtime which doesn't trigger a refresh of the page every time there is communication. It is inspired on the way JSONP works to get around the cross domain restriction in most browsers these days. Because an iFrame will also trigger a command:// url it possible to do a JSONP like action using this technique. The code on the client side (browser):
dojo.provide( "nmpo.io.java" );
dojo.require( "dojo.io.script" );
nmpo.io.java = dojo.delegate( dojo.io.script, {
attach: function(/*String*/id, /*String*/url, /*Document?*/frameDocument){
// summary:
// creates a new tag pointing to the specified URL and
// adds it to the document.
// description:
// Attaches the script element to the DOM. Use this method if you
// just want to attach a script to the DOM and do not care when or
// if it loads.
var frame = dojo.create( "iframe", {
id: id,
frameborder: 0,
framespacing: 0
}, dojo.body( ) );
dojo.style( frame, { display: "none" } );
dojo.attr( frame, { src: url } );
return frame;
},
_makeScriptDeferred: function(/*Object*/args){
//summary:
// sets up a Deferred object for an IO request.
var dfd = dojo._ioSetArgs(args, this._deferredCancel, this._deferredOk, this._deferredError);
var ioArgs = dfd.ioArgs;
ioArgs.id = dojo._scopeName + "IoScript" + (this._counter++);
ioArgs.canDelete = false;
//Special setup for jsonp case
ioArgs.jsonp = args.callbackParamName || args.jsonp;
if(ioArgs.jsonp){
//Add the jsonp parameter.
ioArgs.query = ioArgs.query || "";
if(ioArgs.query.length > 0){
ioArgs.query += "&";
}
ioArgs.query += ioArgs.jsonp
+ "="
+ (args.frameDoc ? "parent." : "")
+ "nmpo.io.java.jsonp_" + ioArgs.id + "._jsonpCallback";
ioArgs.frameDoc = args.frameDoc;
//Setup the Deferred to have the jsonp callback.
ioArgs.canDelete = true;
dfd._jsonpCallback = this._jsonpCallback;
this["jsonp_" + ioArgs.id] = dfd;
}
return dfd; // dojo.Deferred
}
});
When a request is sent to the java runtime a callback argument will be supplied and a webBrowser.executeJavascript( callbackName + "(" + json + ");" ); action can be executed to trigger the callback in the browser.
Usage example client:
dojo.require( "nmpo.io.java" );
nmpo.io.java.get({
// For some reason the first paramater (the one after the '?') is never in the
// paramater array in the java runtime. As a work around we stick in a dummy.
url: "command://sum?_",
callbackParamName: "callback",
content: {
numbers: [ 1, 2, 3, 4, 5 ].join( "," )
},
load: function( result ){
console.log( "A result was returned, the sum was [ " + result.result + " ]" );
}
});
Usage example java:
webBrowser.addWebBrowserListener(new WebBrowserAdapter() {
#Override
public void commandReceived(WebBrowserCommandEvent e) {
// Check if you have the right command here, left out for the example
// Parse the paramaters into a Hashtable or something, also left out for the example
int sum = 0;
for( String number : arguments.get( "numbers" ).split( "," ) ){
sum += Integer.parseInt( number );
}
// Execute the javascript callback like would happen with a regular JSONP call.
webBrowser.executeJavascript( arguments.get( "callback" ) + "({ result: " + sum + " });" );
}
});
Also with IE in the frame I can highly recommend using firebug lite, the dev tools for IE are not available.

Convert Permission Mask to Roles for GetPermissionCollection

We have a requirement where we need to check if a user has "Upload" access to a folder in Sharepoint document library. For that, I am using the "GetPermissionCollection" method of Permissions webservice on the document library. The response I get is of below format:
I am not able to convert the Permission mask to role. I am doing this in Java and I dont have SPBasePermissions class.
Is there a way in Java to convert the Mask into role?
Thanks in advance
Yes, you just need to do bitwise operations against it. You will need to hardwire the bitmask for the permissions you care about, but this should be safe enough since these do not change in SharePoint 2010.
I found this link:
Permission/Deny Mask in SharePoint
which says something about this bitwise AND.
You should also use this link:
http://msdn.microsoft.com/en-us/library/dd304243%28PROT.13%29.aspx
which Enums the Masks for the permissions.
I also made an javascript example that can help you...
however you will have to convert it into java
I used JQuery, SPServices js (http://spservices.codeplex.com/)
and this link for the masks codes
http://msdn.microsoft.com/en-us/library/dd304243%28PROT.13%29.aspx
I Hope this helps you, I did this because I was needing it also, however it may also help others.
You need to replace the LIST NAME HERE with the name of the list, and find out which is the mask for upload.
The script will spit everyone that has access to a list, and say if they can read, add, change and delete things. Hopes this helps you.
$('#divid').html('Working...').SPServices({
operation: "GetPermissionCollection",
objectName: 'LIST NAME HERE',
objectType: "List",
completefunc: function (xData, Status) {
var out = "<ul>";
$(xData.responseXML).find("Permission").each(function () {
if ($(this).attr("MemberIsUser") === "True") {
out += "<li>User: " + $(this).attr("UserLogin") + "</li>";
} else {
out += "<li>Group: " + $(this).attr("GroupName") + "</li>";
}
var readmask = 0x0000000000000001;
var addmask = 0x0000000000000002;
var editmask = 0x0000000000000004;
var deletemask = 0x0000000000000008;
out += "<li>Mask: " + $(this).attr("Mask") + "</li>";
var canread = readmask & $(this).attr("Mask").toString(16) > 0 ? "Yes" : "No";
var canadd = addmask & $(this).attr("Mask").toString(16) > 0 ? "Yes" : "No";
var canedit = editmask & $(this).attr("Mask").toString(16) > 0 ? "Yes" : "No";
var candelete = deletemask & $(this).attr("Mask").toString(16) > 0 ? "Yes" : "No";
out += "<li>Can Read: " + canread + "</li>";
out += "<li>Can Add: " + canadd + "</li>";
out += "<li>Can Edit: " + canedit + "</li>";
out += "<li>Can Delete: " + candelete + "</li>";
});
out += "</ul>";
$('divid').html(out);
}
});

Categories