FileDocCategorySizeDatePackage
SecureCreditAgent.javaAPI DocExample1700Tue Jul 08 12:45:44 BST 1997dcj.examples.security

SecureCreditAgent

public class SecureCreditAgent extends AuthAgent

Fields Summary
protected ACL
creditACL
Constructors Summary
public SecureCreditAgent(String host, int port)

    super(host, port);
    // Initialize our access control lists
    initACL();
  
Methods Summary
protected java.lang.StringgetCreditData(java.lang.String acctName)

    // Real method would use account name to
    // initiate a database query...
    return "No info available.";
  
protected voidinitACL()

    creditACL = new ACL();
    // Read resources and access permissions
    // from a database, initialize the ACL object
         .
         .
         .
  
protected booleanisAuthorized(Identity agent, java.lang.String acctName, java.lang.String access)

    boolean auth;
    Permission p = new PermissionImpl(access);
    auth = creditACL.checkPermission(agent, p);
    return auth;
  
protected voidprocessMsg(java.lang.String msg)

    String name = null;
    String cmd = null;
    String retMsg = new String();

    // Parse the command and account name from the input stream.
    StreamTokenizer stok = new StreamTokenizer(new StringReader(msg));
    try {
      stok.nextToken();
      cmd = stok.sval;
      name = stok.sval;
    }
    catch (IOException e) {}

    if (cmd.compareTo("GET") == 0) {
      if (isAuthorized(getAgentID(), name, "READ")) {
        String cData = getCreditData(name);
        retMsg = name + " " + cData;
      }
      else {
        retMsg = "UNAUTHORIZED";
      }
    }
    else {
      retMsg = "UNKNOWN_CMD";
    }

    // Add return message with results to the message queue.
    addMsg(retMsg);