Example #1
0
        internal void DeleteUserInternal(string loginName, string organizationId)
        {
            HostedSolutionLog.LogStart("DeleteUserInternal");
            HostedSolutionLog.DebugInfo("loginName : {0}", loginName);
            HostedSolutionLog.DebugInfo("organizationId : {0}", organizationId);

            if (string.IsNullOrEmpty(loginName))
            {
                throw new ArgumentNullException("loginName");
            }

            if (string.IsNullOrEmpty(organizationId))
            {
                throw new ArgumentNullException("organizationId");
            }

            string path = GetUserPath(organizationId, loginName);

            if (ActiveDirectoryUtils.AdObjectExists(path))
            {
                ActiveDirectoryUtils.DeleteADObject(path);
            }

            HostedSolutionLog.LogEnd("DeleteUserInternal");
        }
Example #2
0
        private string GetDomainName(string username)
        {
            string domain = ActiveDirectoryUtils.GetNETBIOSDomainName(RootDomain);
            string ret    = string.Format(@"{0}\{1}", domain, username);

            return(ret);
        }
Example #3
0
        /// <summary> Adds domain to AD.</summary>
        /// <param name="organizationId"> The organization identifier.</param>
        /// <param name="domainName"> The domain name.</param>
        private void AddAdDomainName(string organizationId, string domainName)
        {
            string         path = AddADPrefix(GetOrganizationPath(organizationId));
            DirectoryEntry ou   = ActiveDirectoryUtils.GetADObject(path);

            ActiveDirectoryUtils.SetADObjectPropertyValue(ou, "Url", new[] { domainName });
            ou.CommitChanges();
        }
Example #4
0
        /// <summary>
        /// Creates organization domain
        /// </summary>
        /// <param name="organizationDistinguishedName"></param>
        /// <param name="domain"></param>
        private void CreateOrganizationDomainInternal(string organizationDistinguishedName, string domain)
        {
            HostedSolutionLog.LogStart("CreateOrganizationDomainInternal");

            string path = ActiveDirectoryUtils.AddADPrefix(organizationDistinguishedName, PrimaryDomainController);

            ActiveDirectoryUtils.AddUPNSuffix(path, domain);
            HostedSolutionLog.LogEnd("CreateOrganizationDomainInternal");
        }
Example #5
0
        internal bool OrganizationExistsInternal(string organizationId)
        {
            if (string.IsNullOrEmpty(organizationId))
            {
                throw new ArgumentNullException("organizationId");
            }

            string orgPath = GetOrganizationPath(organizationId);

            return(ActiveDirectoryUtils.AdObjectExists(orgPath));
        }
Example #6
0
        internal OrganizationUser GetUserGeneralSettingsInternal(string loginName, string organizationId)
        {
            HostedSolutionLog.LogStart("GetUserGeneralSettingsInternal");
            HostedSolutionLog.DebugInfo("loginName : {0}", loginName);
            HostedSolutionLog.DebugInfo("organizationId : {0}", organizationId);

            if (string.IsNullOrEmpty(loginName))
            {
                throw new ArgumentNullException("loginName");
            }

            string         path  = GetUserPath(organizationId, loginName);
            DirectoryEntry entry = ActiveDirectoryUtils.GetADObject(path);

            OrganizationUser retUser = new OrganizationUser();

            retUser.FirstName         = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.FirstName);
            retUser.LastName          = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.LastName);
            retUser.DisplayName       = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.DisplayName);
            retUser.Initials          = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Initials);
            retUser.JobTitle          = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.JobTitle);
            retUser.Company           = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Company);
            retUser.Department        = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Department);
            retUser.Office            = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Office);
            retUser.BusinessPhone     = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.BusinessPhone);
            retUser.Fax               = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Fax);
            retUser.HomePhone         = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.HomePhone);
            retUser.MobilePhone       = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.MobilePhone);
            retUser.Pager             = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Pager);
            retUser.WebPage           = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.WebPage);
            retUser.Address           = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Address);
            retUser.City              = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.City);
            retUser.State             = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.State);
            retUser.Zip               = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Zip);
            retUser.Country           = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Country);
            retUser.Notes             = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Notes);
            retUser.ExternalEmail     = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.ExternalEmail);
            retUser.Disabled          = (bool)entry.InvokeGet(ADAttributes.AccountDisabled);
            retUser.Manager           = GetManager(entry);
            retUser.DomainUserName    = GetDomainName(loginName);
            retUser.DistinguishedName = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.DistinguishedName);
            retUser.Locked            = (bool)entry.InvokeGet(ADAttributes.AccountLocked);

            HostedSolutionLog.LogEnd("GetUserGeneralSettingsInternal");
            return(retUser);
        }
Example #7
0
        internal PasswordPolicyResult GetPasswordPolicyInternal()
        {
            HostedSolutionLog.LogStart("GetPasswordPolicyInternal");

            PasswordPolicyResult res = new PasswordPolicyResult {
                IsSuccess = true
            };

            string[] policyAttributes = new[] { "minPwdLength",
                                                "pwdProperties",
                                                "objectClass" };
            try
            {
                DirectoryEntry domainRoot = new DirectoryEntry(ActiveDirectoryUtils.ConvertDomainName(RootDomain));

                DirectorySearcher ds = new DirectorySearcher(
                    domainRoot,
                    "(objectClass=domainDNS)",
                    policyAttributes,
                    SearchScope.Base
                    );


                SearchResult result = ds.FindOne();

                PasswordPolicy ret = new PasswordPolicy
                {
                    MinLength          = ((int)result.Properties["minPwdLength"][0]),
                    IsComplexityEnable = ((int)result.Properties["pwdProperties"][0] == 1)
                };
                res.Value = ret;
            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError(ex);
                res.IsSuccess = false;
                res.ErrorCodes.Add(ErrorCodes.CANNOT_GET_PASSWORD_COMPLEXITY);
            }

            HostedSolutionLog.LogEnd("GetPasswordPolicyInternal");
            return(res);
        }
Example #8
0
        private OrganizationUser GetManager(DirectoryEntry entry)
        {
            OrganizationUser retUser = null;
            string           path    = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Manager);

            if (!string.IsNullOrEmpty(path))
            {
                path = ActiveDirectoryUtils.AddADPrefix(path, PrimaryDomainController);
                if (ActiveDirectoryUtils.AdObjectExists(path))
                {
                    DirectoryEntry user = ActiveDirectoryUtils.GetADObject(path);
                    retUser             = new OrganizationUser();
                    retUser.DisplayName = ActiveDirectoryUtils.GetADObjectStringProperty(user, ADAttributes.DisplayName);

                    retUser.AccountName = ActiveDirectoryUtils.GetADObjectStringProperty(user, ADAttributes.Name);
                }
            }

            return(retUser);
        }
Example #9
0
        private void ChangeOrganizationState(Organization org, bool enabled)
        {
            string         path  = GetOrganizationPath(org.OrganizationId);
            DirectoryEntry entry = ActiveDirectoryUtils.GetADObject(path);

            string filter =
                string.Format(CultureInfo.InvariantCulture, "(&(objectClass=user)(!{0}=disabled))",
                              ADAttributes.CustomAttribute2);

            using (DirectorySearcher searcher = new DirectorySearcher(entry, filter))
            {
                SearchResultCollection resCollection = searcher.FindAll();
                foreach (SearchResult res in resCollection)
                {
                    DirectoryEntry de = res.GetDirectoryEntry();
                    de.InvokeSet("AccountDisabled", !enabled);
                    de.CommitChanges();
                }
            }
        }
Example #10
0
        internal void DeleteOrganizationInternal(string organizationId)
        {
            HostedSolutionLog.LogStart("DeleteOrganizationInternal");
            HostedSolutionLog.DebugInfo("OrganizationId : {0}", organizationId);

            if (string.IsNullOrEmpty(organizationId))
            {
                throw new ArgumentNullException("organizationId");
            }

            string groupPath = GetGroupPath(organizationId);

            ActiveDirectoryUtils.DeleteADObject(groupPath);

            string path = GetOrganizationPath(organizationId);

            ActiveDirectoryUtils.DeleteADObject(path, true);



            HostedSolutionLog.LogEnd("DeleteOrganizationInternal");
        }
Example #11
0
        /// <summary> Sets users general settings.</summary>
        /// <param name="organizationId"> The organization identifier.</param>
        /// <param name="userUpn"> The user UPN.</param>
        /// <param name="lyncUser"> The lync user settings.</param>
        /// <returns> The result.</returns>
        internal override bool SetLyncUserGeneralSettingsInternal(string organizationId, string userUpn, LyncUser lyncUser)
        {
            HostedSolutionLog.LogStart("SetLyncUserGeneralSettingsInternal");
            HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId);
            HostedSolutionLog.DebugInfo("userUpn: {0}", userUpn);

            bool            ret         = true;
            Runspace        runspace    = null;
            LyncTransaction transaction = StartTransaction();

            try
            {
                runspace = OpenRunspace();
                Guid     tenantId = GetObjectGuid(organizationId, runspace);
                string[] tmp      = userUpn.Split('@');

                if (tmp.Length < 2)
                {
                    return(false);
                }

                var command = new Command("Get-CsSipDomain");
                Collection <PSObject> sipDomains = ExecuteShellCommand(runspace, command, false);
                bool bSipDomainExists            = sipDomains.Select(domain => (string)GetPSObjectProperty(domain, "Name")).Any(d => d.ToLower() == tmp[1].ToLower());

                if (!bSipDomainExists)
                {
                    command = new Command("New-CsSipDomain");
                    command.Parameters.Add("Identity", tmp[1].ToLower());
                    ExecuteShellCommand(runspace, command, false);

                    transaction.RegisterNewSipDomain(tmp[1].ToLower());

                    string         path      = AddADPrefix(GetOrganizationPath(organizationId));
                    DirectoryEntry ou        = ActiveDirectoryUtils.GetADObject(path);
                    string[]       sipDs     = ActiveDirectoryUtils.GetADObjectPropertyMultiValue(ou, "Url");
                    var            listSipDs = new List <string>();
                    listSipDs.AddRange(sipDs);
                    listSipDs.Add(tmp[1]);

                    ActiveDirectoryUtils.SetADObjectPropertyValue(ou, "Url", listSipDs.ToArray());
                    ou.CommitChanges();

                    CreateSimpleUrl(runspace, tenantId);
                    transaction.RegisterNewSimpleUrl(tmp[1].ToLower(), tenantId.ToString());

                    path = AddADPrefix(GetResultObjectDN(organizationId, runspace));
                    DirectoryEntry user = ActiveDirectoryUtils.GetADObject(path);

                    if (tmp.Length > 0)
                    {
                        string Url = SimpleUrlRoot + tmp[1];
                        ActiveDirectoryUtils.SetADObjectPropertyValue(user, "msRTCSIP-BaseSimpleUrl", Url.ToLower());
                    }

                    user.CommitChanges();
                }

                command = new Command("Set-CsUser");
                command.Parameters.Add("Identity", userUpn);

                if (!string.IsNullOrEmpty(lyncUser.SipAddress))
                {
                    command.Parameters.Add("SipAddress", "SIP:" + lyncUser.SipAddress);
                }

                if (!string.IsNullOrEmpty(lyncUser.LineUri))
                {
                    command.Parameters.Add("LineUri", "TEL:+" + lyncUser.LineUri);
                }
                else
                {
                    command.Parameters.Add("LineUri", null);
                }

                ExecuteShellCommand(runspace, command, false);

                if (!String.IsNullOrEmpty(lyncUser.PIN))
                {
                    command = new Command("Set-CsClientPin");
                    command.Parameters.Add("Identity", userUpn);
                    command.Parameters.Add("Pin", lyncUser.PIN);
                    ExecuteShellCommand(runspace, command, false);
                }

                command = new Command("Update-CsAddressBook");
                ExecuteShellCommand(runspace, command, false);

                command = new Command("Update-CsUserDatabase");
                ExecuteShellCommand(runspace, command, false);
            }
            catch (Exception ex)
            {
                ret = false;
                HostedSolutionLog.LogError("SetLyncUserGeneralSettingsInternal", ex);
                RollbackTransaction(transaction);
            }
            finally
            {
                CloseRunspace(runspace);
            }

            HostedSolutionLog.LogEnd("SetLyncUserGeneralSettingsInternal");

            return(ret);
        }
Example #12
0
        /// <summary> Deletes organization.</summary>
        /// <param name="organizationId"> The organization identifier.</param>
        /// <param name="sipDomain"> The sip domain.</param>
        /// <returns> The result.</returns>
        internal override bool DeleteOrganizationInternal(string organizationId, string sipDomain)
        {
            HostedSolutionLog.LogStart("DeleteOrganizationInternal");
            HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId);
            HostedSolutionLog.DebugInfo("sipDomain: {0}", sipDomain);
            Runspace runspace = null;

            try
            {
                runspace = OpenRunspace();
                string         path  = AddADPrefix(GetOrganizationPath(organizationId));
                DirectoryEntry ou    = ActiveDirectoryUtils.GetADObject(path);
                string[]       sipDs = ActiveDirectoryUtils.GetADObjectPropertyMultiValue(ou, "Url");

                foreach (string sipD in sipDs)
                {
                    DeleteSipDomain(runspace, sipD);
                }

                try
                {
                    DeleteConferencingPolicy(runspace, organizationId);
                }
                catch (Exception)
                {
                }

                try
                {
                    DeleteExternalAccessPolicy(runspace, organizationId);
                }
                catch (Exception)
                {
                }

                try
                {
                    DeleteMobilityPolicy(runspace, organizationId + " EnableOutSideVoice");
                }
                catch (Exception)
                {
                }

                try
                {
                    DeleteMobilityPolicy(runspace, organizationId + " DisableOutSideVoice");
                }
                catch (Exception)
                {
                }

                var command = new Command("Invoke-CsManagementStoreReplication");
                ExecuteShellCommand(runspace, command, false);
            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError("DeleteOrganizationInternal", ex);
                throw;
            }
            finally
            {
                CloseRunspace(runspace);
            }

            HostedSolutionLog.LogEnd("DeleteOrganizationInternal");

            return(true);
        }
Example #13
0
        internal void SetUserGeneralSettingsInternal(string organizationId, string accountName, string displayName, string password,
                                                     bool hideFromAddressBook, bool disabled, bool locked, string firstName, string initials, string lastName,
                                                     string address, string city, string state, string zip, string country, string jobTitle,
                                                     string company, string department, string office, string managerAccountName,
                                                     string businessPhone, string fax, string homePhone, string mobilePhone, string pager,
                                                     string webPage, string notes, string externalEmail)
        {
            string         path  = GetUserPath(organizationId, accountName);
            DirectoryEntry entry = ActiveDirectoryUtils.GetADObject(path);


            ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.FirstName, firstName);
            ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.LastName, lastName);
            ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.DisplayName, displayName);

            ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.Initials, initials);
            ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.JobTitle, jobTitle);
            ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.Company, company);
            ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.Department, department);
            ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.Office, office);
            ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.BusinessPhone, businessPhone);
            ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.Fax, fax);
            ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.HomePhone, homePhone);
            ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.MobilePhone, mobilePhone);
            ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.Pager, pager);
            ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.WebPage, webPage);
            ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.Address, address);
            ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.City, city);
            ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.State, state);
            ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.Zip, zip);
            ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.Country, country);
            ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.Notes, notes);
            ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.ExternalEmail, externalEmail);
            ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.CustomAttribute2, (disabled ? "disabled" : null));


            string manager = string.Empty;

            if (!string.IsNullOrEmpty(managerAccountName))
            {
                string managerPath = GetUserPath(organizationId, managerAccountName);
                manager = ActiveDirectoryUtils.AdObjectExists(managerPath) ? managerPath : string.Empty;
            }

            ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.Manager, ActiveDirectoryUtils.RemoveADPrefix(manager));

            entry.InvokeSet(ADAttributes.AccountDisabled, disabled);
            if (!string.IsNullOrEmpty(password))
            {
                entry.Invoke(ADAttributes.SetPassword, password);
            }

            if (!locked)
            {
                bool isLoked = (bool)entry.InvokeGet(ADAttributes.AccountLocked);
                if (isLoked)
                {
                    entry.InvokeSet(ADAttributes.AccountLocked, locked);
                }
            }


            entry.CommitChanges();
        }
Example #14
0
        internal int CreateUserInternal(string organizationId, string loginName, string displayName, string upn, string password, bool enabled)
        {
            HostedSolutionLog.LogStart("CreateUserInternal");
            HostedSolutionLog.DebugInfo("organizationId : {0}", organizationId);
            HostedSolutionLog.DebugInfo("loginName : {0}", loginName);
            HostedSolutionLog.DebugInfo("displayName : {0}", displayName);

            if (string.IsNullOrEmpty(organizationId))
            {
                throw new ArgumentNullException("organizationId");
            }

            if (string.IsNullOrEmpty(loginName))
            {
                throw new ArgumentNullException("loginName");
            }

            if (string.IsNullOrEmpty(password))
            {
                throw new ArgumentNullException("password");
            }

            bool   userCreated = false;
            string userPath    = null;

            try
            {
                string path = GetOrganizationPath(organizationId);
                userPath = GetUserPath(organizationId, loginName);
                if (!ActiveDirectoryUtils.AdObjectExists(userPath))
                {
                    userPath = ActiveDirectoryUtils.CreateUser(path, loginName, displayName, password, enabled);
                    DirectoryEntry entry = new DirectoryEntry(userPath);
                    ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.UserPrincipalName, upn);
                    entry.CommitChanges();
                    userCreated = true;
                }
                else
                {
                    return(Errors.AD_OBJECT_ALREADY_EXISTS);
                }

                string groupPath = GetGroupPath(organizationId);


                ActiveDirectoryUtils.AddUserToGroup(userPath, groupPath);
            }
            catch (Exception e)
            {
                HostedSolutionLog.LogError(e);
                try
                {
                    if (userCreated)
                    {
                        ActiveDirectoryUtils.DeleteADObject(userPath);
                    }
                }
                catch (Exception ex)
                {
                    HostedSolutionLog.LogError(ex);
                }
            }

            HostedSolutionLog.LogEnd("CreateUserInternal");
            return(Errors.OK);
        }
Example #15
0
        internal Organization CreateOrganizationInternal(string organizationId)
        {
            HostedSolutionLog.LogStart("CreateOrganizationInternal");
            HostedSolutionLog.DebugInfo("OrganizationId : {0}", organizationId);

            if (string.IsNullOrEmpty(organizationId))
            {
                throw new ArgumentNullException("organizationId");
            }

            bool ouCreated    = false;
            bool groupCreated = false;

            Organization org;

            try
            {
                string parentPath = GetRootOU();
                string orgPath    = GetOrganizationPath(organizationId);

                //Create OU
                ActiveDirectoryUtils.CreateOrganizationalUnit(organizationId, parentPath);
                ouCreated = true;

                //Create security group
                ActiveDirectoryUtils.CreateGroup(orgPath, organizationId);
                groupCreated = true;


                org = new Organization();
                org.OrganizationId    = organizationId;
                org.DistinguishedName = ActiveDirectoryUtils.RemoveADPrefix(orgPath);
                org.SecurityGroup     = ActiveDirectoryUtils.RemoveADPrefix(GetGroupPath(organizationId));
            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError(ex);
                try
                {
                    if (groupCreated)
                    {
                        string groupPath = GetGroupPath(organizationId);
                        ActiveDirectoryUtils.DeleteADObject(groupPath);
                    }
                }
                catch (Exception e)
                {
                    HostedSolutionLog.LogError(e);
                }

                try
                {
                    if (ouCreated)
                    {
                        string orgPath = GetOrganizationPath(organizationId);
                        ActiveDirectoryUtils.DeleteADObject(orgPath);
                    }
                }
                catch (Exception e)
                {
                    HostedSolutionLog.LogError(e);
                }

                throw;
            }

            HostedSolutionLog.LogEnd("CreateOrganizationInternal");

            return(org);
        }