Beispiel #1
0
        public static enGageUser GetAccountExecutive(string username)
        {
            //bizSetting biz = new bizSetting();
            //string LDAP = biz.GetSetting("ActiveDirectory.LDAP").Replace("LDAP://", string.Empty);

            PrincipalContext adPrincipalContext = new PrincipalContext(ContextType.Domain, "SMI");
            UserPrincipal    userP = new UserPrincipal(adPrincipalContext);

            userP.Enabled        = true;
            userP.SamAccountName = username;

            //Test that the wildcard search actually works

            PrincipalSearcher pS      = new PrincipalSearcher(userP);
            Principal         results = pS.FindOne();

            if (results == null)
            {
                return(null);
            }
            DirectoryEntry de = (DirectoryEntry)results.GetUnderlyingObject();

            /*
             * bizSetting biz = new bizSetting();
             * System.DirectoryServices.DirectoryEntry de =
             * //bizActiveDirectory.GetUserDetails(biz.GetSetting("ActiveDirectory.LDAP"),username);
             */

            if (de == null)
            {
                return(null);
            }
            enGageUser user = new enGageUser();

            user.UserName    = username;
            user.DisplayName = de.Properties["cn"].Value.ToString();
            user.Branch      = de.Properties["Department"].Value.ToString();
            user.Region      = GetRegionForBranch(user.Branch);
            user.Role        = 0;
            return(user);
        }
Beispiel #2
0
        public static enGageUser GetCurrentUser(string currentLogonWithoutAdPrefix)
        {
            //get the SMI user name
            string SmiUserName = GetAccountExecutiveIdBySmiUserName(currentLogonWithoutAdPrefix);

            System.Security.Principal.WindowsImpersonationContext impersonationContext;
            impersonationContext = ((System.Security.Principal.WindowsIdentity)WindowsIdentity.GetCurrent()).Impersonate();

            //get the adctive directory connection
            bizSetting biz  = new bizSetting();
            string     LDAP = biz.GetSetting("ActiveDirectory.LDAP").Replace("LDAP://", string.Empty);

            PrincipalContext adPrincipalContext = new PrincipalContext(ContextType.Domain, LDAP, null, null);
            UserPrincipal    userP = new UserPrincipal(adPrincipalContext);

            userP.Enabled        = true;
            userP.SamAccountName = currentLogonWithoutAdPrefix;     //updated to use the new SMI user name sourced from SQL

            //Test that the wildcard search actually works
            PrincipalSearcher pS      = new PrincipalSearcher(userP);
            Principal         results = pS.FindOne();

            if (results == null)
            {
                return(null);
            }
            DirectoryEntry de = (DirectoryEntry)results.GetUnderlyingObject();

            /*
             *  bizSetting biz = new bizSetting();
             *  System.DirectoryServices.DirectoryEntry de =
             * // bizActiveDirectory.GetUserDetails(biz.GetSetting("ActiveDirectory.LDAP"),
             *  HttpContext.Current.User.Identity.Name.Replace("OAMPSINS\\", ""));
             */

            if (de == null)
            {
                return(null);
            }

            enGageUser user = new enGageUser();

            user.SMIUserName = currentLogonWithoutAdPrefix; //yes, this is correct, save the current domain user logon
            user.UserName    = SmiUserName;                 //for mapping over to AD, need to use the 'translated from SQL' logon
            user.DisplayName = de.Properties["cn"].Value.ToString();
            user.Branch      = de.Properties["Department"].Value.ToString();
            user.Region      = GetRegionForBranch(user.Branch);
            user.Role        = 0;

            return(user);


            //// FOR TESTING PURPOSES
            //enGageUser user = new enGageUser
            //{
            //    SMIUserName = username,
            //    UserName = GetAccountExecutiveIdBySmiUserName(username),
            //    DisplayName = "Testing Account",
            //    Branch = "Testing Branch",
            //    Region = "Testing Region",
            //    Role = 0
            //};

            // return user;
        }