public AttributeMatch GetMatch()
        {
            AttributeMatch attrib = new AttributeMatch();

            attrib.Load(Value);
            return(attrib);
        }
Exemplo n.º 2
0
        private static List <ResourceAction> GetActionsFromRule(XacmlRule rule, List <RoleGrant> roles)
        {
            List <ResourceAction> actions = new List <ResourceAction>();

            foreach (XacmlAnyOf anyOf in rule.Target.AnyOf)
            {
                foreach (XacmlAllOf allOf in anyOf.AllOf)
                {
                    AttributeMatch actionAttributeMatch = new AttributeMatch();
                    foreach (XacmlMatch xacmlMatch in allOf.Matches)
                    {
                        if (xacmlMatch.AttributeDesignator.Category.Equals(XacmlConstants.MatchAttributeCategory.Action))
                        {
                            actionAttributeMatch.Id    = xacmlMatch.AttributeDesignator.AttributeId.OriginalString;
                            actionAttributeMatch.Value = xacmlMatch.AttributeValue.Value;
                            ResourceAction resourceAction = new ResourceAction
                            {
                                Match      = actionAttributeMatch,
                                RoleGrants = new List <RoleGrant>(),
                                Title      = xacmlMatch.AttributeValue.Value
                            };
                            resourceAction.RoleGrants.AddRange(roles);
                            if (!actions.Contains(resourceAction))
                            {
                                actions.Add(resourceAction);
                            }
                        }
                    }
                }
            }

            return(actions);
        }
Exemplo n.º 3
0
        private static void AssertEqual(AttributeMatch expected, AttributeMatch actual)
        {
            Assert.NotNull(actual);
            Assert.NotNull(expected);

            Assert.Equal(expected.Id, actual.Id);
            Assert.Equal(expected.Value, actual.Value);
        }
Exemplo n.º 4
0
        public bool Matches(AttributeMatch match)
        {
            // if the names don't match, return false
            // if the match has no predicate, return true
            // return the evaluation of the predicate with this one's value

            return(match.Name == Name &&
                   (match.Predicate == null || match.Predicate(Value)));
        }
Exemplo n.º 5
0
        public void WildcardNameMatchesAnyAttribute()
        {
            XmlMatch  match  = new AttributeMatch("*");
            XmlReader reader = GetReader("<foo id='1' enabled='true'></foo>");

            reader.MoveToContent();
            reader.MoveToFirstAttribute();

            Assert.IsTrue(match.Matches(reader, null));

            reader.MoveToNextAttribute();

            Assert.IsTrue(match.Matches(reader, null));
        }
Exemplo n.º 6
0
        public void WildcardNamespaceMatchesAttributesInAnyNamespace()
        {
            XmlMatch  match  = new AttributeMatch("*", "id");
            XmlReader reader = GetReader("<root id='1' x:id='1' xmlns:x='mvp-xml'></foo>");

            reader.MoveToContent();
            reader.MoveToFirstAttribute();

            Assert.IsTrue(match.Matches(reader, null));

            reader.MoveToNextAttribute();

            Assert.IsTrue(match.Matches(reader, null));
        }
Exemplo n.º 7
0
        public void BothWildcardMatchesAnyAttributeAndNamespace()
        {
            XmlMatch  match  = new AttributeMatch("*", "*");
            XmlReader reader = GetReader("<root foo='1' x:id='1' xmlns:x='mvp-xml'></root>");

            reader.MoveToContent();
            reader.MoveToFirstAttribute();

            Assert.IsTrue(match.Matches(reader, null));

            reader.MoveToNextAttribute();

            Assert.IsTrue(match.Matches(reader, null));
        }
Exemplo n.º 8
0
        public void AttributeMatchMatchesOnlyAttribute()
        {
            XmlMatch  match  = new AttributeMatch("id");
            XmlReader reader = GetReader("<bar id='23'><foo>hello</foo></bar>");

            reader.MoveToContent();

            Assert.IsFalse(match.Matches(reader, null));
            reader.MoveToFirstAttribute();
            Assert.IsTrue(match.Matches(reader, null));

            reader.MoveToElement();
            reader.Read();

            Assert.IsFalse(match.Matches(reader, null));
        }
Exemplo n.º 9
0
        public void WildcardNameDoesNotMatchWrongAttributeNamespace()
        {
            XmlMatch  match  = new AttributeMatch("*");
            XmlReader reader = GetReader("<foo id='1' x:enabled='true' xmlns:x='mvp-xml'><bar x:enabled='true' xmlns:x='mvp-xml'/></foo>");

            reader.MoveToContent();
            Assert.IsFalse(match.Matches(reader, null));

            reader.MoveToFirstAttribute();
            Assert.IsTrue(match.Matches(reader, null));

            reader.MoveToNextAttribute();
            Assert.IsFalse(match.Matches(reader, null));

            reader.MoveToNextAttribute();
            Assert.IsFalse(match.Matches(reader, null));

            reader.Read();
            Assert.IsFalse(match.Matches(reader, null));
        }
Exemplo n.º 10
0
        public static RequestToDelete GetRequestToDeleteModel(int lastChangedByUserId, int offeredByPartyId, string org, string app, List <string> ruleIds = null, int?coveredByPartyId = null, int?coveredByUserId = null)
        {
            AttributeMatch coveredBy = new AttributeMatch();

            if (coveredByUserId == null)
            {
                coveredBy.Id    = AltinnXacmlConstants.MatchAttributeIdentifiers.PartyAttribute;
                coveredBy.Value = coveredByPartyId.ToString();
            }
            else
            {
                coveredBy.Id    = AltinnXacmlConstants.MatchAttributeIdentifiers.UserAttribute;
                coveredBy.Value = coveredByUserId.ToString();
            }

            RequestToDelete requestToDelete = new RequestToDelete
            {
                DeletedByUserId = lastChangedByUserId,
                PolicyMatch     = new PolicyMatch
                {
                    CoveredBy = new List <AttributeMatch> {
                        coveredBy
                    },
                    OfferedByPartyId = offeredByPartyId,
                    Resource         = new List <AttributeMatch> {
                        new AttributeMatch {
                            Id = AltinnXacmlConstants.MatchAttributeIdentifiers.OrgAttribute, Value = org
                        }, new AttributeMatch {
                            Id = AltinnXacmlConstants.MatchAttributeIdentifiers.AppAttribute, Value = app
                        }
                    }
                },

                RuleIds = ruleIds
            };

            return(requestToDelete);
        }
Exemplo n.º 11
0
		public void WildcardNameDoesNotMatchWrongAttributeNamespace()
		{
			XmlMatch match = new AttributeMatch("*");
			XmlReader reader = GetReader("<foo id='1' x:enabled='true' xmlns:x='mvp-xml'><bar x:enabled='true' xmlns:x='mvp-xml'/></foo>");

			reader.MoveToContent();
			Assert.IsFalse(match.Matches(reader, null));

			reader.MoveToFirstAttribute();
			Assert.IsTrue(match.Matches(reader, null));

			reader.MoveToNextAttribute();
			Assert.IsFalse(match.Matches(reader, null));

			reader.MoveToNextAttribute();
			Assert.IsFalse(match.Matches(reader, null));

			reader.Read();
			Assert.IsFalse(match.Matches(reader, null));
		}
Exemplo n.º 12
0
		public void AttributeMatchMatchesOnlyAttribute()
		{
			XmlMatch match = new AttributeMatch("id");
			XmlReader reader = GetReader("<bar id='23'><foo>hello</foo></bar>");
			reader.MoveToContent();

			Assert.IsFalse(match.Matches(reader, null));
			reader.MoveToFirstAttribute();
			Assert.IsTrue(match.Matches(reader, null));

			reader.MoveToElement();
			reader.Read();

			Assert.IsFalse(match.Matches(reader, null));
		}
Exemplo n.º 13
0
		public void WildcardNamespaceMatchesAttributesInAnyNamespace()
		{
			XmlMatch match = new AttributeMatch("*", "id");
			XmlReader reader = GetReader("<root id='1' x:id='1' xmlns:x='mvp-xml'></foo>");
			reader.MoveToContent();
			reader.MoveToFirstAttribute();

			Assert.IsTrue(match.Matches(reader, null));

			reader.MoveToNextAttribute();

			Assert.IsTrue(match.Matches(reader, null));
		}
Exemplo n.º 14
0
        public void FullNameContainsPrefixAndName2()
        {
            XmlMatch name = new AttributeMatch("foo", "bar");

            Assert.AreEqual("foo:bar", name.FullName);
        }
Exemplo n.º 15
0
		public void FullNameContainsPrefixAndName2()
		{
			XmlMatch name = new AttributeMatch("foo", "bar");

			Assert.AreEqual("foo:bar", name.FullName);
		}
Exemplo n.º 16
0
		public void BothWildcardMatchesAnyAttributeAndNamespace()
		{
			XmlMatch match = new AttributeMatch("*", "*");
			XmlReader reader = GetReader("<root foo='1' x:id='1' xmlns:x='mvp-xml'></root>");
			reader.MoveToContent();
			reader.MoveToFirstAttribute();

			Assert.IsTrue(match.Matches(reader, null));

			reader.MoveToNextAttribute();

			Assert.IsTrue(match.Matches(reader, null));
		}
Exemplo n.º 17
0
		public void WildcardNameMatchesAnyAttribute()
		{
			XmlMatch match = new AttributeMatch("*");
			XmlReader reader = GetReader("<foo id='1' enabled='true'></foo>");
			reader.MoveToContent();
			reader.MoveToFirstAttribute();

			Assert.IsTrue(match.Matches(reader, null));

			reader.MoveToNextAttribute();

			Assert.IsTrue(match.Matches(reader, null));
		}