Index: fedd/abac-src/rbtm/credential/CVS/Entries
===================================================================
--- fedd/abac-src/rbtm/credential/CVS/Entries	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
+++ fedd/abac-src/rbtm/credential/CVS/Entries	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
@@ -0,0 +1,16 @@
+/Credential.java/1.2/Wed May 15 16:46:19 2002//
+/CredentialParsingException.java/1.1.1.1/Tue Nov 13 17:28:45 2001//
+/Entity.java/1.1.1.1/Tue Nov 13 17:28:45 2001//
+/EntityExpression.java/1.2/Thu Dec 13 02:11:33 2001//
+/Intersection.java/1.3/Thu Dec  6 01:18:07 2001//
+/LinkedRole.java/1.1.1.1/Tue Nov 13 17:28:45 2001//
+/PermissionExpression.java/1.1.1.1/Tue Nov 13 17:28:45 2001//
+/RPermission.java/1.1.1.1/Tue Nov 13 17:28:45 2001//
+/Role.java/1.1.1.1/Tue Nov 13 17:28:45 2001//
+/RoleExpression.java/1.1.1.1/Tue Nov 13 17:28:45 2001//
+/RoleName.java/1.1.1.1/Tue Nov 13 17:28:45 2001//
+/SimpleEntity.java/1.1.1.1/Tue Nov 13 17:28:45 2001//
+/SimpleRoleName.java/1.1.1.1/Tue Nov 13 17:28:45 2001//
+/StaticCredential.java/1.7/Fri May 17 16:17:54 2002//
+/package.html/1.2/Tue Dec 18 01:38:12 2001//
+D
Index: fedd/abac-src/rbtm/credential/CVS/Repository
===================================================================
--- fedd/abac-src/rbtm/credential/CVS/Repository	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
+++ fedd/abac-src/rbtm/credential/CVS/Repository	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
@@ -0,0 +1,1 @@
+rbtm/credential
Index: fedd/abac-src/rbtm/credential/CVS/Root
===================================================================
--- fedd/abac-src/rbtm/credential/CVS/Root	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
+++ fedd/abac-src/rbtm/credential/CVS/Root	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
@@ -0,0 +1,1 @@
+:ext:jjacobs@src.columbia.sparta.com/cvs/abac
Index: fedd/abac-src/rbtm/credential/Credential.java
===================================================================
--- fedd/abac-src/rbtm/credential/Credential.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
+++ fedd/abac-src/rbtm/credential/Credential.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
@@ -0,0 +1,29 @@
+/*
+ * Credential.java
+ */
+
+package edu.stanford.peer.rbtm.credential;
+
+/**
+ * Credential is the top level class for credentials in RBTM framework.  It is 
+ * an abstract class, and has two direct sub-classes: StaticCredential and 
+ * DynamicCredential.
+ */
+public abstract class Credential implements java.io.Serializable
+                            // extends java.security.cert.Certificate
+{
+    /**
+     * Constructor for Role-Based Trust Management certificates.
+    protected Credential() {
+        super("RBTM");
+    }
+     */
+
+    /**
+     * Get the issuer of this credential.
+     */
+    public abstract Entity getIssuer();
+
+    /** converts the credential into an XML formatted string */
+    public abstract String toXML();
+}
Index: fedd/abac-src/rbtm/credential/CredentialParsingException.java
===================================================================
--- fedd/abac-src/rbtm/credential/CredentialParsingException.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
+++ fedd/abac-src/rbtm/credential/CredentialParsingException.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
@@ -0,0 +1,7 @@
+
+package edu.stanford.peer.rbtm.credential;
+
+public class CredentialParsingException extends Exception
+{
+    CredentialParsingException(String info) { super(info); }
+}
Index: fedd/abac-src/rbtm/credential/Entity.java
===================================================================
--- fedd/abac-src/rbtm/credential/Entity.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
+++ fedd/abac-src/rbtm/credential/Entity.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
@@ -0,0 +1,13 @@
+/*
+ * Entity.java
+ */
+
+package edu.stanford.peer.rbtm.credential;
+
+/**
+ * An object of the Entity class represents an entity (or a principal) in RBTM.
+ */
+public interface Entity extends EntityExpression, java.io.Serializable, Comparable
+{
+    String getName();
+}
Index: fedd/abac-src/rbtm/credential/EntityExpression.java
===================================================================
--- fedd/abac-src/rbtm/credential/EntityExpression.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
+++ fedd/abac-src/rbtm/credential/EntityExpression.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
@@ -0,0 +1,18 @@
+package edu.stanford.peer.rbtm.credential;
+
+import edu.stanford.peer.rbtm.engine.*;
+
+/**
+ * An EntityExpression can be one of the following:
+ * <UL>
+ *   <LI>an Entity
+ *   <LI>a Role
+ *   <LI>a LinkedRole
+ *   <LI>an Intersection.
+ * </UL>
+ *  Currently it is a marker interface
+ */
+public interface EntityExpression 
+		extends ForwardSolution, BackwardSolution, java.io.Serializable
+{
+}
Index: fedd/abac-src/rbtm/credential/Intersection.java
===================================================================
--- fedd/abac-src/rbtm/credential/Intersection.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
+++ fedd/abac-src/rbtm/credential/Intersection.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
@@ -0,0 +1,90 @@
+package edu.stanford.peer.rbtm.credential;
+
+import java.util.*;
+
+public class Intersection implements EntityExpression
+{
+    /**
+     * The parts of the intersection
+     */
+    protected LinkedList parts;
+
+    /** 
+     * Default constructor. Expressions to be intersected may be added using
+     * the and() method.
+     */
+    public Intersection() {  parts = new LinkedList(); }
+
+    /**
+     * Default copy constructor. All part references are duplicated, so the
+     * new copy is not relying on the old ones parts list.
+     */
+    public Intersection(Intersection i) {
+	this();
+	Iterator it = i.getParts();
+	while(it.hasNext())
+	    parts.add(it.next());
+    }
+    
+    /**
+     * Adds a new expression to this intersection. And() calls may be 
+     * concatenated similar to appending with a StringBuffer instance.
+     * @param expr An expression to be added (a role or linked role)
+     * @return The updated intersection expression
+     */
+    public Intersection and(EntityExpression expr) {
+	parts.add(expr);
+	return this;
+    }
+
+    /**
+     * Public accessor method for accessing each expression in the 
+     * intersection. 
+     */
+    public Iterator getParts() { return parts.iterator(); }
+
+    /**
+     * Public access method for determining the number of subexpressions
+     * contained in this intersection.
+     */
+    public int getPartsCount() { return parts.size(); }
+
+    /**
+     * Compare the parts of two intersections.
+     * @return a boolean result for equivalence
+     */
+    public boolean equals(Object o) {
+	return (o instanceof Intersection)
+	    &&  parts.equals(((Intersection)o).parts);
+    }
+
+    /**
+     * 
+     * @return a unique hashcode base on the parts of the intersection.
+     */
+    public int hashCode() { return parts.hashCode(); }
+
+    /**
+     * Converts the intersection into a human readable form. Expressions
+     * are separated using a '^' symbol to represent an intersection.
+     *
+     * @return formatted string representation of an intersection
+     */
+    public String toString() {
+	Iterator i = getParts();
+	StringBuffer buff = new StringBuffer();
+
+	while(i.hasNext()) {
+	    buff.append(i.next().toString());
+	    if(i.hasNext())buff.append(" ^ ");
+	}
+	return buff.toString();
+    }
+      
+	    
+
+}
+
+
+
+
Index: fedd/abac-src/rbtm/credential/LinkedRole.java
===================================================================
--- fedd/abac-src/rbtm/credential/LinkedRole.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
+++ fedd/abac-src/rbtm/credential/LinkedRole.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
@@ -0,0 +1,103 @@
+/*
+ * LinkedRole.java
+ */
+
+package edu.stanford.peer.rbtm.credential;
+
+import java.util.*;
+
+/**
+ * Represent a LinkedRole.
+ */
+public class LinkedRole implements EntityExpression
+{
+    private Role        firstRole;
+    private RoleName    secondName;
+
+	public LinkedRole(Role r, RoleName n) { firstRole = r;  secondName = n; }
+
+	public LinkedRole(Role r, String n) { 
+		firstRole = r;
+		secondName = new SimpleRoleName(n);
+	}
+
+	public LinkedRole(Entity issuer, String n1, String n2) {
+		firstRole = new Role(issuer, n1);
+		secondName = new SimpleRoleName(n2);
+	}
+
+	public LinkedRole(String issuer, String n1, String n2) {
+		firstRole = new Role(issuer, n1);
+		secondName = new SimpleRoleName(n2);
+	}
+
+    public int hashCode() {  
+        return firstRole.hashCode() * 2 + secondName.hashCode();
+    }
+
+    public boolean equals(Object o) {
+        return (o instanceof LinkedRole) 
+               && firstRole.equals(((LinkedRole)o).firstRole)
+               && secondName.equals(((LinkedRole)o).secondName);
+    }
+
+    public String toString() {
+        return firstRole.toString() + "." + secondName.toString();
+    }
+
+    public Role getFirstRole() {
+        return firstRole;
+    }
+
+    public RoleName getSecondRoleName() {
+        return secondName;
+    }
+    //public Entity getIssuer() { return (Entity)_names.get(0); }
+
+/*
+    public LinkedRole(String[] strs) {
+        _names = new ArrayList();
+        _names.add(new Entity(strs[0]));
+        for (int i=1; i<strs.length; i++) {
+            _names.add(new SimpleRoleName(strs[i]));
+        }
+    }
+
+    public LinkedRole(ArrayList strs) {
+        _names = new ArrayList();
+        _names.add(new Entity((String)strs.get(0)));
+        for (int i=1; i<strs.size(); i++) {
+            _names.add(new SimpleRoleName((String) strs.get(i)));
+        }
+    }
+    public int hashCode() {
+        long value = 0;
+        for (int i=0; i<_names.size(); i++) {
+            value *= 2;
+            value += _names.get(i).hashCode();
+        }
+        return (int)value;
+    }
+    public boolean equals(Object o) 
+    {
+        return (o instanceof LinkedRole) &&
+               _names.equals(((LinkedRole)o)._names);
+    }
+    public String toString() {
+        StringBuffer buf = new StringBuffer();
+        buf.append("(").append(_names.get(0));
+        for (int i=1; i<_names.size(); i++) {
+            buf.append("'s ").append(_names.get(i));
+        }
+        buf.append(")");
+        return buf.toString();
+    }
+    public RoleName getIthRoleName(int i) { return (RoleName)_names.get(i); }
+
+    public RoleName getLastRoleName() { 
+        return (RoleName)_names.get(_names.size()-1); 
+    }
+
+*/
+
+}
Index: fedd/abac-src/rbtm/credential/PermissionExpression.java
===================================================================
--- fedd/abac-src/rbtm/credential/PermissionExpression.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
+++ fedd/abac-src/rbtm/credential/PermissionExpression.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
@@ -0,0 +1,10 @@
+
+package edu.stanford.peer.rbtm.credential;
+
+/**
+ * An EntityExpression can be: an Entity, a Role, a LinkedRole, or an Intersection.
+ * Right now, it is just a marker interface
+ */
+public interface PermissionExpression
+{
+}
Index: fedd/abac-src/rbtm/credential/RPermission.java
===================================================================
--- fedd/abac-src/rbtm/credential/RPermission.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
+++ fedd/abac-src/rbtm/credential/RPermission.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
@@ -0,0 +1,9 @@
+/*
+ * Permission.java
+ */
+
+package edu.stanford.peer.rbtm.credential;
+
+public interface RPermission extends RoleName 
+{
+}
Index: fedd/abac-src/rbtm/credential/Role.java
===================================================================
--- fedd/abac-src/rbtm/credential/Role.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
+++ fedd/abac-src/rbtm/credential/Role.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
@@ -0,0 +1,57 @@
+/*
+ * Role.java
+ */
+
+package edu.stanford.peer.rbtm.credential;
+
+import java.util.*;
+
+public class Role implements EntityExpression, PermissionExpression, java.io.Serializable
+{
+    private Entity    _base;
+    private RoleName  _name;
+
+    public Role(Entity e, RoleName n) { _base = e; _name = n; }
+
+	public Role(Entity e, String n) {
+		_base = e;
+		_name = new SimpleRoleName(n);
+	}
+
+    public Role(String e, String n) { 
+        _base = new SimpleEntity(e);
+        _name = new SimpleRoleName(n); 
+    }
+
+    /*
+	public Role(RoleName name) {
+		this(Entity.self, name);
+	}
+
+	public Role(String name) {
+		this(Entity.self, name);
+	}
+    */
+
+    public Entity getBase() { return _base; }
+
+    public RoleName getName() { return _name; }
+
+    public String toString() {
+        return _base.toString() + "." + _name.toString();
+    }
+
+    public int hashCode() {
+        return getBase().hashCode() * 2 + getName().hashCode();
+    }
+
+    public boolean equals(Object o) {
+        return (o instanceof Role) &&
+               getBase().equals(((Role)o).getBase()) &&
+               getName().equals(((Role)o).getName());
+    }
+
+	public boolean isPermission() {
+		return _name instanceof RPermission;
+	}
+}
Index: fedd/abac-src/rbtm/credential/RoleExpression.java
===================================================================
--- fedd/abac-src/rbtm/credential/RoleExpression.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
+++ fedd/abac-src/rbtm/credential/RoleExpression.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
@@ -0,0 +1,10 @@
+
+package edu.stanford.peer.rbtm.credential;
+
+/**
+ * An RoleExpression can be: an Entity, a Role, a LinkedRole, or an Intersection.
+ * Right now, it is just a marker interface
+ */
+public interface RoleExpression
+{
+}
Index: fedd/abac-src/rbtm/credential/RoleName.java
===================================================================
--- fedd/abac-src/rbtm/credential/RoleName.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
+++ fedd/abac-src/rbtm/credential/RoleName.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
@@ -0,0 +1,10 @@
+/*
+ * RoleName.java
+ */
+
+package edu.stanford.peer.rbtm.credential;
+
+public interface RoleName extends java.io.Serializable, Comparable
+{
+    String getName();
+}
Index: fedd/abac-src/rbtm/credential/SimpleEntity.java
===================================================================
--- fedd/abac-src/rbtm/credential/SimpleEntity.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
+++ fedd/abac-src/rbtm/credential/SimpleEntity.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
@@ -0,0 +1,49 @@
+/*
+ * Entity.java
+ */
+
+package edu.stanford.peer.rbtm.credential;
+
+import java.io.*;
+//import java.security.*;
+
+/**
+ * An object of the Entity class represents an entity (or a principal) in RBTM.
+ */
+public class SimpleEntity implements Entity
+{
+    private String    _name;
+
+    public SimpleEntity(String n) 
+    { 
+        _name = n; 
+/* 
+        // code to gegerate public key
+        KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA", "SUN");
+        SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN");
+
+        keyGen.initialize(1024, random);
+
+        KeyPair pair = keyGen.generateKeyPair();
+        PrivateKey priv = pair.getPrivate();
+        PublicKey pub = pair.getPublic();
+*/
+    }
+
+    public String getName()     { return _name; }
+
+    public String toString()     { return _name;  }
+
+    public int hashCode()         { return _name.hashCode(); }
+
+    public boolean equals(Object o) {
+        return ((o instanceof SimpleEntity) 
+		       && _name.equals(((SimpleEntity)o)._name));
+    }
+
+    public int compareTo(Object o) {
+        return _name.compareTo(((SimpleEntity)o)._name);
+    }
+
+    //public java.security.PublicKey getPublicKey() { return null; }
+}
Index: fedd/abac-src/rbtm/credential/SimpleRoleName.java
===================================================================
--- fedd/abac-src/rbtm/credential/SimpleRoleName.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
+++ fedd/abac-src/rbtm/credential/SimpleRoleName.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
@@ -0,0 +1,27 @@
+/*
+ * RoleName.java
+ */
+
+package edu.stanford.peer.rbtm.credential;
+
+public class SimpleRoleName implements RoleName
+{
+    private String _name;
+
+    public SimpleRoleName(String n)   { _name = n; }
+
+    public String getName()     { return _name; }
+
+    public String toString()    { return _name; }
+
+    public int hashCode()       { return _name.hashCode(); }
+
+    public boolean equals(Object o) {
+        return (o instanceof SimpleRoleName) 
+		      && _name.equals(((SimpleRoleName)o)._name);
+    }
+
+	public int compareTo(Object o) {
+		return _name.compareTo(((SimpleRoleName)o)._name);
+	}
+}
Index: fedd/abac-src/rbtm/credential/StaticCredential.java
===================================================================
--- fedd/abac-src/rbtm/credential/StaticCredential.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
+++ fedd/abac-src/rbtm/credential/StaticCredential.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
@@ -0,0 +1,138 @@
+/*
+ * StaticCredential.java
+ */
+
+package edu.stanford.peer.rbtm.credential;
+
+import  edu.stanford.peer.rbtm.util.*;
+import java.util.*;
+
+/**
+ * StaticCredential 
+ */
+public class StaticCredential extends Credential
+{
+    private Role      role;
+    private EntityExpression subject;
+
+    public StaticCredential(Role r, EntityExpression s) { 
+        role = r;  
+        subject = s; 
+    }
+    public StaticCredential(String str) 
+	throws CredentialParsingException {
+	StringTokenizer st = new StringTokenizer(str, "<-");
+	//Debug.debugInfo("StaticCredential: cred string " + str + 
+	//		" contains " + st.countTokens() + " tokens");
+	String lhs = st.nextToken().trim();
+	String rhs = st.nextToken().trim();
+	//Debug.debugInfo("StaticCredential: lhs = " + lhs);
+	//Debug.debugInfo("StaticCredential: rhs = " + rhs);
+	role = (Role)getRole(lhs);
+	subject = getEntityExpression(rhs);
+    }
+
+    public StaticCredential(Entity issuer, RoleName n, EntityExpression s) { 
+        role = new Role(issuer, n);
+        subject = s; 
+    }
+
+    public StaticCredential(String e, String rn, String es) 
+                    throws CredentialParsingException  
+    {
+        role = new Role(new SimpleEntity(e), new SimpleRoleName(rn));
+        subject = StaticCredential.getEntityExpression(es);
+    }
+
+    public Entity getIssuer()       { return role.getBase(); }
+
+    //public Role   getRole()         { return role; }
+
+    public Role   getDefinedRole()         { return role; }
+
+    public EntityExpression getSubject()   { return subject; }
+
+    public String toString() {
+        return role.toString() + "<-" + subject.toString();
+    }
+
+    public String toXML() {
+	StringBuffer buff = new StringBuffer("<Credential ");
+	buff.append(" definedRole=\"").append(role).append("\"");
+	buff.append(" subject=\"").append(subject).append("\"");
+	buff.append("/>\n");
+	return buff.toString();
+    }
+
+    public int hashCode() {
+        return role.hashCode() * 2 + subject.hashCode();
+    }
+
+    public boolean equals(Object o) 
+    {
+        return (o instanceof StaticCredential) &&
+               role.equals(((StaticCredential)o).role) &&
+               subject.equals(((StaticCredential)o).subject);
+    }
+
+    public static EntityExpression getRole(String str) 
+	throws CredentialParsingException {
+	EntityExpression expr = null;
+	StringTokenizer st = new StringTokenizer(str.trim(), ".");
+	int count = st.countTokens();
+	String error = null;
+	
+	if(count <= 0) {
+	    error = "Role expression contained one or less parts!";
+	}
+	else if(count == 2) {
+	    expr = (EntityExpression) new Role(st.nextToken(), st.nextToken());
+	}
+	else if(count == 3) {
+	    expr = (EntityExpression)
+		new LinkedRole(st.nextToken(),st.nextToken(), st.nextToken());
+	}
+	else {
+	    error = "Role " + str + " expression contained too many role names";
+	}
+	if(expr == null) {
+	    throw new CredentialParsingException(error);
+	}
+	return expr;
+    }
+
+    /** creates a new Intersection from a string */
+    public static Intersection getIntersection(String str) 
+	throws CredentialParsingException {
+	StringTokenizer st = new StringTokenizer(str, "^");
+	int count = st.countTokens();
+	Intersection i = new Intersection();
+
+	for(int j = 0; j < count; j++) {
+	    i.and(getEntityExpression(st.nextToken()));
+	}
+	return i;
+    }
+
+    /** creates a new SimpleEntity instance from a string */
+    public static Entity getEntity(String str) 
+	throws CredentialParsingException {
+	return new SimpleEntity(str.trim());
+    }
+
+    /**
+     * converts a String into an EntityExpression, deals with Entity, Role,  
+     * LinkedRole, and Intersection. This method uses helper functions for
+     * parsiing entities, roles, and intersections, so these methods may be
+     * overridden in subclassing implementations.
+     */
+    public static EntityExpression getEntityExpression(String str) 
+	throws CredentialParsingException {
+	if(str.indexOf("^") > 0)
+	    return (EntityExpression)getIntersection(str);
+	if(str.indexOf(".") > 0)
+	    return getRole(str);
+	return (EntityExpression)getEntity(str);
+    }
+
+}
Index: fedd/abac-src/rbtm/credential/package.html
===================================================================
--- fedd/abac-src/rbtm/credential/package.html	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
+++ fedd/abac-src/rbtm/credential/package.html	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
@@ -0,0 +1,4 @@
+<BODY>
+<P>A package containing data types for representing credentials of types I-IV. 
+</P>
+</BODY>
