private void ExtractRbacDataFromRunspace(object sender, EventArgs e) { ADObjectId adobjectId = null; OrganizationId organizationId = null; ExchangePropertyContainer.InitializeExchangePropertyContainerIfNeeded(this.context.SessionState, out adobjectId, out organizationId); ExchangeRunspaceConfiguration exchangeRunspaceConfiguration = null; if (this.context.SessionState != null) { exchangeRunspaceConfiguration = ExchangePropertyContainer.GetExchangeRunspaceConfiguration(this.context.SessionState); } OrganizationId organizationId2; string executingUserIdentityName; SmtpAddress executingWindowsLiveId; if (exchangeRunspaceConfiguration == null) { if (this.context.SessionState != null) { organizationId = (organizationId ?? ExchangePropertyContainer.GetExecutingUserOrganizationId(this.context.SessionState)); adobjectId = (adobjectId ?? ExchangePropertyContainer.GetExecutingUserId(this.context.SessionState)); } organizationId2 = organizationId; executingUserIdentityName = ((adobjectId == null) ? string.Empty : adobjectId.Name); } else { exchangeRunspaceConfiguration.TryGetExecutingUserId(out adobjectId); executingUserIdentityName = exchangeRunspaceConfiguration.IdentityName; exchangeRunspaceConfiguration.TryGetExecutingWindowsLiveId(out executingWindowsLiveId); organizationId = (exchangeRunspaceConfiguration.PartnerMode ? OrganizationId.ForestWideOrgId : exchangeRunspaceConfiguration.OrganizationId); organizationId2 = exchangeRunspaceConfiguration.OrganizationId; SecurityIdentifier value; exchangeRunspaceConfiguration.TryGetExecutingUserSid(out value); CmdletLogger.SafeSetLogger(this.context.UniqueId, RpsCmdletMetadata.ExecutingUserSid, value); } if (this.context.InvocationInfo != null && this.context.InvocationInfo.IsVerboseOn && !TaskLogger.IsSetupLogging) { string executingUserId = (adobjectId != null) ? adobjectId.ToCanonicalName() : string.Empty; string executingUserOrganizationId = (organizationId != null) ? organizationId.ToString() : string.Empty; string currentOrganizationId = (organizationId2 != null) ? organizationId2.ToString() : string.Empty; if (this.context.CommandShell != null) { this.context.CommandShell.WriteVerbose(Strings.VerboseExecutingUserContext(executingUserId, executingUserOrganizationId, currentOrganizationId, (exchangeRunspaceConfiguration == null) ? Strings.DisabledString : Strings.EnabledString)); } } this.context.ExchangeRunspaceConfig = exchangeRunspaceConfiguration; this.context.UserInfo = new TaskUserInfo(organizationId, organizationId2, adobjectId, executingUserIdentityName, executingWindowsLiveId); }
public static SharepointValidator Create(IConfigurationSession configurationSession, ExchangeRunspaceConfiguration exchangeRunspaceConfig, Task.TaskErrorLoggingDelegate writeErrorDelegate, Action <LocalizedString> writeWarningDelegate, Func <LocalizedString, bool> shouldContinueDelegate, string logTag, SourceValidator.Clients client, int existingSitesCount, ExecutionLog logger) { bool boolFromConfig = Utils.GetBoolFromConfig("ValidateSharepointUsingSearch", true); ADObjectId executingUserId; if (boolFromConfig) { if (exchangeRunspaceConfig == null || !exchangeRunspaceConfig.TryGetExecutingUserId(out executingUserId)) { throw new SpValidatorException(Strings.FailedToGetExecutingUser); } } else { executingUserId = null; } return(SharepointValidator.Create(configurationSession, executingUserId, writeErrorDelegate, writeWarningDelegate, shouldContinueDelegate, logTag, client, existingSitesCount, logger)); }
private static IPowerShellBudget AcquirePowerShellBudget(ExchangeRunspaceConfiguration configuration) { IPowerShellBudget powerShellBudget; SecurityIdentifier callerSid; if (configuration.DelegatedPrincipal != null) { powerShellBudget = PowerShellBudget.Acquire(new DelegatedPrincipalBudgetKey(configuration.DelegatedPrincipal, BudgetType.PowerShell)); } else if (!configuration.TryGetExecutingUserSid(out callerSid)) { ADObjectId adobjectId; if (!configuration.TryGetExecutingUserId(out adobjectId)) { throw new ExecutingUserPropertyNotFoundException("ExecutingUserSid"); } powerShellBudget = PowerShellBudget.AcquireFallback(adobjectId.ObjectGuid.ToString(), BudgetType.PowerShell); } else { ADObjectId rootOrgId; if (configuration.ExecutingUserOrganizationId == null || configuration.ExecutingUserOrganizationId.Equals(OrganizationId.ForestWideOrgId)) { rootOrgId = ADSystemConfigurationSession.GetRootOrgContainerIdForLocalForest(); } else { rootOrgId = ADSystemConfigurationSession.GetRootOrgContainerId(configuration.ExecutingUserOrganizationId.PartitionId.ForestFQDN, null, null); } powerShellBudget = PowerShellBudget.Acquire(callerSid, BudgetType.PowerShell, ADSessionSettings.FromOrganizationIdWithoutRbacScopes(rootOrgId, configuration.ExecutingUserOrganizationId, configuration.ExecutingUserOrganizationId, true)); } PowerShellThrottlingPolicyUpdater.RevertExpiredThrottlingPolicyIfNeeded(powerShellBudget); if (configuration.IsPowerShellWebService) { IPowerShellBudget result = new PswsBudgetWrapper(((BudgetWrapper <PowerShellBudget>)powerShellBudget).GetInnerBudget()); if (powerShellBudget != null) { powerShellBudget.Dispose(); } return(result); } return(powerShellBudget); }