Changeset 1522
- Timestamp:
- 03/08/07 11:09:10
(2 years ago)
- Author:
- dsugar
- Message:
fix problem with changing the baseresource or basedomain described in ticket:120
Turns out there were a couple of hidden problems with multiple accesses being created which were also fixed.
Also some cleanup.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r1411 |
r1522 |
|
| 23 | 23 | |
|---|
| 24 | 24 | /** the domain associated with the access */ |
|---|
| 25 | | protected final IDomain Domain; |
|---|
| | 25 | private IDomain Domain; |
|---|
| 26 | 26 | |
|---|
| 27 | | protected final Component resource; |
|---|
| | 27 | private Component resource; |
|---|
| 28 | 28 | |
|---|
| 29 | 29 | /** the verb associated defining the type of access */ |
|---|
| … | … | |
| 64 | 64 | } |
|---|
| 65 | 65 | |
|---|
| | 66 | /** |
|---|
| | 67 | * setResource - update the resource for this access. |
|---|
| | 68 | * Will modify the list of accesses for the resource. |
|---|
| | 69 | */ |
|---|
| | 70 | public void setResource (Component i_Component) |
|---|
| | 71 | { |
|---|
| | 72 | Policy pol = resource.getPolicy(); |
|---|
| | 73 | if (pol != null) |
|---|
| | 74 | pol.RemoveAccess(this); |
|---|
| | 75 | else |
|---|
| | 76 | resource.Remove(this); |
|---|
| | 77 | resource = i_Component; |
|---|
| | 78 | pol = resource.getPolicy(); |
|---|
| | 79 | if (pol != null) |
|---|
| | 80 | pol.AddAccess(this); |
|---|
| | 81 | else |
|---|
| | 82 | resource.Add(this); |
|---|
| | 83 | } |
|---|
| | 84 | |
|---|
| | 85 | /** |
|---|
| | 86 | * setDomain - update the domain for this access. |
|---|
| | 87 | * Will modify the list of accesses for the domain. |
|---|
| | 88 | * @param i_domain |
|---|
| | 89 | */ |
|---|
| | 90 | public void setDomain (IDomain i_domain) |
|---|
| | 91 | { |
|---|
| | 92 | Policy pol = Domain.getPolicy (); |
|---|
| | 93 | if (pol != null) |
|---|
| | 94 | pol.RemoveAccess(this); |
|---|
| | 95 | else |
|---|
| | 96 | Domain.Remove(this); |
|---|
| | 97 | Domain = i_domain; |
|---|
| | 98 | pol = Domain.getPolicy(); |
|---|
| | 99 | if (pol != null) |
|---|
| | 100 | pol.AddAccess(this); |
|---|
| | 101 | else |
|---|
| | 102 | Domain.Add(this); |
|---|
| | 103 | } |
|---|
| | 104 | |
|---|
| 66 | 105 | public abstract boolean Validate(); |
|---|
| 67 | 106 | |
|---|
| r1472 |
r1522 |
|
| 21 | 21 | import com.tresys.framework.compiler.dictionary.Verb; |
|---|
| 22 | 22 | import com.tresys.framework.compiler.linkage.flnkage.BaseAccessDefn; |
|---|
| | 23 | import com.tresys.framework.compiler.linkage.flnkage.BaseAccessDefnGroup; |
|---|
| 23 | 24 | |
|---|
| 24 | 25 | import com.tresys.slide.utility.policyxmlparser.Interface; |
|---|
| … | … | |
| 45 | 46 | public void ResetToDefaults() { |
|---|
| 46 | 47 | baseAccessDefns.clear(); |
|---|
| 47 | | baseAccessDefns.addAll(GetBaseResource().GetAccessGroup(verb()).GetDefaultAccessDefns()); |
|---|
| | 48 | BaseAccessDefnGroup group = GetBaseResource().GetAccessGroup(verb()); |
|---|
| | 49 | if (group != null) |
|---|
| | 50 | baseAccessDefns.addAll(group.GetDefaultAccessDefns()); |
|---|
| 48 | 51 | isDefault = true; |
|---|
| 49 | 52 | } |
|---|
| … | … | |
| 62 | 65 | |
|---|
| 63 | 66 | public BaseResource GetBaseResource() { |
|---|
| 64 | | return (BaseResource) resource; |
|---|
| | 67 | return (BaseResource) getResource (); |
|---|
| 65 | 68 | } |
|---|
| 66 | 69 | |
|---|
| … | … | |
| 133 | 136 | */ |
|---|
| 134 | 137 | /*@Override*/public String toString() { |
|---|
| 135 | | return Domain.toString() + Utility.DELIM + GetBaseResource().toString() |
|---|
| | 138 | return getDomain().toString() + Utility.DELIM + GetBaseResource().toString() |
|---|
| 136 | 139 | + Utility.DELIM + Verb.toString(this.m_verb); |
|---|
| 137 | 140 | } |
|---|
| 138 | 141 | |
|---|
| 139 | 142 | public boolean Validate() { |
|---|
| 140 | | if(Domain.GetChildDomains().size() > 0) { |
|---|
| | 143 | if(getDomain().GetChildDomains().size() > 0) { |
|---|
| 141 | 144 | /*for (Domain child: Domain.GetChildDomains())*/ |
|---|
| 142 | | Iterator iter = Domain.GetChildDomains().values().iterator(); |
|---|
| | 145 | Iterator iter = getDomain().GetChildDomains().values().iterator(); |
|---|
| 143 | 146 | while(iter.hasNext()) { |
|---|
| 144 | 147 | Domain child = (Domain) iter.next(); |
|---|
| … | … | |
| 154 | 157 | } |
|---|
| 155 | 158 | } |
|---|
| 156 | | Token.Error("Access from parent not used by any children", ErrorHandler.ERROR_UNUSED_ACCESS, Domain.getName()); |
|---|
| | 159 | Token.Error("Access from parent not used by any children", ErrorHandler.ERROR_UNUSED_ACCESS, getDomain().getName()); |
|---|
| 157 | 160 | return false; |
|---|
| 158 | 161 | } |
|---|
| 159 | 162 | |
|---|
| 160 | 163 | // If the domain and the resource have the same parent, there are no constraints |
|---|
| 161 | | Domain domainParent = Domain.getParent(); |
|---|
| | 164 | Domain domainParent = getDomain().getParent(); |
|---|
| 162 | 165 | |
|---|
| 163 | 166 | if(domainParent != null) { |
|---|
| r1411 |
r1522 |
|
| 23 | 23 | public boolean Validate() { |
|---|
| 24 | 24 | // If the domain and the resource have the same parent, there are no constraints |
|---|
| 25 | | Domain domainParent = Domain.getParent(); |
|---|
| | 25 | Domain domainParent = getDomain().getParent(); |
|---|
| 26 | 26 | |
|---|
| 27 | 27 | if(domainParent != null) { |
|---|
| r1472 |
r1522 |
|
| 80 | 80 | } |
|---|
| 81 | 81 | |
|---|
| 82 | | public Component getResource() { |
|---|
| 83 | | return resource; |
|---|
| 84 | | } |
|---|
| 85 | | |
|---|
| 86 | 82 | /** |
|---|
| 87 | 83 | * Add access definition to list of those for this access |
|---|
| … | … | |
| 152 | 148 | AccessDefnGroup rdefGroup; |
|---|
| 153 | 149 | |
|---|
| 154 | | Map rdefs = ((Resource) resource).GetRdefs(); |
|---|
| | 150 | Map rdefs = ((Resource) getResource ()).GetRdefs(); |
|---|
| 155 | 151 | Iterator itr = rdefs.values().iterator(); |
|---|
| 156 | 152 | while (itr.hasNext()) |
|---|
| … | … | |
| 176 | 172 | */ |
|---|
| 177 | 173 | /*@Override*/public String toString() { |
|---|
| 178 | | return Domain.toString() + Utility.DELIM + getResource().toString() |
|---|
| | 174 | return getDomain().toString() + Utility.DELIM + getResource().toString() |
|---|
| 179 | 175 | + Utility.DELIM + Verb.toString(this.m_verb); |
|---|
| 180 | 176 | } |
|---|
| … | … | |
| 206 | 202 | |
|---|
| 207 | 203 | public boolean Validate() { |
|---|
| 208 | | if(Domain.GetChildDomains().size() > 0) { |
|---|
| | 204 | if(getDomain().GetChildDomains().size() > 0) { |
|---|
| 209 | 205 | /*for (Domain child: Domain.GetChildDomains())*/ |
|---|
| 210 | | Iterator iter = Domain.GetChildDomains().values().iterator(); |
|---|
| | 206 | Iterator iter = getDomain().GetChildDomains().values().iterator(); |
|---|
| 211 | 207 | while(iter.hasNext()) { |
|---|
| 212 | 208 | Domain child = (Domain) iter.next(); |
|---|
| … | … | |
| 221 | 217 | } |
|---|
| 222 | 218 | } |
|---|
| 223 | | Token.Error("AccessResource from parent not used by any children", ErrorHandler.ERROR_UNUSED_ACCESS, Domain.getName()); |
|---|
| | 219 | Token.Error("AccessResource from parent not used by any children", ErrorHandler.ERROR_UNUSED_ACCESS, getDomain().getName()); |
|---|
| 224 | 220 | return false; |
|---|
| 225 | 221 | } |
|---|
| … | … | |
| 231 | 227 | |
|---|
| 232 | 228 | // If the domain and the resource have the same parent, there are no constraints |
|---|
| 233 | | Domain domainParent = Domain.getParent(); |
|---|
| 234 | | |
|---|
| 235 | | if(domainParent != null && domainParent != resource.getParent()) { |
|---|
| | 229 | Domain domainParent = getDomain().getParent(); |
|---|
| | 230 | |
|---|
| | 231 | if(domainParent != null && domainParent != getResource ().getParent()) { |
|---|
| 236 | 232 | |
|---|
| 237 | 233 | Map/*<Component, Access>*/parentAccesses = domainParent.GetAccessMap(m_verb.intValue()); |
|---|
| … | … | |
| 242 | 238 | + domainParent.getName() |
|---|
| 243 | 239 | + "\"'s access to resource \"" |
|---|
| 244 | | + resource.getName() + "\""); |
|---|
| 245 | | return false; |
|---|
| 246 | | } |
|---|
| 247 | | AccessResource parentToResource = (AccessResource) parentAccesses.get(resource); |
|---|
| | 240 | + getResource ().getName() + "\""); |
|---|
| | 241 | return false; |
|---|
| | 242 | } |
|---|
| | 243 | AccessResource parentToResource = (AccessResource) parentAccesses.get(getResource ()); |
|---|
| 248 | 244 | |
|---|
| 249 | 245 | if(parentToResource == null) |
|---|
| … | … | |
| 252 | 248 | + domainParent.getName() |
|---|
| 253 | 249 | + "\"'s access to resource \"" |
|---|
| 254 | | + resource.getName() + "\"", |
|---|
| 255 | | ErrorHandler.ERROR_CHILD_EXCEED_ACCESS, resource.getName()); |
|---|
| | 250 | + getResource ().getName() + "\"", |
|---|
| | 251 | ErrorHandler.ERROR_CHILD_EXCEED_ACCESS, getResource ().getName()); |
|---|
| 256 | 252 | return false; |
|---|
| 257 | 253 | } |
|---|
| … | … | |
| 272 | 268 | + parentToResource.m_bool |
|---|
| 273 | 269 | + ", child permission must also be wrapped by the same boolean", |
|---|
| 274 | | ErrorHandler.ERROR_MISSING_BOOLEAN, resource.getName()); |
|---|
| | 270 | ErrorHandler.ERROR_MISSING_BOOLEAN, getResource ().getName()); |
|---|
| 275 | 271 | return false; |
|---|
| 276 | 272 | } |
|---|
| r1520 |
r1522 |
|
| 248 | 248 | |
|---|
| 249 | 249 | public boolean Add(Access axx) { |
|---|
| 250 | | accesses.add(axx); |
|---|
| | 250 | // Needs to check because it seems that baseresources and basedomains |
|---|
| | 251 | // keep their accesses during policy reload and with out the check |
|---|
| | 252 | // the access is added multiple times. DJS 8-Mar-2007 |
|---|
| | 253 | if (!accesses.contains(axx)) |
|---|
| | 254 | accesses.add(axx); |
|---|
| 251 | 255 | return true; |
|---|
| 252 | 256 | } |
|---|
| … | … | |
| 292 | 296 | { |
|---|
| 293 | 297 | policy = i_poilcy; |
|---|
| | 298 | } |
|---|
| | 299 | |
|---|
| | 300 | public Policy getPolicy () |
|---|
| | 301 | { |
|---|
| | 302 | return policy; |
|---|
| 294 | 303 | } |
|---|
| 295 | 304 | |
|---|
| r1411 |
r1522 |
|
| 43 | 43 | public boolean Remove(Access axx); |
|---|
| 44 | 44 | |
|---|
| | 45 | public Policy getPolicy (); |
|---|
| | 46 | |
|---|
| 45 | 47 | /** |
|---|
| 46 | 48 | * Check if an enter statement is present with the given criteria. |
|---|
| r1453 |
r1522 |
|
| 226 | 226 | */ |
|---|
| 227 | 227 | public boolean Add(AccessResource axx) { |
|---|
| 228 | | if(axx.getResource().IsDescendant(axx.Domain)) { |
|---|
| | 228 | if(axx.getResource().IsDescendant(axx.getDomain ())) { |
|---|
| 229 | 229 | axx.Token |
|---|
| 230 | 230 | .Error("Constraint violation: a domain cannot access its children"); |
|---|
| … | … | |
| 234 | 234 | Domain resourceParent = axx.getResource().getParent(); |
|---|
| 235 | 235 | |
|---|
| 236 | | if(resourceParent != null && !axx.Domain.IsDescendant(resourceParent)) { |
|---|
| | 236 | if(resourceParent != null && !axx.getDomain ().IsDescendant(resourceParent)) { |
|---|
| 237 | 237 | axx.Token |
|---|
| 238 | 238 | .Error("Constraint violation: a domain cannot access a resource enclosed in another domain"); |
|---|
| … | … | |
| 243 | 243 | while(itr.hasNext()) { |
|---|
| 244 | 244 | Access tmpAccess = (Access)itr.next(); |
|---|
| 245 | | if(tmpAccess.getDomain() == axx.Domain && tmpAccess.getResource() == axx.getResource()) { |
|---|
| 246 | | axx.Token.Warning("Domain \"" + axx.Domain.getName() |
|---|
| | 245 | if(tmpAccess.getDomain() == axx.getDomain () && tmpAccess.getResource() == axx.getResource()) { |
|---|
| | 246 | axx.Token.Warning("Domain \"" + axx.getDomain().getName() |
|---|
| 247 | 247 | + "\" already has \"" + Verb.toString(axx.m_verb) |
|---|
| 248 | 248 | + "\" access to resource \"" + axx.getResource().getName() |
|---|
| … | … | |
| 265 | 265 | public boolean Add(AccessBaseResource axx) { |
|---|
| 266 | 266 | // update graph links for information flow |
|---|
| 267 | | if(! axx.Domain.Add(axx)){ |
|---|
| 268 | | axx.Token.Warning("Domain \"" + axx.Domain.getName() |
|---|
| | 267 | if(! axx.getDomain().Add(axx)){ |
|---|
| | 268 | axx.Token.Warning("Domain \"" + axx.getDomain().getName() |
|---|
| 269 | 269 | + "\" already has \"" + Verb.toString(axx.m_verb) |
|---|
| 270 | 270 | + "\" access to resource \"" + axx.GetBaseResource().getName() |
|---|
| … | … | |
| 272 | 272 | return false; |
|---|
| 273 | 273 | } |
|---|
| | 274 | |
|---|
| | 275 | axx.getResource().Add(axx); |
|---|
| 274 | 276 | return true; |
|---|
| 275 | 277 | } |
|---|
| … | … | |
| 284 | 286 | public boolean Add(AccessBoolean axx) { |
|---|
| 285 | 287 | // update graph links for information flow |
|---|
| 286 | | if(!axx.Domain.Add(axx)) { |
|---|
| 287 | | axx.Token.Warning("Domain \"" + axx.Domain.getName() |
|---|
| | 288 | if(!axx.getDomain ().Add(axx)) { |
|---|
| | 289 | axx.Token.Warning("Domain \"" + axx.getDomain().getName() |
|---|
| 288 | 290 | + "\" already has \"" + Verb.toString(axx.m_verb) |
|---|
| 289 | 291 | + "\" access to boolean \"" + axx.getResource().getName() |
|---|
| … | … | |
| 291 | 293 | return false; |
|---|
| 292 | 294 | } |
|---|
| | 295 | |
|---|
| | 296 | axx.getResource().Add(axx); |
|---|
| 293 | 297 | return true; |
|---|
| 294 | 298 | } |
|---|
| r1518 |
r1522 |
|
| 9 | 9 | package com.tresys.framework.plugin.editor.policy.graphic.model; |
|---|
| 10 | 10 | |
|---|
| | 11 | import java.util.ArrayList; |
|---|
| 11 | 12 | import java.util.Arrays; |
|---|
| | 13 | import java.util.Collection; |
|---|
| 12 | 14 | import java.util.Iterator; |
|---|
| 13 | 15 | import java.util.Map; |
|---|
| … | … | |
| 20 | 22 | import org.eclipse.ui.views.properties.PropertyDescriptor; |
|---|
| 21 | 23 | |
|---|
| | 24 | import com.tresys.framework.compiler.policy.Access; |
|---|
| 22 | 25 | import com.tresys.framework.compiler.policy.BaseDomain; |
|---|
| 23 | 26 | import com.tresys.framework.compiler.policy.Component; |
|---|
| … | … | |
| 124 | 127 | |
|---|
| 125 | 128 | return super.getPropertyValue (propertyId); |
|---|
| | 129 | } |
|---|
| | 130 | |
|---|
| | 131 | public void setComponent (Component i_component) |
|---|
| | 132 | { |
|---|
| | 133 | Component oldComponent = getComponent(); |
|---|
| | 134 | super.setComponent (i_component); |
|---|
| | 135 | if (oldComponent == i_component) |
|---|
| | 136 | return; |
|---|
| | 137 | |
|---|
| | 138 | if (!(i_component instanceof BaseDomain)) |
|---|
| | 139 | throw new IllegalArgumentException (); |
|---|
| | 140 | |
|---|
| | 141 | Collection connections = new ArrayList (getSourceConnections()); |
|---|
| | 142 | connections.addAll(getTargetConnections()); |
|---|
| | 143 | |
|---|
| | 144 | for (Iterator itr = connections.iterator(); itr.hasNext(); ) |
|---|
| | 145 | { |
|---|
| | 146 | AccessConnection connection = (AccessConnection) itr.next(); |
|---|
| | 147 | Access access = connection.getAccess(); |
|---|
| | 148 | access.setDomain ((IDomain) i_component); |
|---|
| | 149 | } |
|---|
| | 150 | |
|---|
| 126 | 151 | } |
|---|
| 127 | 152 | |
|---|
| r1518 |
r1522 |
|
| 9 | 9 | package com.tresys.framework.plugin.editor.policy.graphic.model; |
|---|
| 10 | 10 | |
|---|
| | 11 | import java.util.ArrayList; |
|---|
| 11 | 12 | import java.util.Arrays; |
|---|
| | 13 | import java.util.Collection; |
|---|
| 12 | 14 | import java.util.Iterator; |
|---|
| 13 | 15 | import java.util.Map; |
|---|
| … | … | |
| 20 | 22 | import org.eclipse.ui.views.properties.PropertyDescriptor; |
|---|
| 21 | 23 | |
|---|
| | 24 | import com.tresys.framework.compiler.policy.Access; |
|---|
| 22 | 25 | import com.tresys.framework.compiler.policy.BaseResource; |
|---|
| 23 | 26 | import com.tresys.framework.compiler.policy.Component; |
|---|
| … | … | |
| 133 | 136 | } |
|---|
| 134 | 137 | |
|---|
| | 138 | public void setComponent (Component i_component) |
|---|
| | 139 | { |
|---|
| | 140 | Component oldComponent = getComponent(); |
|---|
| | 141 | super.setComponent (i_component); |
|---|
| | 142 | if (oldComponent == i_component) |
|---|
| | 143 | return; |
|---|
| | 144 | |
|---|
| | 145 | if (!(i_component instanceof BaseResource)) |
|---|
| | 146 | throw new IllegalArgumentException (); |
|---|
| | 147 | |
|---|
| | 148 | Collection connections = new ArrayList (getSourceConnections()); |
|---|
| | 149 | connections.addAll(getTargetConnections()); |
|---|
| | 150 | |
|---|
| | 151 | for (Iterator itr = connections.iterator(); itr.hasNext(); ) |
|---|
| | 152 | { |
|---|
| | 153 | AccessConnection connection = (AccessConnection) itr.next(); |
|---|
| | 154 | Access access = connection.getAccess(); |
|---|
| | 155 | access.setResource (i_component); |
|---|
| | 156 | } |
|---|
| | 157 | } |
|---|
| | 158 | |
|---|
| 135 | 159 | private void updateBaseResources () |
|---|
| 136 | 160 | { |
|---|
Download in other formats:
* Generating other formats may take time.