package com.nailabs.abac.trust;
import com.nailabs.abac.process.*;
import edu.stanford.peer.rbtm.credential.*;
import java.util.*;
/**
* An instance of this class repsent a trust target of the form:
*
<V: e <-- S >
* where V is on the negotiators;
* e is a role expression called the target role; and
* S is a role expression called the subject role. S is frequently the
* opponent negotiator of V.
*/
public class TrustTarget extends Goal {
/** The target expression of this trust target */
protected EntityExpression targetRole;
/** Itemized default constructor */
public TrustTarget(Entity v, EntityExpression e, EntityExpression s)
throws TrustTargetParsingException, CredentialParsingException {
verifier = v;
targetRole = e;
subject = s;
}
/** Construct a new trust target from a string */
public TrustTarget(String s)
throws TrustTargetParsingException, CredentialParsingException {
StringTokenizer st = new StringTokenizer(s, ":-");
if(st.countTokens() < 3)
throw new TrustTargetParsingException("Too few elements!", s);
verifier = (Entity)
StaticCredential.getEntityExpression(st.nextToken().trim());
targetRole =
StaticCredential.getEntityExpression(st.nextToken().trim());
subject =
StaticCredential.getEntityExpression(st.nextToken().trim());
}
/** Unique hash function based on a verifier-target-subject triplet */
public int hashCode() {
return verifier.hashCode() * 4 + targetRole.hashCode() * 2 +
subject.hashCode();
}
/** accessor method for the target role expressin of this target */
public EntityExpression getTargetRole() { return targetRole; }
public String getType() {
if(targetRole instanceof Role) {
return new String("RoleTarget");
}
else if(targetRole instanceof LinkedRole) {
return new String("LinkedRoleTarget");
}
else if(targetRole instanceof Intersection) {
return new String("IntersectionTarget");
}
else if(targetRole instanceof Entity) {
return new String("TrivialTarget");
}
return new String("TrustTarget");
}
public ProcessingState getInitialProcessingState(NegotiationContext ctx) {
if(targetRole instanceof Entity) { // trivial trust target
return new ProcessingState(true, true);
}
else if(targetRole instanceof Role) { // simple trust target
RoleName r = ((Role)targetRole).getName();
if(ctx.subjectTracesAll(r))
return new ProcessingState(true, false);
else
return new ProcessingState(false, true);
}
else if(targetRole instanceof LinkedRole) { // linked role trust target
RoleName r1 = ((LinkedRole)targetRole).getFirstRole().getName();
RoleName r2 = ((LinkedRole)targetRole).getSecondRoleName();
if(ctx.subjectTracesAll(r1) && ctx.subjectTracesAll(r2)) {
return new ProcessingState(true, false);
}
else {
return new ProcessingState(false, true);
}
}
else if(targetRole instanceof Intersection) { // intersection TT
if(ctx.getSelf().equals(getVerifier())) {
return new ProcessingState(false, true);
} else {
return new ProcessingState(true, false);
}
}
return new ProcessingState();
}
public String toString() {
StringBuffer buff = new StringBuffer();
buff.append(getVerifier().toString()).append(": ");
buff.append(getTargetRole().toString());
buff.append(" <<-?- ").append(getSubject().toString());
//buff.append("]");
return buff.toString();
}
public String toXML() {
/*
StringBuffer buff = new StringBuffer("\n");
buff.append("\t");
buff.append(getVerifier().toString());
buff.append("\n");
buff.append("\t");
buff.append(getTargetRole().toString());
buff.append("\n");
buff.append("\t");
buff.append(getSubject().toString());
buff.append("\n");
buff.append("\n");
return buff.toString();
*/
return toString().replaceAll("<","<");
}
}