コード例 #1
0
        public void LoadLawsFromJavaScriptFile()
        {
            JudgeAnderson judge = new JudgeAnderson();

            judge.Load(new FileInfo("JusticeDepartment.js"));

            judge.Principal = new GenericPrincipal(
                new GenericIdentity("rico"),
                new string[] { "BankUser" });

            object account = new
            {
                Owner   = "rico",
                Balance = decimal.Zero
            };

            judge.Enforce("CanWithdrawFromAccount", account);
            judge.Enforce("CanDepositToAccount", account);
            judge.Enforce("CanDisplayBalance", account);
        }
コード例 #2
0
        public void SimpleJavaScriptRuleFail()
        {
            JudgeAnderson judge = new JudgeAnderson();

            judge.Load(@"function CanSeeBankAccount(principal) {
                return principal.IsInRole('BankingConsultant'); 
            }");

            judge.Principal = new GenericPrincipal(
                WindowsIdentity.GetCurrent(), new string[0]);

            judge.Enforce("CanSeeBankAccount");
        }