Java Dynamic Management Kit 5.1 Tutorial

23.2.3 Running the Legacy Security Example With Context Checking

The ContextClient and ContextAgent applications in the examplesDir/legacy/Context directory also demonstrate the use of stackable MBean servers and context checking through the legacy HTTP connector.

If you have not done so already, compile all files in this directory with the javac command. For example, on the Solaris platform with the Korn shell, type:

$ cd examplesDir/legacy/Context/
$ javac -classpath classpath *.java
To Run the Legacy Security Example With Context Checking
  1. If the agent and client applications are not already running from the previous example, type the following commands in separate windows:

    $ java -classpath classpath ContextAgent

    $ java -classpath classpath ContextClient

    The classpath should include the current directory (.) for both applications because they rely on classes that were compiled in this directory.

  2. Press Enter in the client application to trigger another set of requests.

    The agent window displays the output of the ContextChecker class. We can see that the checkAny method verifies the “nice” context of every request and that the other checkers just print out their names, providing a trace of the request.

  3. Stop both applications by pressing Control-C in each of the windows.

  4. Restart both applications, but specify a different context string for the client:

    $ java -classpath classpath ContextAgent

    $ java -classpath classpath ContextClient -context BadToTheBone

    This time the context is not recognized. The agent raises a java.lang.SecurityException that is propagated to the client, which then exits.

  5. Press Control-C in the agent window to stop the ContextAgent application.