private void loadsecuritycode()
    {
        // updating token
        try
        {
            int         roleId      = Convert.ToInt32(ddlRole.SelectedValue.ToString());
            AccessToken token       = new AccessToken();
            string      accessToken = AccessToken.ReturnEmptyToken();
            //accessToken = ReadPermissions(accessToken, token);

            // loading existing token
            int        roleid    = Conversion.ParseInt(ddlRole.SelectedValue);
            int        subroleid = Conversion.ParseInt(ddlSubRole.SelectedValue);
            DataTable  dt        = RoleManagement.GetRoleSubroleNGroupByIds(roleid, subroleid);
            List <int> groupids  = new List <int>();
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int j = 0; j < dt.Rows.Count; j++)
                {
                    string groupid = dt.Rows[j]["intGroupID"].ToString();
                    groupids.Add(Convert.ToInt32(groupid));
                }
                System.Data.DataTable resourceTopics = GroupPages.GetAllResources();
                for (int i = 0; i < resourceTopics.Rows.Count; i++)
                {
                    DataRow row        = resourceTopics.Rows[i];
                    int     resourceid = Convert.ToInt32(row["intResourceId"].ToString());
                    //foreach (ResourceType item in Enum.GetValues(typeof(ResourceType)))
                    //{
                    List <string> securityTokens = new List <string>();
                    foreach (int gid in groupids)
                    {
                        securityTokens.Add(RoleManagement.GetSecurityToken(Convert.ToInt32(gid)));
                    }
                    canView = canAdd = canUpdate = canDelete = false;
                    foreach (string st in securityTokens)
                    {
                        PermissionManagement.GetPermissionOnlyFalsed(resourceid, ref canView, ref canAdd, ref canUpdate, ref canDelete, st);
                    }
                    accessToken = ReadDetailPermissions(resourceid, canView, canAdd, canUpdate, canDelete, accessToken, token);
                    //}
                }
            }
            // generating new token
            RoleManagement.UpdateSecurityTokenbyRoleId(subroleid, accessToken);
        }
        catch (Exception ex)
        {
            new SqlLog().InsertSqlLog(0, "GroupPermission.aspx.loadsecuritycode", ex);
        }
    }
Exemple #2
0
    protected void ddlGroupName_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            lblInfo.Text = "";
            if (ddlGroupName.SelectedIndex != 0)
            {
                EnableControls(true);
                chkAdmin.Enabled = true;
                chkAdmin.Checked = false;
                SetAllPermissionsOff();
                int    roleId        = Convert.ToInt32(ddlGroupName.SelectedValue.ToString());
                string securityToken = RoleManagement.GetSecurityToken(roleId);

                AccessToken token = new AccessToken();
                if (token.AdminToken(64, token.EmptyString()).Equals(securityToken))
                {
                    SetAllPermissionsOn();
                    EnableControls(false);
                    chkAdmin.Checked = true;
                }
                else if (!string.IsNullOrEmpty(securityToken))
                {
                    ReadFromAccess(securityToken, token);
                    chkAdmin.Checked = false;
                }
                else
                {
                    SetAllPermissionsOff();
                    chkAdmin.Checked = false;
                    EnableControls(true);
                }
            }
            else
            {
                SetAllPermissionsOff();
                chkAdmin.Enabled = false;
                EnableControls(false);
            }
        }
        catch (Exception ex)
        {
            new SqlLog().InsertSqlLog(0, "PagePermission.aspx ddlGroupName_SelectedIndexChanged", ex);
        }
    }
        public void GetPermission(ResourceType resourceType, ref bool canView, ref bool canAdd, ref bool canUpdate, ref bool canDelete, string groupid)
        {
            HttpCookie cookie        = HttpContext.Current.Request.Cookies.Get("securityToken");
            string     securityToken = string.Empty;

            if (cookie == null || string.IsNullOrEmpty(cookie.Value))
            {
                securityToken = RoleManagement.GetSecurityToken(Convert.ToInt32(groupid));
                HttpCookie securityCookie = new HttpCookie("securityToken");
                securityCookie.Value = Server.UrlEncode(securityToken);
                HttpContext.Current.Response.Cookies.Add(securityCookie);
            }
            else
            {
                securityToken = Server.UrlDecode(cookie.Value);
            }
            PermissionManagement.GetPermission(resourceType, ref canView, ref canAdd, ref canUpdate, ref canDelete, securityToken);
        }