/// <summary> /// 显示授权信息 /// </summary> /// <param name="serviceAuthorizes"></param> private void bindAutorizedInfo(ServiceAuthorize serviceAuthorizes) { textBox1.Text = serviceAuthorizes.UserName; textBox2.Text = serviceAuthorizes.UserPwd; foreach (AuthorizeVerify.ServiceAuthorizeItem authorizeItem in serviceAuthorizes.ServiceAuthorizeItems) { switch (authorizeItem.ServiceName) { case "GetReaderInfoService": ckbReaderService.Checked = true; showReaderServiceAuthorize(authorizeItem.AllowMethodName); break; case "GetReadingRoomInfoService": ckbRoomService.Checked = true; showGetReadingRoomInfoServiceAuthorize(authorizeItem.AllowMethodName); break; case "DelaySeatUsedTimeService": ckbDelaySeatUsedTimeService.Checked = true; showDelaySeatUsedTimeService(authorizeItem.AllowMethodName); break; case "ShortLeaveService": ckbShortLeaveService.Checked = true; showShortLeaveService(authorizeItem.AllowMethodName); break; case "BespeakSeatService": ckbBespeakService.Checked = true; showBespeakSeatService(authorizeItem.AllowMethodName); break; case "ChooseSeatService": ckbChooseSeatService.Checked = true; showChooseSeatService(authorizeItem.AllowMethodName); break; case "FreeSeatService": ckbFreeSeatService.Checked = true; showFreeSeatService(authorizeItem.AllowMethodName); break; case "Other": showOtherAuthorize(authorizeItem.AllowMethodName); break; } } }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.SelectedIndex != -1) { //如果当前已经做了权限设置,先保存当前设置的内容。 if (authorizes == null) { authorizes = new ServiceAuthorize(); } authorizes.UserName = textBox1.Text.Trim(); authorizes.UserPwd = textBox2.Text.Trim(); authorizes.IsAdmin = cb_IsAdmin.Checked; authorizes.SchoolNo = txt_SchoolNo.Text.Trim(); if (!string.IsNullOrEmpty(authorizes.UserName) && !string.IsNullOrEmpty(authorizes.UserPwd) && !string.IsNullOrEmpty(authorizes.SchoolNo)) { authorizes.ServiceAuthorizeItems = getGetReaderInfoService(); if (authorizeInfos.ContainsKey(authorizes.UserName)) { authorizeInfos[authorizes.UserName] = authorizes; } else { authorizeInfos.Add(authorizes.UserName, authorizes); } } string selectUserName = comboBox1.Items[comboBox1.SelectedIndex].ToString(); if (authorizeInfos.ContainsKey(selectUserName)) { AuthorizeEnabled(false); AuthorizeEnabled(true); //initCheckBoxs();//初始化UI上的Checkbox authorizes = authorizeInfos[selectUserName]; //获取下拉列表中的授权 bindAutorizedInfo(authorizes); //绑定授权信息 } else { AuthorizeEnabled(false); } } else { AuthorizeEnabled(false); } }
/// <summary> /// 执行验证操作 /// </summary> /// <param name="serviceName">如果</param> /// <param name="method"></param> /// <returns></returns> public bool Verify(string userName, string pwd, string serviceName, string methodName) { //return true; try { if (!authorizeInfo.ContainsKey(userName)) { readAuthorized(); if (!authorizeInfo.ContainsKey(userName))//如果读取一次之后授权信息还是不存在,则直接返回false { return(false); } } } catch { return(false); } ServiceAuthorize authirize = authorizeInfo[userName]; if (authirize.UserPwd.Equals(pwd)) { foreach (ServiceAuthorizeItem authorizeItem in authirize.ServiceAuthorizeItems) { if (authorizeItem.ServiceName.Equals(serviceName)) { foreach (string method in authorizeItem.AllowMethodName) { if (method.Equals(methodName) && authirize.SchoolNo == SeatManage.Bll.Registry.GetSchoolNum()) { return(true); } //if (method.Equals(methodName)) //{ // return true; //} } } } } return(false); }
/// <summary> /// 执行验证操作 /// </summary> /// <param name="serviceName">如果</param> /// <param name="method"></param> /// <returns></returns> public bool Verify(string userName, string pwd, string serviceName, string methodName) { return(true); try { if (!authorizeInfo.ContainsKey(userName)) { readAuthorized(); if (!authorizeInfo.ContainsKey(userName)) //如果读取一次之后授权信息还是不存在,则直接返回false { return(false); } } } catch { return(false); } ServiceAuthorize authirize = authorizeInfo[userName]; if (authirize.UserPwd.Equals(pwd)) { foreach (ServiceAuthorizeItem authorizeItem in authirize.ServiceAuthorizeItems) { if (authorizeItem.ServiceName.Equals(serviceName)) { foreach (string method in authorizeItem.AllowMethodName) { if (method.Equals(methodName)) { return(true); } } } } } return(false); }
private void button3_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBox1.Text.Trim())) { toolTip1.Show("请输入用户名", textBox1, 3000); return; } if (string.IsNullOrEmpty(textBox2.Text.Trim())) { toolTip1.Show("请输入密码", textBox2, 3000); return; } if (authorizes != null) { authorizes.ServiceAuthorizeItems = getGetReaderInfoService(); if (authorizeInfos.ContainsKey(authorizes.UserName)) { authorizeInfos[authorizes.UserName] = authorizes; } else { authorizeInfos.Add(authorizes.UserName, authorizes); } } AuthorizeEnabled(true); if (authorizeInfos.ContainsKey(textBox1.Text)) { toolTip1.Show("用户名已存在", textBox1, 3000); return; } authorizes = new ServiceAuthorize(); authorizes.UserName = textBox1.Text; authorizes.UserPwd = textBox2.Text; initCheckBoxs(); this.comboBox1.Items.Add(textBox1.Text); this.comboBox1.SelectedIndex = this.comboBox1.Items.Count - 1; }
/// <summary> /// 显示授权信息 /// </summary> /// <param name="serviceAuthorizes"></param> private void bindAutorizedInfo(ServiceAuthorize serviceAuthorizes) { textBox1.Text = serviceAuthorizes.UserName; textBox2.Text = serviceAuthorizes.UserPwd; txt_SchoolNo.Text = serviceAuthorizes.SchoolNo; foreach (AuthorizeVerify.ServiceAuthorizeItem authorizeItem in serviceAuthorizes.ServiceAuthorizeItems) { GroupBox gb = Controls.Find("gb_" + authorizeItem.ServiceName, false)[0] as GroupBox; CheckBox cb = gb.Controls.Find("cb_" + authorizeItem.ServiceName, false)[0] as CheckBox; if (cb != null) { cb.Checked = true; foreach (string methodName in authorizeItem.AllowMethodName) { CheckBox cbc = gb.Controls.Find("cb_" + authorizeItem.ServiceName + "_" + methodName, false)[0] as CheckBox; if (cbc != null) { cbc.Checked = true; } } } } }
/// <summary> /// 读取授权 /// </summary> private void readAuthorized() { string authorized_keys_filePath = string.Format("{0}/ws_authorized_keys", AppDomain.CurrentDomain.BaseDirectory); authorizeInfo = ServiceAuthorize.AnalyzeAuthorize(authorized_keys_filePath); }