<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package extjtech;

import java.io.*;
import java.util.*;

import com.sssw.rt.util.*;
import com.sssw.rts.adminclient.*;
import com.sssw.rts.adminapi.*;

// The ExtAdmin class shows how you can access a SilverStream
// server from an external Java client. It includes an example
// of performing administrative operations on the server from
// the client. 
public class ExtAdmin {

     // Instance variable for the SilverStream server session 
     // object used by the ExtAdmin class.
     AgrServerSession session;

  // Constructor for the ExtAdmin class. It does the following:
  // * Connects to a SilverStream server
  // * Gets a reference to that server for doing administration
  //   work
  // * Generates a report about the server's users and groups  
  //
  // It takes 1 argument:
  // * SilverStream server host
  //     myserver
  public ExtAdmin(String s3serverhost) {

    try  {
      // Initialize the SilverStream runtime environment. Do
      // this if you need to specify a login handler for the 
      // SilverStream server to call back when it requires user
      // authentication. (The login handler is a class that you
      // code and instantiate.)
      AgRuntime.init(new LoginHandler());

      // Connect to the appropriate SilverStream server. This
      // establishes a server session (represented by an instance
      // of AgrServerSession).
      //
      // The following example connects via HTTP. In this case, 
      // you wouldn't use RMI-IIOP (the connectRMI method),
      // because it doesn't support the Server Administration
      // API.
      session = AgRuntime.connect(s3serverhost);


      // Get a reference to the server (represented by an instance
      // of AgiAdmServer) that enables you to perform administration
      // tasks.
      AgiAdmServer admserver = AgAdmin.getServer(session);


      // Generate a report about the server's Silver Security 
      // realm that lists:
      // * Each user
      // * All of the groups each user is in
       
        // Local variables for user and group information.
        AgiAdmDirectory userdir;
        Enumeration users;
        AgiAdmUser  user;
        Enumeration groups;
        AgiAdmGroup group;

        // Get a reference to the directory of users in the Silver 
        // Security realm.
        userdir = (AgiAdmDirectory)admserver.getElement(
                                             AgiAdmDirectory.SILVERUSERS,
                                             AgiAdmDirectory.SILVERUSERS,
                                             null);

        // Get a sorted list of the users in that directory.
        users = userdir.getChildren(AgiAdmContainer.GET_CHILDREN_SORTED);

        // Print the report title.
        System.out.println("&gt;&gt;&gt;Silver Security");
        System.out.println("   &gt;&gt;&gt;Users");

        // Loop through the user list.
        while (users.hasMoreElements()) {

          // Get and print information about an individual user.
          user = (AgiAdmUser)users.nextElement();
          System.out.println("      Name: " + user.getName());
          System.out.println("         Groups:");

          // Get a sorted list of the groups for the current user.
          groups = user.getGroups(true);

          // Loop through the group list.
          while (groups.hasMoreElements()) {

            // Get and print information about an individual group.
            group = (AgiAdmGroup)groups.nextElement();
            System.out.println("            " + group.getName());
          }
          System.out.println();
        }
        System.out.println("&lt;&lt;&lt;End of admin report");
    }
    catch (Exception e) {
      System.out.println("Application error in ExtAdmin");
      e.printStackTrace();
      System.exit(0);
    }
    finally {
      // When all done, close the SilverStream server session.
      session.close();
    }
  }


  // Main method (used for application startup).
  public static void main(String[] args) {

    if (args.length &lt; 1) {
      // Make sure all of the required command-line args
      // have been provided to the application. If not,
      // display an error message and terminate.
      System.out.println(
        "Missing Command-Line Arguments\n\n" +  
        "Required arguments:\n" +
          "*  SilverStream server host\n\n" +
        "Example:\n" + "java extjtech.ExtAdmin " +
          "myserver");
      System.exit(0);
    }
    else {
      // Get the command-line args so the application can
      // pass them to the ExtAdmin constructor.
      String s3serverhost = args[0];

      // Create an instance of ExtAdmin. This executes the 
      // constructor for the class, which then accesses the
      // SilverStream server and performs administrative
      // operations.
      ExtAdmin extadmin = new ExtAdmin(s3serverhost);
    }
  }
}
</pre></body></html>