public AttributeMatch GetMatch() { AttributeMatch attrib = new AttributeMatch(); attrib.Load(Value); return(attrib); }
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); }
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); }
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))); }
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)); }
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)); }
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)); }
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)); }
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)); }
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); }
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)); }
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)); }
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)); }
public void FullNameContainsPrefixAndName2() { XmlMatch name = new AttributeMatch("foo", "bar"); Assert.AreEqual("foo:bar", name.FullName); }
public void FullNameContainsPrefixAndName2() { XmlMatch name = new AttributeMatch("foo", "bar"); Assert.AreEqual("foo:bar", name.FullName); }
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)); }
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)); }