コード例 #1
0
        public void PlaceOrder(OrderMessage message)
        {
            Console.WriteLine("Order:");
            Console.WriteLine("Product name: {0}", message.Order.ProductName);
            Console.WriteLine("Quantity: {0}", message.Order.Quantity);
            Console.WriteLine("Comments: {0}", message.Order.Comments);

            int requiredPoints;

            if (!requiredPointsMap.TryGetValue(message.Order.ProductName, out requiredPoints))
            {
                ReportSenderFault("An unknown product was ordered", "UnknownProduct");
            }

            try
            {
                ClaimsPrincipalPermission.CheckAccess(requiredPoints.ToString(), "BuyAnimal");
            }
            catch (SecurityException)
            {
                ReportSenderFault(string.Format("Required points: {0}.", requiredPoints),
                                  "InsufficientExperiencePoints");
            }

            Console.WriteLine("Order accepted.");
        }
コード例 #2
0
ファイル: program.cs プロジェクト: zhimaqiao51/docs
        static void Main(string[] args)
        {
// <Snippet2>
            //
            // Method 1. Simple access check using static method.
            // Expect this to be most common method.
            //
            ClaimsPrincipalPermission.CheckAccess("resource", "action");
// </Snippet2>

// <Snippet3>
            //
            // Method 2. Programmatic check using the permission class
            // Follows model found at http://msdn.microsoft.com/en-us/library/system.security.permissions.principalpermission.aspx
            //
            ClaimsPrincipalPermission cpp = new ClaimsPrincipalPermission("resource", "action");

            cpp.Demand();
// </Snippet3>

            //
            // Method 3. Access check interacting directly with the authorization manager.
            //
            ClaimsAuthorizationManager am = new ClaimsAuthorizationManager();

            am.CheckAccess(new AuthorizationContext((ClaimsPrincipal)Thread.CurrentPrincipal, "resource", "action"));

            //
            // Method 4. Call a method that is protected using the permission attribute class
            //
            ProtectedMethod();

            Console.WriteLine("Press [Enter] to continue.");
            Console.ReadLine();
        }
コード例 #3
0
ファイル: MainApp.cs プロジェクト: atWinKAS/YetAnotherAuthLib
        /// <summary>
        /// Demo method with direct authorization call
        /// </summary>
        public void AdminsCanDoThis2()
        {
            ClaimsPrincipalPermission.CheckAccess("AdminArea", "Read");

            Console.WriteLine(Environment.NewLine);
            Console.WriteLine("Only the person with 'admin' role can invoke this method (2).");
            Console.WriteLine(Environment.NewLine);
        }
コード例 #4
0
 private static void UsePrincipal()
 {
     ShowCastle();
     //imperative check
     ClaimsPrincipalPermission.CheckAccess("Castle", "Show");
     var authz = FederatedAuthentication.FederationConfiguration.IdentityConfiguration.ClaimsAuthorizationManager;
     AuthorizationContext context = new AuthorizationContext(ClaimsPrincipal.Current, "Castle", "Show");
     bool isAuthz = authz.CheckAccess(context);
 }
コード例 #5
0
        public ActionResult About()
        {
            var ca = new ClaimsAuthorizationManager();

            ClaimsPrincipalPermission.CheckAccess("home/about", "view");
            ViewBag.Message = "Your application description page.";

            return(View());
        }
コード例 #6
0
ファイル: SsoModule.cs プロジェクト: hgdelima/Framework.Net40
        private void Application_AuthorizeRequest(Object source, EventArgs e)
        {
            //Create HttpContext object to access request and response properties.
            var context  = ((HttpApplication)source).Context;
            var identity = Thread.CurrentPrincipal.Identity;

            if (identity.IsAuthenticated &&
                identity.AuthenticationType == AuthenticationTypes.Federation)
            {
                ClaimsPrincipalPermission.CheckAccess(context.Request.Url.OriginalString, context.Request.HttpMethod);
            }
        }
コード例 #7
0
ファイル: contact.aspx.cs プロジェクト: zhimaqiao51/docs
        protected void Page_Load(object sender, EventArgs e)
        {
            ClaimsPrincipalPermission p = new ClaimsPrincipalPermission("Contacts", "Show");

            p.Demand();

            ClaimsPrincipalPermission.CheckAccess("Contacts", "Show");

            ClaimsPrincipal principal = HttpContext.Current.User as ClaimsPrincipal;

            if (null != principal)
            {
                ClaimsIdentity identity = principal.Identity as ClaimsIdentity;
                if (null != identity)
                {
                    foreach (Claim claim in identity.Claims)
                    {
                        Response.Write("CLAIM TYPE: " + claim.Type + "; CLAIM VALUE: " + claim.Value + "</br>");
                    }
                }
            }
        }
コード例 #8
0
        static void Main(string[] args)
        {
            //
            // Configure .NET Framework to use Windows Claims Principals
            // Emulates the authentication phase supported by the Windows Identity Foundation.
            //
            AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
            Thread.CurrentPrincipal = ClaimsPrincipal.CreateFromPrincipal(Thread.CurrentPrincipal);

            //
            // Method 1. Simple access check using static method.
            // Expect this to be most common method.
            //
            ClaimsPrincipalPermission.CheckAccess("resource", "action");

            //
            // Method 2. Programmatic check using the permission class
            // Follows model found at http://msdn.microsoft.com/en-us/library/system.security.permissions.principalpermission.aspx
            //
            ClaimsPrincipalPermission cpp = new ClaimsPrincipalPermission("resource", "action");

            cpp.Demand();

            //
            // Method 3. Access check interacting directly with the authorization manager.
            //
            ClaimsAuthorizationManager am = new ClaimsAuthorizationManager();

            am.CheckAccess(new AuthorizationContext((IClaimsPrincipal)Thread.CurrentPrincipal, "resource", "action"));

            //
            // Method 4. Call a method that is protected using the permission attribute class
            //
            ProtectedMethod();

            Console.WriteLine("Press [Enter] to continue.");
            Console.ReadLine();
        }
コード例 #9
0
 public SecuredClass()
 {
     ClaimsPrincipalPermission.CheckAccess("SecuredClass", "GeneralAccess");
 }
コード例 #10
0
 public static void MyMethod()
 {
     //Here is where we would check access to perform operations in this method.
     ClaimsPrincipalPermission.CheckAccess(AppResources.Foo.ToString(), Operations.Read.ToString());
     //If we made it this far we were authorized and we would perform the actual operations here.
 }