private IEnumerator <IAsyncResult> PutBlobImpl(string contentType, long contentLength, byte[] serviceMetadata, byte[] applicationMetadata, byte[][] blockIdList, BlockSource[] blockSourceList, byte[] contentMD5, OverwriteOption overwriteOption, IBlobObjectCondition condition, AsyncIteratorContext <NoResults> context) { IAsyncResult asyncResult; bool flag = contentLength == (long)-1; object[] objArray = new object[] { contentLength }; NephosAssertionException.Assert(flag, "The contentLength we are going to pass into XStore for commiting blob is invalid: {0}", objArray); try { asyncResult = ((IListBlobObject)this.blob).BeginPutBlob(contentType, contentLength, serviceMetadata, applicationMetadata, blockIdList, blockSourceList, contentMD5, overwriteOption, Helpers.Convert(condition), context.GetResumeCallback(), context.GetResumeState("RealBlobObject.PutBlobImpl")); } catch (Exception exception) { StorageStamp.TranslateException(exception); throw; } yield return(asyncResult); try { this.blob.EndPutBlob(asyncResult); } catch (Exception exception1) { StorageStamp.TranslateException(exception1); throw; } }
public static ConditionInformation GetConditionInfoFromRequest(NameValueCollection requestHeaders, OperationTypeForConditionParsing operationType, string requestVersion) { ConditionalHeaders conditionalHeadersFromRequest = ConditionExtractor.GetConditionalHeadersFromRequest(requestHeaders); if (conditionalHeadersFromRequest == null) { return(null); } if (operationType == OperationTypeForConditionParsing.ReadOperation || operationType == OperationTypeForConditionParsing.WriteOperation) { return(ConditionExtractor.ExecuteExtractors(conditionalHeadersFromRequest, requestHeaders, operationType, requestVersion, ConditionExtractor.extractors)); } NephosAssertionException.Assert(operationType == OperationTypeForConditionParsing.CopyOperation); ConditionInformation copySourceIfModifiedSince = ConditionExtractor.ExecuteExtractors(conditionalHeadersFromRequest, requestHeaders, operationType, requestVersion, ConditionExtractor.extractors); ConditionInformation conditionInformation = ConditionExtractor.ExecuteExtractors(conditionalHeadersFromRequest, requestHeaders, operationType, requestVersion, ConditionExtractor.copySourceExtractors); if (copySourceIfModifiedSince == null) { return(conditionInformation); } if (conditionInformation != null) { copySourceIfModifiedSince.CopySourceIfModifiedSince = conditionInformation.CopySourceIfModifiedSince; copySourceIfModifiedSince.CopySourceIfNotModifiedSince = conditionInformation.CopySourceIfNotModifiedSince; copySourceIfModifiedSince.CopySourceIfMatch = conditionInformation.CopySourceIfMatch; copySourceIfModifiedSince.CopySourceIfNoneMatch = conditionInformation.CopySourceIfNoneMatch; NephosAssertionException.Assert(copySourceIfModifiedSince.ConditionFailStatusCode == conditionInformation.ConditionFailStatusCode); } return(copySourceIfModifiedSince); }
internal static HttpProcessorConfiguration LoadHttpProcessorConfiguration(IServiceEntrySink sink, string hostSuffixesConfigParamName, string enableStorageDomainNamesConfigParamName) { HttpProcessorConfiguration httpProcessorConfiguration = new HttpProcessorConfiguration() { AllowPathStyleUris = ConfigurationHelper.GetConfigSetting <bool>(sink, "NephosAllowPathStyleUris", "Allow path-style URIs"), ValidHostSuffixes = ConfigurationHelper.GetHostSuffixes(sink, hostSuffixesConfigParamName), MaskClientIPAddressesInLog = ConfigurationHelper.GetIPAddressMaskSetting(sink) }; if (!httpProcessorConfiguration.AllowPathStyleUris) { NephosAssertionException.Assert(httpProcessorConfiguration.ValidHostSuffixes != null, "Host suffixes can't be null when AllowPathStyleUris is false. Check service model configuaration."); NephosAssertionException.Assert((int)httpProcessorConfiguration.ValidHostSuffixes.Length > 0, "Host suffixes can't be empty when AllowPathStyleUris is false. Check service model configuaration."); } httpProcessorConfiguration.ValidHostSuffixes = httpProcessorConfiguration.ValidHostSuffixes ?? new string[0]; httpProcessorConfiguration.IncludeInternalDetailsInErrorResponses = ConfigurationHelper.GetConfigSetting <bool>(sink, "NephosIncludeInternalDetailsInErrorResponses", "Include internal details in error responses"); if (!string.IsNullOrEmpty(enableStorageDomainNamesConfigParamName)) { httpProcessorConfiguration.EnableStorageDomainNames = ConfigurationHelper.GetConfigSetting <bool>(sink, enableStorageDomainNamesConfigParamName, "Enable storage domain names"); } try { httpProcessorConfiguration.StampName = ConfigurationHelper.GetConfigSetting <string>(sink, "StampName", "Stamp Name"); } catch (Exception exception1) { Exception exception = exception1; IStringDataEventStream error = Logger <IRestProtocolHeadLogger> .Instance.Error; object[] str = new object[] { exception.ToString() }; error.Log("Hit Exception while reading StampName setting from ACS: {0}", str); } return(httpProcessorConfiguration); }
public NephosErrorDetails(NephosStatusEntry statusEntry, MeasurementEventStatus eventStatus, Exception exception, string userSafeErrorMessage, NameValueCollection headers, NameValueCollection additionalDetails, byte[] errorResponse, bool isFatal, bool hasErrorResponse, bool skipBillingAndMetrics) { NephosAssertionException.Assert(statusEntry != null, "statusEntry can't be null."); NephosAssertionException.Assert(true, "eventStatus can't be null."); this.StatusEntry = statusEntry; this.EventStatus = eventStatus; this.ErrorException = exception; this.ResponseHeaders = headers; this.AdditionalDetails = additionalDetails; this.ErrorResponse = errorResponse; this.IsFatal = isFatal; this.HasErrorResponse = hasErrorResponse; this.SkipBillingAndMetrics = skipBillingAndMetrics; StringBuilder stringBuilder = new StringBuilder(statusEntry.UserMessage); if (!string.IsNullOrEmpty(userSafeErrorMessage)) { stringBuilder.AppendFormat(" Additional detail: {0}", userSafeErrorMessage); } Guid activityId = Trace.ActivityId; if (activityId != Guid.Empty) { string str = activityId.ToString("D"); DateTime utcNow = DateTime.UtcNow; stringBuilder.AppendFormat("\nRequestId:{0}\nTime:{1}", str, utcNow.ToString("o")); } this.UserSafeErrorMessage = stringBuilder.ToString(); }
public MD5MismatchException(string message, byte[] specifiedMD5, byte[] calculatedMD5, Exception innerException) : base(message, innerException) { NephosAssertionException.Assert(specifiedMD5 != null); NephosAssertionException.Assert(calculatedMD5 != null); this.specifiedMD5 = specifiedMD5; this.calculatedMD5 = calculatedMD5; }
public static void AuthorizeSASRequest(TableSignedAccessAccountIdentifier sasAccountIdentifier, PermissionLevel permissionLevel, SASPermission sasPermissionsRequired, string userTableName, bool isUtilityTableCommand) { if (sasAccountIdentifier == null) { return; } SASPermission signedAccessPermission = sasAccountIdentifier.SignedAccessPermission; if (isUtilityTableCommand) { throw new NephosUnauthorizedAccessException("Signed access not supported for this request.", sasAccountIdentifier.AccountName, sasAccountIdentifier.TableName, null, sasAccountIdentifier, permissionLevel, signedAccessPermission, AuthorizationFailureReason.InvalidOperationSAS); } if ((sasPermissionsRequired & ~45) != SASPermission.None) { NephosAssertionException.Fail(string.Format("Signed permission is not well formed. Signed permission: {0}", sasPermissionsRequired)); } if (!string.Equals(sasAccountIdentifier.TableName, userTableName.ToLower(), StringComparison.Ordinal)) { throw new NephosUnauthorizedAccessException("Signed access not supported for this request as table name did not match", sasAccountIdentifier.AccountName, sasAccountIdentifier.TableName, null, sasAccountIdentifier, permissionLevel, signedAccessPermission, AuthorizationFailureReason.InvalidOperationSAS); } if ((sasPermissionsRequired & signedAccessPermission) != sasPermissionsRequired) { throw new NephosUnauthorizedAccessException("Signed access insufficient permission", sasAccountIdentifier.AccountName, sasAccountIdentifier.TableName, null, sasAccountIdentifier, permissionLevel, signedAccessPermission, AuthorizationFailureReason.PermissionMismatch); } }
public bool ComputeSignatureAndCompare(byte[] stringToSign, SecretKeyListV3 keys) { bool flag; NephosAssertionException.Assert(stringToSign != null); NephosAssertionException.Assert(keys != null); if (keys.Count == 0) { throw new ArgumentException("Invalid number of keys"); } bool flag1 = string.IsNullOrEmpty(this.KeyName); List <SecretKeyV3> .Enumerator enumerator = keys.GetEnumerator(); try { while (enumerator.MoveNext()) { SecretKeyV3 current = enumerator.Current; if ((!flag1 || !current.IsDefault()) && !string.Equals(current.Name, this.KeyName) || !SASUtilities.ComputeSignatureAndCompare(stringToSign, current.Value, this.Signature)) { continue; } this.KeyUsedForSigning = current; flag = true; return(flag); } return(false); } finally { ((IDisposable)enumerator).Dispose(); } return(flag); }
public virtual void ValidateAndDeriveEffectiveAccessPolicy(SASIdentifier sasIdentifier) { NephosAssertionException.Assert(sasIdentifier.Id.Equals(this.SignedIdentifier)); if (!this.SignedExpiry.HasValue && !sasIdentifier.AccessPolicy.SignedExpiry.HasValue) { throw new AuthenticationFailureException("Signed expiry must be specified in signature or SAS identifier"); } if (!this.SignedPermission.HasValue && !sasIdentifier.AccessPolicy.SignedPermission.HasValue) { throw new AuthenticationFailureException("Signed permission must be specified in signature or SAS identifier"); } if (this.SignedStart.HasValue && sasIdentifier.AccessPolicy.SignedStart.HasValue || this.SignedExpiry.HasValue && sasIdentifier.AccessPolicy.SignedExpiry.HasValue || this.SignedPermission.HasValue && sasIdentifier.AccessPolicy.SignedPermission.HasValue) { throw new AuthenticationFailureException("Access policy fields can be associated with signature or SAS identifier but not both"); } if (sasIdentifier.AccessPolicy.SignedStart.HasValue) { this.SignedStart = new DateTime?(sasIdentifier.AccessPolicy.SignedStart.Value); } if (sasIdentifier.AccessPolicy.SignedExpiry.HasValue) { NephosAssertionException.Assert(!this.SignedExpiry.HasValue); this.SignedExpiry = new DateTime?(sasIdentifier.AccessPolicy.SignedExpiry.Value); } if (sasIdentifier.AccessPolicy.SignedPermission.HasValue) { NephosAssertionException.Assert(!this.SignedPermission.HasValue); this.SignedPermission = new SASPermission?(sasIdentifier.AccessPolicy.SignedPermission.Value); } }
private void ProcessAsyncCallback(IAsyncResult ar) { Logger <IRestProtocolHeadLogger> .Instance.VerboseDebug.Log("In the process end callback"); using (IProcessor asyncState = (IProcessor)ar.AsyncState) { try { asyncState.EndProcess(ar); } catch (NephosAssertionException nephosAssertionException1) { NephosAssertionException nephosAssertionException = nephosAssertionException1; IStringDataEventStream error = Logger <IRestProtocolHeadLogger> .Instance.Error; object[] str = new object[] { nephosAssertionException.ToString() }; error.Log("ASSERTION: {0}", str); } catch (Exception exception1) { Exception exception = exception1; IStringDataEventStream unhandledException = Logger <IRestProtocolHeadLogger> .Instance.UnhandledException; object[] objArray = new object[] { exception.ToString() }; unhandledException.Log("EXCEPTION thrown: {0}", objArray); } } }
private IEnumerator <IAsyncResult> SnapshotBlobImpl(byte[] metadata, IBlobObjectCondition condition, AsyncIteratorContext <DateTime> context) { IAsyncResult asyncResult; try { asyncResult = this.blob.BeginSnapshotBlob(metadata, Helpers.Convert(condition), context.GetResumeCallback(), context.GetResumeState("BaseBlobObject.SnapshotBlobImpl")); } catch (Exception exception) { StorageStamp.TranslateException(exception); throw; } yield return(asyncResult); DateTime minValue = DateTime.MinValue; try { minValue = this.blob.EndSnapshotBlob(asyncResult); } catch (Exception exception1) { StorageStamp.TranslateException(exception1); throw; } NephosAssertionException.Assert(minValue != DateTime.MinValue, "The snapshot timestamp must be set!"); context.ResultData = minValue; }
public static AuthDataEntry SignedKeyAuthenticate(string stringToSign, string requestSignature, AuthenticationInformation authInfo) { AuthDataEntry authDataEntry; NephosAssertionException.Assert(!string.IsNullOrEmpty(stringToSign)); NephosAssertionException.Assert(!string.IsNullOrEmpty(requestSignature)); NephosAssertionException.Assert(authInfo != null); RequestContext requestContext = authInfo.RequestContext; NephosUriComponents uriComponents = authInfo.UriComponents; NameValueCollection queryParameters = requestContext.QueryParameters; string item = queryParameters["sv"]; byte[] sign = BlobSignedAccessHelper.ComputeUrlDecodedUtf8EncodedStringToSign(queryParameters, uriComponents); using (IEnumerator <AuthDataEntry> enumerator = SharedKeyAuthInfoHelper.GetSharedKeys(authInfo).GetEnumerator()) { while (enumerator.MoveNext()) { AuthDataEntry current = enumerator.Current; byte[] numArray = SASUtilities.ComputeSignedKey(sign, current.AuthValue); if (!SASUtilities.ComputeSignatureAndCompare((new UTF8Encoding()).GetBytes(stringToSign), numArray, requestSignature)) { continue; } authDataEntry = current; return(authDataEntry); } CultureInfo invariantCulture = CultureInfo.InvariantCulture; object[] objArray = new object[] { requestSignature, stringToSign }; throw new AuthenticationFailureException(string.Format(invariantCulture, "The MAC signature found in the HTTP request '{0}' is not the same as any computed signature. Server used following string to sign: '{1}'.", objArray)); } return(authDataEntry); }
private IEnumerator <IAsyncResult> ReadImpl(byte[] buffer, int offset, int count, AsyncIteratorContext <int> context) { IAsyncResult asyncResult = null; this.CheckDisposed(); if (count < 0) { throw new ArgumentOutOfRangeException("The number of bytes to read cannot be negative", "count"); } this.readTimer.Start(); if (count > 0) { asyncResult = this.innerStream.BeginRead(buffer, offset, count, context.GetResumeCallback(), context.GetResumeState("TallyKeepingStream.ReadImpl")); yield return(asyncResult); } int num = 0; if (count > 0) { NephosAssertionException.Assert(asyncResult != null); num = this.innerStream.EndRead(asyncResult); } this.readTimer.Stop(); if (num > 0 && this.readingEvent != null) { this.RecordPreOperationDataCount((long)num); this.readingEvent(this, this.EventArgs); } this.UpdateBytesRead((long)num); context.ResultData = num; }
public static TimeSpan GetSizeBasedTimeout(long dataSize, long dataRateForTimeout) { NephosAssertionException.Assert(dataRateForTimeout > (long)0); double num = (double)dataRateForTimeout / 60000; int num1 = (int)Math.Ceiling((double)dataSize / num); return(TimeSpan.FromMilliseconds((double)num1)); }
protected void ValidateSignatureFormat(string signature) { NephosAssertionException.Assert(signature != null); if ((int)Convert.FromBase64String(signature).Length != SignedAccessHelper.Sha256HashSize / 8) { throw new AuthenticationFailureException("Signature size is invalid"); } }
public VerbNotSupportedProtocolException(RestMethod calledMethod, ReadOnlyCollection <RestMethod> allowedMethods, Exception innerException) : base(string.Format(CultureInfo.InvariantCulture, "The method {0} is not supported for the specified resource. Refer to 'Allow' response header for the list of supported methods.", new object[] { calledMethod }), innerException) { NephosAssertionException.Assert(calledMethod != RestMethod.Unknown); NephosAssertionException.Assert(allowedMethods != null); NephosAssertionException.Assert(allowedMethods.Count > 0); this.calledMethod = calledMethod; this.allowedMethods = allowedMethods; }
public static IContainer CreateContainerInstance(this IStorageManager storageManager, string accountName, string containerName, ServiceType serviceType) { if (serviceType == ServiceType.BlobService) { return(storageManager.CreateBlobContainerInstance(accountName, containerName)); } NephosAssertionException.Fail("Invalid service type {0}.", new object[] { serviceType }); return(null); }
public void Complete() { NephosAssertionException.Assert(this.outStreamAccumulator != null, "The underlying AccumulatorStream must not be null!"); NephosAssertionException.Assert(this.xmlWriter != null, "The underlying XML Writer must not be null!"); this.xmlWriter.Close(); this.outStreamAccumulator.Dispose(); this.xmlWriter = null; this.outStreamAccumulator = null; }
public static IBlobContainerCollection EndListContainers(this IStorageAccount account, ServiceType serviceType, IAsyncResult ar) { if (serviceType == ServiceType.BlobService) { return(account.EndListBlobContainers(ar)); } NephosAssertionException.Fail("Invalid service type {0}.", new object[] { serviceType }); return(null); }
public static IAsyncResult BeginListContainers(this IStorageAccount account, ServiceType serviceType, string containerName, ContainerPropertyNames propertyNames, string separator, string containerNameStart, IContainerCondition condition, int maxContainerNames, AsyncCallback callback, object state) { if (serviceType == ServiceType.BlobService) { return(account.BeginListBlobContainers(containerName, propertyNames, separator, containerNameStart, condition, maxContainerNames, callback, state)); } NephosAssertionException.Fail("Invalid service type {0}.", new object[] { serviceType }); return(null); }
public SignedAccessHelper(Microsoft.Cis.Services.Nephos.Common.RequestContext requestContext, NephosUriComponents uriComponents) { NephosAssertionException.Assert(requestContext != null); NephosAssertionException.Assert(uriComponents != null); NephosAssertionException.Assert(requestContext.QueryParameters != null); this.QueryParams = requestContext.QueryParameters; this.RequestContext = requestContext; this.UriComponents = uriComponents; this.SignedProtocol = SasProtocol.All; }
public IAsyncResult BeginPerformOperation(IAccountIdentifier accountId, string accountName, IDataServiceHost host, RequestStartedCallback requestStartedCallback, CheckPermissionDelegate checkPermissionCallback, QueryRowCommandPropertiesAvailableCallback queryRowCommandPropertiesAvailableCallback, Dictionary <string, string> continuationToken, ContinuationTokenAvailableCallback continuationTokenAvailableCallback, bool operationIsConditional, RequestContext requestContext, AsyncCallback callback, object state) { TableProtocolHead tableProtocolHead = host as TableProtocolHead; NephosAssertionException.Assert(tableProtocolHead != null, "Expecting host to be instance of TableProtocolHead."); AsyncIteratorContext <NoResults> asyncIteratorContext = new AsyncIteratorContext <NoResults>("TableManager.PerformOperation", callback, state); asyncIteratorContext.Begin(this.PerformOperationImpl(accountId, accountName, tableProtocolHead, requestStartedCallback, checkPermissionCallback, queryRowCommandPropertiesAvailableCallback, continuationToken, continuationTokenAvailableCallback, operationIsConditional, requestContext, asyncIteratorContext)); return(asyncIteratorContext); }
public static bool StringContains(string mainString, string stringToSearchFor) { NephosAssertionException.Assert(mainString != null); NephosAssertionException.Assert(stringToSearchFor != null); if (string.IsNullOrEmpty(mainString)) { return(string.IsNullOrEmpty(stringToSearchFor)); } return(mainString.IndexOf(stringToSearchFor, StringComparison.OrdinalIgnoreCase) != -1); }
public AccountIdentifier(IStorageAccount account, SecretKeyPermissions keyUsedPermissions) { if (account == null) { throw new ArgumentNullException("account", "account cannot be null"); } NephosAssertionException.Assert(account.Permissions.HasValue, "account.Permissions cannot be null"); this.AccountName = account.Name; this.IsSecondaryAccess = account.IsSecondaryAccess; this.Permissions = account.Permissions.Value; this.KeyUsedPermissions = keyUsedPermissions; }
public object GetService(Type serviceType) { if (serviceType == null) { throw new ArgumentNullException("serviceType"); } NephosAssertionException.Assert(this.dataSource != null, "DataSource has not been created yet, but IServiceProvider.GetService was called"); if (!(serviceType == typeof(IDataServiceUpdateProvider)) && !(serviceType == typeof(IDataServiceQueryProvider)) && !(serviceType == typeof(IDataServiceMetadataProvider)) && !(serviceType == typeof(IUpdatable))) { return(null); } return(this.dataSource); }
public static bool ComputeSignatureAndCompare(byte[] stringToSign, byte[] key, string expectedSignature) { bool flag; NephosAssertionException.Assert(key != null); using (HMAC hMAC = HMACCryptoCache.Instance.Acquire(key)) { byte[] numArray = hMAC.ComputeHash(stringToSign); NephosAssertionException.Assert((int)numArray.Length == hMAC.HashSize / 8); flag = AuthenticationManager.AreSignaturesEqual(Convert.ToBase64String(numArray), expectedSignature); } return(flag); }
public static void SignedKeyParamsParser(SupportedAuthScheme scheme, string parameter, NephosUriComponents uriComponents, out string accountName, out string signature) { NephosAssertionException.Assert(scheme.Equals(SupportedAuthScheme.SignedKey)); NephosAssertionException.Assert((uriComponents == null ? false : !string.IsNullOrEmpty(uriComponents.AccountName))); if (string.IsNullOrEmpty(parameter)) { CultureInfo invariantCulture = CultureInfo.InvariantCulture; object[] objArray = new object[] { "Authorization", string.Format("{0} {1}", scheme, parameter) }; throw new InvalidAuthenticationInfoException(string.Format(invariantCulture, "{0} value '{1}' is invalid.", objArray)); } accountName = uriComponents.AccountName; signature = parameter; }
public static byte[] ComputeSignedKey(byte[] stringToSign, byte[] key) { byte[] numArray; NephosAssertionException.Assert((stringToSign == null ? false : (int)stringToSign.Length > 0)); NephosAssertionException.Assert(key != null); using (HMACSHA512 hMACSHA512 = new HMACSHA512(key)) { byte[] numArray1 = hMACSHA512.ComputeHash(stringToSign); NephosAssertionException.Assert((int)numArray1.Length == hMACSHA512.HashSize / 8); numArray = numArray1; } return(numArray); }
public static void SharedKeyParamsParser(SupportedAuthScheme scheme, string parameter, NephosUriComponents uriComponents, out string accountName, out string signature) { NephosAssertionException.Assert((scheme.Equals(SupportedAuthScheme.SharedKey) ? true : scheme.Equals(SupportedAuthScheme.SharedKeyLite))); NephosAssertionException.Assert(!string.IsNullOrEmpty(parameter)); string[] strArrays = parameter.Split(HttpRequestAccessorCommon.colonDelimiter, StringSplitOptions.RemoveEmptyEntries); if ((int)strArrays.Length != 2) { CultureInfo invariantCulture = CultureInfo.InvariantCulture; object[] objArray = new object[] { "Authorization", string.Format("{0} {1}", scheme, parameter) }; throw new InvalidAuthenticationInfoException(string.Format(invariantCulture, "{0} value '{1}' is invalid.", objArray)); } accountName = strArrays[0]; signature = strArrays[1]; }
private IEnumerator <IAsyncResult> AuthorizeRequestImpl(IAccountIdentifier requestor, string resourceAccount, string resourceContainer, string resourceIdentifier, PermissionLevel requestedPermission, SASAuthorizationParameters requestedSasParameters, AuthorizationInformation authorizationInfo, TimeSpan timeout, AsyncIteratorContext <AuthorizationResult> context) { Duration startingNow = Duration.StartingNow; IAsyncResult asyncResult = this.BeginSharedKeyAuthorization(requestor, resourceAccount, resourceContainer, resourceIdentifier, requestedPermission, authorizationInfo, startingNow.Remaining(timeout), context.GetResumeCallback(), context.GetResumeState("NephosAuthorizationManager.AuthorizeRequestImpl")); yield return(asyncResult); AuthorizationResult authorizationResult = this.EndAuthorizeRequest(asyncResult); bool authorized = authorizationResult.Authorized; if (!authorized || !(requestor is SignedAccessAccountIdentifier) && !(requestor is AccountSasAccessIdentifier)) { context.ResultData = authorizationResult; } else { NephosAssertionException.Assert((requestor is SignedAccessAccountIdentifier ? true : requestor is AccountSasAccessIdentifier)); if (!(requestor is SignedAccessAccountIdentifier)) { if (!(requestor is AccountSasAccessIdentifier)) { throw new NephosUnauthorizedAccessException("Signed access not supported for this request", resourceAccount, resourceContainer, resourceIdentifier, requestor, requestedPermission, AuthorizationFailureReason.InvalidOperationSAS); } if ((requestedSasParameters.SupportedSasTypes & SasType.AccountSas) != SasType.AccountSas) { throw new NephosUnauthorizedAccessException("Account signed access not supported for this request", resourceAccount, resourceContainer, resourceIdentifier, requestor, requestedPermission, AuthorizationFailureReason.InvalidOperationSAS); } if (requestedSasParameters.SignedPermission == SASPermission.None) { throw new ArgumentException("signedPerrmission"); } authorizationResult = this.AuthorizeAccountSignedAccessRequest(requestor as AccountSasAccessIdentifier, resourceAccount, resourceContainer, resourceIdentifier, requestedPermission, requestedSasParameters); context.ResultData = authorizationResult; } else { if ((requestedSasParameters.SupportedSasTypes & SasType.ResourceSas) != SasType.ResourceSas) { throw new NephosUnauthorizedAccessException("Signed access not supported for this request", resourceAccount, resourceContainer, resourceIdentifier, requestor, requestedPermission, AuthorizationFailureReason.InvalidOperationSAS); } if (requestedSasParameters.SignedPermission == SASPermission.None) { throw new ArgumentException("signedPerrmission"); } authorizationResult = this.AuthorizeResourceSignedAccessRequest(requestor as SignedAccessAccountIdentifier, resourceAccount, resourceContainer, resourceIdentifier, requestedPermission, requestedSasParameters.SignedPermission); context.ResultData = authorizationResult; } } }
public override void AcceptRequest(RequestContext context, Microsoft.Cis.Services.Nephos.Common.ServiceType serviceType) { Logger <IRestProtocolHeadLogger> .Instance.VerboseDebug.Log("Accepting request"); context.ServiceType = serviceType; PerRequestStorageManager perRequestStorageManager = new PerRequestStorageManager(BlobServiceEntry.SharedStorageManager, context.OperationStatus); AuthenticationManager operationStatus = XFEBlobAuthenticationManager.CreateAuthenticationManager(perRequestStorageManager, false); operationStatus.OperationStatus = context.OperationStatus; AuthorizationManager authorizationManager = XFEBlobAuthorizationManager.CreateAuthorizationManager(perRequestStorageManager, true); authorizationManager.OperationStatus = context.OperationStatus; ServiceManager serviceManager = RealServiceManager.CreateServiceManager(authorizationManager, perRequestStorageManager, BlobServiceEntry.SharedConfig); serviceManager.OperationStatus = context.OperationStatus; IProcessor processor = HttpRestProcessor.Create(context, perRequestStorageManager, operationStatus, serviceManager, HttpRestProcessor.HttpProcessorConfigurationDefaultInstance, new TransformExceptionDelegate(SqlExceptionManager.TransformSqlException), null); bool flag = true; try { try { processor.BeginProcess(new AsyncCallback(this.ProcessAsyncCallback), processor); flag = false; } catch (NephosAssertionException nephosAssertionException1) { NephosAssertionException nephosAssertionException = nephosAssertionException1; IStringDataEventStream error = Logger <IRestProtocolHeadLogger> .Instance.Error; object[] str = new object[] { nephosAssertionException.ToString() }; error.Log("ASSERTION in BeginProcess: {0}", str); } catch (Exception exception1) { Exception exception = exception1; IStringDataEventStream unhandledException = Logger <IRestProtocolHeadLogger> .Instance.UnhandledException; object[] objArray = new object[] { exception.ToString() }; unhandledException.Log("BeginProcess threw exception {0}", objArray); } } finally { if (flag) { processor.Dispose(); } } Logger <IRestProtocolHeadLogger> .Instance.VerboseDebug.Log("Returning from AcceptRequest method."); }