1 | package com.nailabs.abac.trust; |
---|
2 | |
---|
3 | import com.nailabs.abac.process.*; |
---|
4 | import edu.stanford.peer.rbtm.credential.*; |
---|
5 | import java.util.*; |
---|
6 | |
---|
7 | /** |
---|
8 | * An instance of this class repsent a trust target of the form: <BR> |
---|
9 | * <CENTER> <V: e <-- S > </CENTER> <BR> |
---|
10 | * where V is on the negotiators; |
---|
11 | * e is a role expression called the target role; and |
---|
12 | * S is a role expression called the subject role. S is frequently the |
---|
13 | * opponent negotiator of V. |
---|
14 | */ |
---|
15 | public class TrustTarget extends Goal { |
---|
16 | |
---|
17 | /** The target expression of this trust target */ |
---|
18 | protected EntityExpression targetRole; |
---|
19 | |
---|
20 | |
---|
21 | /** Itemized default constructor */ |
---|
22 | public TrustTarget(Entity v, EntityExpression e, EntityExpression s) |
---|
23 | throws TrustTargetParsingException, CredentialParsingException { |
---|
24 | verifier = v; |
---|
25 | targetRole = e; |
---|
26 | subject = s; |
---|
27 | } |
---|
28 | |
---|
29 | /** Construct a new trust target from a string */ |
---|
30 | public TrustTarget(String s) |
---|
31 | throws TrustTargetParsingException, CredentialParsingException { |
---|
32 | StringTokenizer st = new StringTokenizer(s, ":<?-"); |
---|
33 | if(st.countTokens() < 3) |
---|
34 | throw new TrustTargetParsingException("Too few elements!", s); |
---|
35 | verifier = (Entity) |
---|
36 | StaticCredential.getEntityExpression(st.nextToken().trim()); |
---|
37 | targetRole = |
---|
38 | StaticCredential.getEntityExpression(st.nextToken().trim()); |
---|
39 | subject = |
---|
40 | StaticCredential.getEntityExpression(st.nextToken().trim()); |
---|
41 | } |
---|
42 | |
---|
43 | /** Unique hash function based on a verifier-target-subject triplet */ |
---|
44 | public int hashCode() { |
---|
45 | return verifier.hashCode() * 4 + targetRole.hashCode() * 2 + |
---|
46 | subject.hashCode(); |
---|
47 | } |
---|
48 | |
---|
49 | |
---|
50 | /** accessor method for the target role expressin of this target */ |
---|
51 | public EntityExpression getTargetRole() { return targetRole; } |
---|
52 | |
---|
53 | |
---|
54 | public String getType() { |
---|
55 | if(targetRole instanceof Role) { |
---|
56 | return new String("RoleTarget"); |
---|
57 | } |
---|
58 | else if(targetRole instanceof LinkedRole) { |
---|
59 | return new String("LinkedRoleTarget"); |
---|
60 | } |
---|
61 | else if(targetRole instanceof Intersection) { |
---|
62 | return new String("IntersectionTarget"); |
---|
63 | } |
---|
64 | else if(targetRole instanceof Entity) { |
---|
65 | return new String("TrivialTarget"); |
---|
66 | } |
---|
67 | return new String("TrustTarget"); |
---|
68 | } |
---|
69 | |
---|
70 | public ProcessingState getInitialProcessingState(NegotiationContext ctx) { |
---|
71 | if(targetRole instanceof Entity) { // trivial trust target |
---|
72 | return new ProcessingState(true, true); |
---|
73 | } |
---|
74 | else if(targetRole instanceof Role) { // simple trust target |
---|
75 | RoleName r = ((Role)targetRole).getName(); |
---|
76 | if(ctx.subjectTracesAll(r)) |
---|
77 | return new ProcessingState(true, false); |
---|
78 | else |
---|
79 | return new ProcessingState(false, true); |
---|
80 | } |
---|
81 | else if(targetRole instanceof LinkedRole) { // linked role trust target |
---|
82 | RoleName r1 = ((LinkedRole)targetRole).getFirstRole().getName(); |
---|
83 | RoleName r2 = ((LinkedRole)targetRole).getSecondRoleName(); |
---|
84 | if(ctx.subjectTracesAll(r1) && ctx.subjectTracesAll(r2)) { |
---|
85 | return new ProcessingState(true, false); |
---|
86 | } |
---|
87 | else { |
---|
88 | return new ProcessingState(false, true); |
---|
89 | } |
---|
90 | } |
---|
91 | else if(targetRole instanceof Intersection) { // intersection TT |
---|
92 | if(ctx.getSelf().equals(getVerifier())) { |
---|
93 | return new ProcessingState(false, true); |
---|
94 | } else { |
---|
95 | return new ProcessingState(true, false); |
---|
96 | } |
---|
97 | } |
---|
98 | return new ProcessingState(); |
---|
99 | } |
---|
100 | |
---|
101 | public String toString() { |
---|
102 | StringBuffer buff = new StringBuffer(); |
---|
103 | buff.append(getVerifier().toString()).append(": "); |
---|
104 | buff.append(getTargetRole().toString()); |
---|
105 | buff.append(" <<-?- ").append(getSubject().toString()); |
---|
106 | //buff.append("]"); |
---|
107 | return buff.toString(); |
---|
108 | } |
---|
109 | |
---|
110 | public String toXML() { |
---|
111 | /* |
---|
112 | StringBuffer buff = new StringBuffer("<TrustTarget>\n"); |
---|
113 | buff.append("\t<Verifier>"); |
---|
114 | buff.append(getVerifier().toString()); |
---|
115 | buff.append("</Verifier>\n"); |
---|
116 | buff.append("\t<Target>"); |
---|
117 | buff.append(getTargetRole().toString()); |
---|
118 | buff.append("</Target>\n"); |
---|
119 | buff.append("\t<Subject>"); |
---|
120 | buff.append(getSubject().toString()); |
---|
121 | buff.append("</Subject>\n"); |
---|
122 | buff.append("</TrustTarget>\n"); |
---|
123 | return buff.toString(); |
---|
124 | */ |
---|
125 | return toString().replaceAll("<","<"); |
---|
126 | } |
---|
127 | } |
---|
128 | |
---|
129 | |
---|
130 | |
---|
131 | |
---|
132 | |
---|
133 | |
---|
134 | |
---|
135 | |
---|