public IRMConfigurationValidator(RmsClientManagerContext context, SmtpAddress sender, SmtpAddress[] recipients) { if (context == null) { throw new ArgumentNullException("context"); } this.organizationId = context.OrgId; this.senderAddress = sender.ToString(); List <string> list = new List <string>(); if (recipients != null) { foreach (SmtpAddress smtpAddress in recipients) { list.Add(smtpAddress.ToString()); } } if (list.Count == 0) { this.recipientsAddress = new string[] { this.senderAddress }; } else { this.recipientsAddress = list.ToArray(); } this.context = context; }
public static ActiveCryptoModeRpcResult[] GetTenantActiveCryptoMode(RmsClientManagerContext clientContext) { if (clientContext == null) { throw new ArgumentNullException("clientContext"); } RpcClientWrapper.InitializeIfNeeded(); string randomRpcTargetServerName = RpcClientWrapper.instance.GetRandomRpcTargetServerName(); byte[] data = null; ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Entry, clientContext, string.Format("OfflineRmsRpcClient.GetTenantActiveCryptoMode against RPC server {0}", randomRpcTargetServerName)); try { using (OfflineRmsRpcClient offlineRmsRpcClient = new OfflineRmsRpcClient(randomRpcTargetServerName)) { data = offlineRmsRpcClient.GetTenantActiveCryptoMode(1, new GetTenantActiveCryptoModeRpcParameters(clientContext).Serialize()); } } catch (RpcException ex) { ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Error, clientContext, string.Format("OfflineRmsRpcClient.GetTenantActiveCryptoMode against RPC server {0} failed with RPC Exception {1}", randomRpcTargetServerName, ServerManagerLog.GetExceptionLogString(ex, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException))); throw new RightsManagementServerException(ServerStrings.RpcClientException("GetTenantActiveCryptoMode", randomRpcTargetServerName), ex, false); } GetTenantActiveCryptoModeRpcResults getTenantActiveCryptoModeRpcResults = new GetTenantActiveCryptoModeRpcResults(data); if (getTenantActiveCryptoModeRpcResults.OverallRpcResult.Status == OverallRpcStatus.Success) { return(getTenantActiveCryptoModeRpcResults.ActiveCryptoModeRpcResults); } string serializedString = ErrorResult.GetSerializedString(getTenantActiveCryptoModeRpcResults.OverallRpcResult.ErrorResults); ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Error, clientContext, string.Format("OfflineRmsRpcClient.GetTenantActiveCryptoMode against RPC server {0} failed with WellKnownErrorCode {1}, and with Exception {2}", randomRpcTargetServerName, getTenantActiveCryptoModeRpcResults.OverallRpcResult.WellKnownErrorCode, serializedString)); throw new RightsManagementServerException(ServerStrings.FailedToRpcAcquireUseLicenses(clientContext.OrgId.ToString(), serializedString, randomRpcTargetServerName), getTenantActiveCryptoModeRpcResults.OverallRpcResult.WellKnownErrorCode, getTenantActiveCryptoModeRpcResults.OverallRpcResult.Status == OverallRpcStatus.PermanentFailure); }
public GetTenantActiveCryptoModeRpcParameters(RmsClientManagerContext rmsClientManagerContext) : base(rmsClientManagerContext) { if (rmsClientManagerContext == null) { throw new ArgumentNullException("rmsClientManagerContext"); } }
public DirectoryServiceProvider(RmsClientManagerContext clientContext) { if (clientContext == null) { throw new ArgumentNullException("clientContext"); } this.clientContext = clientContext; }
public TrustedPublishingDomainPrivateKeyProvider(RmsClientManagerContext clientContext, Dictionary <string, PrivateKeyInformation> privateKeyInfos) { this.privateKeyInfos = privateKeyInfos; this.clientContext = clientContext; foreach (PrivateKeyInformation privateKeyInformation in this.privateKeyInfos.Values) { if (privateKeyInformation.IsSLCKey) { this.slcKey = privateKeyInformation; } } this.disposeTracker = this.GetDisposeTracker(); }
public static bool IsMemberOf(RmsClientManagerContext clientContext, string recipientAddress, string groupAddress) { ArgumentValidator.ThrowIfNull("recipientAddress", recipientAddress); ArgumentValidator.ThrowIfNullOrEmpty("groupAddress", groupAddress); if (!ServerManager.instance.isHostingInstance) { throw new InvalidOperationException("Can't call IsMemberOf directly as ServerManager is NOT allowed to host in current calling process"); } if (!SmtpAddress.IsValidSmtpAddress(recipientAddress)) { ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.DirectoryServiceProvider, ServerManagerLog.EventType.Error, clientContext, string.Format("recipientAddress {0} is invalid SMTP Address", recipientAddress)); return(false); } if (!RoutingAddress.IsValidAddress(groupAddress)) { ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.DirectoryServiceProvider, ServerManagerLog.EventType.Error, clientContext, string.Format("groupAddress {0} is invalid SMTP Address", groupAddress)); return(false); } ServerManager.InitializeIfNeeded(); bool result; if (ServerManager.CheckForSpecialRmsOnlineTenantMembershipQuery(recipientAddress, groupAddress, out result)) { return(result); } ADRawEntry adrawEntry = clientContext.ResolveRecipient(recipientAddress); if (adrawEntry == null) { ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.DirectoryServiceProvider, ServerManagerLog.EventType.Verbose, clientContext, string.Format("Failed to resolve recipientAddress {0} in Active Directory. Treat IsMemberOf for {1} against {2} as false", recipientAddress, recipientAddress, groupAddress)); return(false); } ProxyAddressCollection proxyAddressCollection = (ProxyAddressCollection)adrawEntry[ADRecipientSchema.EmailAddresses]; SmtpProxyAddress other = new SmtpProxyAddress(groupAddress, true); foreach (ProxyAddress proxyAddress in proxyAddressCollection) { if (proxyAddress.Equals(other)) { ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.DirectoryServiceProvider, ServerManagerLog.EventType.Success, clientContext, string.Format("IsMemberOf return true as proxyAddress {0} is the same is groupAddress {1}", recipientAddress, groupAddress)); return(true); } } RoutingAddress groupKey = new RoutingAddress(groupAddress); bool result2 = ServerManager.instance.isMemberOfResolver.IsMemberOf(clientContext.RecipientSession, adrawEntry.Id, groupKey); ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.DirectoryServiceProvider, ServerManagerLog.EventType.Success, clientContext, string.Format("IsMemberOf return {0} for proxyAddress {1} against groupAddress {2}", result2.ToString(CultureInfo.InvariantCulture), recipientAddress, groupAddress)); return(result2); }
public LicensingRpcParameters(RmsClientManagerContext rmsClientManagerContext) { if (rmsClientManagerContext == null) { throw new ArgumentNullException("rmsClientManagerContext"); } if (rmsClientManagerContext.OrgId == null) { throw new ArgumentNullException("rmsClientManagerContext.OrgId"); } base.SetParameterValue("OrgId", rmsClientManagerContext.OrgId); base.SetParameterValue("ContextId", rmsClientManagerContext.ContextID); base.SetParameterValue("ContextValue", rmsClientManagerContext.ContextValue); base.SetParameterValue("TransactioniId", rmsClientManagerContext.TransactionId); base.SetParameterValue("ExternalDirectoryOrgId", rmsClientManagerContext.ExternalDirectoryOrgId); }
public AcquireTenantLicensesRpcParameters(RmsClientManagerContext rmsClientManagerContext, string identity, XmlNode[] machineCertificateChain) : base(rmsClientManagerContext) { if (rmsClientManagerContext == null) { throw new ArgumentNullException("rmsClientManagerContext"); } if (string.IsNullOrEmpty(identity)) { throw new ArgumentNullException("identity"); } if (machineCertificateChain == null || machineCertificateChain.Length <= 0) { throw new ArgumentNullException("machineCertificateChain"); } base.SetParameterValue("Identity", identity); base.SetParameterValue("MachineCertificateChainStringArray", DrmClientUtils.ConvertXmlNodeArrayToStringArray(machineCertificateChain)); }
public static UseLicenseRpcResult[] AcquireUseLicenses(RmsClientManagerContext clientContext, XmlNode[] rightsAccountCertificate, XmlNode[] issuanceLicense, LicenseeIdentity[] licenseeIdentities) { if (clientContext == null) { throw new ArgumentNullException("clientContext"); } if (rightsAccountCertificate == null) { throw new ArgumentNullException("rightsAccountCertificate"); } if (issuanceLicense == null || issuanceLicense.Length < 1) { throw new ArgumentNullException("issuanceLicense"); } if (licenseeIdentities == null || licenseeIdentities.Length < 1) { throw new ArgumentNullException("licenseeIdentities"); } RpcClientWrapper.InitializeIfNeeded(); string randomRpcTargetServerName = RpcClientWrapper.instance.GetRandomRpcTargetServerName(); byte[] data = null; ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Entry, clientContext, string.Format("OfflineRmsRpcClient.AcquireUseLicenses against RPC server {0}", randomRpcTargetServerName)); try { using (OfflineRmsRpcClient offlineRmsRpcClient = new OfflineRmsRpcClient(randomRpcTargetServerName)) { data = offlineRmsRpcClient.AcquireUseLicenses(1, new AcquireUseLicensesRpcParameters(clientContext, rightsAccountCertificate, issuanceLicense, licenseeIdentities).Serialize()); } } catch (RpcException ex) { ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Error, clientContext, string.Format("OfflineRmsRpcClient.AcquireUseLicenses against RPC server {0} failed with RPC Exception {1}", randomRpcTargetServerName, ServerManagerLog.GetExceptionLogString(ex, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException))); throw new RightsManagementServerException(ServerStrings.RpcClientException("AcquireUseLicenses", randomRpcTargetServerName), ex, false); } AcquireUseLicensesRpcResults acquireUseLicensesRpcResults = new AcquireUseLicensesRpcResults(data); if (acquireUseLicensesRpcResults.OverallRpcResult.Status == OverallRpcStatus.Success) { return(acquireUseLicensesRpcResults.UseLicenseRpcResults); } string serializedString = ErrorResult.GetSerializedString(acquireUseLicensesRpcResults.OverallRpcResult.ErrorResults); ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Error, clientContext, string.Format("OfflineRmsRpcClient.AcquireUseLicenses against RPC server {0} failed with WellKnownErrorCode {1}, and with Exception {2}", randomRpcTargetServerName, acquireUseLicensesRpcResults.OverallRpcResult.WellKnownErrorCode, serializedString)); throw new RightsManagementServerException(ServerStrings.FailedToRpcAcquireUseLicenses(clientContext.OrgId.ToString(), serializedString, randomRpcTargetServerName), acquireUseLicensesRpcResults.OverallRpcResult.WellKnownErrorCode, acquireUseLicensesRpcResults.OverallRpcResult.Status == OverallRpcStatus.PermanentFailure); }
public static void AcquireTenantLicenses(RmsClientManagerContext clientContext, XmlNode[] machineCertificateChain, string identity, out XmlNode[] racXml, out XmlNode[] clcXml) { if (clientContext == null) { throw new ArgumentNullException("clientContext"); } if (machineCertificateChain == null || machineCertificateChain.Length < 1) { throw new ArgumentNullException("machineCertificateChain"); } if (string.IsNullOrEmpty(identity)) { throw new ArgumentNullException("identity"); } racXml = null; clcXml = null; RpcClientWrapper.InitializeIfNeeded(); string randomRpcTargetServerName = RpcClientWrapper.instance.GetRandomRpcTargetServerName(); byte[] data = null; ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Entry, clientContext, string.Format("OfflineRmsRpcClient.AcquireTenantLicenses against RPC server {0}", randomRpcTargetServerName)); try { using (OfflineRmsRpcClient offlineRmsRpcClient = new OfflineRmsRpcClient(randomRpcTargetServerName)) { data = offlineRmsRpcClient.AcquireTenantLicenses(1, new AcquireTenantLicensesRpcParameters(clientContext, identity, machineCertificateChain).Serialize()); } } catch (RpcException ex) { ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Error, clientContext, string.Format("OfflineRmsRpcClient.AcquireTenantLicenses against RPC server {0} failed with RPC Exception {1}", randomRpcTargetServerName, ServerManagerLog.GetExceptionLogString(ex, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException))); throw new RightsManagementServerException(ServerStrings.RpcClientException("AcquireTenantLicenses", randomRpcTargetServerName), ex, false); } AcquireTenantLicensesRpcResults acquireTenantLicensesRpcResults = new AcquireTenantLicensesRpcResults(data); if (acquireTenantLicensesRpcResults.OverallRpcResult.Status == OverallRpcStatus.Success) { racXml = acquireTenantLicensesRpcResults.RacXml; clcXml = acquireTenantLicensesRpcResults.ClcXml; return; } string serializedString = ErrorResult.GetSerializedString(acquireTenantLicensesRpcResults.OverallRpcResult.ErrorResults); ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Error, clientContext, string.Format("OfflineRmsRpcClient.AcquireTenantLicenses against RPC server {0} failed with WellKnownErrorCode {1} and with Exception {2}", randomRpcTargetServerName, acquireTenantLicensesRpcResults.OverallRpcResult.WellKnownErrorCode, serializedString)); throw new RightsManagementServerException(ServerStrings.FailedToRpcAcquireRacAndClc(clientContext.OrgId.ToString(), serializedString, randomRpcTargetServerName), acquireTenantLicensesRpcResults.OverallRpcResult.WellKnownErrorCode, acquireTenantLicensesRpcResults.OverallRpcResult.Status == OverallRpcStatus.PermanentFailure); }
public ContextProvider(RmsClientManagerContext clientContext, PerTenantRMSTrustedPublishingDomainConfiguration perTenantconfig) { if (clientContext == null) { throw new ArgumentNullException("clientContext"); } if (perTenantconfig == null) { throw new ArgumentNullException("perTenantconfig"); } if (perTenantconfig.PrivateKeys == null) { throw new ArgumentNullException("perTenantconfig.PrivateKeys"); } this.clientContext = clientContext; this.configProvider = new ConfigurationInformationProvider(perTenantconfig); this.privateKeyProvider = new TrustedPublishingDomainPrivateKeyProvider(clientContext, perTenantconfig.PrivateKeys); this.globalConfigurationProvider = new GlobalConfigurationCacheProvider(); this.directoryServiceProvider = new DirectoryServiceProvider(clientContext); }
public static int GetTenantActiveCryptoMode(RmsClientManagerContext clientContext) { ArgumentValidator.ThrowIfNull("clientContext", clientContext); ServerManager.InitializeIfNeeded(); if (ServerManager.instance.isHostingInstance) { PerTenantRMSTrustedPublishingDomainConfiguration tenantTrustedPublishingDomainConfig = ServerManager.instance.GetTenantTrustedPublishingDomainConfig(clientContext); return(tenantTrustedPublishingDomainConfig.ActiveCryptoMode); } ActiveCryptoModeRpcResult[] tenantActiveCryptoMode = RpcClientWrapper.GetTenantActiveCryptoMode(clientContext); ActiveCryptoModeResult[] array = new ActiveCryptoModeResult[tenantActiveCryptoMode.Length]; for (int i = 0; i < tenantActiveCryptoMode.Length; i++) { RightsManagementServerException e = null; if (tenantActiveCryptoMode[i].ErrorResults != null && tenantActiveCryptoMode[i].ErrorResults.Count > 0) { e = new RightsManagementServerException(tenantActiveCryptoMode[i].GetSerializedString(), tenantActiveCryptoMode[i].IsPermanentFailure); } array[i] = new ActiveCryptoModeResult(tenantActiveCryptoMode[i].ActiveCryptoMode, e); } return(array[0].ActiveCryptoMode); }
public AcquireUseLicensesRpcParameters(RmsClientManagerContext rmsClientManagerContext, XmlNode[] rightsAccountCertificate, XmlNode[] issuanceLicense, LicenseeIdentity[] licenseeIdentities) : base(rmsClientManagerContext) { if (rmsClientManagerContext == null) { throw new ArgumentNullException("rmsClientManagerContext"); } if (rightsAccountCertificate == null || rightsAccountCertificate.Length <= 0) { throw new ArgumentNullException("rightsAccountCertificate"); } if (issuanceLicense == null || issuanceLicense.Length <= 0) { throw new ArgumentNullException("issuanceLicense"); } if (licenseeIdentities == null || licenseeIdentities.Length <= 0) { throw new ArgumentNullException("licenseeIdentities"); } base.SetParameterValue("RightsAccountCertificateStringArray", DrmClientUtils.ConvertXmlNodeArrayToStringArray(rightsAccountCertificate)); base.SetParameterValue("IssuanceLicenseStringArray", DrmClientUtils.ConvertXmlNodeArrayToStringArray(issuanceLicense)); base.SetParameterValue("LicenseeIdentities", licenseeIdentities); }
public static UseLicenseResult[] AcquireUseLicenses(RmsClientManagerContext clientContext, XmlNode[] rightsAccountCertificate, XmlNode[] issuanceLicense, LicenseeIdentity[] licenseeIdentities) { ArgumentValidator.ThrowIfNull("clientContext", clientContext); ArgumentValidator.ThrowIfNull("rightsAccountCertificate", rightsAccountCertificate); ArgumentValidator.ThrowIfNull("issuanceLicense", issuanceLicense); ArgumentValidator.ThrowIfNull("licenseeIdentities", licenseeIdentities); Stopwatch watch = Stopwatch.StartNew(); ServerManager.InitializeIfNeeded(); if (ServerManager.instance.isHostingInstance) { PerTenantRMSTrustedPublishingDomainConfiguration tenantTrustedPublishingDomainConfig = ServerManager.instance.GetTenantTrustedPublishingDomainConfig(clientContext); ContextProvider contextProvider = null; try { IEndUserLicenseGenerator endUserLicenseGenerator; try { contextProvider = new ContextProvider(clientContext, tenantTrustedPublishingDomainConfig); endUserLicenseGenerator = GeneratorFactory.CreateEndUserLicenseGenerator(contextProvider); } catch (ConfigurationProviderException ex) { ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireUseLicense, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed in CreateEndUserLicenseGenerator with Exception: {0}", ServerManagerLog.GetExceptionLogString(ex, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException))); throw new RightsManagementServerException(ServerStrings.FailedToCreateLicenseGenerator(clientContext.OrgId.ToString(), "UseLicenseGenerator"), ex); } catch (LicensingException ex2) { ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireUseLicense, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed in CreateEndUserLicenseGenerator with WellKnownError {0} and Exception: {1}", ex2.ErrorCode, ServerManagerLog.GetExceptionLogString(ex2, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException))); throw new RightsManagementServerException(ServerStrings.FailedToCreateLicenseGenerator(clientContext.OrgId.ToString(), "UseLicenseGenerator"), ex2); } XrmlCertificateChain xrmlCertificateChain = new XrmlCertificateChain(DrmClientUtils.ConvertXmlNodeArrayToStringArray(issuanceLicense)); XrmlCertificateChain xrmlCertificateChain2 = new XrmlCertificateChain(DrmClientUtils.ConvertXmlNodeArrayToStringArray(rightsAccountCertificate)); ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireUseLicense, ServerManagerLog.EventType.Entry, clientContext, string.Format("AcquireLicenses for {0} licensees, they are {1}", licenseeIdentities.Length, ServerManager.GetLicenseeLogString(licenseeIdentities))); LicensingBatchResults licensingBatchResults; try { licensingBatchResults = endUserLicenseGenerator.AcquireLicenses(xrmlCertificateChain2, xrmlCertificateChain, licenseeIdentities); } catch (LicensingException ex3) { ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireUseLicense, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed useLicenseGenerator.AcquireLicenses with WellKnownErrorCode {0}, Exception: {1}", ex3.ErrorCode, ServerManagerLog.GetExceptionLogString(ex3, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException))); throw new RightsManagementServerException(ServerStrings.FailedToAcquireUseLicenses(clientContext.OrgId.ToString()), ex3); } int num = 0; UseLicenseResult[] array = new UseLicenseResult[licensingBatchResults.LicensingResults.Count]; for (int i = 0; i < licensingBatchResults.LicensingResults.Count; i++) { StringBuilder stringBuilder = null; if (licensingBatchResults.LicensingResults[i].EndUserLicense != null && licensingBatchResults.LicensingResults[i].Error == null) { stringBuilder = new StringBuilder(); stringBuilder.Append(licensingBatchResults.LicensingResults[i].EndUserLicense); string[] array2 = licensingBatchResults.ServerLicensorCertificateChain.ToStringArray(); foreach (string value in array2) { stringBuilder.Append(value); } } LicensingException error = licensingBatchResults.LicensingResults[i].Error; RightsManagementServerException ex4 = (error != null) ? new RightsManagementServerException(ServerStrings.FailedToAcquireUseLicenses(clientContext.OrgId.ToString()), error) : null; if (error != null) { num++; ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireUseLicense, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed to AcquireLicenses for Licensee {0} with WellKnownErrorCode {1}, Exception: {2}", licenseeIdentities[i], error.ErrorCode, ServerManagerLog.GetExceptionLogString(error, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException))); } if (stringBuilder != null && ex4 != null) { throw new InvalidOperationException("LicensingResult.EndUserLicense and LicensingResult.Error are both non-null"); } if (stringBuilder == null && ex4 == null) { throw new InvalidOperationException("LicensingResult.EndUserLicense and LicensingResult.Error are null"); } array[i] = new UseLicenseResult((stringBuilder != null) ? stringBuilder.ToString() : null, ex4); } ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireUseLicense, (num == 0) ? ServerManagerLog.EventType.Success : ServerManagerLog.EventType.Error, clientContext, string.Format("AcquireLicenses finishes with successs count {0} and failed count {1}", array.Length - num, num)); ServerManager.instance.rpcAcquireUseLicensePerformanceMonitor.Record(watch); return(array); } finally { if (contextProvider != null) { contextProvider.Dispose(); } } } UseLicenseRpcResult[] array4 = RpcClientWrapper.AcquireUseLicenses(clientContext, rightsAccountCertificate, issuanceLicense, licenseeIdentities); UseLicenseResult[] array5 = new UseLicenseResult[array4.Length]; for (int k = 0; k < array4.Length; k++) { RightsManagementServerException e = null; if (array4[k].ErrorResults != null && array4[k].ErrorResults.Count > 0) { e = new RightsManagementServerException(array4[k].GetSerializedString(), array4[k].IsPermanentFailure); } array5[k] = new UseLicenseResult(array4[k].EndUseLicense, e); } ServerManager.instance.acquireUseLicensePerformanceMonitor.Record(watch); return(array5); }
public static void LogEvent(ServerManagerLog.Subcomponent subcomponent, ServerManagerLog.EventType eventType, RmsClientManagerContext clientManagerContext, string data) { if (string.IsNullOrEmpty(data)) { throw new ArgumentNullException("data"); } ServerManagerLog.InitializeIfNeeded(); LogRowFormatter logRowFormatter = new LogRowFormatter(ServerManagerLog.LogSchema); logRowFormatter[1] = subcomponent; logRowFormatter[2] = eventType; if (clientManagerContext != null) { logRowFormatter[3] = clientManagerContext.OrgId.OrganizationalUnit.ToString(); logRowFormatter[6] = clientManagerContext.TransactionId.ToString(); if (clientManagerContext.ContextID != RmsClientManagerContext.ContextId.None && !string.IsNullOrEmpty(clientManagerContext.ContextStringForm)) { logRowFormatter[5] = clientManagerContext.ContextStringForm; } } logRowFormatter[4] = data; ServerManagerLog.instance.logInstance.Append(logRowFormatter, 0); }
public static void AcquireTenantLicenses(RmsClientManagerContext clientContext, XmlNode[] machineCertificateChain, string identity, out XmlNode[] racXml, out XmlNode[] clcXml) { ArgumentValidator.ThrowIfNull("clientContext", clientContext); ArgumentValidator.ThrowIfNull("machineCertificateChain", machineCertificateChain); ArgumentValidator.ThrowIfNullOrEmpty("identity", identity); racXml = null; clcXml = null; ServerManager.InitializeIfNeeded(); if (ServerManager.instance.isHostingInstance) { PerTenantRMSTrustedPublishingDomainConfiguration tenantTrustedPublishingDomainConfig = ServerManager.instance.GetTenantTrustedPublishingDomainConfig(clientContext); ContextProvider contextProvider = null; try { IRightsAccountCertificateGenerator rightsAccountCertificateGenerator; IClientLicensorCertificateGenerator clientLicensorCertificateGenerator; try { contextProvider = new ContextProvider(clientContext, tenantTrustedPublishingDomainConfig); rightsAccountCertificateGenerator = GeneratorFactory.CreateRightsAccountCertificateGenerator(contextProvider); clientLicensorCertificateGenerator = GeneratorFactory.CreateClientLicensorCertificateGenerator(contextProvider); } catch (ConfigurationProviderException ex) { ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireTenantLicenses, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed to create Generator with Exception: {0}", ServerManagerLog.GetExceptionLogString(ex, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException))); throw new RightsManagementServerException(ServerStrings.FailedToCreateLicenseGenerator(clientContext.OrgId.ToString(), "RacClc"), ex); } catch (CertificationException ex2) { ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireTenantLicenses, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed to create Generator with WellKnownErrorCode {0}, Exception: {1}", ex2.ErrorCode, ServerManagerLog.GetExceptionLogString(ex2, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException))); throw new RightsManagementServerException(ServerStrings.FailedToCreateLicenseGenerator(clientContext.OrgId.ToString(), "Rac"), ex2); } catch (PublishingException ex3) { ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireTenantLicenses, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed to create Generator with WellKnownErrorCode {0}, Exception: {1}", ex3.ErrorCode, ServerManagerLog.GetExceptionLogString(ex3, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException))); throw new RightsManagementServerException(ServerStrings.FailedToCreateLicenseGenerator(clientContext.OrgId.ToString(), "Clc"), ex3); } XrmlCertificateChain xrmlCertificateChain = new XrmlCertificateChain(DrmClientUtils.ConvertXmlNodeArrayToStringArray(machineCertificateChain)); ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireTenantLicenses, ServerManagerLog.EventType.Entry, clientContext, string.Format("AcquireTenantLicenses for identity {0}", identity)); XrmlCertificateChain xrmlCertificateChain2; XrmlCertificateChain xrmlCertificateChain3; try { string text = ServerManager.ReadOrganizationRacKeysFromIRMConfig(clientContext.OrgId); xrmlCertificateChain2 = rightsAccountCertificateGenerator.AcquireCertificate(xrmlCertificateChain, identity, text); xrmlCertificateChain3 = clientLicensorCertificateGenerator.AcquireCertificate(xrmlCertificateChain2); } catch (CertificationException ex4) { ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireTenantLicenses, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed to AcquireTenantLicenses with WellKnownErrorCode {0}, Exception: {1}", ex4.ErrorCode, ServerManagerLog.GetExceptionLogString(ex4, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException))); throw new RightsManagementServerException(ServerStrings.FailedToAcquireRacAndClc(clientContext.OrgId.ToString(), identity), ex4); } catch (PublishingException ex5) { ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireTenantLicenses, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed to AcquireTenantLicenses with WellKnownErrorCode {0}, Exception: {1}", ex5.ErrorCode, ServerManagerLog.GetExceptionLogString(ex5, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException))); throw new RightsManagementServerException(ServerStrings.FailedToAcquireRacAndClc(clientContext.OrgId.ToString(), identity), ex5); } if (!RMUtil.TryConvertCertChainStringArrayToXmlNodeArray(xrmlCertificateChain2.ToStringArray(), out racXml)) { throw new RightsManagementServerException(ServerStrings.FailedToAcquireRacAndClc(clientContext.OrgId.ToString(), identity), true); } if (!RMUtil.TryConvertCertChainStringArrayToXmlNodeArray(xrmlCertificateChain3.ToStringArray(), out clcXml)) { throw new RightsManagementServerException(ServerStrings.FailedToAcquireRacAndClc(clientContext.OrgId.ToString(), identity), true); } return; } finally { if (contextProvider != null) { contextProvider.Dispose(); } } } RpcClientWrapper.AcquireTenantLicenses(clientContext, machineCertificateChain, identity, out racXml, out clcXml); }
private bool TryCalculateIrmBodyTag(StoreDriverDeliveryEventArgsImpl argsImpl) { MessageItem messageItem = null; bool result; try { OrganizationId organizationId = argsImpl.ADRecipientCache.OrganizationId; MessageItem replayItem = argsImpl.ReplayItem; using (Attachment attachment = this.TryOpenFirstAttachment(replayItem)) { StreamAttachmentBase streamAttachmentBase = attachment as StreamAttachmentBase; if (streamAttachmentBase == null) { ConversationsProcessingAgent.tracer.TraceError((long)this.GetHashCode(), "message.rpmsg attachment is not of the correct type"); return(false); } using (Stream contentStream = streamAttachmentBase.GetContentStream(PropertyOpenMode.ReadOnly)) { if (contentStream == null) { ConversationsProcessingAgent.tracer.TraceError((long)this.GetHashCode(), "The rights protected message is not properly formatted"); return(false); } using (DrmEmailMessageContainer drmEmailMessageContainer = new DrmEmailMessageContainer()) { try { drmEmailMessageContainer.Load(contentStream, (object param0) => Streams.CreateTemporaryStorageStream()); } catch (InvalidRpmsgFormatException) { ConversationsProcessingAgent.tracer.TraceError((long)this.GetHashCode(), "The rights protected message is not properly formatted"); return(false); } string text = null; if (!argsImpl.MailItemDeliver.MbxTransportMailItem.ExtendedProperties.TryGetValue <string>("Microsoft.Exchange.RightsManagement.TransportDecryptionUL", out text) || string.IsNullOrEmpty(text)) { ConversationsProcessingAgent.tracer.TraceError((long)this.GetHashCode(), "Failed to load the useLicense"); return(false); } try { Uri licenseUri; XmlNode[] array; bool flag; RmsClientManager.GetLicensingUri(organizationId, drmEmailMessageContainer.PublishLicense, out licenseUri, out array, out flag); RpMsgToMsgConverter rpMsgToMsgConverter = new RpMsgToMsgConverter(drmEmailMessageContainer, organizationId, false); RmsClientManagerContext context = new RmsClientManagerContext(organizationId, RmsClientManagerContext.ContextId.MessageId, replayItem.InternetMessageId, argsImpl.ADRecipientCache, new RmsLatencyTracker(argsImpl.MailItemDeliver.MbxTransportMailItem.LatencyTracker), drmEmailMessageContainer.PublishLicense); using (DisposableTenantLicensePair disposableTenantLicensePair = RmsClientManager.AcquireTenantLicenses(context, licenseUri)) { messageItem = rpMsgToMsgConverter.ConvertRpmsgToMsg(replayItem, text, disposableTenantLicensePair.EnablingPrincipalRac); } } catch (RightsManagementException arg) { ConversationsProcessingAgent.tracer.TraceError <RightsManagementException>((long)this.GetHashCode(), "Conversion failed: {0}", arg); return(false); } catch (InvalidRpmsgFormatException arg2) { ConversationsProcessingAgent.tracer.TraceError <InvalidRpmsgFormatException>((long)this.GetHashCode(), "Conversion failed: {0}", arg2); return(false); } catch (ExchangeConfigurationException arg3) { ConversationsProcessingAgent.tracer.TraceError <ExchangeConfigurationException>((long)this.GetHashCode(), "Conversion failed: {0}", arg3); return(false); } catch (AttachmentProtectionException arg4) { ConversationsProcessingAgent.tracer.TraceError <AttachmentProtectionException>((long)this.GetHashCode(), "Conversion failed: {0}", arg4); return(false); } } } } this.bodyTag = messageItem.Body.CalculateBodyTag(out this.latestMessageWordCount); if (messageItem.AttachmentCollection.Count == 0) { this.forceAllAttachmentsHidden = true; } else { foreach (AttachmentHandle attachmentHandle in messageItem.AttachmentCollection) { if (!attachmentHandle.IsInline) { break; } this.forceAllAttachmentsHidden = true; } } result = true; } finally { if (messageItem != null) { messageItem.Dispose(); } } return(result); }
private PerTenantRMSTrustedPublishingDomainConfiguration GetTenantTrustedPublishingDomainConfig(RmsClientManagerContext clientContext) { PerTenantRMSTrustedPublishingDomainConfiguration value; try { if (ServerManager.aDSession != null) { value = this.trustedPublishingDomainConfigCache.GetValue(ServerManager.aDSession); } else { value = this.trustedPublishingDomainConfigCache.GetValue(clientContext.OrgId); } } catch (ADTransientException ex) { ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.PerTenantRMSTrustedPublishingDomainConfiguration, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed to GetTenantTrustedPublishingDomainConfig with Exception: {0}", ServerManagerLog.GetExceptionLogString(ex, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException))); throw new RightsManagementServerException(ServerStrings.FailedToReadConfiguration, ex, false); } catch (ADOperationException ex2) { ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.PerTenantRMSTrustedPublishingDomainConfiguration, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed to GetTenantTrustedPublishingDomainConfig with Exception: {0}", ServerManagerLog.GetExceptionLogString(ex2, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException))); throw new RightsManagementServerException(ServerStrings.FailedToReadConfiguration, ex2, true); } catch (DataValidationException ex3) { ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.PerTenantRMSTrustedPublishingDomainConfiguration, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed to GetTenantTrustedPublishingDomainConfig with Exception: {0}", ServerManagerLog.GetExceptionLogString(ex3, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException))); throw new RightsManagementServerException(ServerStrings.FailedToReadConfiguration, ex3, true); } return(value); }