package edu.stanford.peer.rbtm.engine; import edu.stanford.peer.rbtm.credential.*; import edu.stanford.peer.rbtm.util.*; import java.util.*; /** * A predicate for determining whether a credential is sensitive. */ public class Sens implements Predicate { /** A list of sensitive credentials for this predicate */ protected Vector sens; /** * Create a new sens predicate with no sensitive credentials. */ public Sens() { sens = new Vector(); } /** * Create a new sens predicate with a list of pre-defined sensitive * credentials. */ public Sens(Vector creds) { sens = new Vector(); for(int i = 0; i < creds.size(); i++) { try { Role r = (Role)creds.elementAt(i); sens.addElement(r); } catch(Exception ex) { ex.printStackTrace(); } } } /** Mark a credential as sensitive w/o exposing internal data structures */ public void addSensCred(Role role) { sens.add(role); } /** Remove a credential from the sensitive list (opaquely) */ public void removeSensCred(Role role) { sens.remove(role); } /** * Predicate function to test whether the supplied role expression is * sensitive or not. The obj must be a credential for the test to succeed. * * @param obj a credential instance for the predicate to test * @return success of failure of the predicate */ public boolean test(EntityExpression obj) { if(!(obj instanceof Role))return true; Role role = (Role)obj; return (sens.contains(role)); /* if(!sens.contains(role)) { return false; } return true; */ } }