Ejemplo n.º 1
0
        public static Program.ExitCode AddAssignment(AuthUserRole assgnUR, rbacLINQ2SQLDataContext db)
        {
            //check if the role exists
            var query = from  aur in db.AuthUserRole
                        where aur.Role_Id == assgnUR.Role_Id && aur.User_Id == assgnUR.User_Id
                        select aur;
            //if does not exist, add:
            if (query.Count() == 0)
            {
                //here must be checking role addition posibility within SSOD
                //...

                db.AuthUserRole.InsertOnSubmit(assgnUR);
                try
                {
                    db.SubmitChanges();
                    return Program.ExitCode.Success;
                }
                catch (Exception exc)
                {
                    return Program.ExitCode.Error;
                }
            }
            //if exists, Ignore or Update:
            else
            {
                return Program.ExitCode.ElementExists;
            }
        }
Ejemplo n.º 2
0
        private void btn_rmAssignment_Save_Click(object sender, EventArgs e)
        {
            Program.ExitCode status;

            if (cb_Role.Text == "")
            {
                MessageBox.Show(this,
                            "Выберите пользователя и роль, которую хотите удалить!",
                            "Warning",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Warning);
                return;
            }
            //Создать Assignment:
            AuthUserRole assgnUR = new AuthUserRole
            {
                User_Id = Convert.ToInt32(cb_User.SelectedValue),
                Role_Id = Convert.ToInt32(cb_Role.SelectedValue),
            };

            status = RBACManager.RmAssignment(assgnUR, mainForm.db);

            if (status == Program.ExitCode.Success)
            {
                MessageBox.Show(this,
                            "Роль успешно удалена!",
                            "Success",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
                this.Close();
                return;
            }
            if (status == Program.ExitCode.Error)
            {
                MessageBox.Show(this,
                            "Error while submitting deletion to the DataBase",
                            "Error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                return;
            }
            if (status == Program.ExitCode.ElementDoesNotExists)
            {
                MessageBox.Show(this,
                            "Пользователь не авторизован для указанной роли!",
                            "Warning",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Warning);
                return;
            }
        }
Ejemplo n.º 3
0
        private void btn_addAssignment_Save_Click(object sender, EventArgs e)
        {
            Program.ExitCode status;

            //Создать Assignment:
            AuthUserRole assgnUR = new AuthUserRole
            {
                User_Id = Convert.ToInt32(cb_User.SelectedValue),
                Role_Id = Convert.ToInt32(cb_Role.SelectedValue),
            };

            status = RBACManager.AddAssignment(assgnUR, mainForm.db);

            if (status == Program.ExitCode.Success)
            {
                MessageBox.Show(this,
                            "Роль успешно авторизована для пользователя!",
                            "Success",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
                this.Close();
                return;
            }
            if (status == Program.ExitCode.Error)
            {
                MessageBox.Show(this,
                            "Error while submitting deletion to the DataBase",
                            "Error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                return;
            }
            if (status == Program.ExitCode.ElementExists)
            {
                MessageBox.Show(this,
                            "Выбранная роль уже авторизована для выбранного пользователя!",
                            "Warning",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Warning);
                return;
            }
        }
Ejemplo n.º 4
0
		private void detach_AuthUserRole(AuthUserRole entity)
		{
			this.SendPropertyChanging();
			entity.User = null;
		}
Ejemplo n.º 5
0
		private void attach_AuthUserRole(AuthUserRole entity)
		{
			this.SendPropertyChanging();
			entity.User = this;
		}
Ejemplo n.º 6
0
 partial void DeleteAuthUserRole(AuthUserRole instance);
Ejemplo n.º 7
0
 partial void UpdateAuthUserRole(AuthUserRole instance);
Ejemplo n.º 8
0
 partial void InsertAuthUserRole(AuthUserRole instance);
Ejemplo n.º 9
0
        public static void AddAssignment_noTryCatch(AuthUserRole assgnUR, rbacLINQ2SQLDataContext db)
        {
            //check if the role exists
            var query = from aur in db.AuthUserRole
                        where aur.Role_Id == assgnUR.Role_Id && aur.User_Id == assgnUR.User_Id
                        select aur;
            //if does not exist, add:
            if (query.Count() == 0)
            {
                //here must be checking role addition posibility within SSOD
                //...

                db.AuthUserRole.InsertOnSubmit(assgnUR);
                db.SubmitChanges();
                System.Diagnostics.Debug.WriteLine("Added User->Role: {0}->{1}", assgnUR.User_Id, assgnUR.Role_Id);
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Existing User->Role: {0}->{1}", assgnUR.User_Id, assgnUR.Role_Id);
            }
        }
Ejemplo n.º 10
0
 public static Program.ExitCode RmAssignment(AuthUserRole assgnUR, rbacLINQ2SQLDataContext db)
 {
     //check if the Assignment exists
     var query = from aur in db.AuthUserRole
                 where aur.Role_Id == assgnUR.Role_Id && aur.User_Id == assgnUR.User_Id
                 select aur;
     //if does exist, delete:
     if (query.Count() != 0)
     {
         //Без учета Активных ролей.
         db.AuthUserRole.DeleteOnSubmit(query.First());
         try
         {
             db.SubmitChanges();
             return Program.ExitCode.Success;
         }
         catch (Exception exc)
         {
             return Program.ExitCode.Error;
         }
     }
     else
     {
         return Program.ExitCode.ElementDoesNotExists;
     }
 }
Ejemplo n.º 11
0
        private static bool XMLReadUser(XmlNode userNode, int pid, rbacLINQ2SQLDataContext db)
        {
            User user;
            Role role;
            AuthUserRole authUR;

            user = new User()
            {
                Name = userNode.Attributes["name"].Value,
                Password = userNode.Attributes["password"].Value,
                Policy_Id = pid,
            };
            RBACManager.AddUser_noTryCatch(user, db);
            // Depending on our specification we could have to update an existing user
            //RBACManager.UpdateUser(user,db);

            // Get this user (just added to the database or existing in it)
            user = db.User.Single(x => x.Name == user.Name && x.Policy_Id == user.Policy_Id);

            // If there's no single AuthRoles block, error:
            if (userNode.ChildNodes.Count != 1)
            {
                return false;
            }
            XmlNode authRoleBlock = userNode.ChildNodes.Item(0);
            foreach (XmlNode authRoleNode in authRoleBlock.ChildNodes)
            {
                role = db.Role.Single(x => x.Name == authRoleNode.Attributes["name"].Value
                                                    && x.Policy_Id == pid);
                authUR = new AuthUserRole()
                {
                    User_Id = user.Id,
                    Role_Id = role.Id,
                };
                RBACManager.AddAssignment_noTryCatch(authUR, db);
            }

            return true;
        }