Changeset 1991
- Timestamp:
- 03/11/08 10:39:44 (9 months ago)
- Files:
-
- branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/custom/ICustomPolicy.java (modified) (1 diff)
- branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/policy/Access.java (modified) (3 diffs)
- branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/policy/BaseDomain.java (modified) (1 diff)
- branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/policy/Component.java (modified) (2 diffs)
- branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/policy/Conditional.java (modified) (2 diffs)
- branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/policy/Enter.java (modified) (2 diffs)
- branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/policy/EntrypointResource.java (modified) (3 diffs)
- branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/policy/Resource.java (modified) (3 diffs)
- branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/policy/UserDomain.java (modified) (2 diffs)
- branches/custome_policy/framework-plugin/src/com/tresys/framework/plugin/builder/SELinuxSystem.java (modified) (6 diffs)
- branches/custome_policy/framework-plugin/src/com/tresys/framework/plugin/editor/custom/AddCustomPolicy.java (modified) (7 diffs)
- branches/custome_policy/framework-plugin/src/com/tresys/framework/plugin/editor/policy/graphic/GraphicPolicyEditor.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/custom/ICustomPolicy.java
r1987 r1991 19 19 20 20 public boolean hasCustomization(); 21 22 public void markCustomized(); 23 24 public void removeCustomization(); 25 21 26 } branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/policy/Access.java
r1987 r1991 36 36 37 37 protected final AbstractToken Token; 38 39 private boolean mIsModified; 38 40 39 41 public Access(IDomain dom, IResource res, Integer /*Verb*/verb, … … 45 47 m_bool = bool; 46 48 m_onOrOff = activeOnBool; 49 mIsModified = false; 47 50 } 48 51 … … 190 193 public boolean hasCustomization() 191 194 { 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; 193 206 } 194 207 branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/policy/BaseDomain.java
r1989 r1991 249 249 return false; 250 250 } 251 252 public boolean supportsCustomPolicy()253 {254 return false;255 }256 257 public boolean hasCustomization()258 {259 return false;260 }261 262 251 } branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/policy/Component.java
r1989 r1991 22 22 import com.tresys.framework.compiler.ErrorHandler; 23 23 import com.tresys.framework.compiler.AbstractToken; 24 import com.tresys.framework.compiler.custom.ICustomPolicy;25 24 26 25 /** … … 40 39 public abstract class Component 41 40 extends Object 42 implements Comparable/*<Component>*/, IPolicyVisitable , ICustomPolicy41 implements Comparable/*<Component>*/, IPolicyVisitable 43 42 { 44 43 45 44 /** The sub-name of the component instance of the class */ 46 45 protected String m_subName; // component name 46 47 protected boolean mIsModified; 47 48 48 49 protected final AbstractToken m_token; branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/policy/Conditional.java
r1987 r1991 10 10 11 11 import com.tresys.framework.compiler.AbstractToken; 12 import com.tresys.framework.compiler.custom.ICustomPolicy; 12 13 13 14 public class Conditional 14 15 extends Component 15 implements IResource 16 implements IResource, ICustomPolicy 16 17 { 17 18 protected boolean defaultState; … … 58 59 public boolean supportsCustomPolicy() 59 60 { 60 return false;61 return true; 61 62 } 62 63 63 64 public boolean hasCustomization() 64 65 { 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; 66 77 } 67 78 branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/policy/Enter.java
r1987 r1991 50 50 protected EntrypointResource m_entrypoint_resource; 51 51 52 52 protected boolean mIsModified; 53 53 54 54 /* … … 227 227 public boolean hasCustomization() 228 228 { 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; 230 240 } 231 241 branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/policy/EntrypointResource.java
r1989 r1991 15 15 16 16 import com.tresys.framework.compiler.AbstractToken; 17 import com.tresys.framework.compiler.custom.ICustomPolicy; 17 18 import com.tresys.framework.compiler.dictionary.Entrypoint; 18 19 import com.tresys.framework.compiler.mls.MLSLevel; … … 31 32 public final class EntrypointResource 32 33 extends Component 33 implements IMLSSetting 34 implements IMLSSetting, ICustomPolicy 34 35 { 35 36 … … 160 161 public boolean hasCustomization() 161 162 { 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; 163 174 } 164 175 } branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/policy/Resource.java
r1987 r1991 17 17 18 18 import com.tresys.framework.compiler.AbstractToken; 19 import com.tresys.framework.compiler.custom.ICustomPolicy; 19 20 import com.tresys.framework.compiler.dictionary.Rdef; 20 21 import com.tresys.framework.compiler.dictionary.Verb; … … 31 32 public class Resource 32 33 extends ComponentWithDictObjects 33 implements IResource 34 implements IResource, ICustomPolicy 34 35 { 35 36 … … 150 151 public boolean hasCustomization() 151 152 { 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; 153 164 } 154 165 branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/policy/UserDomain.java
r1989 r1991 20 20 21 21 import com.tresys.framework.compiler.AbstractToken; 22 import com.tresys.framework.compiler.custom.ICustomPolicy; 22 23 23 24 public class UserDomain 24 25 extends Component 25 implements IDomain 26 implements IDomain, ICustomPolicy 26 27 { 27 28 /** … … 189 190 public boolean hasCustomization() 190 191 { 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; 192 203 } 193 204 branches/custome_policy/framework-plugin/src/com/tresys/framework/plugin/builder/SELinuxSystem.java
r1989 r1991 27 27 import org.eclipse.core.resources.IWorkspaceRunnable; 28 28 import org.eclipse.core.runtime.CoreException; 29 import org.eclipse.core.runtime.IPath; 29 30 import org.eclipse.core.runtime.IProgressMonitor; 30 31 import org.eclipse.core.runtime.Path; … … 68 69 implements IWorkbenchAdapter, PolicyXMLListener, IAnalysisListener 69 70 { 71 72 73 private static final String CDS_LAYER = "/policy/modules/cds"; 74 70 75 71 76 /** The saved reference to the Policy */ … … 84 89 /** Folder this system lives in */ 85 90 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 87 98 /** Name of the system */ 88 99 private final String m_name; … … 507 518 } 508 519 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 509 554 public void Translate() 510 555 throws CoreException … … 521 566 } 522 567 523 final String policyPath = " /policy/modules/apps/cdsframework-" + m_name;524 525 final IFile teFile = get Folder().getFile(policyPath + ".te");526 final IFile ifFile = get Folder().getFile(policyPath + ".if");527 final IFile fcFile = get Folder().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"); 528 573 529 574 final IFile dictionaryFile = getFolder ().getFile ("policy/support/cdsdictionary.spt"); … … 702 747 } 703 748 } 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 704 820 } branches/custome_policy/framework-plugin/src/com/tresys/framework/plugin/editor/custom/AddCustomPolicy.java
r1987 r1991 10 10 package com.tresys.framework.plugin.editor.custom; 11 11 12 import java.io.ByteArrayInputStream; 12 13 import java.io.OutputStream; 13 14 15 import org.eclipse.core.internal.resources.WorkspaceRoot; 16 import org.eclipse.core.resources.IFile; 17 import org.eclipse.core.resources.IFolder; 18 import org.eclipse.core.resources.IResource; 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.core.runtime.IPath; 21 import org.eclipse.core.runtime.Platform; 14 22 import org.eclipse.gef.ui.actions.SelectionAction; 23 import org.eclipse.jface.dialogs.ErrorDialog; 15 24 import org.eclipse.jface.dialogs.MessageDialog; 16 25 import org.eclipse.jface.viewers.IStructuredSelection; 17 26 import org.eclipse.jface.viewers.StructuredSelection; 18 27 import org.eclipse.swt.widgets.Shell; 19 28 import org.eclipse.ui.PartInitException; 29 import org.eclipse.ui.PlatformUI; 30 import org.eclipse.ui.ide.IDE; 31 32 import com.tresys.framework.compiler.custom.ICustomPolicy; 20 33 import com.tresys.framework.compiler.linkage.Linkage; 21 34 import com.tresys.framework.compiler.policy.Component; 22 35 import com.tresys.framework.compiler.translator.SELinuxPolicy; 23 36 import com.tresys.framework.plugin.SEFramework_Plugin; 37 import com.tresys.framework.plugin.builder.SELinuxSystem.CPolicyContainer; 24 38 import com.tresys.framework.plugin.editor.policy.graphic.GraphicPolicyEditor; 25 39 import com.tresys.framework.plugin.editor.policy.graphic.GraphicPolicyMetaVisitor; … … 31 45 import com.tresys.framework.plugin.editor.policy.graphic.parts.ShapeEditPart; 32 46 import 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; 33 50 34 51 public class AddCustomPolicy … … 95 112 if( stream == null ) 96 113 { 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(); 97 123 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) 110 151 { 111 152 Linkage linkage = mEditor.getSystem ().getLinkage (); … … 122 163 Shape shape = (Shape)model; 123 164 Component comp = shape.getComponent (); 124 supports_customization = comp.supportsCustomPolicy (); 165 if( comp instanceof ICustomPolicy ) 166 supports_customization = ((ICustomPolicy)comp).supportsCustomPolicy (); 125 167 } 126 168 } … … 132 174 { 133 175 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 (); 136 179 } 137 180 } … … 146 189 Connection con = (Connection)model; 147 190 GraphicPolicyMetaVisitor meta_visitor = new GraphicPolicyMetaVisitor(policy); 191 if( con instanceof ICustomPolicy ) 192 supports_customization = ((ICustomPolicy)con).supportsCustomPolicy (); 148 193 con.Accept (meta_visitor); 149 194 OutputStream p = policy.GetPolicy (); … … 152 197 } 153 198 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 { 154 230 } 155 231 branches/custome_policy/framework-plugin/src/com/tresys/framework/plugin/editor/policy/graphic/GraphicPolicyEditor.java
r1989 r1991 91 91 import com.tresys.framework.plugin.builder.GUIErrorHandler; 92 92 import com.tresys.framework.plugin.builder.SELinuxSystem; 93 import com.tresys.framework.plugin.editor.custom.AddCustomPolicy; 93 94 import com.tresys.framework.plugin.editor.policy.IPolicyEditor; 94 95 import com.tresys.framework.plugin.editor.policy.graphic.model.ModelElement; … … 851 852 registry.registerAction(action); 852 853 getSelectionActions().add(action.getId()); 854 855 action = new AddCustomPolicy(this); 856 registry.registerAction(action); 857 getSelectionActions().add(action.getId()); 858 853 859 } 854 860
