[8780cbec] | 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 | * This is a specialized standard trust target which knows how to process |
---|
| 9 | * linked trust targets. |
---|
| 10 | */ |
---|
| 11 | public class LinkTTNode extends StandardTTNode { |
---|
| 12 | private LinkingGoal monitorId = null; |
---|
| 13 | |
---|
| 14 | /** default constructor for standard trust target node */ |
---|
| 15 | public LinkTTNode(TrustTarget target) { |
---|
| 16 | super(target); |
---|
| 17 | processor = new ProcessingState(false, false); |
---|
| 18 | subName = "LinkedTarget"; |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | public Role getFirstRole() { |
---|
| 22 | LinkedRole role = (LinkedRole)getTargetExpression(); |
---|
| 23 | return role.getFirstRole(); |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | public RoleName getSecondRoleName() { |
---|
| 27 | LinkedRole role = (LinkedRole)getTargetExpression(); |
---|
| 28 | return role.getSecondRoleName(); |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | protected void _process(NegotiationContext context) { |
---|
| 32 | TTG graph = context.getGraph(); |
---|
| 33 | |
---|
| 34 | if(monitorId == null) { |
---|
| 35 | try { |
---|
| 36 | Entity v = getVerifier(); |
---|
| 37 | EntityExpression s = getSubject(); |
---|
| 38 | monitorId = new LinkingGoal(v, getSecondRoleName(), s); |
---|
| 39 | } catch (Exception ex) { |
---|
| 40 | // add a warning message here--something has gone very wrong |
---|
| 41 | return; |
---|
| 42 | } |
---|
| 43 | } |
---|
| 44 | // 1. Add the (unique( linking-monitor edge, T <--< <V: ?X.r2 <<-?- S> |
---|
| 45 | if(!children.containsKey(monitorId)) { |
---|
| 46 | graph.addLinkingMonitorEdge((TrustTarget)getGoal(), monitorId); |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | // |
---|
| 50 | // This happens when the LinkingGoalNode is processed. It doesn't |
---|
| 51 | // actually happen here. |
---|
| 52 | // |
---|
| 53 | // 2. After (1) is done, V can add a linking implication edge |
---|
| 54 | // T <--< <V: A.r1 <<-?- B> for each linking-solution edge |
---|
| 55 | // <V: ?X.r2 <<-?- S> <--< <V: B.r2 <<-?- S> such that each |
---|
| 56 | // grandchild (<V: B.r2 <<-?- S>) is satisfied. |
---|
| 57 | // |
---|
| 58 | |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | /** |
---|
| 62 | * Process a node whose trust target verifier entity is not self |
---|
| 63 | * @see RMINegotiator |
---|
| 64 | */ |
---|
| 65 | public void opponentProcess(NegotiationContext context) { |
---|
| 66 | TTG graph = context.getGraph(); |
---|
| 67 | Entity v = getVerifier(); |
---|
| 68 | EntityExpression s = getSubject(); |
---|
| 69 | |
---|
| 70 | //Initialize the unique id for the linking monitor child linking goal |
---|
| 71 | if(monitorId == null) { |
---|
| 72 | try { |
---|
| 73 | monitorId = new LinkingGoal(v, getSecondRoleName(), s); |
---|
| 74 | } catch (Exception ex) { |
---|
| 75 | // add a warning message here--something has gone very wrong |
---|
| 76 | return; |
---|
| 77 | } |
---|
| 78 | } |
---|
| 79 | // 1. Add the (unique( linking-monitor edge, T <--< <V: ?X.r2 <<-?- S> |
---|
| 80 | if(!children.containsKey(monitorId)) { |
---|
| 81 | graph.addLinkingMonitorEdge((TrustTarget)getGoal(), monitorId); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | // |
---|
| 85 | // This happens when the LinkingGoalNode is processed. It doesn't |
---|
| 86 | // actually happen here. |
---|
| 87 | // |
---|
| 88 | // 2. After (1) is done, V can add a linking implication edge |
---|
| 89 | // T <--< <V: A.r1 <<-?- B> for each linking-solution edge |
---|
| 90 | // <V: ?X.r2 <<-?- S> <--< <V: B.r2 <<-?- S> such that each |
---|
| 91 | // grandchild (<V: B.r2 <<-?- S>) is satisfied. |
---|
| 92 | // |
---|
| 93 | |
---|
| 94 | LinkingGoalNode childNode = |
---|
| 95 | (LinkingGoalNode)graph.getNodeByHash(monitorId); |
---|
| 96 | _process(context); |
---|
| 97 | // 3. Mark this node verifier processed only after both 1 & 2 |
---|
| 98 | // are done and <V: ?X.r2 <<-?- S> has a complete completion state. |
---|
| 99 | if(childNode.getProcessingState().isOpponentProcessed() |
---|
| 100 | && childNode.isComplete()) { |
---|
| 101 | graph.setOpponentProcessed(getGoal()); |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | /** |
---|
| 107 | * Process a node whose trust target verifier entity is self |
---|
| 108 | * @see RMINegotiator |
---|
| 109 | */ |
---|
| 110 | public void verifierProcess(NegotiationContext context) { |
---|
| 111 | FrontierManager fm = context.getFrontier(); |
---|
| 112 | TTG graph = context.getGraph(); |
---|
| 113 | RoleName r1 = getFirstRole().getName(); |
---|
| 114 | |
---|
| 115 | // |
---|
| 116 | // If r1 is issuer-traces-def |
---|
| 117 | // |
---|
| 118 | if(fm.isIssuerTracesDef(r1)) { |
---|
| 119 | if(monitorId == null) { |
---|
| 120 | try { |
---|
| 121 | Entity v = getVerifier(); |
---|
| 122 | EntityExpression s = getSubject(); |
---|
| 123 | monitorId = new LinkingGoal(v, getSecondRoleName(), s); |
---|
| 124 | } catch (Exception ex) { |
---|
| 125 | // add a warning message here |
---|
| 126 | // something has gone very wrong!! |
---|
| 127 | return; |
---|
| 128 | } |
---|
| 129 | } |
---|
| 130 | // 1. Add the (unique) linking-monitor edge, |
---|
| 131 | // T <--< <V: ?X.r2 <<-?- S> |
---|
| 132 | if(!children.containsKey(monitorId)) { |
---|
| 133 | graph.addLinkingMonitorEdge((TrustTarget)getGoal(), monitorId); |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | // |
---|
| 137 | // This happens when the LinkingGoalNode is processed. It doesn't |
---|
| 138 | // actually happen here. |
---|
| 139 | // |
---|
| 140 | // 2. After (1) is done, V can add a linking implication edge |
---|
| 141 | // T <--< <V: A.r1 <<-?- B> for each linking-solution edge |
---|
| 142 | // <V: ?X.r2 <<-?- S> <--< <V: B.r2 <<-?- S> such that each |
---|
| 143 | // grandchild (<V: B.r2 <<-?- S>) is satisfied. |
---|
| 144 | // |
---|
| 145 | |
---|
| 146 | // 3. Mark this node verifier processed only after both 1 & 2 |
---|
| 147 | // are done and <V: ?X.r2 <<-?- S> has a complete completion state. |
---|
| 148 | LinkingGoalNode childNode = |
---|
| 149 | (LinkingGoalNode)graph.getNodeByHash(monitorId); |
---|
| 150 | if(childNode.getProcessingState().isVerifierProcessed() |
---|
| 151 | && childNode.isComplete()) { |
---|
| 152 | graph.setVerifierProcessed(getGoal()); |
---|
| 153 | } |
---|
| 154 | } |
---|
| 155 | // |
---|
| 156 | // If r1 is issuer-traces-all |
---|
| 157 | // |
---|
| 158 | if(fm.isIssuerTracesAll(r1)) { |
---|
| 159 | // 1. For each entity B such that A.r1 <<-?- B, and for each e |
---|
| 160 | // such that e is an element of oppoFrontier(B.r2), V can add a |
---|
| 161 | // standard implication edge T,--< <V: e <<-?- S> |
---|
| 162 | Iterator i = |
---|
| 163 | fm.getOppoLocal(getFirstRole()).resultSet().iterator(); |
---|
| 164 | while(i.hasNext()) { |
---|
| 165 | EntityExpression expr=(EntityExpression)i.next(); |
---|
| 166 | //debug("linked", "issuer-traces-all matched " + cred); |
---|
| 167 | try { |
---|
| 168 | if(expr instanceof Entity) { |
---|
| 169 | Entity b = (Entity)expr; |
---|
| 170 | Role bDotR2 = new Role(b, getSecondRoleName()); |
---|
| 171 | Iterator oppoSet = |
---|
| 172 | fm.getOppoFrontier(bDotR2).resultSet().iterator(); |
---|
| 173 | while(oppoSet.hasNext()) { |
---|
| 174 | EntityExpression e = (EntityExpression)oppoSet.next(); |
---|
| 175 | TrustTarget child = new |
---|
| 176 | TrustTarget(getVerifier(), e, getSubject()); |
---|
| 177 | //get evidence here |
---|
| 178 | graph.addImplicationEdge(getGoal(), child, null); |
---|
| 179 | } |
---|
| 180 | } |
---|
| 181 | } catch (Exception ex) { |
---|
| 182 | ex.printStackTrace(); |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | } |
---|
| 186 | // 2. V can mark T as verifier-processed only after step 1 is done |
---|
| 187 | graph.setVerifierProcessed(getGoal()); |
---|
| 188 | } |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | /** |
---|
| 192 | * A comparator function to see if the specified role matches the second |
---|
| 193 | * role name. |
---|
| 194 | */ |
---|
| 195 | protected boolean isLinkingSolution(Role r) { |
---|
| 196 | RoleName r2 = getSecondRoleName(); |
---|
| 197 | |
---|
| 198 | return (r2.equals(r.getName())); |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | /** |
---|
| 202 | * When the linking child monitor becomes complete, this node needs to |
---|
| 203 | * change it's processing state. |
---|
| 204 | * @param state The new satisfaction state to be propagated. |
---|
| 205 | */ |
---|
| 206 | public void receive(LinkingGoal source, CompletionState state) { |
---|
| 207 | TTG graph = getContext().getGraph(); |
---|
| 208 | FrontierManager fm = getContext().getFrontier(); |
---|
| 209 | Entity me = fm.getSelf(); |
---|
| 210 | RoleName r1 = getFirstRole().getName(); |
---|
| 211 | boolean subjectTraceable = fm.isSubjectTraceable(r1); |
---|
| 212 | |
---|
| 213 | if(state.isComplete() && source.equals(monitorId)) { |
---|
| 214 | if(me.equals(getVerifier())) { |
---|
| 215 | if(!subjectTraceable) { |
---|
| 216 | //if r1 is not subject traceable |
---|
| 217 | graph.setVerifierProcessed(getGoal()); |
---|
| 218 | } |
---|
| 219 | } else { |
---|
| 220 | if(subjectTraceable) { |
---|
| 221 | //if r1 is subject traceable |
---|
| 222 | graph.setOpponentProcessed(getGoal()); |
---|
| 223 | } |
---|
| 224 | } |
---|
| 225 | } |
---|
| 226 | } |
---|
| 227 | } |
---|