Changeset 1991

Show
Ignore:
Timestamp:
03/11/08 10:39:44 (9 months ago)
Author:
apatel
Message:

it opens up an editor and puts policy in it.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/custom/ICustomPolicy.java

    r1987 r1991  
    1919         
    2020        public boolean hasCustomization(); 
     21         
     22        public void markCustomized(); 
     23         
     24        public void removeCustomization(); 
     25         
    2126} 
  • branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/policy/Access.java

    r1987 r1991  
    3636 
    3737        protected final AbstractToken Token; 
     38         
     39        private boolean mIsModified; 
    3840 
    3941        public Access(IDomain dom, IResource res, Integer /*Verb*/verb, 
     
    4547                m_bool = bool; 
    4648                m_onOrOff = activeOnBool; 
     49                mIsModified = false; 
    4750        } 
    4851 
     
    190193        public boolean hasCustomization() 
    191194        { 
    192                 return false; 
     195                return mIsModified; 
     196        } 
     197         
     198        public void markCustomized () 
     199        { 
     200                mIsModified = true; 
     201        } 
     202         
     203        public void removeCustomization () 
     204        { 
     205                mIsModified = false; 
    193206        } 
    194207 
  • branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/policy/BaseDomain.java

    r1989 r1991  
    249249                return false; 
    250250        } 
    251          
    252         public boolean supportsCustomPolicy() 
    253         { 
    254                 return false; 
    255         } 
    256          
    257         public boolean hasCustomization() 
    258         { 
    259                 return false; 
    260         } 
    261  
    262251} 
  • branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/policy/Component.java

    r1989 r1991  
    2222import com.tresys.framework.compiler.ErrorHandler; 
    2323import com.tresys.framework.compiler.AbstractToken; 
    24 import com.tresys.framework.compiler.custom.ICustomPolicy; 
    2524 
    2625/** 
     
    4039public abstract class Component  
    4140        extends Object 
    42         implements Comparable/*<Component>*/, IPolicyVisitable, ICustomPolicy 
     41        implements Comparable/*<Component>*/, IPolicyVisitable 
    4342{ 
    4443 
    4544        /** The sub-name of the component instance of the class */ 
    4645        protected String m_subName; // component name 
     46         
     47        protected boolean mIsModified; 
    4748 
    4849        protected final AbstractToken m_token; 
  • branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/policy/Conditional.java

    r1987 r1991  
    1010 
    1111import com.tresys.framework.compiler.AbstractToken; 
     12import com.tresys.framework.compiler.custom.ICustomPolicy; 
    1213 
    1314public class Conditional  
    1415        extends Component 
    15         implements IResource 
     16        implements IResource, ICustomPolicy 
    1617{ 
    1718        protected boolean defaultState; 
     
    5859        public boolean supportsCustomPolicy() 
    5960        { 
    60                 return false; 
     61                return true; 
    6162        } 
    6263         
    6364        public boolean hasCustomization() 
    6465        { 
    65                 return false; 
     66                return mIsModified; 
     67        } 
     68         
     69        public void markCustomized () 
     70        { 
     71                mIsModified = true; 
     72        } 
     73         
     74        public void removeCustomization () 
     75        { 
     76                mIsModified = false; 
    6677        } 
    6778 
  • branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/policy/Enter.java

    r1987 r1991  
    5050        protected EntrypointResource m_entrypoint_resource; 
    5151         
    52          
     52        protected boolean mIsModified; 
    5353 
    5454        /* 
     
    227227        public boolean hasCustomization() 
    228228        { 
    229                 return false; 
     229                return mIsModified; 
     230        } 
     231         
     232        public void markCustomized () 
     233        { 
     234                mIsModified = true; 
     235        } 
     236         
     237        public void removeCustomization () 
     238        { 
     239                mIsModified = false; 
    230240        } 
    231241 
  • branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/policy/EntrypointResource.java

    r1989 r1991  
    1515 
    1616import com.tresys.framework.compiler.AbstractToken; 
     17import com.tresys.framework.compiler.custom.ICustomPolicy; 
    1718import com.tresys.framework.compiler.dictionary.Entrypoint; 
    1819import com.tresys.framework.compiler.mls.MLSLevel; 
     
    3132public final class EntrypointResource  
    3233        extends Component 
    33         implements IMLSSetting 
     34        implements IMLSSetting, ICustomPolicy 
    3435{ 
    3536 
     
    160161        public boolean hasCustomization() 
    161162        { 
    162                 return false; 
     163                return mIsModified; 
     164        } 
     165         
     166        public void markCustomized () 
     167        { 
     168                mIsModified = true; 
     169        } 
     170         
     171        public void removeCustomization () 
     172        { 
     173                mIsModified = false; 
    163174        } 
    164175} 
  • branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/policy/Resource.java

    r1987 r1991  
    1717 
    1818import com.tresys.framework.compiler.AbstractToken; 
     19import com.tresys.framework.compiler.custom.ICustomPolicy; 
    1920import com.tresys.framework.compiler.dictionary.Rdef; 
    2021import com.tresys.framework.compiler.dictionary.Verb; 
     
    3132public class Resource  
    3233        extends ComponentWithDictObjects 
    33         implements IResource 
     34        implements IResource, ICustomPolicy 
    3435{ 
    3536 
     
    150151        public boolean hasCustomization() 
    151152        { 
    152                 return false; 
     153                return mIsModified; 
     154        } 
     155         
     156        public void markCustomized () 
     157        { 
     158                mIsModified = true; 
     159        } 
     160         
     161        public void removeCustomization () 
     162        { 
     163                mIsModified = false; 
    153164        } 
    154165 
  • branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/policy/UserDomain.java

    r1989 r1991  
    2020 
    2121import com.tresys.framework.compiler.AbstractToken; 
     22import com.tresys.framework.compiler.custom.ICustomPolicy; 
    2223 
    2324public class UserDomain  
    2425        extends Component  
    25         implements IDomain  
     26        implements IDomain, ICustomPolicy 
    2627{ 
    2728        /** 
     
    189190        public boolean hasCustomization() 
    190191        { 
    191                 return false; 
     192                return mIsModified; 
     193        } 
     194         
     195        public void markCustomized () 
     196        { 
     197                mIsModified = true; 
     198        } 
     199         
     200        public void removeCustomization () 
     201        { 
     202                mIsModified = false; 
    192203        } 
    193204 
  • branches/custome_policy/framework-plugin/src/com/tresys/framework/plugin/builder/SELinuxSystem.java

    r1989 r1991  
    2727import org.eclipse.core.resources.IWorkspaceRunnable; 
    2828import org.eclipse.core.runtime.CoreException; 
     29import org.eclipse.core.runtime.IPath; 
    2930import org.eclipse.core.runtime.IProgressMonitor; 
    3031import org.eclipse.core.runtime.Path; 
     
    6869        implements IWorkbenchAdapter, PolicyXMLListener, IAnalysisListener 
    6970{ 
     71 
     72         
     73        private static final String CDS_LAYER = "/policy/modules/cds"; 
     74         
    7075         
    7176        /** The saved reference to the Policy */ 
     
    8489        /** Folder this system lives in */ 
    8590        private final IFolder m_folder; 
    86  
     91         
     92        /** Folder of the cds policy */ 
     93        private IFolder mLayer; 
     94         
     95        /** Container that knows everythign about custom policy */ 
     96        private CPolicyContainer mCustomPolicy; 
     97         
    8798        /** Name of the system */ 
    8899        private final String m_name; 
     
    507518        } 
    508519         
     520        public final IFolder getDefaultLayer() 
     521        { 
     522                if( mLayer != null ) 
     523                        return mLayer; 
     524                mLayer = m_folder.getFolder (CDS_LAYER); 
     525                if( mLayer.exists () ) 
     526                        return mLayer; 
     527                try 
     528                { 
     529                        mLayer.create (true, true, null); 
     530                        mLayer.getProjectRelativePath().append("metadata.xml"); //$NON-NLS-1$ 
     531                        IFile metadataFile = getProject ().getFile(mLayer.getProjectRelativePath().append("metadata.xml")); //$NON-NLS-1$ 
     532                         
     533                        String summary = "<summary> </summary>"; 
     534                        InputStream stream = new ByteArrayInputStream (summary.getBytes()); //$NON-NLS-1$ 
     535                        metadataFile.create(stream, true, null); 
     536                        metadataFile.refreshLocal (IResource.DEPTH_ZERO, null); 
     537                } 
     538                catch(CoreException ce) 
     539                { 
     540                        mLayer = null; 
     541                        ce.printStackTrace (); 
     542                        return mLayer; 
     543                } 
     544                return mLayer; 
     545        } 
     546         
     547        public CPolicyContainer getCustomPoilcyContainer() 
     548        { 
     549                if( mCustomPolicy == null ) 
     550                        mCustomPolicy = new CPolicyContainer(getName ()); 
     551                return mCustomPolicy; 
     552        } 
     553         
    509554        public void Translate() 
    510555                throws CoreException 
     
    521566                } 
    522567 
    523                 final String policyPath = "/policy/modules/apps/cdsframework-" + m_name; 
    524  
    525                 final IFile teFile = getFolder().getFile(policyPath + ".te"); 
    526                 final IFile ifFile = getFolder().getFile(policyPath + ".if");          
    527                 final IFile fcFile = getFolder().getFile(policyPath + ".fc"); 
     568                final String policyPath = "cdsframework-" + m_name; 
     569 
     570                final IFile teFile = getDefaultLayer ().getFile(policyPath + ".te"); 
     571                final IFile ifFile = getDefaultLayer ().getFile(policyPath + ".if");           
     572                final IFile fcFile = getDefaultLayer ().getFile(policyPath + ".fc"); 
    528573 
    529574                final IFile dictionaryFile = getFolder ().getFile ("policy/support/cdsdictionary.spt"); 
     
    702747                } 
    703748        } 
     749         
     750        public class CPolicyContainer 
     751        { 
     752                public static final int IF_FILE = 0; 
     753                public static final int TE_FILE = 1; 
     754                public static final int FC_FILE = 2; 
     755                 
     756                private String CUSTOM_MODULE_NAME; 
     757                 
     758                private HashMap mModified; 
     759 
     760                 
     761                /** Three module file */ 
     762                private IFile[] mModule; 
     763 
     764                public CPolicyContainer(String mod_postfix) 
     765                { 
     766                        CUSTOM_MODULE_NAME = "cds-custom" + mod_postfix; 
     767                        mModified = new HashMap (10); 
     768                } 
     769                 
     770                public IFile[] getCustomModuleFiles() 
     771                { 
     772                        IFolder layer = getDefaultLayer (); 
     773                        if( layer == null ) 
     774                                return null; 
     775                        if( mModule != null ) 
     776                                return mModule; 
     777                        String if_file = CUSTOM_MODULE_NAME + ".if"; 
     778                        String te_file = CUSTOM_MODULE_NAME + ".te"; 
     779                        String fc_file = CUSTOM_MODULE_NAME + ".fc"; 
     780                         
     781                        Object [][]array =  
     782                        { 
     783                                {layer.getFile (if_file), "## <summary> </summary>\n"}, 
     784                                {layer.getFile (te_file), "policy_module("+ CUSTOM_MODULE_NAME + "," + "1.0.0) \n\n"}, 
     785                                {layer.getFile (fc_file), "\n"}, 
     786                        }; 
     787                         
     788                        try 
     789                        { 
     790                                mModule = new IFile[array.length]; 
     791                                for( int i=0; i < mModule.length; i++) 
     792                                { 
     793                                        IFile file = (IFile)array[i][0]; 
     794                                        InputStream stream = new ByteArrayInputStream (((String)array[i][1]).getBytes()); 
     795                                        mModule[i] = file; 
     796                                        mModule[i].create (stream, true, null); 
     797                                        mModule[i].refreshLocal (IResource.DEPTH_ZERO, null); 
     798                                } 
     799                        } 
     800                        catch(CoreException ce) 
     801                        { 
     802                                ce.printStackTrace (); 
     803                                mModule = null; 
     804                        } 
     805                        return mModule; 
     806                } 
     807                 
     808                public final String getCustomModuleName() 
     809                { 
     810                         return CUSTOM_MODULE_NAME; 
     811                } 
     812                 
     813                void modified(String key, Object o) 
     814                { 
     815                        mModified.put (key, o); 
     816                } 
     817        } 
     818         
     819 
    704820} 
  • branches/custome_policy/framework-plugin/src/com/tresys/framework/plugin/editor/custom/AddCustomPolicy.java

    r1987 r1991  
    1010package com.tresys.framework.plugin.editor.custom; 
    1111 
     12import java.io.ByteArrayInputStream; 
    1213import java.io.OutputStream; 
    1314 
     15import org.eclipse.core.internal.resources.WorkspaceRoot; 
     16import org.eclipse.core.resources.IFile; 
     17import org.eclipse.core.resources.IFolder; 
     18import org.eclipse.core.resources.IResource; 
     19import org.eclipse.core.runtime.CoreException; 
     20import org.eclipse.core.runtime.IPath; 
     21import org.eclipse.core.runtime.Platform; 
    1422import org.eclipse.gef.ui.actions.SelectionAction; 
     23import org.eclipse.jface.dialogs.ErrorDialog; 
    1524import org.eclipse.jface.dialogs.MessageDialog; 
    1625import org.eclipse.jface.viewers.IStructuredSelection; 
    1726import org.eclipse.jface.viewers.StructuredSelection; 
    1827import org.eclipse.swt.widgets.Shell; 
    19  
     28import org.eclipse.ui.PartInitException; 
     29import org.eclipse.ui.PlatformUI; 
     30import org.eclipse.ui.ide.IDE; 
     31 
     32import com.tresys.framework.compiler.custom.ICustomPolicy; 
    2033import com.tresys.framework.compiler.linkage.Linkage; 
    2134import com.tresys.framework.compiler.policy.Component; 
    2235import com.tresys.framework.compiler.translator.SELinuxPolicy; 
    2336import com.tresys.framework.plugin.SEFramework_Plugin; 
     37import com.tresys.framework.plugin.builder.SELinuxSystem.CPolicyContainer; 
    2438import com.tresys.framework.plugin.editor.policy.graphic.GraphicPolicyEditor; 
    2539import com.tresys.framework.plugin.editor.policy.graphic.GraphicPolicyMetaVisitor; 
     
    3145import com.tresys.framework.plugin.editor.policy.graphic.parts.ShapeEditPart; 
    3246import com.tresys.slide.plugin.editors.module.ModuleEditor; 
     47//import com.tresys.slide.plugin.editors.module.ModuleEditorInput; 
     48//import com.tresys.slide.plugin.views.policyexplorer.PLayer; 
     49//import com.tresys.slide.plugin.views.policyexplorer.PModule; 
    3350 
    3451public class AddCustomPolicy 
     
    95112                if( stream == null ) 
    96113                { 
     114                        System.out.println ("AddCustomPolicy.run() --> No Policy Found"); 
     115                        return; 
     116                } 
     117                 
     118                 
     119                try 
     120                { 
     121                        CPolicyContainer container = mEditor.getSystem ().getCustomPoilcyContainer (); 
     122                        IFile []files = container.getCustomModuleFiles(); 
    97123                         
    98                 } 
    99                  
    100                 ModuleEditor ediotr = new ModuleEditor(); 
    101                  
    102                 /** 
    103                  * provide input to editor and open up the editor. 
    104                  */ 
    105 //              IDE.openEditor (page, input) 
    106                 System.out.println ("Hello world"); 
    107         } 
    108          
    109         private boolean customizationAllowed(Object selected_item) 
     124                        if( files == null ) 
     125                        { 
     126                                MessageDialog.openError (shell, "Custom Policy", "Could not find files."); 
     127                                return; 
     128                        } 
     129                                 
     130                        if( files[CPolicyContainer.TE_FILE].exists () ) 
     131                        { 
     132                                ByteArrayInputStream input = new ByteArrayInputStream(stream.toString ().getBytes ()); 
     133                                files[0].appendContents (input, IResource.KEEP_HISTORY, null); 
     134                        } 
     135                        /** 
     136                         * provide input to editor and open up the editor. 
     137                         */ 
     138                                IDE.openEditor (mEditor.getSite ().getPage (), files[0], ModuleEditor.ID, true); 
     139                } 
     140                catch(PartInitException pe) 
     141                { 
     142                        ErrorDialog.openError (shell,"Error" ,pe.getMessage (), pe.getStatus ()); 
     143                } 
     144                catch(CoreException ce) 
     145                { 
     146                        ErrorDialog.openError (shell,"Error" ,ce.getMessage (), ce.getStatus ()); 
     147                } 
     148        } 
     149         
     150        private final boolean customizationAllowed(Object selected_item) 
    110151        { 
    111152                Linkage linkage = mEditor.getSystem ().getLinkage (); 
     
    122163                                Shape shape = (Shape)model; 
    123164                                Component comp = shape.getComponent ();  
    124                                 supports_customization = comp.supportsCustomPolicy (); 
     165                                if( comp instanceof ICustomPolicy ) 
     166                                        supports_customization = ((ICustomPolicy)comp).supportsCustomPolicy (); 
    125167                        } 
    126168                } 
     
    132174                        { 
    133175                                Shape shape = (Shape)model; 
    134                                 Component comp = shape.getComponent ();  
    135                                 supports_customization = comp.supportsCustomPolicy (); 
     176                                Component comp = shape.getComponent (); 
     177                                if( comp instanceof ICustomPolicy ) 
     178                                        supports_customization = ((ICustomPolicy)comp).supportsCustomPolicy (); 
    136179                        } 
    137180                } 
     
    146189                                Connection con = (Connection)model; 
    147190                                GraphicPolicyMetaVisitor meta_visitor = new GraphicPolicyMetaVisitor(policy); 
     191                                if( con instanceof ICustomPolicy ) 
     192                                        supports_customization = ((ICustomPolicy)con).supportsCustomPolicy (); 
    148193                                con.Accept (meta_visitor); 
    149194                                OutputStream p = policy.GetPolicy (); 
     
    152197                } 
    153198                return supports_customization; 
     199        } 
     200         
     201         
     202        private final Object getModel() 
     203        { 
     204                IStructuredSelection selection = (StructuredSelection)getSelection (); 
     205                Object selected_item = selection.getFirstElement (); 
     206                 
     207                Linkage linkage = mEditor.getSystem ().getLinkage (); 
     208                SELinuxPolicy policy = new SELinuxPolicy(linkage, null, null); 
     209                 
     210                if( selected_item instanceof ShapeEditPart) 
     211                { 
     212                        ShapeEditPart shape_part = (ShapeEditPart)selected_item; 
     213                        Object model = shape_part.getModel (); 
     214                } 
     215                else if( selected_item instanceof AbstractConnectionEditPart ) 
     216                { 
     217                        AbstractConnectionEditPart part = (AbstractConnectionEditPart)selected_item; 
     218                        Object model = part.getModel (); 
     219                        if( model instanceof Connection) 
     220                        { 
     221                                Connection con = (Connection)model; 
     222                                GraphicPolicyMetaVisitor meta_visitor = new GraphicPolicyMetaVisitor(policy); 
     223                        } 
     224                } 
     225                return null; 
     226        } 
     227         
     228        void getPolicy(Object model) 
     229        { 
    154230        } 
    155231         
  • branches/custome_policy/framework-plugin/src/com/tresys/framework/plugin/editor/policy/graphic/GraphicPolicyEditor.java

    r1989 r1991  
    9191import com.tresys.framework.plugin.builder.GUIErrorHandler; 
    9292import com.tresys.framework.plugin.builder.SELinuxSystem; 
     93import com.tresys.framework.plugin.editor.custom.AddCustomPolicy; 
    9394import com.tresys.framework.plugin.editor.policy.IPolicyEditor; 
    9495import com.tresys.framework.plugin.editor.policy.graphic.model.ModelElement; 
     
    851852                registry.registerAction(action); 
    852853                getSelectionActions().add(action.getId()); 
     854                 
     855                action = new AddCustomPolicy(this); 
     856                registry.registerAction(action); 
     857                getSelectionActions().add(action.getId()); 
     858                 
    853859} 
    854860