internal static string GetAllowedMethods(DataServiceConfiguration configuration, ResourceSetWrapper container, RequestDescription description)
        {
            if (container == null)
            {
                return(null);
            }
            StringBuilder   builder           = new StringBuilder();
            EntitySetRights resourceSetRights = configuration.GetResourceSetRights(container.ResourceSet);

            if (description.IsSingleResult)
            {
                AppendRight(resourceSetRights, EntitySetRights.ReadSingle, "GET", builder);
                AppendRight(resourceSetRights, EntitySetRights.WriteReplace, "PUT", builder);
                if (description.TargetKind != RequestTargetKind.MediaResource)
                {
                    AppendRight(resourceSetRights, EntitySetRights.WriteMerge, "MERGE", builder);
                    AppendRight(resourceSetRights, EntitySetRights.WriteMerge, "PATCH", builder);
                    AppendRight(resourceSetRights, EntitySetRights.WriteDelete, "DELETE", builder);
                }
            }
            else
            {
                AppendRight(resourceSetRights, EntitySetRights.ReadMultiple, "GET", builder);
                AppendRight(resourceSetRights, EntitySetRights.WriteAppend, "POST", builder);
            }
            return(builder.ToString());
        }
예제 #2
0
 internal DataServiceCacheItem(DataServiceConfiguration dataServiceConfiguration)
 {
     this.configuration = dataServiceConfiguration;
     this.resourceSetWrapperCache = new Dictionary<string, ResourceSetWrapper>(EqualityComparer<string>.Default);
     this.visibleTypeCache = new Dictionary<string, ResourceType>(EqualityComparer<string>.Default);
     this.resourceAssociationSetCache = new Dictionary<string, ResourceAssociationSet>(EqualityComparer<string>.Default);
 }
예제 #3
0
 public void ApplyConfiguration(DataServiceConfiguration configuration, DataServiceProviderWrapper provider)
 {
     if (this.Kind == OperationKind.ServiceOperation)
     {
         this.serviceOperationRights = configuration.GetServiceOperationRights(this.ServiceOperation);
     }
     else
     {
         this.serviceActionRights = configuration.GetServiceActionRights(this.ServiceAction);
     }
     if (((this.Kind == OperationKind.ServiceOperation) && ((this.serviceOperationRights & ~System.Data.Services.ServiceOperationRights.OverrideEntitySetRights) != System.Data.Services.ServiceOperationRights.None)) || ((this.Kind == OperationKind.Action) && (this.serviceActionRights != System.Data.Services.ServiceActionRights.None)))
     {
         if (this.operation.ResourceSet != null)
         {
             this.resourceSet = provider.TryResolveResourceSet(this.operation.ResourceSet.Name);
             if (this.resourceSet == null)
             {
                 throw new InvalidOperationException(System.Data.Services.Strings.OperationWrapper_OperationResourceSetNotVisible(this.Name, this.operation.ResourceSet.Name));
             }
         }
         else if (this.ResultSetPathExpression != null)
         {
             this.ResultSetPathExpression.InitializePathSegments(provider);
         }
     }
 }
예제 #4
0
 public static void InitializeService(DataServiceConfiguration config)
 {
     config.SetEntitySetAccessRule("*", EntitySetRights.All);
     config.DataServiceBehavior.MaxProtocolVersion = System.Data.Services.Common.DataServiceProtocolVersion.V3;
     config.DataServiceBehavior.AcceptCountRequests = true;
     config.DataServiceBehavior.AcceptProjectionRequests = true;
     config.UseVerboseErrors = true;
 }
예제 #5
0
 // This method is called only once to initialize service-wide policies.
 public static void InitializeService(DataServiceConfiguration config)
 {
     // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
     config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
     config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
     config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
     config.DataServiceBehavior.AcceptCountRequests = true;
     config.DataServiceBehavior.AcceptProjectionRequests = true;
     config.UseVerboseErrors = true;
 }
예제 #6
0
 private void ApplyConfiguration(DataServiceConfiguration configuration)
 {
     this.rights = configuration.GetResourceSetRights(this.resourceSet);
     this.pageSize = configuration.GetResourceSetPageSize(this.resourceSet);
     if (this.pageSize < 0)
     {
         throw new DataServiceException(500, System.Data.Services.Strings.DataService_SDP_PageSizeMustbeNonNegative(this.pageSize, this.Name));
     }
     this.readAuthorizationMethods = configuration.GetReadAuthorizationMethods(this.resourceSet);
     this.writeAuthorizationMethods = configuration.GetWriteAuthorizationMethods(this.resourceSet);
 }
        internal static string GetAllowedMethods(DataServiceConfiguration configuration, RequestDescription description)
        {
            if ((description.TargetKind == RequestTargetKind.Metadata) || (description.TargetKind == RequestTargetKind.ServiceDirectory))
            {
                return("GET");
            }
            if (description.TargetKind == RequestTargetKind.Batch)
            {
                return("POST");
            }
            int indexOfTargetEntityResource    = description.GetIndexOfTargetEntityResource();
            ResourceSetWrapper targetContainer = description.SegmentInfos[indexOfTargetEntityResource].TargetContainer;

            return(GetAllowedMethods(configuration, targetContainer, description));
        }
예제 #8
0
        public static new void InitializeService(DataServiceConfiguration config)
        {
            config.UseVerboseErrors = true;
            config.SetEntitySetAccessRule("Review", EntitySetRights.All);
            config.SetEntitySetAccessRule("ReviewComment", EntitySetRights.All);
            config.SetEntitySetAccessRule("ReviewFieldValue", EntitySetRights.All);
            config.SetEntitySetAccessRule("UserBlackList", EntitySetRights.All);
            config.SetEntitySetAccessRule("ReviewSchema", EntitySetRights.All);
            config.SetEntitySetAccessRule("Subscription", EntitySetRights.All);
            config.SetEntitySetAccessRule("ReviewFieldSchema", EntitySetRights.All);

            //This could be "*" and could also be ReadSingle, etc, etc.
            config.SetServiceOperationAccessRule("GetTopReviews", ServiceOperationRights.AllRead);
			
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
        }
예제 #9
0
		public static void InitializeService(DataServiceConfiguration config)
		{
			config.SetEntitySetAccessRule("*", EntitySetRights.All);
			config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
			config.DataServiceBehavior.AcceptProjectionRequests = true;
			config.UseVerboseErrors = true;
			config.SetEntitySetPageSize("*", DataServiceController.Current.Configuration.GetResultSetLimit("*"));
			foreach (DSConfiguration.WcfConfigElement entitySet in DataServiceController.Current.Configuration.DataServicesConfig.EntitySets)
			{
				config.SetEntitySetPageSize(entitySet.Name, entitySet.MaxResults);
			}
			config.MaxExpandCount = DataServiceController.Current.Configuration.DataServicesConfig.MaxExpandCount;
			config.MaxExpandDepth = DataServiceController.Current.Configuration.DataServicesConfig.MaxExpandDepth;
			config.DataServiceBehavior.AcceptAnyAllRequests = true;
			config.DataServiceBehavior.AcceptSpatialLiteralsInQuery = false;
		}
        // This method is called just once to initialize global service policies.
        public static void InitializeService(DataServiceConfiguration config)
        {
            config.SetEntitySetAccessRule("*", EntitySetRights.All);
            config.DataServiceBehavior.AcceptAnyAllRequests = true;
            config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
            config.SetServiceActionAccessRule("*", ServiceActionRights.Invoke);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
            config.DataServiceBehavior.AcceptProjectionRequests = true;
            config.DataServiceBehavior.AcceptCountRequests = true;
            config.AnnotationsBuilder = CreateAnnotationsBuilder(() => serviceContext);
            config.DataServiceBehavior.AcceptReplaceFunctionInQuery = true;
            config.DataServiceBehavior.AcceptSpatialLiteralsInQuery = true;
            config.DisableValidationOnMetadataWrite = true;
#if DEBUG
            config.UseVerboseErrors = true;
#endif
        }
예제 #11
0
 internal static string GetAllowedMethods(DataServiceConfiguration configuration, RequestDescription description)
 {
     if ((description.TargetKind == RequestTargetKind.Metadata) || (description.TargetKind == RequestTargetKind.ServiceDirectory))
     {
         return "GET";
     }
     if (description.TargetKind == RequestTargetKind.Batch)
     {
         return "POST";
     }
     int indexOfTargetEntityResource = description.GetIndexOfTargetEntityResource();
     ResourceSetWrapper targetContainer = description.SegmentInfos[indexOfTargetEntityResource].TargetContainer;
     return GetAllowedMethods(configuration, targetContainer, description);
 }
예제 #12
0
        private ExpandSegmentCollection CheckSingleExpandPath(List <string> path)
        {
            ResourceType            targetResourceType = this.description.TargetResourceType;
            ResourceSetWrapper      targetContainer    = this.description.LastSegmentInfo.TargetContainer;
            ExpandSegmentCollection segments           = new ExpandSegmentCollection(path.Count);
            bool flag = false;
            bool previousSegmentIsTypeSegment = false;

            for (int i = 0; i < path.Count; i++)
            {
                string propertyName                     = path[i];
                ResourcePropertyKind stream             = ResourcePropertyKind.Stream;
                ResourceProperty     navigationProperty = targetResourceType.TryResolvePropertyName(propertyName, stream);
                if (navigationProperty == null)
                {
                    ResourceType type2 = WebUtil.ResolveTypeIdentifier(this.service.Provider, propertyName, targetResourceType, previousSegmentIsTypeSegment);
                    if (type2 == null)
                    {
                        if (targetResourceType.IsOpenType)
                        {
                            throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.OpenNavigationPropertiesNotSupportedOnOpenTypes(propertyName));
                        }
                        throw DataServiceException.CreateSyntaxError(System.Data.Services.Strings.RequestUriProcessor_PropertyNotFound(targetResourceType.FullName, propertyName));
                    }
                    this.description.VerifyProtocolVersion(RequestDescription.Version3Dot0, this.service);
                    targetResourceType           = type2;
                    previousSegmentIsTypeSegment = true;
                }
                else
                {
                    previousSegmentIsTypeSegment = false;
                    if (navigationProperty.TypeKind == ResourceTypeKind.EntityType)
                    {
                        targetContainer = this.service.Provider.GetContainer(targetContainer, targetResourceType, navigationProperty);
                        if (targetContainer == null)
                        {
                            throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.BadRequest_InvalidPropertyNameSpecified(navigationProperty.Name, targetResourceType.FullName));
                        }
                        bool singleResult = navigationProperty.Kind == ResourcePropertyKind.ResourceReference;
                        DataServiceConfiguration.CheckResourceRightsForRead(targetContainer, singleResult);
                        Expression filter = DataServiceConfiguration.ComposeQueryInterceptors(this.service, targetContainer);
                        if (((targetContainer.PageSize != 0) && !singleResult) && !this.IsCustomPaged)
                        {
                            OrderingInfo        orderingInfo = new OrderingInfo(true);
                            ParameterExpression expression   = Expression.Parameter(targetContainer.ResourceType.InstanceType, "p");
                            foreach (ResourceProperty property2 in targetContainer.GetKeyPropertiesForOrderBy())
                            {
                                Expression expression3;
                                if (property2.CanReflectOnInstanceTypeProperty)
                                {
                                    expression3 = Expression.Property(expression, targetContainer.ResourceType.GetPropertyInfo(property2));
                                }
                                else
                                {
                                    expression3 = Expression.Convert(Expression.Call(null, DataServiceProviderMethods.GetValueMethodInfo, expression, Expression.Constant(property2)), property2.Type);
                                }
                                orderingInfo.Add(new OrderingExpression(Expression.Lambda(expression3, new ParameterExpression[] { expression }), true));
                            }
                            segments.Add(new ExpandSegment(navigationProperty.Name, filter, targetContainer.PageSize, targetContainer, targetResourceType, navigationProperty, orderingInfo));
                            this.description.VerifyProtocolVersion(RequestDescription.Version2Dot0, this.service);
                            this.description.VerifyAndRaiseResponseVersion(RequestDescription.Version2Dot0, this.service);
                        }
                        else
                        {
                            if (!singleResult && this.IsCustomPaged)
                            {
                                this.CheckAndApplyCustomPaging(null);
                            }
                            segments.Add(new ExpandSegment(navigationProperty.Name, filter, this.service.Configuration.MaxResultsPerCollection, targetContainer, targetResourceType, navigationProperty, null));
                        }
                        this.description.UpdateAndCheckEpmFeatureVersion(targetContainer, this.service);
                        this.description.UpdateVersions(this.service.OperationContext.Host.RequestAccept, targetContainer, this.service);
                        flag = false;
                        targetResourceType = navigationProperty.ResourceType;
                    }
                    else
                    {
                        flag = true;
                    }
                }
            }
            if (previousSegmentIsTypeSegment)
            {
                throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_QueryParametersPathCannotEndInTypeIdentifier("$expand", targetResourceType.FullName));
            }
            if (!flag)
            {
                return(segments);
            }
            return(null);
        }
예제 #13
0
 /// <summary>
 /// Raise the version for features used in the user's request
 /// </summary>
 /// <param name="major">The major segment of the version</param>
 /// <param name="minor">The minor segment of the version</param>
 /// <param name="config">Data service configuration instance to validate the feature version.</param>
 internal void RaiseFeatureVersion(int major, int minor, DataServiceConfiguration config)
 {
     this.maxFeatureVersion = RaiseVersion(this.maxFeatureVersion, major, minor);
     config.ValidateMaxProtocolVersion(this);
 }
 public static void InitializeService(DataServiceConfiguration config)
 {
     config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
     config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
     config.DataServiceBehavior.AcceptProjectionRequests = true;
 }
예제 #15
0
 protected virtual void CheckConfigurationConsistency(DataServiceConfiguration configuration)
 {
 }
예제 #16
0
 internal void ApplyConfiguration(DataServiceConfiguration configuration)
 {
     if (this.metadataRequiresInitialization)
     {
         this.PopulateMetadataForUserSpecifiedTypes(configuration.GetKnownTypes(), this.TypeCache, this.ChildTypesCache, this.EntitySets.Values);
         if (configuration.DataServiceBehavior.UseMetadataKeyOrderForBuiltInProviders)
         {
             foreach (ResourceSet set in this.EntitySets.Values)
             {
                 set.UseMetadataKeyOrder = true;
             }
         }
         this.CheckConfigurationConsistency(configuration);
     }
 }
예제 #17
0
 /// <summary>Gets a string with methods allowed on the target for the <paramref name="description"/>.</summary>
 /// <param name="configuration">configuration object which has the data</param>
 /// <param name="description">Description with target.</param>
 /// <returns>A string with methods allowed on the description; possibly null.</returns>
 internal static string GetAllowedMethods(DataServiceConfiguration configuration, RequestDescription description)
 {
     Debug.Assert(description != null, "description != null");
     Debug.Assert(
         description.TargetKind != RequestTargetKind.Nothing,
         "description.TargetKind != RequestTargetKind.Void - otherwise it hasn't been determined yet");
     Debug.Assert(
         description.TargetKind != RequestTargetKind.VoidServiceOperation,
         "description.TargetKind != RequestTargetKind.VoidServiceOperation - this method is only for containers");
     if (description.TargetKind == RequestTargetKind.Metadata ||
         description.TargetKind == RequestTargetKind.ServiceDirectory)
     {
         return XmlConstants.HttpMethodGet;
     }
     else if (description.TargetKind == RequestTargetKind.Batch)
     {
         return XmlConstants.HttpMethodPost;
     }
     else
     {
         int index = description.GetIndexOfTargetEntityResource();
         Debug.Assert(index >= 0 && index < description.SegmentInfos.Length, "index >=0 && index <description.SegmentInfos.Length");
         ResourceSetWrapper container = description.SegmentInfos[index].TargetContainer;
         return GetAllowedMethods(configuration, container, description);
     }
 }
예제 #18
0
        /// <summary>
        /// Gets a string representation of allowed methods on the container (with the specified target cardinality),
        /// suitable for an 'Allow' header.
        /// </summary>
        /// <param name="configuration">configuration object which has the data</param>
        /// <param name="container">Targetted container, possibly null.</param>
        /// <param name="description">Description with target.</param>
        /// <returns>A value for an 'Allow' header; null if <paramref name="container"/> is null.</returns>
        internal static string GetAllowedMethods(DataServiceConfiguration configuration, ResourceSetWrapper container, RequestDescription description)
        {
            if (container == null)
            {
                return null;
            }
            else
            {
                System.Text.StringBuilder result = new System.Text.StringBuilder();
                EntitySetRights rights = configuration.GetResourceSetRights(container.ResourceSet);
                if (description.IsSingleResult)
                {
                    AppendRight(rights, EntitySetRights.ReadSingle, XmlConstants.HttpMethodGet, result);
                    AppendRight(rights, EntitySetRights.WriteReplace, XmlConstants.HttpMethodPut, result);
                    if (description.TargetKind != RequestTargetKind.MediaResource)
                    {
                        AppendRight(rights, EntitySetRights.WriteMerge, XmlConstants.HttpMethodMerge, result);
                        AppendRight(rights, EntitySetRights.WriteDelete, XmlConstants.HttpMethodDelete, result);
                    }
                }
                else
                {
                    AppendRight(rights, EntitySetRights.ReadMultiple, XmlConstants.HttpMethodGet, result);
                    AppendRight(rights, EntitySetRights.WriteAppend, XmlConstants.HttpMethodPost, result);
                }

                return result.ToString();
            }
        }
예제 #19
0
 /// <summary>
 /// Raise the version for features used in the user's request
 /// </summary>
 /// <param name="major">The major segment of the version</param>
 /// <param name="minor">The minor segment of the version</param>
 /// <param name="config">Data service configuration instance to validate the feature version.</param>
 internal void RaiseFeatureVersion(int major, int minor, DataServiceConfiguration config)
 {
     this.maxFeatureVersion = RaiseVersion(this.maxFeatureVersion, major, minor);
     config.ValidateMaxProtocolVersion(this);
 }
예제 #20
0
 internal static string GetAllowedMethods(DataServiceConfiguration configuration, ResourceSetWrapper container, RequestDescription description)
 {
     if (container == null)
     {
         return null;
     }
     StringBuilder builder = new StringBuilder();
     EntitySetRights resourceSetRights = configuration.GetResourceSetRights(container.ResourceSet);
     if (description.IsSingleResult)
     {
         AppendRight(resourceSetRights, EntitySetRights.ReadSingle, "GET", builder);
         AppendRight(resourceSetRights, EntitySetRights.WriteReplace, "PUT", builder);
         if (description.TargetKind != RequestTargetKind.MediaResource)
         {
             AppendRight(resourceSetRights, EntitySetRights.WriteMerge, "MERGE", builder);
             AppendRight(resourceSetRights, EntitySetRights.WriteMerge, "PATCH", builder);
             AppendRight(resourceSetRights, EntitySetRights.WriteDelete, "DELETE", builder);
         }
     }
     else
     {
         AppendRight(resourceSetRights, EntitySetRights.ReadMultiple, "GET", builder);
         AppendRight(resourceSetRights, EntitySetRights.WriteAppend, "POST", builder);
     }
     return builder.ToString();
 }