예제 #1
0
        private void SaveRecord()
        {
            var key   = txtKey.Text.Trim();
            var value = txtValue.Text.Trim();

            if (key != String.Empty && value != String.Empty)
            {
                _Storage.BeginTransaction(AzManIsolationLevel.ReadUncommitted);

                switch (_Mode)
                {
                case Mode.Create:
                    _Authorization.CreateAttribute(key, value);
                    break;

                case Mode.Delete:
                    break;

                case Mode.Update:
                    _Authorization.GetAttribute(key).Update(key, value);
                    break;
                }

                _Storage.CommitTransaction();

                _Dirty = true;
            }
        }
예제 #2
0
        /// <summary>
        /// Create an Authorization Delegate
        /// </summary>
        private void CreateDelegate()
        {
            // USER MUST BE A MEMBER OF SQL DATABASE ROLE: NetSqlAzMan_Users

            //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);
            IAzManStore       mystore = storage.GetStore("My Store"); //or storage["My Store"]
            IAzManApplication myapp   = mystore.GetApplication("My Application");
            IAzManItem        myop    = myapp.GetItem("My Operation");
            //Retrieve current user identity (delegating user)
            WindowsIdentity userIdentity = ((System.Threading.Thread.CurrentPrincipal.Identity as WindowsIdentity) ?? WindowsIdentity.GetCurrent()); //for Windows Applications
            //WindowsIdentity userIdentity = this.Request.LogonUserIdentity; //for ASP.NET Applications
            //Retrieve delegate user Login
            NTAccount delegateUserLogin = new NTAccount("DOMAIN", "delegateuseraccount");
            //Retrieve delegate user SID
            SecurityIdentifier delegateSID            = (SecurityIdentifier)delegateUserLogin.Translate(typeof(SecurityIdentifier));
            IAzManSid          delegateNetSqlAzManSID = new SqlAzManSID(delegateSID);
            //Estabilish delegate authorization (only Allow or Deny)
            RestrictedAuthorizationType delegateAuthorization = RestrictedAuthorizationType.Allow;
            //Create delegate
            IAzManAuthorization del = myop.CreateDelegateAuthorization(userIdentity, delegateNetSqlAzManSID, delegateAuthorization, new DateTime(2006, 1, 1, 0, 0, 0), new DateTime(2006, 12, 31, 23, 59, 59));

            //Set custom Attribute on Authorization Delegate
            del.CreateAttribute("MyCustomInfoKey", "MyCustomInfoValue");
        }
예제 #3
0
    protected void btnDelegateForBudgetCheck_Click(object sender, EventArgs e)
    {
        NTAccount          delegatedNTAccount = new NTAccount("ProductManager1");
        SecurityIdentifier delegatedSid       = (SecurityIdentifier)delegatedNTAccount.Translate(typeof(SecurityIdentifier));

        this.application.Store.Storage.OpenConnection();
        this.application.Store.Storage.BeginTransaction(AzManIsolationLevel.ReadUncommitted);
        IAzManAuthorization delegateAuthorization = this.application["Controllo del Budget"].CreateDelegateAuthorization(this.identity, new SqlAzManSID(delegatedSid), RestrictedAuthorizationType.Allow, null, null);

        delegateAuthorization.CreateAttribute("SomeBusinessAttribute", "Business profile data");
        this.application.Store.Storage.CommitTransaction();
        this.application.Store.Storage.CloseConnection();
        this.btnDelegateForBudgetCheck.Enabled = false;
        this.btnUndelegate.Enabled             = true;
    }
예제 #4
0
        /// <summary>
        /// Create a Full Storage through .NET code
        /// </summary>
        private void CreateFullStorage()
        {
            // USER MUST BE A MEMBER OF SQL DATABASE ROLE: NetSqlAzMan_Administrators

            //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);

            //Open Storage Connection
            storage.OpenConnection();
            //Begin a new Transaction
            storage.BeginTransaction(AzManIsolationLevel.ReadUncommitted);
            //Create a new Store
            IAzManStore newStore = storage.CreateStore("My Store", "Store description");
            //Create a new Basic StoreGroup
            IAzManStoreGroup newStoreGroup = newStore.CreateStoreGroup(SqlAzManSID.NewSqlAzManSid(), "My Store Group", "Store Group Description", String.Empty, GroupType.Basic);
            //Retrieve current user SID
            IAzManSid mySid = new SqlAzManSID(((System.Threading.Thread.CurrentPrincipal.Identity as WindowsIdentity) ?? WindowsIdentity.GetCurrent()).User);
            //Add myself as sid of "My Store Group"
            IAzManStoreGroupMember storeGroupMember = newStoreGroup.CreateStoreGroupMember(mySid, WhereDefined.Local, true);
            //Create a new Application
            IAzManApplication newApp = newStore.CreateApplication("New Application", "Application description");
            //Create a new Role
            IAzManItem newRole = newApp.CreateItem("New Role", "Role description", ItemType.Role);
            //Create a new Task
            IAzManItem newTask = newApp.CreateItem("New Task", "Task description", ItemType.Task);
            //Create a new Operation
            IAzManItem newOp = newApp.CreateItem("New Operation", "Operation description", ItemType.Operation);

            //Add "New Operation" as a sid of "New Task"
            newTask.AddMember(newOp);
            //Add "New Task" as a sid of "New Role"
            newRole.AddMember(newTask);
            //Create an authorization for myself on "New Role"
            IAzManAuthorization auth = newRole.CreateAuthorization(mySid, WhereDefined.Local, mySid, WhereDefined.Local, AuthorizationType.AllowWithDelegation, null, null);
            //Create a custom attribute
            IAzManAttribute <IAzManAuthorization> attr = auth.CreateAttribute("New Key", "New Value");
            //Create an authorization for DB User "Andrea" on "New Role"
            IAzManAuthorization auth2 = newRole.CreateAuthorization(mySid, WhereDefined.Local, storage.GetDBUser("Andrea").CustomSid, WhereDefined.Local, AuthorizationType.AllowWithDelegation, null, null);

            //Commit transaction
            storage.CommitTransaction();
            //Close connection
            storage.CloseConnection();
        }