-
Standalone Application JVM: The following class simply
lists all the properties and values to the Standard output stream.
Note that the method props.list() truncates long line entries. For
full unabbreviated values, see the examples for browser or servlet below.
import java.util.Properties;
class props {
static public void main(String args[]){
Properties props;
props = System.getProperties();
props.list(System.out);
}
}
- Browser Applet JVM:: Enumeration of all the System properties
requires capability beyond the usual Java security sandbox. If the browser's
own JVM is used, to return all
the System properties, the applet must be digitally signed. The following
applet uses the netscape.security.PrivilegeManager class for Netscape browsers, and
the com.ms.security.PolicyEngine class for IE browsers. Because the privileged
method is called automatically in the applet init() method, explicit permissions
assertion is required for IE, as discussed in
MSKB Q175622.
A signed deployed version is available for use at:
http://204.191.136.6/~neutron/signedparm/
/* class SignedParm2 displays in textarea the system parameters.
designed to run as signed applet in both Communicator 4+ and IE4+
web browsers. Since the applet runs it's privileged method in
the init() method, IE code must explicitly assert permissions here.
M. Gallant 11/04/1999
*/
import com.ms.security.*;
import java.awt.*;
import java.applet.*;
import java.io.* ;
import java.util.*;
import netscape.security.PrivilegeManager;
public class SignedParm2 extends Applet {
FontMetrics fm;
int xtab, ystep ;
String nl ; // new line character
String[] graphString = new String[20] ;
int strings = 0;
TextArea ta = new TextArea (25, 80);
public void init() {
try {
if (Class.forName("com.ms.security.PolicyEngine") != null) { // required for IE
PolicyEngine.assertPermission(PermissionID.PROPERTY);
}
}
catch (Throwable cnfe) {
}
this.setBackground(new Color(192,192,192)) ;
add(ta) ;
try{
PrivilegeManager.enablePrivilege("UniversalPropertyWrite") ; // required for NN
}
catch(Exception cnfe) {
System.out.println("netscape.security.PrivilegeManager class not found") ;
}
Properties sysprops = System.getProperties() ;
Enumeration enprop = sysprops.propertyNames() ;
String str = "" ;
ta.setText("") ;
while ( enprop.hasMoreElements() ) {
String key = (String) enprop.nextElement() ;
// System.out.println(key+"\t"+sysprops.getProperty(key));
str = key+"\t"+sysprops.getProperty(key) ;
ta.append(str + "\n");
}
// PrivilegeManager.disablePrivilege("UniversalPropertyWrite") ;
}
}
An alternate approach for browsers using the JavaPlugin1.2 and the JRE1.2 makes use of a local policy file
to specify file-grained privileges. This approach can grant the privileges even without code-signing. An
example of this approach (requires policy file modification) is available at:
http://204.191.136.6/~neutron/signedparmj2/
- Server Java Servlet JVM: A server's JVM System properties
used by servlet implementations can be made readily available via
the web with this simple servlet. If a query parameter "long" is
received, the full value of parameters is returned (otherwise,
props.list() is used with abbreviated values); e.g.
http://yourserver/servlet/javasysprops?long=yes
import java.io.*;
import javax.servlet.*;
import java.util.Properties;
import java.util.Enumeration;
public class javasysprops extends GenericServlet {
public void service(ServletRequest req,
ServletResponse res)
throws ServletException, IOException
{
res.setContentType("text/plain");
Properties props;
props = System.getProperties(); //get server JVM properties
PrintWriter out = res.getWriter();
out.println("-------- Server Java System properties ---------------") ;
out.println(" M. Gallant 02/99\n") ;
if(req.getParameter("long")!=null){
out.println(" (long form listing)") ;
Enumeration enprop = props.propertyNames() ;
String key = "";
while ( enprop.hasMoreElements() ){
key = (String) enprop.nextElement() ;
out.println(key+"\t"+props.getProperty(key)) ;
}
out.close();
return;
}
props.list(out); // abbreviated listing is default.
out.close();
}
}