public bool CheckUserDBAccess(out long userId, out string errosMsg) { userId = _userid; errosMsg = string.Empty; string loginName = HttpContext.Current.User.Identity.Name.Replace("MS\\", ""); BLUserAdministration objBLUserAdministration = new BLUserAdministration(); UIUserLogin loggedInUser; ExceptionTypes res = objBLUserAdministration.GetUserAccessPermission(loginName, null, null, null, out loggedInUser); if (res == ExceptionTypes.ZeroRecords) { errosMsg = "You are not part of ERS DB, Please contact your Administrator."; return(false); } else if (res != ExceptionTypes.Success) { errosMsg = "An error occured while authorization, Please contact your Administrator."; return(false); } else { userId = loggedInUser.ADM_UserMasterId; return(true); } }
/// <summary> /// load session while session timeout in Login Page /// </summary> /// <returns></returns> private bool LoadCurrentUserSession(out UIUserLogin loggedInUser) { bool isSuccess = false; BLUserAdministration objBLUserAdministration = new BLUserAdministration(); try { string[] strLoginName = System.Web.HttpContext.Current.User.Identity.Name.Split(new string[] { @"\" }, StringSplitOptions.RemoveEmptyEntries); string domain = strLoginName[0]; string loginName = strLoginName[1]; ExceptionTypes result = objBLUserAdministration.GetUserAccessPermission(loginName, null, null, null, out loggedInUser); if (result == ExceptionTypes.ZeroRecords) { loggedInUser.IsAuthorizedUser = false; loggedInUser.ErrorMessage = ConstantTexts.NotPartOfERSDBError; return(isSuccess); } if (result != (long)ExceptionTypes.Success) { BLCommon.LogError(0, MethodBase.GetCurrentMethod().Name, (long)ErrorModuleName.Login, (long)ExceptionTypes.Uncategorized, string.Empty, "Error while fetching logged in user data"); return(isSuccess); } else { #region Check User AD Groups System.Security.Principal.WindowsIdentity winIdnt = System.Web.HttpContext.Current.User.Identity as System.Security.Principal.WindowsIdentity; System.Security.Principal.IdentityReferenceCollection grps = winIdnt.Groups; ////Admin if (IsUserInADGroup(grps, WebConfigData.AdminSID)) { loggedInUser.IsAdminUser = true; } //OST if (IsUserInADGroup(grps, WebConfigData.AdminOSTSID)) { loggedInUser.IsAdmOSTUser = true; } if (IsUserInADGroup(grps, WebConfigData.ManagerOSTSID)) { loggedInUser.IsMgrOSTUser = true; } if (IsUserInADGroup(grps, WebConfigData.ProcessorOSTSID)) { loggedInUser.IsPrcrOSTUser = true; } if (IsUserInADGroup(grps, WebConfigData.ViewerOSTSID)) { loggedInUser.IsVwrOSTUser = true; } //Eligibility if (IsUserInADGroup(grps, WebConfigData.AdminEligSID)) { loggedInUser.IsAdmEligUser = true; } if (IsUserInADGroup(grps, WebConfigData.ManagerEligSID)) { loggedInUser.IsMgrEligUser = true; } if (IsUserInADGroup(grps, WebConfigData.ProcessorEligSID)) { loggedInUser.IsPrcrEligUser = true; } if (IsUserInADGroup(grps, WebConfigData.ViewerEligSID)) { loggedInUser.IsVwrEligUser = true; } //RPR if (IsUserInADGroup(grps, WebConfigData.AdminRPRSID)) { loggedInUser.IsAdmRPRUser = true; } if (IsUserInADGroup(grps, WebConfigData.ManagerRPRSID)) { loggedInUser.IsMgrRPRUser = true; } if (IsUserInADGroup(grps, WebConfigData.ProcessorRPRSID)) { loggedInUser.IsPrcrRPRUser = true; } if (IsUserInADGroup(grps, WebConfigData.ViewerRPRSID)) { loggedInUser.IsVwrRPRUser = true; } #endregion //check if user has atleast one AD group assigned if (loggedInUser.IsAdminUser || loggedInUser.IsAdmOSTUser || loggedInUser.IsAdmEligUser || loggedInUser.IsAdmRPRUser || loggedInUser.IsMgrOSTUser || loggedInUser.IsMgrEligUser || loggedInUser.IsMgrRPRUser || loggedInUser.IsPrcrOSTUser || loggedInUser.IsPrcrEligUser || loggedInUser.IsPrcrRPRUser || loggedInUser.IsVwrOSTUser || loggedInUser.IsVwrEligUser || loggedInUser.IsVwrRPRUser || loggedInUser.IsWebServiceUser || loggedInUser.IsMacroServiceUser) { if (loggedInUser.UserSkills != null && loggedInUser.UserSkills.Count > 0) { loggedInUser.IsAuthorizedUser = true; loggedInUser = LoadDataForLogin(loggedInUser); Session[ConstantTexts.UserSessionBeforeLoginKey] = loggedInUser; isSuccess = true; } else { loggedInUser.IsAuthorizedUser = false; loggedInUser.ErrorMessage = ConstantTexts.NoAccessGroupAssignedError; } } else { loggedInUser.IsAuthorizedUser = false; loggedInUser.ErrorMessage = ConstantTexts.NotPartOfADGroupError; } } } catch (Exception ex) { throw ex; } return(isSuccess); }
private ExceptionTypes CreateSession(WorkBasket objWorkBasket) { ExceptionTypes result = ExceptionTypes.UnauthorizedAccessException; string[] strLoginName = System.Web.HttpContext.Current.User.Identity.Name.Split(new string[] { @"\" }, StringSplitOptions.RemoveEmptyEntries); string domain = strLoginName[0]; string loginName = strLoginName[1]; string errorMessage = string.Empty; try { if (IsUserInADGroup()) { if (Session[ConstantTexts.CurrentUserSessionKey] == null) { BLUserAdministration objBLUserAdministration = new BLUserAdministration(); UserAdminstrationController objUserAdminstrationController = new UserAdminstrationController(); //check user access result = objBLUserAdministration.GetUserAccessPermission(loginName, null, null, null, out UIUserLogin loggedInUser); if (result == ExceptionTypes.ZeroRecords) { //insert new User to DB, get details from LDAP bool isUserFound = objUserAdminstrationController.GetUserDetails(loginName, true, out DOADM_UserMaster objDOADM_UserMaster); if (isUserFound) { objDOADM_UserMaster.CreatedByRef = _currentLoginUserId; objDOADM_UserMaster.MSID = loginName; objDOADM_UserMaster.StartDate = DateTime.UtcNow.AddYears(-1); objDOADM_UserMaster.EndDate = DateTime.UtcNow.AddYears(30); objDOADM_UserMaster.lstDOADM_AccessGroupUserCorrelation = new List <DOADM_AccessGroupUserCorrelation>(); //AddAccessGroups(objDOADM_UserMaster); result = objBLUserAdministration.SaveUser(objDOADM_UserMaster, out errorMessage); } else { //user details not found in LDAP MIIMServiceLog(MethodBase.GetCurrentMethod().Name, "", "Session Creation failed for new User. LDAP details not found", _currentLoginUserId, TarceMethodLkup.Completed.ToLong(), (long)MIIMServiceMethod.GetCaseDetails); BLCommon.LogError(_currentLoginUserId, MethodBase.GetCurrentMethod().Name, (long)ErrorModuleName.MIIMConnector, (long)ExceptionTypes.Uncategorized, "Session Creartion failed, LDAP Details not found", "CREATE session failed"); return(ExceptionTypes.UnknownError); } result = objBLUserAdministration.GetUserAccessPermission(loginName, null, null, null, out loggedInUser); } else if (result != ExceptionTypes.Success) { BLCommon.LogError(_currentLoginUserId, MethodBase.GetCurrentMethod().Name, (long)ErrorModuleName.MIIMConnector, (long)ExceptionTypes.Uncategorized, string.Empty, "Error while fetching logged in user data"); return(result); } // Not adding access groups to MIIM user, so they should not be able to access ERS web application. //adding access groups if no access groups assigned //if (loggedInUser.UserSkills == null || loggedInUser.UserSkills.Count <= 0) //{ // DOADM_UserMaster objDOADM_UserMaster = new DOADM_UserMaster(); // objDOADM_UserMaster.IsActive = true; // objDOADM_UserMaster.MSID = loginName; // objDOADM_UserMaster = objUserAdminstrationController.GetUserSearchResult(objDOADM_UserMaster, out errorMessage).FirstOrDefault(); // AddAccessGroups(objDOADM_UserMaster); // objBLUserAdministration.SaveUser(objDOADM_UserMaster, out errorMessage); //} _currentLoginUserId = loggedInUser.ADM_UserMasterId; loggedInUser.WorkBasketLkup = (long)objWorkBasket; loggedInUser.BusinessSegmentLkup = (long)BusinessSegment.MNR; loggedInUser.RoleLkup = (long)RoleLkup.Processor; //login user result = objBLUserAdministration.LoginUser(loginName); if (result != (long)ExceptionTypes.Success) { BLCommon.LogError(_currentLoginUserId, MethodBase.GetCurrentMethod().Name, (long)ErrorModuleName.MIIMConnector, (long)ExceptionTypes.Uncategorized, string.Empty, "Error while fetching logged in user data"); } //create session Session[ConstantTexts.CurrentUserSessionKey] = loggedInUser; return(ExceptionTypes.Success); } else { UIUserLogin loggedInUser = (UIUserLogin)Session[ConstantTexts.CurrentUserSessionKey]; _currentLoginUserId = loggedInUser.ADM_UserMasterId; //pick current user object and check access group is assigned //check user has access to AD group return(ExceptionTypes.Success); } } else { return(ExceptionTypes.UnauthorizedAccessException); } } catch (Exception ex) { BLCommon.LogError(_currentLoginUserId, MethodBase.GetCurrentMethod().Name, (long)ErrorModuleName.MIIMConnector, (long)ExceptionTypes.Uncategorized, ex.ToString(), ex.Message); return(ExceptionTypes.UnknownError); } }
public ActionResult Login() { try { //check If session exists if (System.Web.HttpContext.Current.Session[ConstantTexts.CurrentUserSessionKey] == null) { string[] strLoginName = System.Web.HttpContext.Current.User.Identity.Name.Split(new string[] { @"\" }, StringSplitOptions.RemoveEmptyEntries); string domain = strLoginName[0]; string loginName = strLoginName[1]; //Checking user in Database. BLUserAdministration objBLUserAdministration = new BLUserAdministration(); ExceptionTypes result = objBLUserAdministration.GetUserAccessPermission(loginName, null, null, null, out UIUserLogin loggedInUser); if (result == ExceptionTypes.ZeroRecords) { loggedInUser.IsAuthorizedUser = false; loggedInUser.ErrorMessage = string.Format(ConstantTexts.NotPartOfERSDBError, loginName); return(View(loggedInUser)); } if (result != (long)ExceptionTypes.Success) { BLCommon.LogError(0, MethodBase.GetCurrentMethod().Name, (long)ErrorModuleName.Login, (long)ExceptionTypes.Uncategorized, string.Empty, "Error while fetching logged in user data"); return(RedirectToAction("Maintenance", "Error", new { Error = MethodBase.GetCurrentMethod().Name + " Action terminated and redirected to Maintenance. Error:Something went wrong while retriving user details from login." })); } else { #region Check User AD Groups System.Security.Principal.WindowsIdentity winIdnt = System.Web.HttpContext.Current.User.Identity as System.Security.Principal.WindowsIdentity; System.Security.Principal.IdentityReferenceCollection grps = winIdnt.Groups; ////Admin if (IsUserInADGroup(grps, WebConfigData.AdminSID)) { loggedInUser.IsAdminUser = true; } //OST if (IsUserInADGroup(grps, WebConfigData.AdminOSTSID)) { loggedInUser.IsAdmOSTUser = true; } if (IsUserInADGroup(grps, WebConfigData.ManagerOSTSID)) { loggedInUser.IsMgrOSTUser = true; } if (IsUserInADGroup(grps, WebConfigData.ProcessorOSTSID)) { loggedInUser.IsPrcrOSTUser = true; } if (IsUserInADGroup(grps, WebConfigData.ViewerOSTSID)) { loggedInUser.IsVwrOSTUser = true; } //Eligibility if (IsUserInADGroup(grps, WebConfigData.AdminEligSID)) { loggedInUser.IsAdmEligUser = true; } if (IsUserInADGroup(grps, WebConfigData.ManagerEligSID)) { loggedInUser.IsMgrEligUser = true; } if (IsUserInADGroup(grps, WebConfigData.ProcessorEligSID)) { loggedInUser.IsPrcrEligUser = true; } if (IsUserInADGroup(grps, WebConfigData.ViewerEligSID)) { loggedInUser.IsVwrEligUser = true; } //RPR if (IsUserInADGroup(grps, WebConfigData.AdminRPRSID)) { loggedInUser.IsAdmRPRUser = true; } if (IsUserInADGroup(grps, WebConfigData.ManagerRPRSID)) { loggedInUser.IsMgrRPRUser = true; } if (IsUserInADGroup(grps, WebConfigData.ProcessorRPRSID)) { loggedInUser.IsPrcrRPRUser = true; } if (IsUserInADGroup(grps, WebConfigData.ViewerRPRSID)) { loggedInUser.IsVwrRPRUser = true; } if (IsUserInADGroup(grps, WebConfigData.RestrictedSID)) { loggedInUser.IsRestrictedUser = true; } #endregion //check if user has atleast one AD group assigned if (loggedInUser.IsAdminUser || loggedInUser.IsAdmOSTUser || loggedInUser.IsAdmEligUser || loggedInUser.IsAdmRPRUser || loggedInUser.IsMgrOSTUser || loggedInUser.IsMgrEligUser || loggedInUser.IsMgrRPRUser || loggedInUser.IsPrcrOSTUser || loggedInUser.IsPrcrEligUser || loggedInUser.IsPrcrRPRUser || loggedInUser.IsVwrOSTUser || loggedInUser.IsVwrEligUser || loggedInUser.IsVwrRPRUser || loggedInUser.IsWebServiceUser || loggedInUser.IsMacroServiceUser) { if (loggedInUser.UserSkills != null && loggedInUser.UserSkills.Count > 0) { loggedInUser.IsAuthorizedUser = true; loggedInUser = LoadDataForLogin(loggedInUser); Session[ConstantTexts.UserSessionBeforeLoginKey] = loggedInUser; return(View(loggedInUser)); } else { loggedInUser.IsAuthorizedUser = false; loggedInUser.ErrorMessage = string.Format(ConstantTexts.NoAccessGroupAssignedError, loginName); return(View(loggedInUser)); } } else { loggedInUser.IsAuthorizedUser = false; loggedInUser.ErrorMessage = string.Format(ConstantTexts.NotPartOfADGroupError, loginName); return(View(loggedInUser)); } } } else { //session exists return(RedirectToAction("Home", "Home")); } } catch (Exception ex) { BLCommon.LogError(0, MethodBase.GetCurrentMethod().Name, (long)ErrorModuleName.Login, (long)ExceptionTypes.Uncategorized, string.Empty, ex.ToString()); return(RedirectToAction("Maintenance", "Error", new { Error = MethodBase.GetCurrentMethod().Name + " Action terminated and redirected to Maintenance. Error:" + ex.ToString() })); } }
private bool UserLoggedIn(out UIUserLogin loggedInUser) { loggedInUser = null; try { if (CurrentUser == null) { string[] strLoginName = System.Web.HttpContext.Current.User.Identity.Name.Split(new string[] { @"\" }, StringSplitOptions.RemoveEmptyEntries); string domain = strLoginName[0]; string loginName = strLoginName[1]; //Checking user in Database. BLUserAdministration objBLUserAdministration = new BLUserAdministration(); ExceptionTypes result = objBLUserAdministration.GetUserAccessPermission(loginName, null, null, null, out loggedInUser); if (result == ExceptionTypes.ZeroRecords) { return(false); } if (result != (long)ExceptionTypes.Success) { return(false); } else { System.Security.Principal.WindowsIdentity winIdnt = System.Web.HttpContext.Current.User.Identity as System.Security.Principal.WindowsIdentity; System.Security.Principal.IdentityReferenceCollection grps = winIdnt.Groups; //Admin if (IsUserInADGroup(grps, WebConfigData.AdminSID)) { loggedInUser.IsAdminUser = true; } //OST if (IsUserInADGroup(grps, WebConfigData.AdminOSTSID)) { loggedInUser.IsAdmOSTUser = true; } if (IsUserInADGroup(grps, WebConfigData.ManagerOSTSID)) { loggedInUser.IsMgrOSTUser = true; } if (IsUserInADGroup(grps, WebConfigData.ProcessorOSTSID)) { loggedInUser.IsPrcrOSTUser = true; } if (IsUserInADGroup(grps, WebConfigData.ViewerOSTSID)) { loggedInUser.IsVwrOSTUser = true; } //Eligibility if (IsUserInADGroup(grps, WebConfigData.AdminEligSID)) { loggedInUser.IsAdmEligUser = true; } if (IsUserInADGroup(grps, WebConfigData.ManagerEligSID)) { loggedInUser.IsMgrEligUser = true; } if (IsUserInADGroup(grps, WebConfigData.ProcessorEligSID)) { loggedInUser.IsPrcrEligUser = true; } if (IsUserInADGroup(grps, WebConfigData.ViewerEligSID)) { loggedInUser.IsVwrEligUser = true; } //RPR if (IsUserInADGroup(grps, WebConfigData.AdminRPRSID)) { loggedInUser.IsAdmRPRUser = true; } if (IsUserInADGroup(grps, WebConfigData.ManagerRPRSID)) { loggedInUser.IsMgrRPRUser = true; } if (IsUserInADGroup(grps, WebConfigData.ProcessorRPRSID)) { loggedInUser.IsPrcrRPRUser = true; } if (IsUserInADGroup(grps, WebConfigData.ViewerRPRSID)) { loggedInUser.IsVwrRPRUser = true; } if (loggedInUser.IsAdminUser == false && loggedInUser.IsAdmOSTUser == false && loggedInUser.IsAdmEligUser == false && loggedInUser.IsAdmRPRUser == false && loggedInUser.IsMgrOSTUser == false && loggedInUser.IsMgrEligUser == false && loggedInUser.IsMgrRPRUser == false && loggedInUser.IsPrcrOSTUser == false && loggedInUser.IsPrcrEligUser == false && loggedInUser.IsPrcrRPRUser == false && loggedInUser.IsVwrOSTUser == false && loggedInUser.IsVwrEligUser == false && loggedInUser.IsVwrRPRUser == false && loggedInUser.IsWebServiceUser == false && loggedInUser.IsMacroServiceUser == false ) { return(false); } else { CurrentUser = loggedInUser; } } } return(true); } catch { return(false); } }