Exemplo n.º 1
0
        public ActionResult Login(long BusinessSegmentLkup = 0, long WorkBasketLkup = 0, long RoleLkup = 0)
        {
            try
            {
                ReLogin : string s = string.Empty;
                if (BusinessSegmentLkup > 0 && WorkBasketLkup > 0 && RoleLkup > 0)
                {
                    string[] strLoginName = System.Web.HttpContext.Current.User.Identity.Name.Split(new string[] { @"\" }, StringSplitOptions.RemoveEmptyEntries);
                    string   domain       = strLoginName[0];
                    string   loginName    = strLoginName[1];

                    if (Session[ConstantTexts.UserSessionBeforeLoginKey] != null)
                    {
                        DO.UIUserLogin loggedInUser = (DO.UIUserLogin)Session[ConstantTexts.UserSessionBeforeLoginKey];

                        loggedInUser.WorkBasketLkup      = WorkBasketLkup;
                        loggedInUser.BusinessSegmentLkup = BusinessSegmentLkup;
                        loggedInUser.RoleLkup            = RoleLkup;

                        bool   IsADGroupAssigned         = true;
                        string WorkBasletADGroupRequired = "";
                        string RoleADGroupRequired       = "";

                        //check if user has AD group access to slected Role and Workbasket
                        switch (RoleLkup)
                        {
                        case (long)Utility.RoleLkup.Admin:
                            RoleADGroupRequired = Utility.RoleLkup.Admin.ToString();
                            switch (WorkBasketLkup)
                            {
                            case (long)Utility.WorkBasket.GPSvsMMR:
                                IsADGroupAssigned         = loggedInUser.IsAdmEligUser;
                                WorkBasletADGroupRequired = Utility.WorkBasket.GPSvsMMR.ToString();
                                break;

                            case (long)Utility.WorkBasket.OST:
                                IsADGroupAssigned         = loggedInUser.IsAdmOSTUser;
                                WorkBasletADGroupRequired = Utility.WorkBasket.OST.ToString();
                                break;

                            case (long)Utility.WorkBasket.RPR:
                                IsADGroupAssigned         = loggedInUser.IsAdmRPRUser;
                                WorkBasletADGroupRequired = Utility.WorkBasket.RPR.ToString();
                                break;
                            }
                            break;

                        case (long)Utility.RoleLkup.Processor:
                            RoleADGroupRequired = Utility.RoleLkup.Processor.ToString();
                            switch (WorkBasketLkup)
                            {
                            case (long)Utility.WorkBasket.GPSvsMMR:
                                IsADGroupAssigned         = loggedInUser.IsPrcrEligUser;
                                WorkBasletADGroupRequired = Utility.WorkBasket.GPSvsMMR.ToString();
                                break;

                            case (long)Utility.WorkBasket.OST:
                                IsADGroupAssigned         = loggedInUser.IsPrcrOSTUser;
                                WorkBasletADGroupRequired = Utility.WorkBasket.OST.ToString();
                                break;

                            case (long)Utility.WorkBasket.RPR:
                                IsADGroupAssigned         = loggedInUser.IsPrcrRPRUser;
                                WorkBasletADGroupRequired = Utility.WorkBasket.RPR.ToString();
                                break;
                            }
                            break;

                        case (long)Utility.RoleLkup.Manager:
                            RoleADGroupRequired = Utility.RoleLkup.Manager.ToString();
                            switch (WorkBasketLkup)
                            {
                            case (long)Utility.WorkBasket.GPSvsMMR:
                                IsADGroupAssigned         = loggedInUser.IsMgrEligUser;
                                WorkBasletADGroupRequired = Utility.WorkBasket.GPSvsMMR.ToString();
                                break;

                            case (long)Utility.WorkBasket.OST:
                                IsADGroupAssigned         = loggedInUser.IsMgrOSTUser;
                                WorkBasletADGroupRequired = Utility.WorkBasket.OST.ToString();
                                break;

                            case (long)Utility.WorkBasket.RPR:
                                IsADGroupAssigned         = loggedInUser.IsMgrRPRUser;
                                WorkBasletADGroupRequired = Utility.WorkBasket.RPR.ToString();
                                break;
                            }
                            break;

                        case (long)Utility.RoleLkup.Viewer:
                            RoleADGroupRequired = Utility.RoleLkup.Viewer.ToString();
                            switch (WorkBasketLkup)
                            {
                            case (long)Utility.WorkBasket.GPSvsMMR:
                                IsADGroupAssigned         = loggedInUser.IsVwrEligUser;
                                WorkBasletADGroupRequired = Utility.WorkBasket.GPSvsMMR.ToString();
                                break;

                            case (long)Utility.WorkBasket.OST:
                                IsADGroupAssigned         = loggedInUser.IsVwrOSTUser;
                                WorkBasletADGroupRequired = Utility.WorkBasket.OST.ToString();
                                break;

                            case (long)Utility.WorkBasket.RPR:
                                IsADGroupAssigned         = loggedInUser.IsVwrRPRUser;
                                WorkBasletADGroupRequired = Utility.WorkBasket.RPR.ToString();
                                break;
                            }
                            break;
                        }

                        if (!IsADGroupAssigned)
                        {
                            //If no AD group Access return error message
                            loggedInUser.ErrorMessage = string.Format(ConstantTexts.NotPartofADgroupForRoleError, RoleADGroupRequired, WorkBasletADGroupRequired);
                            return(View(loggedInUser));
                        }

                        BLUserAdministration objBLUserAdministration = new BLUserAdministration();
                        ExceptionTypes       result = objBLUserAdministration.LoginUser(loginName);
                        if (result != (long)ExceptionTypes.Success)
                        {
                            loggedInUser.ErrorMessage = ConstantTexts.LoginException;
                            return(View(loggedInUser));
                        }

                        //filter skills for slected workbasket and roles
                        loggedInUser.UserSkills = loggedInUser.UserSkills.Where(x => x.WorkBasketLkup.Equals(WorkBasketLkup) && x.RoleLkup.Equals(RoleLkup)).ToList();

                        //Filter Queues avalaible to user in current access group
                        loggedInUser.UserQueueList = (from UQL in loggedInUser.UserQueueList
                                                      join US in loggedInUser.UserSkills on UQL.QueueLkp equals US.WorkQueuesLkup
                                                      where US.WorkQueuesLkup > 0
                                                      select UQL).GroupBy(x => x.QueueLkp).Select(y => y.FirstOrDefault()).ToList();

                        //Set Menu Visibilities
                        switch (WorkBasketLkup)
                        {
                        case (long)WorkBasket.GPSvsMMR:
                            loggedInUser.IsMMREligibilityMenuVisible = loggedInUser.UserSkills.Any(x => x.DiscrepancyCategoryLkup == (long)DiscripancyCategory.Eligibility);
                            if (loggedInUser.IsMMREligibilityMenuVisible)
                            {
                                loggedInUser.EligibilityMMRCanCreate = loggedInUser.UserSkills.Any(x => x.CanCreate && x.DiscrepancyCategoryLkup == (long)DiscripancyCategory.Eligibility);
                                loggedInUser.EligibilityMMRCanSearch = loggedInUser.UserSkills.Any(x => x.CanSearch && x.DiscrepancyCategoryLkup == (long)DiscripancyCategory.Eligibility);
                            }
                            loggedInUser.IsDOBMenuVisible = loggedInUser.UserSkills.Any(x => x.DiscrepancyCategoryLkup == (long)DiscripancyCategory.DOB);
                            if (loggedInUser.IsDOBMenuVisible)
                            {
                                loggedInUser.EligibilityDOBCanCreate = loggedInUser.UserSkills.Any(x => x.CanCreate && x.DiscrepancyCategoryLkup == (long)DiscripancyCategory.DOB);
                                loggedInUser.EligibilityDOBCanSearch = loggedInUser.UserSkills.Any(x => x.CanSearch && x.DiscrepancyCategoryLkup == (long)DiscripancyCategory.DOB);
                            }
                            loggedInUser.IsGENDERMenuVisible = loggedInUser.UserSkills.Any(x => x.DiscrepancyCategoryLkup == (long)DiscripancyCategory.Gender);
                            if (loggedInUser.IsGENDERMenuVisible)
                            {
                                loggedInUser.EligibilityGenderCanCreate = loggedInUser.UserSkills.Any(x => x.CanCreate && x.DiscrepancyCategoryLkup == (long)DiscripancyCategory.Gender);
                                loggedInUser.EligibilityGenderCanSearch = loggedInUser.UserSkills.Any(x => x.CanSearch && x.DiscrepancyCategoryLkup == (long)DiscripancyCategory.Gender);
                            }
                            break;

                        case (long)WorkBasket.OST:
                            loggedInUser.IsOOAMenuVisible = loggedInUser.UserSkills.Any(x => x.DiscrepancyCategoryLkup == (long)DiscripancyCategory.OOA);
                            if (loggedInUser.IsOOAMenuVisible)
                            {
                                loggedInUser.OSTOOACanCreate = loggedInUser.UserSkills.Any(x => x.CanCreate && x.DiscrepancyCategoryLkup == (long)DiscripancyCategory.OOA);
                                loggedInUser.OSTOOACanSearch = loggedInUser.UserSkills.Any(x => x.CanSearch && x.DiscrepancyCategoryLkup == (long)DiscripancyCategory.OOA);
                            }
                            loggedInUser.IsSCCMenuVisible = loggedInUser.UserSkills.Any(x => x.DiscrepancyCategoryLkup == (long)DiscripancyCategory.SCC);
                            if (loggedInUser.IsSCCMenuVisible)
                            {
                                loggedInUser.OSTSCCCanCreate = loggedInUser.UserSkills.Any(x => x.CanCreate && x.DiscrepancyCategoryLkup == (long)DiscripancyCategory.SCC);
                                loggedInUser.OSTSCCCanSearch = loggedInUser.UserSkills.Any(x => x.CanSearch && x.DiscrepancyCategoryLkup == (long)DiscripancyCategory.SCC);
                            }
                            loggedInUser.IsTRRMenuVisible = loggedInUser.UserSkills.Any(x => x.DiscrepancyCategoryLkup == (long)DiscripancyCategory.TRR);
                            if (loggedInUser.IsTRRMenuVisible)
                            {
                                loggedInUser.OSTTRRCanCreate = loggedInUser.UserSkills.Any(x => x.CanCreate && x.DiscrepancyCategoryLkup == (long)DiscripancyCategory.TRR);
                                loggedInUser.OSTTRRCanSearch = loggedInUser.UserSkills.Any(x => x.CanSearch && x.DiscrepancyCategoryLkup == (long)DiscripancyCategory.TRR);
                            }
                            break;

                        case (long)WorkBasket.RPR:
                            loggedInUser.IsRPRMenuVisible = loggedInUser.UserSkills.Any(x => x.DiscrepancyCategoryLkup == (long)DiscripancyCategory.RPR);
                            if (loggedInUser.IsRPRMenuVisible)
                            {
                                loggedInUser.RPRCanCreate  = loggedInUser.UserSkills.Any(x => x.CanCreate && x.DiscrepancyCategoryLkup == (long)DiscripancyCategory.RPR);
                                loggedInUser.RPRCanCSearch = loggedInUser.UserSkills.Any(x => x.CanSearch && x.DiscrepancyCategoryLkup == (long)DiscripancyCategory.RPR);
                            }
                            break;
                        }

                        //Set Manager Sub Menu Visibilities
                        if (RoleLkup == (long)Utility.RoleLkup.Manager || RoleLkup == (long)Utility.RoleLkup.Admin)
                        {
                            loggedInUser.CanMassReassign = loggedInUser.UserSkills.Any(x => x.CanReassign && x.WorkBasketLkup == WorkBasketLkup);
                            loggedInUser.CanMassUnlock   = loggedInUser.UserSkills.Any(x => x.CanUnlock && x.WorkBasketLkup == WorkBasketLkup);
                            loggedInUser.CanMassUpdate   = loggedInUser.UserSkills.Any(x => x.CanMassUpdate && x.WorkBasketLkup == WorkBasketLkup);
                            loggedInUser.CanMassUpload   = loggedInUser.UserSkills.Any(x => x.CanUpload && x.WorkBasketLkup == WorkBasketLkup);
                        }

                        if (loggedInUser.LocationLkup == (long)Location.Onshore && loggedInUser.IsRestrictedUser)
                        {
                            loggedInUser.IsRestrictedUser = true;
                        }
                        else
                        {
                            loggedInUser.IsRestrictedUser = false;
                        }

                        LastActivity = DateTime.Now;

                        Session[ConstantTexts.CurrentUserSessionKey] = loggedInUser;
                        return(RedirectToAction("Home", "Home"));
                    }
                    else
                    {
                        Session[ConstantTexts.CurrentUserSessionKey] = null;
                        UIUserLogin loggedInUser;
                        if (LoadCurrentUserSession(out loggedInUser))
                        {
                            goto ReLogin;
                        }
                        return(View(loggedInUser));
                    }
                }
                Session[ConstantTexts.CurrentUserSessionKey] = null;
                return(RedirectToAction("Login", "Login"));
            }
            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() }));
            }
        }
Exemplo n.º 2
0
        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);
            }
        }