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

            attrib.Load(Value);
            return(attrib);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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)));
        }
Beispiel #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));
        }
Beispiel #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));
        }
Beispiel #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));
        }
Beispiel #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));
        }
Beispiel #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));
        }
Beispiel #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);
        }
Beispiel #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));
		}
Beispiel #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));
		}
Beispiel #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));
		}
Beispiel #14
0
        public void FullNameContainsPrefixAndName2()
        {
            XmlMatch name = new AttributeMatch("foo", "bar");

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

			Assert.AreEqual("foo:bar", name.FullName);
		}
Beispiel #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));
		}
Beispiel #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));
		}