public static LicenseIdentity GetLicenseIdentity(RmsClientManagerContext context, string recipientAddress) { ArgumentValidator.ThrowIfNull("context", context); ArgumentValidator.ThrowIfNullOrEmpty("recipientAddress", recipientAddress); ADRawEntry adrawEntry; try { adrawEntry = context.ResolveRecipient(recipientAddress); } catch (ADTransientException innerException) { throw new ExchangeConfigurationException(ServerStrings.FailedToReadUserConfig(recipientAddress), innerException); } catch (ADOperationException innerException2) { throw new RightsManagementException(RightsManagementFailureCode.ADUserNotFound, ServerStrings.FailedToReadUserConfig(recipientAddress), innerException2); } if (adrawEntry == null) { throw new RightsManagementException(RightsManagementFailureCode.ADUserNotFound, ServerStrings.FailedToReadUserConfig(recipientAddress)); } List <string> federatedEmailAddresses = RmsClientManagerUtils.GetFederatedEmailAddresses(context.OrgId, (ProxyAddressCollection)adrawEntry[ADRecipientSchema.EmailAddresses]); if (federatedEmailAddresses.Count == 0) { RmsClientManager.TraceFail(null, context.SystemProbeId, "GetLicenseIdentity: User {0} doesn't have any SMTP proxy address from a domain that is federated.", new object[] { recipientAddress }); throw new RightsManagementException(RightsManagementFailureCode.ADUserNotFederated, DirectoryStrings.UserHasNoSmtpProxyAddressWithFederatedDomain); } return(new LicenseIdentity(federatedEmailAddresses[0], federatedEmailAddresses.ToArray())); }
private static void AcquireServerLicensingMexCallback(ICancelableAsyncResult asyncResult) { RmsServerInfoManager.Tracer.TraceDebug(0L, "AcquireServerLicensingMexCallback invoked"); ArgumentValidator.ThrowIfNull("asyncResult", asyncResult); ArgumentValidator.ThrowIfNull("asyncResult.AsyncState", asyncResult.AsyncState); AcquireServerInfoAsyncResult acquireServerInfoAsyncResult = asyncResult.AsyncState as AcquireServerInfoAsyncResult; if (acquireServerInfoAsyncResult == null) { throw new InvalidOperationException("asyncResult.AsyncState has to be type of AcquireServerInfoAsyncResult."); } acquireServerInfoAsyncResult.AddBreadCrumb(Constants.State.AcquireServerLicensingMexCallback); Exception ex = null; try { DownloadResult downloadResult = acquireServerInfoAsyncResult.HttpClient.EndDownload(asyncResult); acquireServerInfoAsyncResult.LatencyTracker.EndTrackRmsLatency(RmsOperationType.AcquireServerLicensingMexData); if (downloadResult.IsSucceeded) { Uri targetUriFromResponse = RmsClientManagerUtils.GetTargetUriFromResponse(downloadResult.ResponseStream); if (targetUriFromResponse == null) { ex = new RightsManagementException(RightsManagementFailureCode.FailedToExtractTargetUriFromMex, ServerStrings.FailedToFindTargetUriFromMExData(acquireServerInfoAsyncResult.ServerLicensingMExUri), acquireServerInfoAsyncResult.LicenseUri.ToString()); } else { acquireServerInfoAsyncResult.ServerInfo.ServerLicensingWSTargetUri = TokenTarget.Fix(targetUriFromResponse); RmsServerInfoManager.serverInfoMap.Add(acquireServerInfoAsyncResult.ServerInfo); } } else { RmsClientManager.TraceFail(null, acquireServerInfoAsyncResult.Context.SystemProbeId, "Failed to download data from server licensing MEx {0}. Exception is {1}", new object[] { acquireServerInfoAsyncResult.ServerLicensingMExUri, downloadResult.Exception }); ex = new RightsManagementException(RightsManagementFailureCode.FailedToDownloadMexData, ServerStrings.FailedToDownloadServerLicensingMExData(downloadResult.ResponseUri), downloadResult.Exception, acquireServerInfoAsyncResult.LicenseUri.ToString()); ((RightsManagementException)ex).IsPermanent = !downloadResult.IsRetryable; } } finally { acquireServerInfoAsyncResult.Release(); } RmsServerInfoManager.Tracer.TraceDebug(0L, "AcquireServiceLocationCallback: Invoking find service location callbacks"); RmsServerInfoManager.outstandingFindServiceLocationCalls.InvokeCallbacks(acquireServerInfoAsyncResult.LicenseUri, ex); }
private static ADOperationResult TryGetOrganizationIdFromExternalDirectoryOrgId(Guid externalDirectoryOrgId, out OrganizationId organizationId) { RmsClientManagerUtils.< > c__DisplayClass10 CS$ < > 8__locals1 = new RmsClientManagerUtils.< > c__DisplayClass10(); CS$ < > 8__locals1.externalDirectoryOrgId = externalDirectoryOrgId; if (CS$ < > 8__locals1.externalDirectoryOrgId == Guid.Empty) { throw new ArgumentException("Guid.Empty is not a valid external directory org id", "externalDirectoryOrgId"); } RmsClientManagerUtils.< > c__DisplayClass10 CS$ < > 8__locals2 = CS$ < > 8__locals1; OrganizationId localOrgId; organizationId = (localOrgId = null); CS$ < > 8__locals2.localOrgId = localOrgId; try { ADNotificationAdapter.RunADOperation(delegate() { ITenantConfigurationSession tenantConfigurationSession = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ConsistencyMode.IgnoreInvalid, CS$ < > 8__locals1.externalDirectoryOrgId, 1406, "TryGetOrganizationIdFromExternalDirectoryOrgId", "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\rightsmanagement\\RmsClientManagerUtils.cs"); if (tenantConfigurationSession == null) { return; } Organization orgContainer = tenantConfigurationSession.GetOrgContainer(); if (orgContainer != null) { CS$ < > 8__locals1.localOrgId = orgContainer.OrganizationId; return; } throw new DataSourceOperationException(ServerStrings.FailedToGetOrgContainer(CS$ < > 8__locals1.externalDirectoryOrgId)); }); } catch (TransientException ex) { RmsClientManager.TraceFail(0, Guid.Empty, "Cannot resolve the External OrgID {0} - exception is {1}", new object[] { CS$ < > 8__locals1.externalDirectoryOrgId, ex });
public static IAsyncResult BeginAcquireServerInfo(RmsClientManagerContext context, Uri licenseUri, object state, AsyncCallback callback) { RmsServerInfoManager.ThrowIfNotInitialized(); ArgumentValidator.ThrowIfNull("licenseUri", licenseUri); AcquireServerInfoAsyncResult acquireServerInfoAsyncResult = new AcquireServerInfoAsyncResult(context, licenseUri, state, callback); acquireServerInfoAsyncResult.AddBreadCrumb(Constants.State.BeginAcquireServerInfo); ExternalRMSServerInfo externalRMSServerInfo; if (RmsServerInfoManager.serverInfoMap.TryGet(licenseUri, out externalRMSServerInfo)) { acquireServerInfoAsyncResult.InvokeCallback(); return(acquireServerInfoAsyncResult); } RmsClientManagerLog.LogUriEvent(RmsClientManagerLog.RmsClientManagerFeature.ServerInfo, RmsClientManagerLog.RmsClientManagerEvent.Acquire, context, licenseUri); WebProxy localServerProxy; try { localServerProxy = RmsClientManagerUtils.GetLocalServerProxy(true); } catch (ExchangeConfigurationException value) { acquireServerInfoAsyncResult.InvokeCallback(value); return(acquireServerInfoAsyncResult); } bool flag = RmsServerInfoManager.outstandingFindServiceLocationCalls.EnqueueResult(licenseUri, acquireServerInfoAsyncResult); if (flag) { acquireServerInfoAsyncResult.ServerWSManager = new ServerWSManager(licenseUri, RmsServerInfoManager.perfCounters, acquireServerInfoAsyncResult.LatencyTracker, localServerProxy, RmsClientManager.AppSettings.RmsSoapQueriesTimeout); ServiceType[] serviceTypes = new ServiceType[] { ServiceType.CertificationWSService, ServiceType.ServerLicensingWSService, ServiceType.CertificationMexService, ServiceType.ServerLicensingMexService }; RmsClientManager.TracePass(null, context.SystemProbeId, "Querying the RMS server {0} for server info", new object[] { licenseUri }); acquireServerInfoAsyncResult.AddBreadCrumb(Constants.State.BeginFindServiceLocationsFirstRequest); try { acquireServerInfoAsyncResult.ServerWSManager.BeginFindServiceLocations(serviceTypes, RmsClientManagerUtils.WrapCallbackWithUnhandledExceptionHandlerAndUpdatePoisonContext(new AsyncCallback(RmsServerInfoManager.AcquireServiceLocationCallback)), acquireServerInfoAsyncResult); return(acquireServerInfoAsyncResult); } catch (InvalidOperationException ex) { RmsClientManager.TraceFail(null, context.SystemProbeId, "Hit an exception during BeginFindServiceLocations {0}", new object[] { ex }); acquireServerInfoAsyncResult.InvokeCallback(new RightsManagementException(RightsManagementFailureCode.FindServiceLocationFailed, ServerStrings.FailedToFindServerInfo(licenseUri), ex)); return(acquireServerInfoAsyncResult); } } RmsClientManager.TracePass(null, context.SystemProbeId, "A request for server info for the license uri {0} is already pending. Enqueuing the result", new object[] { licenseUri }); acquireServerInfoAsyncResult.AddBreadCrumb(Constants.State.BeginFindServiceLocationsPendingRequest); return(acquireServerInfoAsyncResult); }
private static void AcquireCertificationMexCallback(ICancelableAsyncResult asyncResult) { RmsServerInfoManager.Tracer.TraceDebug(0L, "AcquireCertificationMexCallback invoked"); ArgumentValidator.ThrowIfNull("asyncResult", asyncResult); ArgumentValidator.ThrowIfNull("asyncResult.AsyncState", asyncResult.AsyncState); AcquireServerInfoAsyncResult acquireServerInfoAsyncResult = asyncResult.AsyncState as AcquireServerInfoAsyncResult; if (acquireServerInfoAsyncResult == null) { throw new InvalidOperationException("asyncResult.AsyncState has to be type of AcquireServerInfoAsyncResult."); } acquireServerInfoAsyncResult.AddBreadCrumb(Constants.State.AcquireCertificationMexCallback); Exception ex = null; try { DownloadResult downloadResult = acquireServerInfoAsyncResult.HttpClient.EndDownload(asyncResult); acquireServerInfoAsyncResult.LatencyTracker.EndTrackRmsLatency(RmsOperationType.AcquireCertificationMexData); if (downloadResult.IsSucceeded) { Uri targetUriFromResponse = RmsClientManagerUtils.GetTargetUriFromResponse(downloadResult.ResponseStream); if (targetUriFromResponse == null) { ex = new RightsManagementException(RightsManagementFailureCode.FailedToExtractTargetUriFromMex, ServerStrings.FailedToFindTargetUriFromMExData(acquireServerInfoAsyncResult.CertificationMExUri), acquireServerInfoAsyncResult.LicenseUri.ToString()); } else { acquireServerInfoAsyncResult.ServerInfo.CertificationWSTargetUri = TokenTarget.Fix(targetUriFromResponse); acquireServerInfoAsyncResult.AddBreadCrumb(Constants.State.BeginDownloadServerLicensingMexData); WebProxy localServerProxy; try { localServerProxy = RmsClientManagerUtils.GetLocalServerProxy(true); } catch (ExchangeConfigurationException ex2) { ex = ex2; return; } HttpSessionConfig httpSessionConfig = new HttpSessionConfig(); if (localServerProxy != null) { httpSessionConfig.Proxy = localServerProxy; } acquireServerInfoAsyncResult.LatencyTracker.BeginTrackRmsLatency(RmsOperationType.AcquireServerLicensingMexData); acquireServerInfoAsyncResult.HttpClient.BeginDownload(acquireServerInfoAsyncResult.ServerLicensingMExUri, httpSessionConfig, RmsClientManagerUtils.WrapCancellableCallbackWithUnhandledExceptionHandlerAndUpdatePoisonContext(new CancelableAsyncCallback(RmsServerInfoManager.AcquireServerLicensingMexCallback)), acquireServerInfoAsyncResult); } } else { RmsClientManager.TraceFail(null, acquireServerInfoAsyncResult.Context.SystemProbeId, "Failed to download data from certification MEx {0}. Exception is {1}", new object[] { acquireServerInfoAsyncResult.CertificationMExUri, downloadResult.Exception }); ex = new RightsManagementException(RightsManagementFailureCode.FailedToDownloadMexData, ServerStrings.FailedToDownloadCertificationMExData(downloadResult.ResponseUri), downloadResult.Exception, acquireServerInfoAsyncResult.LicenseUri.ToString()); ((RightsManagementException)ex).IsPermanent = !downloadResult.IsRetryable; } } finally { if (ex != null) { acquireServerInfoAsyncResult.Release(); RmsServerInfoManager.Tracer.TraceDebug(0L, "AcquireServiceLocationCallback: Invoking find service location callbacks"); RmsServerInfoManager.outstandingFindServiceLocationCalls.InvokeCallbacks(acquireServerInfoAsyncResult.LicenseUri, ex); } } }
private static void AcquireServiceLocationCallback(IAsyncResult asyncResult) { RmsServerInfoManager.Tracer.TraceDebug(0L, "AcquireServiceLocationCallback invoked"); ArgumentValidator.ThrowIfNull("asyncResult", asyncResult); ArgumentValidator.ThrowIfNull("asyncResult.AsyncState", asyncResult.AsyncState); AcquireServerInfoAsyncResult acquireServerInfoAsyncResult = asyncResult.AsyncState as AcquireServerInfoAsyncResult; if (acquireServerInfoAsyncResult == null) { throw new InvalidOperationException("asyncResult.AsyncState has to be type of AcquireServerInfoAsyncResult."); } acquireServerInfoAsyncResult.AddBreadCrumb(Constants.State.AcquireServiceLocationCallback); Exception ex = null; try { acquireServerInfoAsyncResult.ServiceLocationResponses = acquireServerInfoAsyncResult.ServerWSManager.EndFindServiceLocations(asyncResult); LocalizedString value; if (!RmsServerInfoManager.ValidateResponsesAndUpdateServerInfo(acquireServerInfoAsyncResult, out value)) { ex = new RightsManagementException(RightsManagementFailureCode.FindServiceLocationFailed, ServerStrings.ValidationForServiceLocationResponseFailed(acquireServerInfoAsyncResult.LicenseUri, value)); } else { HttpSessionConfig httpSessionConfig = new HttpSessionConfig(); WebProxy localServerProxy = RmsClientManagerUtils.GetLocalServerProxy(true); if (localServerProxy != null) { httpSessionConfig.Proxy = localServerProxy; } acquireServerInfoAsyncResult.HttpClient = new HttpClient(); acquireServerInfoAsyncResult.AddBreadCrumb(Constants.State.BeginDownloadCertificationMexData); acquireServerInfoAsyncResult.LatencyTracker.BeginTrackRmsLatency(RmsOperationType.AcquireCertificationMexData); acquireServerInfoAsyncResult.HttpClient.BeginDownload(acquireServerInfoAsyncResult.CertificationMExUri, httpSessionConfig, RmsClientManagerUtils.WrapCancellableCallbackWithUnhandledExceptionHandlerAndUpdatePoisonContext(new CancelableAsyncCallback(RmsServerInfoManager.AcquireCertificationMexCallback)), acquireServerInfoAsyncResult); } } catch (RightsManagementException ex2) { RmsClientManager.TraceFail(null, acquireServerInfoAsyncResult.Context.SystemProbeId, "Hit an exception during AcquireServiceLocationCallback {0}", new object[] { ex2 }); ex = ex2; } catch (ExchangeConfigurationException ex3) { RmsClientManager.TraceFail(null, acquireServerInfoAsyncResult.Context.SystemProbeId, "Hit an exception during AcquireServiceLocationCallback {0}", new object[] { ex3 }); ex = ex3; } finally { if (ex != null) { acquireServerInfoAsyncResult.Release(); RmsServerInfoManager.Tracer.TraceError(0L, "AcquireServiceLocationCallback: Invoking find service location callbacks"); RmsServerInfoManager.outstandingFindServiceLocationCalls.InvokeCallbacks(acquireServerInfoAsyncResult.LicenseUri, ex); } } }