/// <summary>
 /// Creates a TargetItemCollection, with the items contained in a ReadWriteTargetItemCollection
 /// </summary>
 /// <param name="items"></param>
 public TargetItemCollection(TargetItemReadWriteCollection items)
 {
     if (items == null)
     {
         throw new ArgumentNullException("items");
     }
     foreach (TargetItemBaseReadWrite item in items)
     {
         SubjectElementReadWrite     sItem = item as SubjectElementReadWrite;
         ActionElementReadWrite      aItem = item as ActionElementReadWrite;
         ResourceElementReadWrite    rItem = item as ResourceElementReadWrite;
         EnvironmentElementReadWrite eItem = item as EnvironmentElementReadWrite;
         if (sItem != null)
         {
             this.List.Add(new SubjectElement(sItem.Match, sItem.SchemaVersion));
         }
         else if (aItem != null)
         {
             this.List.Add(new ActionElement(aItem.Match, aItem.SchemaVersion));
         }
         else if (rItem != null)
         {
             this.List.Add(new ResourceElement(rItem.Match, rItem.SchemaVersion));
         }
         else if (eItem != null)
         {
             this.List.Add(new EnvironmentElement(eItem.Match, eItem.SchemaVersion));
         }
     }
 }
Exemple #2
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="args"></param>
		private void CreateTargetItem( object sender, EventArgs args )
		{
			if( mainTree.SelectedNode is AnySubject )
			{
				AnySubject anyNode = (AnySubject)mainTree.SelectedNode;
				Target targetNode = (Target)anyNode.Parent;

				int idx = targetNode.Nodes.IndexOf( anyNode );
				targetNode.Nodes.RemoveAt( idx );

				pol.TargetMatchReadWriteCollection matchCollection = new pol.TargetMatchReadWriteCollection();
				matchCollection.Add( 
					new pol.SubjectMatchElementReadWrite( 
						InternalFunctions.StringEqual, 
						new pol.AttributeValueElementReadWrite( InternalDataTypes.XsdString, "Somebody", XacmlVersion.Version11 ),  //TODO: check version
						new pol.SubjectAttributeDesignatorElement( InternalDataTypes.XsdString, false, SubjectElement.ActionSubjectId, "", "", XacmlVersion.Version11 ), XacmlVersion.Version11 ) );  //TODO: check version
				pol.SubjectElementReadWrite targetItem = new pol.SubjectElementReadWrite( matchCollection, XacmlVersion.Version11 );  //TODO: check version

				TargetItem targetItemNode = new TargetItem( targetItem );

				targetNode.Nodes.Insert( idx, targetItemNode ); 
				targetNode.TargetDefinition.Subjects.IsAny = false;
				targetNode.TargetDefinition.Subjects.ItemsList.Add( targetItem );
				targetItemNode.NodeFont = new Font( mainTree.Font, FontStyle.Bold );

				mainTree.SelectedNode = targetItemNode;
			}
			else if( mainTree.SelectedNode is AnyAction )
			{
				AnyAction anyActionNode = (AnyAction)mainTree.SelectedNode;
				Target targetNode = (Target)anyActionNode.Parent;

				int idx = targetNode.Nodes.IndexOf( anyActionNode );
				targetNode.Nodes.RemoveAt( idx );

				pol.TargetMatchReadWriteCollection matchCollection = new pol.TargetMatchReadWriteCollection();
				matchCollection.Add( 
					new pol.ActionMatchElementReadWrite( 
						InternalFunctions.StringEqual, 
						new pol.AttributeValueElementReadWrite( InternalDataTypes.XsdString, "DoSomething", XacmlVersion.Version11 ),  //TODO: check version
						new pol.ActionAttributeDesignatorElement( InternalDataTypes.XsdString, false, ActionElement.ActionId, "", XacmlVersion.Version11 ), XacmlVersion.Version11 ) ); //TODO: check version
				pol.ActionElementReadWrite action = new pol.ActionElementReadWrite( matchCollection, XacmlVersion.Version11 ); //TODO: check version

				TargetItem actionNode = new TargetItem( action );

				targetNode.Nodes.Insert( idx, actionNode ); 
				targetNode.TargetDefinition.Actions.IsAny = false;
				targetNode.TargetDefinition.Actions.ItemsList.Add( action );
				actionNode.NodeFont = new Font( mainTree.Font, FontStyle.Bold );

				mainTree.SelectedNode = actionNode;
			}
			else if( mainTree.SelectedNode is AnyResource )
			{
				AnyResource anyNode = (AnyResource)mainTree.SelectedNode;
				Target targetNode = (Target)anyNode.Parent;

				int idx = targetNode.Nodes.IndexOf( anyNode );
				targetNode.Nodes.RemoveAt( idx );

				pol.TargetMatchReadWriteCollection matchCollection = new pol.TargetMatchReadWriteCollection();
				matchCollection.Add( 
					new pol.ResourceMatchElementReadWrite( 
						InternalFunctions.StringEqual, 
						new pol.AttributeValueElementReadWrite( InternalDataTypes.XsdString, "Something", XacmlVersion.Version11 ),  //TODO: check version
						new pol.ResourceAttributeDesignatorElement( InternalDataTypes.XsdString, false, ResourceElement.ResourceId, "", XacmlVersion.Version11 ), XacmlVersion.Version11 ) ); //TODO: check version
				pol.ResourceElementReadWrite targetItem = new pol.ResourceElementReadWrite( matchCollection, XacmlVersion.Version11 ); //TODO: check version

				TargetItem targetItemNode = new TargetItem( targetItem );

				targetNode.Nodes.Insert( idx, targetItemNode ); 
				targetNode.TargetDefinition.Resources.IsAny = false;
				targetNode.TargetDefinition.Resources.ItemsList.Add( targetItem );
				targetItemNode.NodeFont = new Font( mainTree.Font, FontStyle.Bold );

				mainTree.SelectedNode = targetItemNode;
			}			
		}