package com.nailabs.abac.process;
import edu.stanford.peer.rbtm.credential.*;
public class AckFact {
/**
* This attribute defines the scope of the AckFact instance.
*/
protected EntityExpression attribute;
/**
* Optional string meta-identifier for the value field.
*/
protected String field;
/**
* Optional value corresponding to the named field.
*/
protected Object value;
/**
* The credential role required to match with the requesting subject.
*/
protected EntityExpression requirement;
/**
* A constant to represent a default value (aka a wildcard).
*/
static final String DEFAULT = "default";
/**
* A true constant for denoting that no requirements are necessary.
* This can also be implicitly represented as a null requirement.
*/
static final String TRUE = "true";
/**
* Basic constructor method. This method subtitutes a default key-value
* pair.
*/
public AckFact(EntityExpression attribute, EntityExpression req) {
this(attribute, DEFAULT, DEFAULT, req);
}
/**
* Explicit constructor method. This represents a fully expanded policy
* fact.
*/
public AckFact(EntityExpression attr,String key,Object val,EntityExpression req) {
attribute = attr;
field = key;
value = val;
requirement = req;
}
/**
* An accessor method for the attribute which needs to be unlocked.
* This is private policy information and should not be xmitted
*/
public RoleName getAttribute() {
if(attribute instanceof Role) {
return ((Role)attribute).getName();
}
else if(attribute instanceof LinkedRole) {
return ((LinkedRole)attribute).getFirstRole().getName();
}
else {
return null;
}
}
/**
* An accessor method for the optional special case meta-type.
* This is private policy information and should not be xmitted
*/
public String getField() { return field; }
/**
* An accessor method for the optional special case value.
* This is private policy information and should not be xmitted
*/
public Object getValue() { return value; }
/**
* An accessor method for an expression which can unlocked the attribute
* if the expression is proved to be true.
* This is public policy information but if transmitted may indicate
* that particular credential is possessed.
*/
public EntityExpression getRequirement() { return requirement; }
/**
* Unique hash function, which is based on the attribute's hash code.
*/
public int hashCode() { return attribute.hashCode(); }
/**
* Tabular printout of the fact in the following order: attribute,
* field, value, and attribute expression. The list is comma delimited.
*/
public String toString() {
StringBuffer buff = new StringBuffer("[AckFact ");
String separator = ", ";
buff.append(attribute).append(separator);
buff.append(field).append(separator);
buff.append(value).append(separator);
buff.append(requirement).append("]");
return buff.toString();
}
}