示例#1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void lstMatch_SelectedIndexChanged(object sender, System.EventArgs e)
 {
     if (lstMatch.SelectedItem != null)
     {
         if (index != -1 && index != lstMatch.SelectedIndex)
         {
             TargetMatchBaseReadWrite indexMatch = lstMatch.Items[index] as TargetMatchBaseReadWrite;
             lstMatch.Items.RemoveAt(index);
             lstMatch.Items.Insert(index, indexMatch);
         }
         TargetMatchBaseReadWrite match = lstMatch.SelectedItem as TargetMatchBaseReadWrite;
         index = lstMatch.SelectedIndex;
         try
         {
             LoadingData = true;
             Match matchControl = _list[lstMatch.SelectedIndex] as Match;
             if (matchControl == null)
             {
                 matchControl = new Match(_targetItem, match, lstMatch.SelectedIndex);
                 _list[lstMatch.SelectedIndex] = matchControl;
             }
             mainPanel.Controls.Clear();
             mainPanel.Controls.Add(matchControl);
         }
         finally
         {
             LoadingData = false;
         }
     }
 }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAdd_Click(object sender, System.EventArgs e)
        {
            TargetMatchBaseReadWrite targetMatch = null;

            if (_targetItem is ActionElementReadWrite)
            {
                targetMatch = new ActionMatchElementReadWrite(
                    Consts.Schema1.InternalFunctions.StringEqual,
                    new pol.AttributeValueElementReadWrite(Consts.Schema1.InternalDataTypes.XsdString, "Somebody", Xacml.XacmlVersion.Version11),  //TODO: check version
                    new ActionAttributeDesignatorElement(Consts.Schema1.InternalDataTypes.XsdString, false, "", "", Xacml.XacmlVersion.Version11), //TODO: check version
                    Xacml.XacmlVersion.Version11);
            }
            else if (_targetItem is EnvironmentElementReadWrite)
            {
                targetMatch = new EnvironmentMatchElementReadWrite(
                    Consts.Schema1.InternalFunctions.StringEqual,
                    new pol.AttributeValueElementReadWrite(Consts.Schema1.InternalDataTypes.XsdString, "Somebody", Xacml.XacmlVersion.Version11),       //TODO: check version
                    new EnvironmentAttributeDesignatorElement(Consts.Schema1.InternalDataTypes.XsdString, false, "", "", Xacml.XacmlVersion.Version11), //TODO: check version
                    Xacml.XacmlVersion.Version11);
            }
            else if (_targetItem is ResourceElementReadWrite)
            {
                targetMatch = new ResourceMatchElementReadWrite(
                    Consts.Schema1.InternalFunctions.StringEqual,
                    new pol.AttributeValueElementReadWrite(Consts.Schema1.InternalDataTypes.XsdString, "Somebody", Xacml.XacmlVersion.Version11),    //TODO: check version
                    new ResourceAttributeDesignatorElement(Consts.Schema1.InternalDataTypes.XsdString, false, "", "", Xacml.XacmlVersion.Version11), //TODO: check version
                    Xacml.XacmlVersion.Version11);
            }
            else if (_targetItem is SubjectElementReadWrite)
            {
                targetMatch = new SubjectMatchElementReadWrite(
                    Consts.Schema1.InternalFunctions.StringEqual,
                    new pol.AttributeValueElementReadWrite(Consts.Schema1.InternalDataTypes.XsdString, "Somebody", Xacml.XacmlVersion.Version11),       //TODO: check version
                    new SubjectAttributeDesignatorElement(Consts.Schema1.InternalDataTypes.XsdString, false, "", "", "", Xacml.XacmlVersion.Version11), //TODO: check version
                    Xacml.XacmlVersion.Version11);
            }

            _targetItem.Match.Add(targetMatch); //TODO: check version

            try
            {
                LoadingData = true;
                Match matchControl = new Match(_targetItem, targetMatch, lstMatch.Items.Count);
                _list[lstMatch.Items.Count] = matchControl;
            }
            finally
            {
                LoadingData = false;
            }

            index = -1;
            lstMatch.Items.Clear();
            foreach (TargetMatchBaseReadWrite match in _targetItem.Match)
            {
                lstMatch.Items.Add(match);
            }
        }
示例#3
0
		/// <summary>
		/// Resolves the attribute reference defined within the given match.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="match">The target item match.</param>
		/// <param name="contextTargetItem">The context target item.</param>
		/// <returns>The context attribute.</returns>
		public static Context.AttributeElement Resolve(EvaluationContext context, TargetMatchBaseReadWrite match, ctx.TargetItemBase contextTargetItem)
		{
			Context.AttributeElementReadWrite attribute = null;
			if (match.AttributeReference is pol.AttributeDesignatorBase)
			{
				var attrDesig = (pol.AttributeDesignatorBase)match.AttributeReference;
				context.Trace("Looking for attribute: {0}", attrDesig.AttributeId);
				foreach (Context.AttributeElementReadWrite tempAttribute in contextTargetItem.Attributes)
				{
					if (tempAttribute.Match(attrDesig))
					{
						attribute = tempAttribute;
						break;
					}
				}

				if (attribute == null)
				{
					context.Trace("Attribute not found, loading searching an external repository");
					attribute = GetAttribute(context, attrDesig);
				}
			}
			else if (match.AttributeReference is pol.AttributeSelectorElement)
			{
				var attrSelec = (pol.AttributeSelectorElement)match.AttributeReference;
				var content = (ctx.ResourceContentElement)((ctx.ResourceElement)contextTargetItem).ResourceContent;
				if (content != null)
				{
					XmlDocument doc = context.ContextDocument.XmlDocument;

					if (context.ContextDocument.XmlNamespaceManager == null)
					{
						context.ContextDocument.AddNamespaces(context.PolicyDocument.Namespaces);
					}

					string xpath = attrSelec.RequestContextPath;
					try
					{
						Debug.Assert(doc.DocumentElement != null, "doc.DocumentElement != null");
						XmlNode node = doc.DocumentElement.SelectSingleNode(xpath, context.ContextDocument.XmlNamespaceManager);
						if (node != null)
						{
							attribute = new ctx.AttributeElement(null, attrSelec.DataType, null, null, node.InnerText, attrSelec.SchemaVersion);
						}
					}
					catch (XPathException e)
					{
						context.Trace("ERR: {0}", e.Message);
						context.ProcessingError = true;
					}
				}
			}

			if (!context.ProcessingError && attribute == null && match.AttributeReference.MustBePresent)
			{
				context.IsMissingAttribute = true;
				context.AddMissingAttribute(match.AttributeReference);
			}

			if (attribute != null)
			{
				return new Context.AttributeElement(attribute.AttributeId, attribute.DataType, attribute.Issuer, attribute.IssueInstant,
					attribute.Value, attribute.SchemaVersion);
			}
			return null;
		}
示例#4
0
文件: Match.cs 项目: zszqwe/anycmd
        /// <summary>
        ///
        /// </summary>
        /// <param name="targetItem"></param>
        /// <param name="match"></param>
        /// <param name="index"></param>
        public Match(TargetItemBaseReadWrite targetItem, TargetMatchBaseReadWrite match, int index)
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            LoadingData = true;

            foreach (FieldInfo field in typeof(Consts.Schema1.InternalDataTypes).GetFields())
            {
                cmbASDataType.Items.Add(field.GetValue(null));
                cmbADDataType.Items.Add(field.GetValue(null));
                cmbAVDataType.Items.Add(field.GetValue(null));
            }

            foreach (FieldInfo field in typeof(Consts.Schema1.InternalFunctions).GetFields())
            {
                cmbFunctions.Items.Add(field.GetValue(null));
            }

            txtSubjectCategory.Visible = false;
            lblSubjectCategory.Visible = false;

            _match = match;
            _index = index;

            if (targetItem is ActionElementReadWrite)
            {
                _targetItemName = "Action";
            }
            else if (targetItem is SubjectElementReadWrite)
            {
                _targetItemName            = "Subject";
                txtSubjectCategory.Visible = true;
                lblSubjectCategory.Visible = true;
            }
            else if (targetItem is ResourceElementReadWrite)
            {
                _targetItemName = "Resource";
            }

            grpMatch.Text = _targetItemName + "Match";

            cmbFunctions.SelectedIndex = cmbFunctions.FindStringExact(_match.MatchId);
            cmbFunctions.DataBindings.Add("SelectedItem", _match, "MatchId");

            cmbAVDataType.SelectedIndex = cmbAVDataType.FindStringExact(match.AttributeValue.DataType);
            cmbAVDataType.DataBindings.Add("SelectedItem", _match.AttributeValue, "DataType");

            txtAttributeValue.Text = match.AttributeValue.Contents;
            txtAttributeValue.DataBindings.Add("Text", _match.AttributeValue, "Contents");

            if (match.AttributeReference is pol.AttributeDesignatorBase)
            {
                rdbAttributeDesignator.Checked = true;
                rdbAttributeSelector.Checked   = false;

                cmbADDataType.SelectedIndex = cmbADDataType.FindStringExact(match.AttributeReference.DataType);
                cmbADDataType.DataBindings.Add("SelectedItem", _match.AttributeReference, "DataType");

                chkADMustBePresent.Checked = match.AttributeReference.MustBePresent;
                chkADMustBePresent.DataBindings.Add("Checked", _match.AttributeReference, "MustBePresent");

                pol.AttributeDesignatorBase attributeDesignator = (pol.AttributeDesignatorBase)match.AttributeReference;
                txtAttributeId.Text = attributeDesignator.AttributeId;
                txtAttributeId.DataBindings.Add("Text", _match.AttributeReference, "AttributeId");

                txtIssuer.Text = attributeDesignator.Issuer;
                txtIssuer.DataBindings.Add("Text", _match.AttributeReference, "Issuer");
            }
            else if (match.AttributeReference is pol.AttributeSelectorElement)
            {
                rdbAttributeDesignator.Checked = false;
                rdbAttributeSelector.Checked   = true;

                cmbASDataType.SelectedIndex = cmbASDataType.FindStringExact(match.AttributeReference.DataType);
                cmbASDataType.DataBindings.Add("SelectedItem", _match.AttributeReference, "DataType");

                chkASMustBePresent.Checked = match.AttributeReference.MustBePresent;
                chkASMustBePresent.DataBindings.Add("Checked", _match.AttributeReference, "MustBePresent");

                txtRequestContextPath.Text = ((pol.AttributeSelectorElement)match.AttributeReference).RequestContextPath;
                txtRequestContextPath.DataBindings.Add("Text", _match.AttributeReference, "RequestContextPath");
            }

            LoadingData = false;
        }