Changeset 1974

Show
Ignore:
Timestamp:
03/04/08 13:34:57 (9 months ago)
Author:
dsugar
Message:

Lots of cleanup
let refreshVisuals set our background color - rather than all over the place
each object needs to detect if it's MLS label was removed - not just the ones with default

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/mls/framework-plugin/src/com/tresys/framework/compiler/policy/ComponentWithDictObjects.java

    r1973 r1974  
    7070                sysResources = new TreeMap/*<IDictionaryObject, List<SystemResource>>*/(); 
    7171                 
    72                 MLSSupport mlsSupport = pol.getLinkage ().getMLSSupport (); 
    73                 if (mlsSupport !=  null) 
    74                         m_MLSLevel = mlsSupport.getDefaultMLSLevel (); 
     72                if (getPolicy () != null) 
     73                { 
     74                        MLSSupport mlsSupport = getPolicy ().getLinkage ().getMLSSupport (); 
     75                        if (mlsSupport !=  null) 
     76                                m_MLSLevel = mlsSupport.getDefaultMLSLevel (); 
     77                } 
    7578        } 
    7679         
  • branches/mls/framework-plugin/src/com/tresys/framework/plugin/builder/AccessCheckBuilder.java

    r1973 r1974  
    2222import org.eclipse.core.resources.IFile; 
    2323import org.eclipse.core.resources.IProject; 
     24import org.eclipse.core.resources.IResource; 
     25import org.eclipse.core.resources.IResourceVisitor; 
    2426import org.eclipse.core.resources.IncrementalProjectBuilder; 
    2527import org.eclipse.core.runtime.CoreException; 
     
    5759import com.tresys.framework.compiler.policy.UserDomain; 
    5860import com.tresys.framework.plugin.SEFramework_Plugin; 
     61import com.tresys.slide.plugin.nature.BaseProjectNature; 
    5962 
    6063/** 
     64 * Simple builder to do access check and verify there is not something that will cause them to fail 
    6165 * @author dsugar 
    6266 * 
     
    8791                        SELinuxSystem sys = (SELinuxSystem) itr.next(); 
    8892 
    89                         IFile buildPolicy = sys.getFolder ().getFile ("policy.19"); 
    90                         if (!buildPolicy.exists ()) 
    91                                 continue; 
    92                          
    9393                        try 
    9494                        { 
    95 //                              SELinuxSystem sys = getSystem (i_policy); 
    96                                 AccessCheckVisitor visitor = null; 
    97                                  
    98                                 visitor = new AccessCheckVisitor (buildPolicy, sys.getFPOLErrorHandler ()); 
     95                                sys.getFolder ().accept (new PolicyFolderVisitor (), 1, false); 
     96                        } 
     97                        catch (CoreException ce) 
     98                        {} 
     99                } 
     100                 
     101                return null; 
     102        } 
     103 
     104        /** 
     105         * Visit the policy directory looking for the policy.xx and (future) modules 
     106         * @author dsugar 
     107         * 
     108         */ 
     109        protected class PolicyFolderVisitor 
     110                implements IResourceVisitor 
     111        { 
     112        /* (non-Javadoc) 
     113                 * @see org.eclipse.core.resources.IResourceVisitor#visit(org.eclipse.core.resources.IResource) 
     114                 */ 
     115                public boolean visit (IResource resource) 
     116                { 
     117                        try 
     118                        { 
     119                                if (!(resource instanceof IFile)) 
     120                                        return true; 
     121                                 
     122                                // match policy file 
     123                                String sExtn = resource.getFileExtension (); 
     124                                if (sExtn == null) 
     125                                        return false; 
     126                                 
     127                                //TODO: need to deal with modular builds!!                               
     128                                String sSubName = resource.getName (); 
     129                                sSubName = sSubName.substring (0, sSubName.length () - sExtn.length () -1); 
     130                                if (!BaseProjectNature.FILE_POLICY_BASE.equals (sSubName)) 
     131                                        return false; 
     132                                 
     133                                if (Integer.valueOf (sExtn) == null) 
     134                                        return false; 
     135                                 
     136                                FrameworkNature nat = FrameworkNature.getNature (resource.getProject ()); 
     137                                 
     138                                // visit the actual policy 
     139                                SELinuxSystem sys = nat.getSystem (resource); 
     140                                AccessCheckVisitor visitor = new AccessCheckVisitor ((IFile) resource, sys.getFPOLErrorHandler ()); 
    99141 
    100142                                if (visitor != null) 
     
    109151                                e.printStackTrace(); 
    110152                        } 
    111                 } 
    112                  
    113                 return null; 
     153                        return false; 
     154                }        
    114155        } 
    115  
     156         
    116157        /** 
    117158         * Check all accesses in the policy to verify that they grant the access described 
  • branches/mls/framework-plugin/src/com/tresys/framework/plugin/builder/FrameworkNature.java

    r1973 r1974  
    154154                } 
    155155                 
    156                 if (event.getKey ().equals (SEFPreferencePage.DEFAULT_MLS_LEVEL_REMOVED)) 
    157                 { 
    158                         IShapeVisitor isv = new DefaultMLSLevelUpdateVisitor(event); 
    159                         for (Iterator _iter = getSystems ().iterator (); _iter.hasNext (); ) 
    160                         { 
    161                                 SELinuxSystem sels = (SELinuxSystem)_iter.next (); 
    162                                 sels.getDiagram ().Accept (isv); 
    163                         } 
    164                 } 
    165                  
    166156                return; 
    167157        } 
  • branches/mls/framework-plugin/src/com/tresys/framework/plugin/editor/policy/graphic/model/ResourceShape.java

    r1973 r1974  
    6060 
    6161                Token tok = new Token (sName, getErrorHandler()); 
    62                 Resource resource = new Resource (tok, null, getPolicy()); 
     62                Resource resource = new Resource (tok, null, i_system.getPolicy()); 
    6363 
    6464                setComponent (resource); 
  • branches/mls/framework-plugin/src/com/tresys/framework/plugin/editor/policy/graphic/model/UserDomainShape.java

    r1825 r1974  
    4444                 
    4545                Token tok = new Token (sName, getErrorHandler()); 
    46                 UserDomain dom = new UserDomain (tok, getPolicy()); 
     46                UserDomain dom = new UserDomain (tok, i_system.getPolicy()); 
    4747                 
    4848                setComponent (dom); 
  • branches/mls/framework-plugin/src/com/tresys/framework/plugin/editor/policy/graphic/parts/DomainEditPart.java

    r1973 r1974  
    2929import org.eclipse.gef.Request; 
    3030 
    31 import com.tresys.framework.compiler.mls.MLSLevel; 
    32 import com.tresys.framework.compiler.mls.MLSSupport; 
    3331import com.tresys.framework.compiler.policy.Access; 
    3432import com.tresys.framework.compiler.policy.Component; 
    3533import com.tresys.framework.compiler.policy.Enter; 
    36 import com.tresys.framework.compiler.policy.IMLSSetting; 
    3734import com.tresys.framework.compiler.policy.IResource; 
    3835import com.tresys.framework.plugin.editor.policy.graphic.figure.ConnectionAnchorFigure; 
     
    4542import com.tresys.framework.plugin.editor.policy.graphic.model.EntryConnection; 
    4643import com.tresys.framework.plugin.editor.policy.graphic.model.IDomainShape; 
    47 import com.tresys.framework.plugin.editor.policy.graphic.model.IShape; 
    4844import com.tresys.framework.plugin.editor.policy.graphic.model.Shape; 
    4945import com.tresys.framework.plugin.editor.policy.graphic.model.UserDomainShape; 
    50 import com.tresys.framework.plugin.preferences.MLSEclipseLevel; 
    5146 
    5247public class DomainEditPart 
     
    129124                { 
    130125                        DomainFigure domFig = new DomainFigure(); 
    131                         MLSSupport mlss = MLSSupport.getInstance (); 
    132                          
    133                         if (null != mlss) 
    134                         { 
    135                                 IShape is = (IShape)getModel (); 
    136                                 IMLSSetting ims = (IMLSSetting)is.getComponent (); 
    137                                 MLSLevel level = ims.getMLSLevel (); 
    138                                  
    139                                 if (level != null) 
    140                                         domFig.setBackgroundColor (MLSEclipseLevel.getColorInstance (level)); 
    141                         }                        
     126 
    142127                        m_connectionAnchor = new ConnectionAnchorFigure (domFig); 
    143128                        fig = domFig; 
  • branches/mls/framework-plugin/src/com/tresys/framework/plugin/editor/policy/graphic/parts/PolicyEditPart.java

    r1973 r1974  
    2626import org.eclipse.swt.widgets.Display; 
    2727 
    28 import com.tresys.framework.compiler.linkage.Linkage; 
    2928import com.tresys.framework.compiler.mls.MLSLevel; 
    3029import com.tresys.framework.compiler.mls.MLSSupport; 
     
    5049        private ConnectionAnchor anchor; 
    5150        private static List EMPTY_LIST = new ArrayList (); 
    52         private String _oldDefaultLevel = null; 
    53         private String _newDefaultLevel = null; 
    5451 
    5552        final static protected boolean DEBUG = SEFramework_Plugin.getDefault ().isDebugging ("/debug/part"); 
     
    196193                else if (Shape.MLS_PROP.equals (prop)) 
    197194                { 
    198                         String levelName = evt.getNewValue ().toString (); 
    199                          
    200                         MLSSupport mlsSupport = MLSSupport.getInstance (); 
    201                          
    202                         if (null != mlsSupport) 
    203                         {                                
    204                                 MLSLevel mls = mlsSupport.getLevel (levelName); 
    205                                  
    206                                 if (null != mls) 
    207                                 { 
    208                                         this.figure.setBackgroundColor (MLSEclipseLevel.getColorInstance (mls)); 
    209                                         refreshVisuals (); 
    210                                 } 
    211                         }                        
     195                        refreshVisuals (); 
    212196                } 
    213197                else if (SEFPreferencePage.MLS_UPDATE.equals (prop)) 
     
    215199                        if (getCastedModel ().getComponent () instanceof IMLSSetting) 
    216200                        { 
    217                                 MLSLevel mls = ((IMLSSetting) getCastedModel ().getComponent ()).getMLSLevel (); 
    218                                 if (mls != null) 
    219                                         getFigure ().setBackgroundColor (MLSEclipseLevel.getColorInstance (mls)); 
    220                         } 
    221                 } 
    222                 else if (SEFPreferencePage.DEFAULT_MLS_LEVEL.equals (prop)) 
    223                 { 
    224                         Object ov = evt.getOldValue (); 
    225                         if (null != ov) 
    226                         { 
    227                                 this._oldDefaultLevel = ov.toString (); 
    228                                 this._newDefaultLevel = evt.getNewValue ().toString (); 
    229                         } 
    230                 } 
    231                 else if (SEFPreferencePage.DEFAULT_MLS_LEVEL_REMOVED.equals (prop)) 
    232                 { 
    233                         Object ov = evt.getOldValue (); 
    234                         if (null != ov) 
    235                         { 
    236                                 if (Boolean.TRUE.toString ().equals (evt.getNewValue ().toString ())) 
     201                                IMLSSetting mlsComponent = (IMLSSetting) getCastedModel ().getComponent (); 
     202                                MLSLevel mls = mlsComponent.getMLSLevel (); 
     203         
     204                                MLSSupport mlsSupport = getCastedModel ().getMLSSupport (); 
     205                                if (mls == null || mlsSupport.getLevel (mls.getName ()) == null) 
    237206                                { 
    238                                         Shape s = this.getCastedModel (); 
    239                                          
    240                                         IMLSSetting ims = (IMLSSetting) s.getComponent (); 
    241                                          
    242                                         if (_oldDefaultLevel.equals (ims.getMLSLabel ())) 
     207                                        mls = mlsSupport.getDefaultMLSLevel (); 
     208                                        if (mls != null) 
    243209                                        { 
    244                                                 Linkage linkage = getCastedModel ().getPolicy ().getLinkage (); 
    245                                                 MLSSupport mlsSupport = linkage.getMLSSupport (); 
    246                                                  
    247                                                 //String levelName = _newDefaultLevel; 
    248                                                 MLSLevel mlsLevel = mlsSupport.getLevel (_newDefaultLevel); 
    249                                                 ims.setMLSLabel (mlsLevel); 
    250                                                  
    251 ///                                             MLSSupport mlsSupport = MLSSupport.getInstance (); 
    252                                                  
    253                                                 if (null != mlsSupport) 
    254                                                 {                                
    255 //                                                      MLSLevel mls = mlsSupport.getLevel (levelName); 
    256                                                          
    257                                                         if (null != mlsLevel) 
    258                                                         { 
    259                                                                 this.figure.setBackgroundColor (MLSEclipseLevel.getColorInstance (mlsLevel)); 
    260                                                                 refreshVisuals (); 
    261                                                         } 
    262                                                 }                                
     210                                                getCastedModel ().setMLS (mls); 
     211                                                refreshVisuals (); 
    263212                                        } 
    264213                                } 
     
    269218                        Display.getDefault().asyncExec(new Runnable () 
    270219                        { 
    271                                        public void run()  
    272                                        
    273                                                refreshVisuals(); 
    274                                        }; 
     220                                public void run()  
     221                               
     222                                        refreshVisuals(); 
     223                                }; 
    275224                        }); 
    276225                } 
     
    301250                ((PolicyComponentFigure) tmpFigure).setSeverity (shape.getProblemSeverity().intValue()); 
    302251                 
     252                if (shape.getComponent () instanceof IMLSSetting) 
     253                { 
     254                        MLSLevel mls = ((IMLSSetting) shape.getComponent ()).getMLSLevel (); 
     255                        if (mls != null) 
     256                                tmpFigure.setBackgroundColor (MLSEclipseLevel.getColorInstance (mls)); 
     257                } 
    303258        } 
    304259         
  • branches/mls/framework-plugin/src/com/tresys/framework/plugin/editor/policy/graphic/parts/ShapeEditPart.java

    r1973 r1974  
    2222import org.eclipse.gef.EditPolicy; 
    2323 
    24 import com.tresys.framework.compiler.mls.MLSLevel; 
    25 import com.tresys.framework.compiler.mls.MLSSupport; 
    26 import com.tresys.framework.compiler.policy.IMLSSetting; 
    2724import com.tresys.framework.plugin.editor.policy.graphic.figure.BaseDomainFigure; 
    2825import com.tresys.framework.plugin.editor.policy.graphic.figure.BaseResourceFigure; 
     
    3633import com.tresys.framework.plugin.editor.policy.graphic.model.ControlResourceShape; 
    3734import com.tresys.framework.plugin.editor.policy.graphic.model.IDomainShape; 
    38 import com.tresys.framework.plugin.editor.policy.graphic.model.IShape; 
    3935import com.tresys.framework.plugin.editor.policy.graphic.model.ResourceShape; 
    4036import com.tresys.framework.plugin.editor.policy.graphic.model.EntryPointShape; 
    4137import com.tresys.framework.plugin.editor.policy.graphic.model.Shape; 
    4238import com.tresys.framework.plugin.editor.policy.graphic.model.UserDomainShape; 
    43 import com.tresys.framework.plugin.preferences.MLSEclipseLevel; 
    4439 
    4540/** 
     
    9085        { 
    9186                IFigure retValue = null; 
    92                 boolean isMLSAware = false; 
    9387                 
    9488                if (getModel() instanceof ResourceShape)  
    9589                { 
    9690                        retValue = new ResourceFigure(); 
    97                         isMLSAware = true; 
    9891                } 
    9992                else if (getModel () instanceof BaseResourceShape) 
     
    112105                { 
    113106                        retValue = new EntryPointFigure(); 
    114                         isMLSAware = true; 
    115107                } 
    116108                else if (getModel() instanceof IDomainShape)  
    117109                { 
    118110                        retValue = new DomainFigure(); 
    119                         isMLSAware = true;                       
    120111                } 
    121112                else if (getModel () instanceof ControlResourceShape) 
    122113                { 
    123114                        retValue = new ControlResourceFigure (); 
    124                         isMLSAware = true; 
    125115                } 
    126116                else  
     
    129119                        throw new IllegalArgumentException(); 
    130120                } 
    131                  
    132                 // Determine if the Figure's background needs to be set... 
    133                 if (isMLSAware) 
    134                 { 
    135                         MLSSupport mlss = MLSSupport.getInstance (); 
    136                          
    137                         if (null != mlss) 
    138                         { 
    139                                 IShape is = (IShape)getModel (); 
    140                                 IMLSSetting ims = (IMLSSetting)is.getComponent (); 
    141                                 MLSLevel level = ims.getMLSLevel (); 
    142                                 if (level != null) 
    143                                         retValue.setBackgroundColor (MLSEclipseLevel.getColorInstance (level)); 
    144                         }                        
    145                 } 
    146                  
     121 
    147122                return retValue; 
    148123        } 
     
    158133                return getCastedModel ().getEntryConnections(); 
    159134        } 
    160          
    161  
    162          
     135 
    163136        public void refresh()  
    164137        { 
  • branches/mls/framework-plugin/src/com/tresys/framework/plugin/preferences/MLSSettingsProjProperties.java

    r1973 r1974  
    106106        protected ComboViewer _levelsDefault = null;  
    107107        protected IEclipsePreferences projPrefs = null; 
    108         protected boolean _defaultWasRemoved = false; 
    109108         
    110109        /** 
     
    174173                this.initProjPrefs (); 
    175174 
    176                 this._defaultWasRemoved = false; 
    177                  
    178175                // Define the basics of the page 
    179176                setTitle (Messages.mls_settings); 
     
    410407                                                MLSLevel dl = _levels.getLevelOrderedAt (0); 
    411408                                                _levelsDefault.setSelection (new StructuredSelection(dl)); 
    412                                                 _defaultWasRemoved = true; 
    413409                                        } 
    414410                                         
     
    535531                        this.projPrefs.put (SEFPreferencePage.MLS_UPDATE, Long.toHexString (System.currentTimeMillis ())); 
    536532                         
    537                         if (_defaultWasRemoved) 
    538                         { 
    539                                 this.projPrefs.put(SEFPreferencePage.DEFAULT_MLS_LEVEL_REMOVED, Boolean.FALSE.toString ()); 
    540                                 this.projPrefs.put(SEFPreferencePage.DEFAULT_MLS_LEVEL_REMOVED, Boolean.TRUE.toString ()); 
    541                         } 
    542533                         
    543534                        projPrefs.flush ();                                                              
  • branches/mls/framework-plugin/src/com/tresys/framework/plugin/preferences/SEFPreferencePage.java

    r1955 r1974  
    5353         */ 
    5454        public static final String DEFAULT_MLS_LEVEL = "defaultMLSLevel"; 
    55         public static final String DEFAULT_MLS_LEVEL_REMOVED = "defaultMLSLevelRemoved"; 
    5655        public static final String MLS_UPDATE = "mlsUpdated"; 
    5756