AddPolicyRule() 공개 메소드

public AddPolicyRule ( Uri scopeUri, ClaimsPolicyEngine.Model.PolicyRule rule ) : void
scopeUri System.Uri
rule ClaimsPolicyEngine.Model.PolicyRule
리턴 void
예제 #1
0
        public void AddPolicyRuleShouldPassIfExistingScope()
        {
            XmlPolicyStore store = new XmlPolicyStore("My Xml Store Path", new MockXmlRepository(@".\content\claimMappings-PassingTest2.xml"));

            int initialScopeCount = store.RetrieveScopes().Count();

            IList<InputPolicyClaim> inputClaims = new List<InputPolicyClaim>();
            Issuer issuer = new Issuer("http://myIssuer1");
            ClaimType claimType = new ClaimType("http://myClaimType", "myClaimType");
            inputClaims.Add(new InputPolicyClaim(issuer, claimType, "nicolas"));
            PolicyRule newRule = new PolicyRule(AssertionsMatch.Any, inputClaims, new OutputPolicyClaim(claimType, string.Empty, CopyFromConstants.InputValue));

            store.AddPolicyRule(new Uri("http://localhost/1"), newRule);

            int expectedScopeCount = initialScopeCount;
            Assert.AreEqual(expectedScopeCount, store.RetrieveScopes().Count());
            Assert.AreEqual(2, store.RetrieveScopes().ElementAt(0).Rules.Count());
        }
예제 #2
0
        public void ShouldPassEvaluateRuleIfCopyOutputValueFromInputIssuer()
        {
            var store = new XmlPolicyStore("My Xml Store Path", new MockXmlRepository(@"content\integrationTest2.xml"));

            PolicyScope scope = store.RetrieveScope(new Uri("http://localhost/1"));
            var issuer = scope.Issuers.ElementAt(0);
            IList<InputPolicyClaim> inputClaims = new List<InputPolicyClaim>();
            ClaimType claimType = new ClaimType("http://myClaimType", "myClaimType");
            inputClaims.Add(new InputPolicyClaim(issuer, claimType, "*"));
            PolicyRule newRule = new PolicyRule(AssertionsMatch.Any, inputClaims, new OutputPolicyClaim(claimType, string.Empty, CopyFromConstants.InputIssuer));

            store.AddPolicyRule(new Uri("http://localhost/1"), newRule);
            string claimValue = "myInputClaimValue33";

            ClaimsPolicyEvaluator evaluator = new ClaimsPolicyEvaluator(store);
            Claim inputClaim = new Claim("http://myClaimType", claimValue, string.Empty, "http://myIssuer1");
            IEnumerable<Claim> evaluatedOutputClaims = evaluator.Evaluate(new Uri("http://localhost/1"), new[] { inputClaim });

            Assert.IsNotNull(evaluatedOutputClaims);
            Assert.AreEqual("http://myClaimType", evaluatedOutputClaims.ElementAt(0).ClaimType);
        }
예제 #3
0
        public void AddPolicyRuleShouldAddNewOutputClaimTypeIfDoesNotExists()
        {
            XmlPolicyStore store = new XmlPolicyStore("My Xml Store Path", new MockXmlRepository(@".\content\claimMappings-PassingTest3.xml"));
            var scopeUri = new Uri("http://localhost/1");

            IList<InputPolicyClaim> inputClaims = new List<InputPolicyClaim>();
            Issuer issuer = new Issuer("http://myIssuer1", "6f7051ece706096ac5a05ecb1860e2151c11b491", "myIssuer1");
            ClaimType claimType = new ClaimType("http://myClaimType", "myClaimType");

            inputClaims.Add(new InputPolicyClaim(issuer, claimType, "nicolas"));

            ClaimType newClaimType = new ClaimType("http://newClaimType", "myNewClaimType");

            PolicyRule newRule = new PolicyRule(AssertionsMatch.Any, inputClaims, new OutputPolicyClaim(newClaimType, string.Empty, CopyFromConstants.InputValue));

            store.AddPolicyRule(scopeUri, newRule);
            var scope = store.RetrieveScope(scopeUri);

            Assert.AreEqual(2, scope.ClaimTypes.Count);
            Assert.AreEqual(newClaimType.FullName, scope.ClaimTypes.ElementAt(1).FullName);
            Assert.AreEqual(newClaimType.DisplayName, scope.ClaimTypes.ElementAt(1).DisplayName);
        }
예제 #4
0
        public void AddPolicyRuleShouldThrowIfNotExistingScope()
        {
            XmlPolicyStore store = new XmlPolicyStore("My Xml Store Path", new MockXmlRepository(@".\content\claimMappings-PassingTest2.xml"));

            IList<InputPolicyClaim> inputClaims = new List<InputPolicyClaim>();
            Issuer issuer = new Issuer("http://myIssuer1");
            ClaimType claimType = new ClaimType("http://myClaimType", "myClaimType");
            inputClaims.Add(new InputPolicyClaim(issuer, claimType, "nicolas"));
            PolicyRule newRule = new PolicyRule(AssertionsMatch.Any, inputClaims, new OutputPolicyClaim(claimType, string.Empty, CopyFromConstants.InputValue));

            store.AddPolicyRule(new Uri("http://notExistingScope/1"), newRule);
        }