Exemple #1
0
        /// <summary>
        /// Check Access from your Application [FOR Windows Users ONLY].
        /// </summary>
        /// <param name="userIdentity">Windows User Identity.</param>
        private void CheckAccessPermissionsForWindowsUsers(WindowsIdentity userIdentity, bool useCache)
        {
            // USER MUST BE A MEMBER OF SQL DATABASE ROLE: NetSqlAzMan_Readers

            //Sql Storage connection string
            string sqlConnectionString = "data source=(local);initial catalog=NetSqlAzManStorage;user id=netsqlazmanuser;password=password";
            //Create an instance of SqlAzManStorage class
            IAzManStorage storage = new SqlAzManStorage(sqlConnectionString);
            //To Pass current user identity:
            //WindowsIdentity.GetCurrent() -> for Windows Applications
            //this.Request.LogonUserIdentity -> for ASP.NET Applications
            List <KeyValuePair <string, string> > attributes;
            AuthorizationType auth;

            if (useCache)
            {
                //Build the cache Only one time per session/application/user
                NetSqlAzMan.Cache.UserPermissionCache cache = new NetSqlAzMan.Cache.UserPermissionCache(storage, "My Store", "My Application", userIdentity, true, true);
                //Then Check Access
                auth = cache.CheckAccess("My Operation", DateTime.Now, out attributes);
            }
            else
            {
                auth = storage.CheckAccess("My Store", "My Application", "My Operation", userIdentity, DateTime.Now, true, out attributes);
            }
            switch (auth)
            {
            case AuthorizationType.AllowWithDelegation:
                //Yes, I can ... and I can delegate
                break;

            case AuthorizationType.Allow:
                //Yes, I can
                break;

            case AuthorizationType.Neutral:
            case AuthorizationType.Deny:
                //No, I cannot
                break;
            }
            //Do something with attributes found
        }
Exemple #2
0
        private void btnTestNetSqlAzMan_Click(object sender, EventArgs e)
        {
            this.Clessidra(true);
            this.StartTimer();
            int n   = int.Parse(this.txtNetSqlAzManThreads.Text);
            int max = int.Parse(this.txtUnita.Text);

            this.pb.Maximum = n - 1;
            if (!this.chkNetSqlAzManMultiThread.Checked)
            {
                if (!this.chkCache.Checked)
                {
                    for (int i = 0; i < n; i++)
                    {
                        this.TestSuNetSqlAzMan(this.txtNetSqlAzManConnectionString.Text, max);
                        this.pb.Value = i;
                        Application.DoEvents();
                    }
                }
                else
                {
                    WindowsIdentity id      = WindowsIdentity.GetCurrent();
                    IAzManStorage   storage = new SqlAzManStorage(this.txtNetSqlAzManConnectionString.Text);
                    storage.OpenConnection();
                    int rnd = new Random().Next(max);
                    NetSqlAzMan.Cache.UserPermissionCache c = new NetSqlAzMan.Cache.UserPermissionCache(storage, "Store Stress Test", "Application" + rnd.ToString(), id, true, true);
                    for (int i = 0; i < n; i++)
                    {
                        List <KeyValuePair <string, string> > attr;
                        AuthorizationType res = c.CheckAccess("Operation" + rnd.ToString(), DateTime.Now, out attr);
                        this.pb.Value = i;
                        Application.DoEvents();
                    }
                    storage.CloseConnection();
                    storage.Dispose();
                }
            }
            else
            {
                Thread[] tt = new Thread[n];
                //Threads Prepare
                for (int i = 0; i < n; i++)
                {
                    tt[i] = new Thread(new ThreadStart(this.TestSuNetSqlAzManForThread));
                    tt[i].Start();
                    this.pb.Value = i;
                }
                //Threads Consume
                for (int i = 0; i < n; i++)
                {
                    tt[i].Join();
                    this.pb.Value = i;
                }
                //Threads Destroy
                for (int i = 0; i < n; i++)
                {
                    tt[i]         = null;
                    this.pb.Value = i;
                }
            }
            this.StopTimer(this.txtNetSqlAzManElapsed);
            this.Clessidra(false);
        }
        /// <summary>
        /// Check Access from your Application [FOR Windows Users ONLY].
        /// </summary>
        /// <param name="userIdentity">Windows User Identity.</param>
        private void CheckAccessPermissionsForWindowsUsers(WindowsIdentity userIdentity, bool useCache)
        {
            // USER MUST BE A MEMBER OF SQL DATABASE ROLE: NetSqlAzMan_Readers

            //Sql Storage connection string
            string sqlConnectionString = "data source=(local);initial catalog=NetSqlAzManStorage;user id=netsqlazmanuser;password=password";
            //Create an instance of SqlAzManStorage class
            IAzManStorage storage = new SqlAzManStorage(sqlConnectionString);
            //To Pass current user identity:
            //WindowsIdentity.GetCurrent() -> for Windows Applications
            //this.Request.LogonUserIdentity -> for ASP.NET Applications
            List<KeyValuePair<string, string>> attributes;
            AuthorizationType auth;
            if (useCache)
            {
                //Build the cache Only one time per session/application/user
                NetSqlAzMan.Cache.UserPermissionCache cache = new NetSqlAzMan.Cache.UserPermissionCache(storage, "My Store", "My Application", userIdentity, true, true);
                //Then Check Access
                auth = cache.CheckAccess("My Operation", DateTime.Now,out attributes);
            }
            else
            {
                auth = storage.CheckAccess("My Store", "My Application", "My Operation", userIdentity, DateTime.Now, true, out attributes);
            }
            switch (auth)
            {
                case AuthorizationType.AllowWithDelegation:
                    //Yes, I can ... and I can delegate
                    break;
                case AuthorizationType.Allow:
                    //Yes, I can
                    break;
                case AuthorizationType.Neutral:
                case AuthorizationType.Deny:
                    //No, I cannot
                    break;
            }
            //Do something with attributes found
        }
Exemple #4
0
 private void btnTestNetSqlAzMan_Click(object sender, EventArgs e)
 {
     this.Clessidra(true);
     this.StartTimer();
     int n = int.Parse(this.txtNetSqlAzManThreads.Text);
     int max = int.Parse(this.txtUnita.Text);
     this.pb.Maximum = n - 1;
     if (!this.chkNetSqlAzManMultiThread.Checked)
     {
         if (!this.chkCache.Checked)
         {
             for (int i = 0; i < n; i++)
             {
                 this.TestSuNetSqlAzMan(this.txtNetSqlAzManConnectionString.Text, max);
                 this.pb.Value = i;
                 Application.DoEvents();
             }
         }
         else
         {
             WindowsIdentity id = WindowsIdentity.GetCurrent();
             IAzManStorage storage = new SqlAzManStorage(this.txtNetSqlAzManConnectionString.Text);
             storage.OpenConnection();
             int rnd = new Random().Next(max);
             NetSqlAzMan.Cache.UserPermissionCache c = new NetSqlAzMan.Cache.UserPermissionCache(storage, "Store Stress Test", "Application" + rnd.ToString(), id, true, true);
             for (int i = 0; i < n; i++)
             {
                 List<KeyValuePair<string, string>> attr;
                 AuthorizationType res = c.CheckAccess("Operation" + rnd.ToString(), DateTime.Now, out attr);
                 this.pb.Value = i;
                 Application.DoEvents();
             }
             storage.CloseConnection();
             storage.Dispose();
         }
     }
     else
     {
         Thread[] tt = new Thread[n];
         //Threads Prepare
         for (int i = 0; i < n; i++)
         {
             tt[i] = new Thread(new ThreadStart(this.TestSuNetSqlAzManForThread));
             tt[i].Start();
             this.pb.Value = i;
         }
         //Threads Consume
         for (int i = 0; i < n; i++)
         {
             tt[i].Join();
             this.pb.Value = i;
         }
         //Threads Destroy
         for (int i = 0; i < n; i++)
         {
             tt[i] = null;
             this.pb.Value = i;
         }
     }
     this.StopTimer(this.txtNetSqlAzManElapsed);
     this.Clessidra(false);
 }