public class EnvCheck extends Object
The following items are discussed below:
the simplest invocation of the tool would be:java -Djava.security.policy=mypolicy -jar /jini/lib/start.jar mystart.config
Note that the entire command line, including thejava -jar /jini/lib/envcheck.jar java -Djava.security.policy=mypolicy -jar /jini/lib/start.jar mystart.config
java
command,
is supplied as arguments to the tool. The java
command used to
run the tool may be different than the java
command invoked by
the command line under test. The first token in the command line being
analyzed must not begin with a '-' and must end with the string "java".
-traces
-explain
-explain
option is a hint that may result in the generation of additional output
describing the purpose and context of the check. An explanation is output
the first time its associated message is output, and is not repeated. It
is the responsibility of the individual plugin implementation to honor
this option.
-level
info|warning|error
localhost
in a codebase annotation.
java.util.logging.config.file
system property.
This option is used to set the level at which message records are generated. The default value is warning.
-plugin
file
META-INF/services/com.sun.jini.tool.envcheck.Plugin
, which
contains the class names of the plugins to run listed one per line.
Every class listed must implement the
com.sun.jini.tool.envcheck.Plugin
interface. This option
may be supplied zero or more times.
-security
isPlugOption
method of the
Plugin
interface.
main
method:
In this case, the tool is limited to performing validity checks on the classpath, policy, and codebase values identified by the system properties and options provided on the service command line. Thejava -jar /jini/lib/envcheck.jar -level info -explain -traces /usr/bin/java -cp mylib/myservice.jar:/jini/lib/jsk-platform.jar -Djava.security.policy=mypolicy -Djava.server.rmi.codebase=http://myhost/myservice-dl.jar myservice.MyServiceImpl
-level
,
-explain
, and -traces
options supplied will result
in the most verbose output possible from the tool.
The following example will analyze a command line used to start reggie using the service starter. The command being analyzed uses a policy and service starter configuration located in the working directory:
The tool can perform many more checks in this case because the bundled plugins include built-in knowledge about the service starter and its public configuration entries. The tool options used will minimize the output produced by the tool.java -jar /jini/lib/envcheck.jar -level error /usr/bin/java -Djava.security.policy=mystarterpolicy -jar /jini/lib/start.jar reggie.config
If the command line being analyzed invokes the service starter, the tool will
create a Configuration
from the arguments of the command line
being analyzed. Failure to create the Configuration
will result
in termination of the tool, otherwise the
com.sun.jini.start.ServiceDescriptor
s provided by the
Configuration
are examined. The following checks are done for
each ServiceDescriptor
:
getPolicy
method returns a reference to a
policy file that is valid and accessible
AllPermissions
to all
protection domains
NonActivatableServiceDescriptor
and each
SharedActivatableServiceDescriptor
getServerConfigArgs
does not return
null
or an empty array
Configuration
can be constructed from those
args
Configuration
named
initialLookupGroups
does not have a value of
ALL_GROUPS
-security
option was specified:
javax.net.ssl.trustStore
is defined and
that the trust store it references is accessible
com.sun.jini.discovery.x500.trustStore
is defined, and if so that the trust store it references is
accessible
javax.net.ssl.keyStore
is defined, and
if so that the key store it references is accessible
SharedActivatableServiceDescriptor
:
Configuration
named
persistenceDirectory
refers to either an empty directory
or a non-existant directory
SharedActivationGroupDescriptor
:
jsk-policy.jar
is loaded from the extensions
directory
jsk-platform.jar
is in the classpath
java.util.logging.config.file
is defined in the
properties returned by calling getServerProperties
then
verify that the file it references is accessible
java.rmi.server.codebase
java.security.policy
jsk-policy
being loaded by the extension
class loader
jsk-platform
in the classpath
-security
was specified
Constructor and Description |
---|
EnvCheck() |
Modifier and Type | Method and Description |
---|---|
String |
checkFile(String prop,
String desc)
Check for the existence of a file identified by a property
supplied on the command line being analyzed.
|
String[] |
getArgs()
Get the command line arguments of the command being analyzed.
|
String |
getClasspath()
Get the classpath provided by the command line being analyzed.
|
ServiceDescriptor[] |
getDescriptors()
Return the
ServiceDescriptor s contained in the service
starter configuration. |
SharedActivationGroupDescriptor |
getGroupDescriptor()
Return the
SharedActivationGroupDescriptor contained in the
service starter configuration. |
String |
getJarToRun()
Return the name of the executable JAR file supplied on the
command line being analyzed.
|
String |
getJavaCmd()
Return the
java command for the command line being analyzed. |
Properties |
getProperties()
Return a copy of the properties that were specified on the
command line being analyzed.
|
String |
getProperty(String key)
Return a property value that was specified on the command line being
analyzed.
|
Object |
launch(NonActivatableServiceDescriptor d,
SharedActivationGroupDescriptor gd,
String taskName)
Launch a subtask using the environment defined by the given service
descriptors.
|
Object |
launch(NonActivatableServiceDescriptor d,
SharedActivationGroupDescriptor gd,
String taskName,
String[] args)
Launch a subtask using the environment defined by the given service
descriptors.
|
Object |
launch(String task)
Launch a child VM using the
java command, properties, and
options supplied on the command line. |
Object |
launch(String javaCmd,
Properties props,
String[] opts,
String[] args)
Launch a subtask VM using the
java command given by
javaCmd . |
Object |
launch(String task,
String[] args)
Launch a child VM using the
java command, properties, and
options supplied on the command line being analyzed. |
static void |
main(String[] args)
The entry point for the tool.
|
boolean |
printStacks()
Return the flag indicating whether to output stack traces that
result from a check.
|
public static void main(String[] args)
java.protocol.handler.pkgs
for the tool VM is set
to net.jini.url
to ensure that the tool can manipulate
HTTPMD URLs.args
- the command line argumentspublic ServiceDescriptor[] getDescriptors()
ServiceDescriptor
s contained in the service
starter configuration. If the command being analyzed does not invoke the
service starter, a zero-length array will be returned.public SharedActivationGroupDescriptor getGroupDescriptor()
SharedActivationGroupDescriptor
contained in the
service starter configuration. Returns null
if there is no
such descriptor, or if the command being analyzed does not invoke the
service starter.SharedActivationGroupDescriptor
or
null
public String[] getArgs()
public boolean printStacks()
public Object launch(String task, String[] args)
java
command, properties, and
options supplied on the command line being analyzed. If an executable JAR
file was specified, the classpath of the child VM consists of the JAR
file name augmented with the classpath of the tool and plugins. If a main
class was specified, the classpath of the child VM consists of the
-cp/-classpath
option value of the command line being
analyzed augmented with the classpath of the tool and plugins.task
- the class name of the task to launch, which must implement
the SubVMTask
interfaceargs
- the arguments to pass to the main method of the taskSystem.out
stream.public Object launch(String task)
java
command, properties, and
options supplied on the command line. If an executable JAR file was
specified, the classpath of the child VM consists of the JAR file name
augmented with the classpath of the tool and plugins. If a main class was
specified, the classpath of the child VM consists of the
-cp/-classpath
option value of the command line being
analyzed augmented with the classpath of the tool and plugins.task
- the class name of the task to launch, which must implement
the SubVMTask
interfaceSystem.out
stream.public String getProperty(String key)
key
- the name of the propertynull
if undefinedpublic Properties getProperties()
public Object launch(String javaCmd, Properties props, String[] opts, String[] args)
java
command given by
javaCmd
. If javaCmd
is null
, the
command to run is derived from the value of the java.home
property of the tool VM. The first value in args
must name
a class that implements the SubVMTask
interface. The
props
and opts
arrays must contain fully
formatted command line values for properties and options
(i.e. "-Dfoo=bar" or "-opt"). opts
must include a
-cp
or -classpath
option and its value must
completely specify the classpath required to run the subtask.javaCmd
- the java
command to execute, or
null
to create another instance of the
tool VMprops
- properties to define, which may be null
or
emptyopts
- options to define, which must include a classpath
definitionargs
- arguments to pass to the child VMSystem.out
stream.IllegalArgumentException
- if opts
does not
include a classpath definition, or if args[0]
does not contain the name of a class that implements
SubVMTask
public Object launch(NonActivatableServiceDescriptor d, SharedActivationGroupDescriptor gd, String taskName)
launch(d, g, taskName, null)
.d
- the services descriptor, which may be null
gd
- the group descriptor, which may be null
taskName
- the name of the subtask to runSystem.out
stream.public Object launch(NonActivatableServiceDescriptor d, SharedActivationGroupDescriptor gd, String taskName, String[] args)
If d
and gd
are both null
, then
calling this method is equivalent to calling
launch(taskName, args)
.
If d
is null
and gd
is
non-null
then the properties are taken from
gd.getServerProperties()
and the
java.security.policy
property is added or replaced with the
value of gd.getPolicy()
. The options are taken from
gd.getServerOptions()
, but any -cp/-classpath
option is discarded; a -cp
option is added that is the value
of gd.getClasspath()
augmented with the classpath of the
tool and plugins. If gd.getServerCommand()
is
non-null
, its value is used to invoke the child VM;
otherwise the java
command of the command line being
analyzed is used. The arguments passed to the child VM consist of an
array whose first element is taskName
and whose remaining
elements are taken from args
.
If d
is not null
, but gd
is
null
, then if d
is an instance of
SharedActivatableServiceDescriptor
an
IllegalArgumentException
is thrown. Otherwise the properties
and options are taken from the command line being analyzed. The
java.security.policy
property is added or replaced using the
value of d.getPolicy()
. The -cp/-classpath
option is replaced with the value of d.getImportCodebase()
augmented with the classpath of the tool and plugins. The arguments
passed to the child VM consist of taskName
followed by
args
if args
is non-null
, or
followed by d.getServerConfigArgs()
otherwise. The VM is
invoked using the java
command of the command line being
analyzed.
if d
and gd
are both non-null
then
if d
is an instance of
SharedActivatableServiceDescriptor
then the properties,
options, and java
command are taken from
gd.getServerProperties()
,
gd.getServerOptions()
, and
gd.getServerCommand()
; however, if the value of
gd.getServerCommand()
is null
, the
java
command is taken from the command line being
analysed. If d
is not an instance of
SharedActivatableServiceDescriptor
then the properties,
options, and java
command are taken from the command line
being analyzed. In all cases the java.security.policy
property is added or replaced using the value of
d.getPolicy()
. The -cp/-classpath
option is
added or replaced with the value of d.getImportCodebase()
augmented with the value of the classpath of the tool and plugins. The
arguments passed to the child VM consist of taskName
followed by args
if args
is
non-null
, or followed by
d.getServerConfigArgs()
otherwise.
d
- the service descriptor, which may be null
gd
- the group descriptor, which may be null
taskName
- the name of the subtask to runargs
- the arguments to pass to the child VM, which may be
null
System.out
stream.public String getJavaCmd()
java
command for the command line being analyzed.java
commandpublic String checkFile(String prop, String desc)
prop
- the name of the propertydesc
- a brief description of the filenull
if undefinedpublic String getJarToRun()
null
if the command line
did not specify one.public String getClasspath()
getJarToRun()
returns a non-null
value then
its value is returned. Otherwise the value supplied by the command
line -cp/-classpath
option is returned.Copyright © GigaSpaces.