Пример #1
0
        internal static ActiveDirectoryGroup[] GetGroupsFromUser(string userName, string domain)
        {
            ADWrapper ad = new ADWrapper(domain, ActiveDirectoryService.CnnStringName);

            List <ADGroup> list = ad.User_SearchGroupList(userName);

            ad.Dispose();
            if (list.Count != 0)
            {
                var activeDirectoryGroupList = from g in list select new ActiveDirectoryGroup(g);

                return(activeDirectoryGroupList.ToArray <ActiveDirectoryGroup>());
            }
            else
            {
                return(null);
            }
        }
        internal static ActiveDirectoryGroup[] GetGroups(string domain)
        {
            ADWrapper ad = new ADWrapper(domain, ActiveDirectoryService.CnnStringName, performCustomWindowsContextImpersonalization);

            List <ADGroup> list = ad.Groups_GetAll();

            ad.Dispose();

            if (list.Count != 0)
            {
                var userList = from u in list select new ActiveDirectoryGroup(u);

                return(userList.ToArray <ActiveDirectoryGroup>());
            }
            else
            {
                return(null);
            }
        }
Пример #3
0
        internal static void User_SetActivation(string userName, bool disabled, string domain)
        {
            ADWrapper ad = new ADWrapper(domain, Common.CnnStringNameAD, false);


            if (performCustomWindowsContextImpersonalization)
            {
                using (var impersonation = new ImpersonateUser(ad.LDAPUser, ad.LDAPDomain, ad.LDAPPassword, ImpersonateUser.LOGON32_LOGON_NEW_CREDENTIALS))
                {
                    ad.User_SetActivation(userName, disabled);
                }
            }
            else
            {
                ad.User_SetActivation(userName, disabled);
            }

            ad.Dispose();
        }
Пример #4
0
        internal static void User_Unlock(string userName, string domain)
        {
            ADWrapper ad = new ADWrapper(domain, Common.CnnStringNameAD, false);

            //ad.User_SetLockedStatus(userName, false);

            if (performCustomWindowsContextImpersonalization)
            {
                var safeAccessTokenHandle = TryImpersonate(ad);
                WindowsIdentity.RunImpersonated(safeAccessTokenHandle, () =>
                {
                    ad.User_Unlock(userName);
                });
            }
            else
            {
                ad.User_Unlock(userName);
            }
            ad.Dispose();
        }
Пример #5
0
        internal static void User_Reset_Password(string userName, string newPassword, string domain)
        {
            //ADWrapper ad3 = new ADWrapper(domain, ActiveDirectoryService.CnnStringName, performCustomWindowsContextImpersonalization);

            //ADWrapper ad = new ADWrapper("LDAP://allus.ar/DC=allus,DC=ar", "LDAP_Reseteo_WSReset", "R3s3t30s++");
            //domain = "LDAP://allus.ar/DC=allus,DC=ar";
            //domain = "LDAP://alcomovistar.com.ar/DC=alcomovistar,DC=com,DC=ar";
            //ADWrapper ad3 = new ADWrapper("LDAP://alcomovistar.com.ar/DC=alcomovistar,DC=com,DC=ar", "LDAP_Reseteo_WSReset", "R3s3t30s++");
            //ADWrapper ad = new ADWrapper(domain, "reseteos", "*R3s3t30s+");
            ImpersonateLogin impersonateLogin = new ImpersonateLogin();

            impersonateLogin.ldap     = "LDAP://allus.ar/DC=allus,DC=ar";
            impersonateLogin.user     = "******";
            impersonateLogin.password = "******";
            impersonateLogin.domain   = "allus-ar";
            ADWrapper ad = new ADWrapper(impersonateLogin.domain, impersonateLogin);

            ad.User_ResetPwd(userName, newPassword, true);

            ad.Dispose();
        }
Пример #6
0
        /// <summary>
        /// Intenta con el método ResetPassword2 y si falla utiliza ResetPassword
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="newPassword"></param>
        /// <param name="domain"></param>
        internal static void User_Reset_Password(string userName, string newPassword, string domain)
        {
            try
            {
                ResetPassword(userName, domain, newPassword, true, Common.mustChangedNextLogon);
            }
            catch (Exception y)
            {
                //userDirectoryEntry.Properties["pwdLastSet"].Value =
                //pwdLastSet = 0  must be changed at the next logon.
                // -1  = This value does the reverse of 0.It makes the password not expired
                //
                int flagmustChangedNextLogon = -1;
                if (Common.mustChangedNextLogon)
                {
                    flagmustChangedNextLogon = 0;
                }

                ADWrapper ad = new ADWrapper(domain, Common.CnnStringNameAD, performCustomWindowsContextImpersonalization);
                //ADWrapper ad3 = new ADWrapper(domain,"reseteos","*R3s3t30s+");

                if (performCustomWindowsContextImpersonalization)
                {
                    using (var impersonation = new ImpersonateUser(ad.LDAPUser, ad.LDAPDomain, ad.LDAPPassword, ImpersonateUser.LOGON32_LOGON_NEW_CREDENTIALS))
                    {
                        ad.User_ResetPwd(userName, newPassword, true, flagmustChangedNextLogon);
                    }
                }
                else
                {
                    ad.User_ResetPwd(userName, newPassword, true, flagmustChangedNextLogon);
                }

                ad.Dispose();
            }
        }
Пример #7
0
        internal static List <ActiveDirectoryUser> GetUsersFromGroup(string groupName, string domain)
        {
            try {
                ADWrapper ad = new ADWrapper(domain, Common.CnnStringNameAD);

                List <ADUser> list = ad.Users_SearchByGroupName(groupName);

                ad.Dispose();
                if (list.Count != 0)
                {
                    var userList = from u in list select new ActiveDirectoryUser(u);

                    return(userList.ToList());
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #8
0
 public static Boolean ResetPassword_ADWrapper(string usernameToresset, string newPassword, ADWrapper ad)
 {
     ad.User_ResetPwd(usernameToresset, newPassword, true);
     ad.Dispose();
     return(true);
 }