internal static ADOrganizationalUnit GetOUFromOrganizationId(OrganizationIdParameter organization, IConfigurationSession session, Task.TaskErrorLoggingDelegate errorLogger, bool reportError) { bool useConfigNC = session.UseConfigNC; ADOrganizationalUnit result = null; try { session.UseConfigNC = false; IEnumerable <ADOrganizationalUnit> objects = organization.GetObjects <ADOrganizationalUnit>(null, session); using (IEnumerator <ADOrganizationalUnit> enumerator = objects.GetEnumerator()) { if (enumerator.MoveNext()) { result = enumerator.Current; if (reportError && enumerator.MoveNext()) { errorLogger(new ManagementObjectAmbiguousException(Strings.ErrorOrganizationNotUnique(organization.ToString())), ErrorCategory.InvalidArgument, null); } } else if (reportError) { errorLogger(new ManagementObjectNotFoundException(Strings.ErrorOrganizationNotFound(organization.ToString())), ErrorCategory.InvalidArgument, null); } } } finally { session.UseConfigNC = useConfigNC; } return(result); }
internal static OrganizationId ResolveOrganization(OrganizationIdParameter organization, OrganizationId currentOrganizationId, OrganizationId executingUserOrganizationId) { if (organization == null) { return(null); } ADObjectId rootOrgContainerIdForLocalForest = ADSystemConfigurationSession.GetRootOrgContainerIdForLocalForest(); ADSessionSettings sessionSettings = ADSessionSettings.FromOrganizationIdWithoutRbacScopes(rootOrgContainerIdForLocalForest, currentOrganizationId, executingUserOrganizationId, false); IConfigurationSession tenantOrTopologyConfigurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(null, true, ConsistencyMode.PartiallyConsistent, null, sessionSettings, ConfigScopes.TenantSubTree, 48, "ResolveOrganization", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\FfoReporting\\Common\\ADHelper.cs"); tenantOrTopologyConfigurationSession.UseConfigNC = false; ADOrganizationalUnit adorganizationalUnit = null; LocalizedString? localizedString = null; IEnumerable <ADOrganizationalUnit> objects = organization.GetObjects <ADOrganizationalUnit>(null, tenantOrTopologyConfigurationSession, null, out localizedString); using (IEnumerator <ADOrganizationalUnit> enumerator = objects.GetEnumerator()) { if (!enumerator.MoveNext()) { throw new ManagementObjectNotFoundException(Strings.ErrorOrganizationNotFound(organization.ToString())); } adorganizationalUnit = enumerator.Current; if (enumerator.MoveNext()) { throw new ManagementObjectAmbiguousException(Strings.ErrorOrganizationNotUnique(organization.ToString())); } } return(adorganizationalUnit.OrganizationId); }
internal static OrganizationId ResolveOrganizationId(OrganizationIdParameter tenantId) { if (tenantId == null) { throw new ArgumentNullException("tenantId"); } IConfigurationSession tenantOrTopologyConfigurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(true, ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromRootOrgScopeSet(), 146, "ResolveOrganizationId", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\CompliancePolicy\\DarTasks\\GetDarTask.cs"); tenantOrTopologyConfigurationSession.UseConfigNC = false; ADOrganizationalUnit adorganizationalUnit = tenantId.GetObjects <ADOrganizationalUnit>(null, tenantOrTopologyConfigurationSession).FirstOrDefault <ADOrganizationalUnit>(); if (adorganizationalUnit == null) { throw new ArgumentException(Strings.ErrorOrganizationNotFound(tenantId.ToString())); } return(adorganizationalUnit.OrganizationId); }