Changeset 1522

Show
Ignore:
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
  • trunk/framework-plugin/src/com/tresys/framework/compiler/policy/Access.java

    r1411 r1522  
    2323 
    2424        /** the domain associated with the access */ 
    25         protected final IDomain Domain; 
     25        private IDomain Domain; 
    2626 
    27         protected final Component resource; 
     27        private Component resource; 
    2828 
    2929        /** the verb associated defining the type of access */ 
     
    6464        } 
    6565 
     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         
    66105        public abstract boolean Validate(); 
    67106 
  • trunk/framework-plugin/src/com/tresys/framework/compiler/policy/AccessBaseResource.java

    r1472 r1522  
    2121import com.tresys.framework.compiler.dictionary.Verb; 
    2222import com.tresys.framework.compiler.linkage.flnkage.BaseAccessDefn; 
     23import com.tresys.framework.compiler.linkage.flnkage.BaseAccessDefnGroup; 
    2324 
    2425import com.tresys.slide.utility.policyxmlparser.Interface; 
     
    4546        public void ResetToDefaults() { 
    4647                baseAccessDefns.clear(); 
    47                 baseAccessDefns.addAll(GetBaseResource().GetAccessGroup(verb()).GetDefaultAccessDefns()); 
     48                BaseAccessDefnGroup group = GetBaseResource().GetAccessGroup(verb()); 
     49                if (group != null) 
     50                        baseAccessDefns.addAll(group.GetDefaultAccessDefns()); 
    4851                isDefault = true;        
    4952        } 
     
    6265 
    6366        public BaseResource GetBaseResource() { 
    64                 return (BaseResource) resource
     67                return (BaseResource) getResource ()
    6568        } 
    6669 
     
    133136         */ 
    134137        /*@Override*/public String toString() { 
    135                 return Domain.toString() + Utility.DELIM + GetBaseResource().toString() 
     138                return getDomain().toString() + Utility.DELIM + GetBaseResource().toString() 
    136139                        + Utility.DELIM + Verb.toString(this.m_verb); 
    137140        } 
    138141 
    139142        public boolean Validate() { 
    140                 if(Domain.GetChildDomains().size() > 0) { 
     143                if(getDomain().GetChildDomains().size() > 0) { 
    141144                        /*for (Domain child: Domain.GetChildDomains())*/ 
    142                         Iterator iter = Domain.GetChildDomains().values().iterator(); 
     145                        Iterator iter = getDomain().GetChildDomains().values().iterator(); 
    143146                        while(iter.hasNext()) { 
    144147                                Domain child = (Domain) iter.next(); 
     
    154157                                } 
    155158                        } 
    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()); 
    157160                        return false; 
    158161                } 
    159162 
    160163                // If the domain and the resource have the same parent, there are no constraints 
    161                 Domain domainParent = Domain.getParent(); 
     164                Domain domainParent = getDomain().getParent(); 
    162165 
    163166                if(domainParent != null) { 
  • trunk/framework-plugin/src/com/tresys/framework/compiler/policy/AccessBoolean.java

    r1411 r1522  
    2323        public boolean Validate() { 
    2424                // If the domain and the resource have the same parent, there are no constraints 
    25                 Domain domainParent = Domain.getParent(); 
     25                Domain domainParent = getDomain().getParent(); 
    2626 
    2727                if(domainParent != null) { 
  • trunk/framework-plugin/src/com/tresys/framework/compiler/policy/AccessResource.java

    r1472 r1522  
    8080        } 
    8181 
    82         public Component getResource() { 
    83                 return resource; 
    84         } 
    85  
    8682        /** 
    8783         * Add access definition to list of those for this access 
     
    152148                AccessDefnGroup rdefGroup; 
    153149 
    154                 Map rdefs = ((Resource) resource).GetRdefs(); 
     150                Map rdefs = ((Resource) getResource ()).GetRdefs(); 
    155151                Iterator itr = rdefs.values().iterator(); 
    156152                while (itr.hasNext())  
     
    176172         */ 
    177173        /*@Override*/public String toString() { 
    178                 return Domain.toString() + Utility.DELIM + getResource().toString() 
     174                return getDomain().toString() + Utility.DELIM + getResource().toString() 
    179175                        + Utility.DELIM + Verb.toString(this.m_verb); 
    180176        } 
     
    206202 
    207203        public boolean Validate() { 
    208                 if(Domain.GetChildDomains().size() > 0) { 
     204                if(getDomain().GetChildDomains().size() > 0) { 
    209205                        /*for (Domain child: Domain.GetChildDomains())*/ 
    210                         Iterator iter = Domain.GetChildDomains().values().iterator(); 
     206                        Iterator iter = getDomain().GetChildDomains().values().iterator(); 
    211207                        while(iter.hasNext()) { 
    212208                                Domain child = (Domain) iter.next(); 
     
    221217                                } 
    222218                        } 
    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()); 
    224220                        return false; 
    225221                } 
     
    231227 
    232228                // 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()) { 
    236232 
    237233                        Map/*<Component, Access>*/parentAccesses = domainParent.GetAccessMap(m_verb.intValue()); 
     
    242238                                                + domainParent.getName() 
    243239                                                + "\"'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 ()); 
    248244 
    249245                        if(parentToResource == null)  
     
    252248                                                + domainParent.getName() 
    253249                                                + "\"'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()); 
    256252                                return false; 
    257253                        } 
     
    272268                                                + parentToResource.m_bool 
    273269                                                + ", child permission must also be wrapped by the same boolean", 
    274                                                 ErrorHandler.ERROR_MISSING_BOOLEAN, resource.getName()); 
     270                                                ErrorHandler.ERROR_MISSING_BOOLEAN, getResource ().getName()); 
    275271                                return false; 
    276272                        } 
  • trunk/framework-plugin/src/com/tresys/framework/compiler/policy/Component.java

    r1520 r1522  
    248248         
    249249        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); 
    251255                return true; 
    252256        } 
     
    292296        { 
    293297                policy = i_poilcy; 
     298        } 
     299         
     300        public Policy getPolicy () 
     301        { 
     302                return policy; 
    294303        } 
    295304         
  • trunk/framework-plugin/src/com/tresys/framework/compiler/policy/IDomain.java

    r1411 r1522  
    4343        public boolean Remove(Access axx); 
    4444 
     45        public Policy getPolicy (); 
     46         
    4547        /** 
    4648         * Check if an enter statement is present with the given criteria. 
  • trunk/framework-plugin/src/com/tresys/framework/compiler/policy/Policy.java

    r1453 r1522  
    226226         */ 
    227227        public boolean Add(AccessResource axx) { 
    228                 if(axx.getResource().IsDescendant(axx.Domain)) { 
     228                if(axx.getResource().IsDescendant(axx.getDomain ())) { 
    229229                        axx.Token 
    230230                                .Error("Constraint violation: a domain cannot access its children"); 
     
    234234                Domain resourceParent = axx.getResource().getParent(); 
    235235 
    236                 if(resourceParent != null && !axx.Domain.IsDescendant(resourceParent)) { 
     236                if(resourceParent != null && !axx.getDomain ().IsDescendant(resourceParent)) { 
    237237                        axx.Token 
    238238                                .Error("Constraint violation: a domain cannot access a resource enclosed in another domain"); 
     
    243243                while(itr.hasNext()) { 
    244244                        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() 
    247247                                        + "\" already has \"" + Verb.toString(axx.m_verb) 
    248248                                        + "\" access to resource \"" + axx.getResource().getName() 
     
    265265        public boolean Add(AccessBaseResource axx) { 
    266266                // 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() 
    269269                                + "\" already has \"" + Verb.toString(axx.m_verb) 
    270270                                + "\" access to resource \"" + axx.GetBaseResource().getName() 
     
    272272                        return false; 
    273273                } 
     274                 
     275                axx.getResource().Add(axx); 
    274276                return true; 
    275277        } 
     
    284286        public boolean Add(AccessBoolean axx) { 
    285287                // 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() 
    288290                                + "\" already has \"" + Verb.toString(axx.m_verb) 
    289291                                + "\" access to boolean \"" + axx.getResource().getName() 
     
    291293                        return false; 
    292294                } 
     295                 
     296                axx.getResource().Add(axx); 
    293297                return true; 
    294298        } 
  • trunk/framework-plugin/src/com/tresys/framework/plugin/editor/policy/graphic/model/BaseDomainShape.java

    r1518 r1522  
    99package com.tresys.framework.plugin.editor.policy.graphic.model; 
    1010 
     11import java.util.ArrayList; 
    1112import java.util.Arrays; 
     13import java.util.Collection; 
    1214import java.util.Iterator; 
    1315import java.util.Map; 
     
    2022import org.eclipse.ui.views.properties.PropertyDescriptor; 
    2123 
     24import com.tresys.framework.compiler.policy.Access; 
    2225import com.tresys.framework.compiler.policy.BaseDomain; 
    2326import com.tresys.framework.compiler.policy.Component; 
     
    124127                 
    125128                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 
    126151        } 
    127152         
  • trunk/framework-plugin/src/com/tresys/framework/plugin/editor/policy/graphic/model/BaseResourceShape.java

    r1518 r1522  
    99package com.tresys.framework.plugin.editor.policy.graphic.model; 
    1010 
     11import java.util.ArrayList; 
    1112import java.util.Arrays; 
     13import java.util.Collection; 
    1214import java.util.Iterator; 
    1315import java.util.Map; 
     
    2022import org.eclipse.ui.views.properties.PropertyDescriptor; 
    2123 
     24import com.tresys.framework.compiler.policy.Access; 
    2225import com.tresys.framework.compiler.policy.BaseResource; 
    2326import com.tresys.framework.compiler.policy.Component; 
     
    133136        } 
    134137 
     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         
    135159        private void updateBaseResources () 
    136160        {