예제 #1
0
        private void DisableButtons()
        {
            System.Security.Principal.IdentityReferenceCollection t = System.Security.Principal.WindowsIdentity.GetCurrent().Groups;
            if (System.Security.Principal.WindowsIdentity.GetCurrent().Groups.Where(p => p.Value == "S-1-5-21-394331043-2906864525-1991675871-1006").Count() != 0)
            {
                WhoLabel.Text += "админ.";
                return;
            }
            CallDTeacherForm.Visible = CallETeacherForm.Visible = CallNTeacherForm.Visible = false;
            CallDSchoolForm.Visible  = false;
            CallDSubjectForm.Visible = false;
            CallEStudentForm.Visible = CallDStudentForm.Visible = false;
            CallNCourseForm.Visible  = CallECourseForm.Visible = CallDCourseForm.Visible = false;
            if (System.Security.Principal.WindowsIdentity.GetCurrent().Groups.Where(p => p.Value == "S-1-5-21-394331043-2906864525-1991675871-1005").Count() != 0)
            {
                WhoLabel.Text += "учитель.";
                return;
            }

            CallESchoolForm.Visible  = CallNSchoolForm.Visible = false;
            CallESubjectForm.Visible = CallNSubjectForm.Visible = false;
            CallNStudentForm.Visible = false;
            if (System.Security.Principal.WindowsIdentity.GetCurrent().Groups.Where(p => p.Value == "S-1-5-21-394331043-2906864525-1991675871-1007").Count() != 0)
            {
                WhoLabel.Text += "ученик.";
                return;
            }
            Close();
        }
예제 #2
0
        /// <summary>
        /// Retrieves identity and role information from the currently
        /// logged in Windows user.
        /// </summary>
        protected void PopulateWindowsIdentity()
        {
            string DomainDelimiter = "\\";

            System.Security.Principal.IdentityReferenceCollection groups = System.Security.Principal.WindowsIdentity.GetCurrent().Groups;
            MobileList <string> roles = new MobileList <string>();

            foreach (System.Security.Principal.IdentityReference item in groups)
            {
                System.Security.Principal.NTAccount account = (System.Security.Principal.NTAccount)item.Translate(typeof(System.Security.Principal.NTAccount));
                if (account.Value.Contains(DomainDelimiter))
                {
                    roles.Add(account.Value.Substring(account.Value.LastIndexOf(DomainDelimiter) + 1));
                }
                else
                {
                    roles.Add(account.Value);
                }
            }
            string identityName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

            if (identityName.Contains(DomainDelimiter))
            {
                identityName = identityName.Substring(identityName.LastIndexOf(DomainDelimiter) + 1);
            }
            this.LoadProperty(RolesProperty, roles);
            this.LoadProperty(IsAuthenticatedProperty, true);
            this.LoadProperty(NameProperty, identityName);
        }
예제 #3
0
        private bool IsUserInADGroup(System.Security.Principal.IdentityReferenceCollection grps, string SIDs)
        {
            string[] ADGroupSIDs = SIDs.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);

            bool isUserInADGroup = (from g in grps
                                    where ADGroupSIDs.Any(s => s == g.Value)
                                    select g).Any();

            return(isUserInADGroup);
        }
예제 #4
0
 private void DisableButtons()
 {
     System.Security.Principal.IdentityReferenceCollection t = System.Security.Principal.WindowsIdentity.GetCurrent().Groups;
     if (System.Security.Principal.WindowsIdentity.GetCurrent().Groups.Where(p => p.Value == "S-1-5-21-394331043-2906864525-1991675871-1006").Count() != 0)
     {
         return;
     }
     CallDBStudentForm.Visible = false;
     if (System.Security.Principal.WindowsIdentity.GetCurrent().Groups.Where(p => p.Value == "S-1-5-21-394331043-2906864525-1991675871-1005").Count() != 0)
     {
         return;
     }
     if (System.Security.Principal.WindowsIdentity.GetCurrent().Groups.Where(p => p.Value == "S-1-5-21-394331043-2906864525-1991675871-1007").Count() != 0)
     {
         return;
     }
     Close();
 }
예제 #5
0
        private bool IsUserInADGroup()
        {
            try
            {
                System.Security.Principal.WindowsIdentity             winIdnt = System.Web.HttpContext.Current.User.Identity as System.Security.Principal.WindowsIdentity;
                System.Security.Principal.IdentityReferenceCollection grps    = winIdnt.Groups;
                string   SIDs        = WebConfigData.MIIMSID;
                string[] ADGroupSIDs = SIDs.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);

                bool isUserInADGroup = (from g in grps
                                        where ADGroupSIDs.Any(s => s == g.Value)
                                        select g).Any();
                return(isUserInADGroup);
            }
            catch (Exception ex)
            {
                BLCommon.LogError(_currentLoginUserId, MethodBase.GetCurrentMethod().Name, (long)ErrorModuleName.MIIMConnector, (long)ExceptionTypes.Uncategorized, ex.ToString(), ex.Message);
                return(false);
            }
        }
예제 #6
0
        public WindowsIdentity GetUser(System.Security.Principal.WindowsIdentity user)
        {
            //Create Extentrix Windows Identity object.
            WindowsIdentity identity = new WindowsIdentity();

            //Use name domain
            string[] dn = user.Name.Split(new char[] { '\\' });
            if (dn.Length > 1)
            {
                identity.Domain   = dn[0];
                identity.UserName = dn[1];
            }

            identity.UPN = user.Name;
            // set the values for web services windows identity
            identity.SAM = user.Name;

            // get all the groups that the user belongs to.
            System.Security.Principal.IdentityReferenceCollection irc = user.Groups;

            // define list to contains groups
            ArrayList list = new ArrayList();

            // Add the SID for each group
            foreach (System.Security.Principal.IdentityReference ir in irc)
            {
                list.Add(ir.Value);
            }

            // Add the SID for the current login user
            list.Add(user.User.Value);

            // assgine the collected SID list (user and the groups belongs to).
            identity.SIDs = (string[])list.ToArray(typeof(string));

            return(identity);
        }
예제 #7
0
        /// <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);
        }
예제 #8
0
        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() }));
            }
        }
예제 #9
0
        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);
            }
        }