protected void btnDelete_Click(object sender, EventArgs e)
        {
            GroupAuthorization clsGroup = new GroupAuthorization();

            clsGroup.DeleteGroup((string)ViewState["GroupID"]);
            //记录操作员操作
            RecordOperate.SaveRecord(Session["UserID"].ToString(), "组权限设置", "删除用户组权限信息");
            Server.Transfer("System_GroupAuthorization_Index.aspx");
        }
示例#2
0
        /// <summary>
        /// Verifica se o usuário tem acesso ao recurso
        /// </summary>
        /// <exception cref="Exception">Caso o usuário não tiver autorização dispara uma exçecão</exception>
        /// <param name="pPermId">ID da Permissão</param>
        /// <param name="accessRequest">Permissão requerida</param>
        /// <param name="userName">Empresa</param>
        /// <param name="companyDb">Banco de dados da empresa</param>
        /// <param name="throwException">Gera Exceção</param>
        public static bool HasPermission(string pPermId, PermissionType accessRequest, string userName,
                                         string companyDb, bool throwException = true)
        {
            var user = B1Helper.GetUser(userName, companyDb);

            if (user.SUPERUSER == eYesNo.Yes)
            {
                return(true);
            }

            var permi         = new UserAuthorization(companyDb);
            var hasPermission = false;

            if (permi.GetByKey(user.InternalK, pPermId))
            {
                switch (accessRequest)
                {
                case PermissionType.Full:
                    hasPermission = permi.Permission == PermissionType.Full;
                    break;

                case PermissionType.ReadOnly:
                    hasPermission = permi.Permission != PermissionType.None;
                    break;
                }
            }

            if (!hasPermission && SboVersion.EqualOrMoreThenSap91Pl04())
            {
                var groupUserAssociation = new GroupUserAssociation(companyDb);
                if (groupUserAssociation.GetByKey(user.UserId))
                {
                    var groupAuthorization = new GroupAuthorization(companyDb);
                    if (groupAuthorization.GetByKey(groupUserAssociation.GroupId, pPermId))
                    {
                        switch (accessRequest)
                        {
                        case PermissionType.Full:
                            hasPermission = groupAuthorization.Permission == PermissionType.Full;
                            break;

                        case PermissionType.ReadOnly:
                            hasPermission = groupAuthorization.Permission != PermissionType.None;
                            break;
                        }
                    }
                }
            }

            if (!hasPermission && throwException)
            {
                throw new Exception("Usuário não tem permissão para acessar esse recurso !");
            }

            return(hasPermission);
        }
示例#3
0
        /// <summary>
        /// 绑定数据到DataGrid控件MyDataGrid上
        /// </summary>
        private void BindDataGrid()
        {
            GroupAuthorization clsRight = new GroupAuthorization(); //创建用户组权限数据表操作类实例
            DataTable          dt       = clsRight.GetGroName();    //获取绑定数据的数据集对象

            if (dt != null)
            {
                int intCountRecNum = dt.Rows.Count;     //获取数据表记录数
                MyDataGrid.DataSource = dt.DefaultView;
                MyDataGrid.DataBind();
                lblRecNum.Text = intCountRecNum.ToString(); //显示总记录数
                ShowStats();                                //显示页数信息
            }
        }
示例#4
0
 /// <summary>
 /// DataGrid选择项响应事件方法
 /// </summary>
 /// <param name="source"></param>
 /// <param name="e"></param>
 protected void DataOperate(object source, DataGridCommandEventArgs e)
 {
     if (e.CommandName == "Delete")
     {
         GroupAuthorization clsGroup = new GroupAuthorization();
         string             GroupID  = ((Label)e.Item.Cells[0].Controls[1]).Text;
         clsGroup.DeleteGroup(GroupID);
         //记录操作员操作
         RecordOperate.SaveRecord(Session["UserID"].ToString(), "组权限设置", "删除用户组权限信息");
         Server.Transfer("System_GroupAuthorization_Index.aspx");
     }
     else
     {
         //使用弹出屏幕对话窗口方式快整录入房间
         string Url = "System_GroupAuthorization_Edit.aspx?GroupID=" + ((Label)e.Item.Cells[0].Controls[1]).Text;
         Server.Transfer(Url);
     }
 }
        /// <summary>
        /// 填充数据到表单文本控件,下拉框控件
        /// </summary>
        /// <param name="IsFill"></param>
        private void FillDataToCtrl(bool IsFill)
        {
            GroupAuthorizationDB clsGroupDB;            //创建用户权限表类对象

            if (IsFill)
            {
                GroupAuthorization clsGroup = new GroupAuthorization();
                clsGroupDB              = clsGroup.FindGroup((string)ViewState["GroupID"]);
                this.txtGroupID.Text    = ViewState["GroupID"].ToString();
                this.txtGroupID.Enabled = false;
            }
            else
            {
                clsGroupDB              = new GroupAuthorizationDB();
                this.txtGroupID.Text    = "";
                this.txtGroupID.Enabled = true;
            }
            this.txtGroupName.Text = clsGroupDB.GroupName;
        }
        /// <summary>
        /// 生成用户权限表格
        /// </summary>
        /// <param name="UserID">用户代码ID</param>
        private void FillRightTable(string GroupID)
        {
            GroupAuthorization clsGroup = new GroupAuthorization();

            String[,] strProgram = clsGroup.ShowGroupRightInPrograms(ViewState["GroupID"].ToString());
            if (strProgram != null)
            {
                //生成表体部分
                int          j = 0;
                CheckBoxList cblTmp;
                while (strProgram[j, 0] != null && strProgram[j, 0] != String.Empty)
                {
                    cblTmp = (CheckBoxList)FindControl("cbl" + strProgram[j, 0]);

                    //判断是否有权限,如果没有,则CheckBox为“未选”状态。
                    if (strProgram[j, 2] != null && strProgram[j, 2] != "")
                    {
                        if (strProgram[j, 2].IndexOf('r') != -1)
                        {
                            cblTmp.Items[0].Selected = true;
                        }

                        if (strProgram[j, 2].IndexOf('m') != -1)
                        {
                            cblTmp.Items[1].Selected = true;
                        }

                        if (strProgram[j, 2].IndexOf('a') != -1)
                        {
                            cblTmp.Items[2].Selected = true;
                        }

                        if (strProgram[j, 2].IndexOf('d') != -1)
                        {
                            cblTmp.Items[3].Selected = true;
                        }
                    }
                    j++;
                }
            }
        }
示例#7
0
        /// <summary>
        /// 填充数据到表单文本控件,下拉框控件
        /// </summary>
        /// <param name="IsFill"></param>
        private void FillDataToCtrl(bool IsFill)
        {
            UserAuthorizationDB clsUserDB;                               //创建用户权限表类对象
            GroupAuthorization  clsGroupUser = new GroupAuthorization(); //创建用户组权限表操作类对象
            DataTable           dt           = clsGroupUser.GetGroName();

            //DataRow dr = dt.NewRow();
            //dr["GroupID"] = "";
            //dr["GroupName"] = "--请选择--";
            //dt.Rows.Add(dr);
            this.ddlGroupID.DataTextField  = "GroupName";
            this.ddlGroupID.DataValueField = "GroupID";
            this.ddlGroupID.DataSource     = dt.DefaultView;
            this.ddlGroupID.DataBind();

            string    strSql = "select userid,username from Sys_User";
            DBManager db     = DBManager.Instance();
            DataTable dt1    = db.GetDataTable(strSql);
            DataRow   df     = dt1.NewRow();

            df["UserName"] = "******";
            df["UserId"]   = "0";
            dt1.Rows.InsertAt(df, 0);
            ddlFather.DataSource     = dt1;
            ddlFather.DataTextField  = "UserName";
            ddlFather.DataValueField = "UserId";
            ddlFather.DataBind();

            this.ddlSex.Items.Clear();
            //this.ddlSex.Items.Add("---请选择---");
            this.ddlSex.Items.Add("男");
            this.ddlSex.Items.Add("女");
            this.ddlSex.SelectedIndex = 0;

            this.ddlStatus.Items.Clear();
            this.ddlStatus.Items.Add("禁用");
            this.ddlStatus.Items.Add("激活");
            this.ddlStatus.SelectedIndex = 0;

            if (IsFill)
            {
                OperatorAuthorization clsUser = new OperatorAuthorization();
                clsUserDB              = clsUser.FindUser((string)ViewState["UserID"]);
                this.txtUserID.Text    = ViewState["UserID"].ToString();
                this.txtUserID.Enabled = false;

                txtPassword.Text = Common.CCToEmpty(clsUserDB.Pwd);
                txtUserName.Text = Common.CCToEmpty(clsUserDB.UserName);
                txtAge.Text      = Common.CCToEmpty(clsUserDB.Age);
                txtBirthday.Text = Common.CCToEmpty(clsUserDB.Birthday);
                txtJob.Text      = Common.CCToEmpty(clsUserDB.Job);
                txtMobile.Text   = Common.CCToEmpty(clsUserDB.Mobile);
                txtAddr.Text     = Common.CCToEmpty(clsUserDB.Addr);
                txtTel.Text      = Common.CCToEmpty(clsUserDB.Tel);
                if (clsUserDB.Sex.Trim() == "男")
                {
                    ddlSex.SelectedIndex = 0;
                }
                else if (clsUserDB.Sex.Trim() == "女")
                {
                    ddlSex.SelectedIndex = 1;
                }

                if (clsUserDB.Status.ToString() == "0")
                {
                    ddlStatus.SelectedIndex = 0;
                }
                else if (clsUserDB.Status.ToString() == "1")
                {
                    ddlStatus.SelectedIndex = 1;
                }

                for (int i = 0; i < ddlGroupID.Items.Count; i++)
                {
                    if (this.ddlGroupID.Items[i].Value == clsUserDB.GroupID)
                    {
                        ddlGroupID.SelectedIndex = i;
                        break;
                    }
                }

                for (int i = 0; i < ddlFather.Items.Count; i++)
                {
                    if (this.ddlFather.Items[i].Value == clsUserDB.Father)
                    {
                        ddlFather.SelectedIndex = i;
                        break;
                    }
                }
            }
            else
            {
                clsUserDB              = new UserAuthorizationDB();
                this.txtUserID.Text    = "";
                this.txtUserID.Enabled = true;
            }
        }
示例#8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddDbContext <VandivierProductManagerContext>(options => options.UseSqlServer(Configuration.GetConnectionString("Connection")));

            services.AddSingleton <Security.AuthHelper>();

            services.AddAuthentication(AzureADDefaults.AuthenticationScheme).AddAzureAD(AzureADDefaults.AuthenticationScheme,
                                                                                        OpenIdConnectDefaults.AuthenticationScheme, CookieAuthenticationDefaults.AuthenticationScheme, "Test",
                                                                                        options => Configuration.Bind("AzureAd", options));

            services.AddAuthorization(policies =>
            {
                policies.AddPolicy(GroupAuthorization.AdminPolicyName, policy => policy.RequireAssertion(x => GroupAuthorization.AdminPolicyAssertion(x, Configuration)));
                policies.AddPolicy(GroupAuthorization.HeadQuartersPolicyName, policy => policy.RequireAssertion(x => GroupAuthorization.HeadQuartersPolicyAssertion(x, Configuration)));
                policies.AddPolicy(GroupAuthorization.StoreManagerPolicyName, policy => policy.RequireAssertion(x => GroupAuthorization.StoreManagersPolicyAssertion(x, Configuration)));
                policies.AddPolicy(GroupAuthorization.EmployeePolicyName, policy => policy.RequireAssertion(x => GroupAuthorization.EmployeePolicyAssertion(x, Configuration)));
            });

            services.Configure <OpenIdConnectOptions>(AzureADDefaults.OpenIdScheme, options =>
            {
                options.Authority = options.Authority + "/v2.0/";
                options.TokenValidationParameters.ValidateIssuer = false;
            });

            // Injectable data access service
            services.AddScoped <IDbReadService, DbReadService>();
            services.AddScoped <IDbWriteService, DbWriteService>();

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }