internal bool IsGrantedUser(string loginname, string applicationCode, CommonParam commonParam) { bool result = false; try { AasAuthorizeSDO authorizeSDO = new AasAuthorizeSDO(); authorizeSDO.ApplicationCode = applicationCode; authorizeSDO.Loginname = loginname; User user = null; if (!new TokenAuthorizeProcessor(commonParam).Run(authorizeSDO, ref user)) { LogSystem.Warn("Khong tim thay du lieu User dang nhap"); } else { result = true; } } catch (Exception ex) { DungLH.Util.CommonLogging.LogSystem.Error(ex); result = false; } return(result); }
internal bool VerifyRequireField(AasAuthorizeSDO data) { bool valid = true; try { if (data == null) { throw new ArgumentNullException("data"); } if (String.IsNullOrWhiteSpace(data.ApplicationCode)) { throw new ArgumentNullException("data.ApplicationCode"); } if (String.IsNullOrWhiteSpace(data.Loginname)) { throw new ArgumentNullException("data.Loginname"); } data.Loginname = data.Loginname.ToLower().Trim(); } catch (ArgumentNullException ex) { BugUtil.SetBugCode(param, LibraryBug.Bug.Enum.Common__ThieuThongTinBatBuoc); LogSystem.Error(ex); valid = false; } catch (Exception ex) { LogSystem.Error(ex); valid = false; param.HasException = true; } return(valid); }
internal bool Run(AasAuthorizeSDO data, ref User resultData) { bool result = false; try { bool valid = true; User raw = null; Application application = null; TokenAuthorizeCheck checker = new TokenAuthorizeCheck(param); AasUserCheck userChecker = new AasUserCheck(param); valid = valid && checker.VerifyRequireField(data); valid = valid && userChecker.VerifyLoginname(data.Loginname, ref raw); if (valid) { application = new ApplicationManagerGet().GetByCode(data.ApplicationCode); if (application == null) { MessageUtil.SetMessage(param, LibraryMessage.Message.Enum.Common_UngDungChuaDuocDangKyTrenHeThong); throw new Exception("ApplicationCode invalid: " + data.ApplicationCode); } List <ApplicationRole> appRoles = new ApplicationRoleManagerGet().GetByApplicationId(application.Id); if (!IsNotNullOrEmpty(appRoles)) { MessageUtil.SetMessage(param, LibraryMessage.Message.Enum.Common_TaiKhoanKhongCoQuyenTruyCapUngDung); throw new Exception("Ung dung cua duc gan vao vao tro nao"); } List <UserRole> userRoles = new UserRoleManagerGet().GetByUserId(raw.Id); if (!IsNotNullOrEmpty(userRoles)) { MessageUtil.SetMessage(param, LibraryMessage.Message.Enum.Common_TaiKhoanKhongCoQuyenTruyCapUngDung); throw new Exception("Nguoi dung chua duc gan vai trong o cho naof"); } List <long> userRoleIds = userRoles.Select(s => s.RoleId).ToList(); if (!appRoles.Exists(e => userRoleIds.Contains(e.RoleId))) { MessageUtil.SetMessage(param, LibraryMessage.Message.Enum.Common_TaiKhoanKhongCoQuyenTruyCapUngDung); throw new Exception("Nguoi dung khong duoc phan quyen truy cap vao ung dung"); } raw.Password = ""; resultData = raw; result = true; } } catch (Exception ex) { DungLH.Util.CommonLogging.LogSystem.Error(ex); result = false; } return(result); }