package com.nailabs.abac.credential; import edu.stanford.peer.rbtm.credential.*; import edu.stanford.rt.credential.Principal; /** * A hybrid entity instance which is RTML aware but can also emulate a simple * entity used by the RBTM package. */ public class RtmlEntity implements Entity { //The entity will have either a key OR a value but not both /** a base-64 encoded hash of the entity's key material */ protected String hashCode = null; /** a short name used in the RTML to refer back to a Principal */ protected String shortName = null; /** constructor for discovery service */ public RtmlEntity(String shortName) { this.shortName = shortName; } public RtmlEntity(String shortName, String hashCode) { this.shortName = shortName; this.hashCode = hashCode; } /** default constructor */ public RtmlEntity(String shortName, Principal principal) { this.shortName = shortName; hashCode = principal.toString(); } /** public accessor method for the abbreviated name of an entity */ public String getName() { return shortName; } /** public accessor method for the BASE-64 encoded signature hash */ public String getHash() { return hashCode; } /** public accessor method for the hash code of an entity's key material */ public int hashCode() { if(hashCode == null) { return shortName.hashCode(); } return hashCode.hashCode(); } /** * equivalency should be based on identical hash codes (but potentially * short names may be desired). */ public boolean equals(Object o) { // warning this is allows an RtmlEntity to be matched by EITHER // the hash or the short name. It should probably only be the hash. // The RtmlEngine may need to make sure entities have proper hash // codes. return(o.hashCode()==hashCode() || o.hashCode()==shortName.hashCode()); } /** compare to entities based on their unique hash codes */ public int compareTo(Object obj) { return obj.hashCode() - hashCode(); } /** returns the entity's unique hash code as a string */ public String toString() { return shortName; } }