internal static void CheckResourceContainerRights(EntitySetRights rights, string parameterName) { if ((rights < EntitySetRights.None) || (rights > EntitySetRights.All)) { throw System.Data.Services.Error.ArgumentOutOfRange(parameterName); } }
/// <summary> /// Initializes a new <see cref="DataServiceConfiguration"/> with /// the specified <paramref name="provider"/>. /// </summary> /// <param name="provider">Non-null provider for this configuration.</param> internal DataServiceConfiguration(IDataServiceMetadataProvider provider) { WebUtil.CheckArgumentNull(provider, "provider"); this.provider = provider; this.resourceRights = new Dictionary <string, EntitySetRights>(EqualityComparer <string> .Default); this.serviceOperationRights = new Dictionary <string, ServiceOperationRights>(EqualityComparer <string> .Default); this.serviceActionRights = new Dictionary <string, ServiceActionRights>(EqualityComparer <string> .Default); this.pageSizes = new Dictionary <string, int>(EqualityComparer <string> .Default); this.rightsForUnspecifiedResourceContainer = EntitySetRights.None; this.rightsForUnspecifiedServiceOperation = ServiceOperationRights.None; this.rightsForUnspecifiedServiceAction = ServiceActionRights.None; this.knownTypes = new List <Type>(); this.maxBatchCount = Int32.MaxValue; this.maxChangeSetCount = Int32.MaxValue; this.maxExpandCount = Int32.MaxValue; this.maxExpandDepth = Int32.MaxValue; this.maxResultsPerCollection = Int32.MaxValue; this.maxObjectCountOnInsert = Int32.MaxValue; this.accessEnabledResourceTypes = new HashSet <string>(EqualityComparer <string> .Default); this.dataServiceBehavior = new DataServiceBehavior(); // default value is true since in V1, we always did the type conversion // and this configuration settings was introduced in V2 this.typeConversion = true; }
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()); }
/// <summary> /// Apply the given configuration to the resource set. /// </summary> /// <param name="configuration">data service configuration instance.</param> public void ApplyConfiguration(DataServiceConfiguration configuration) { #if DEBUG Debug.Assert(!this.isReadOnly, "Can only apply the configuration once."); #endif // Set entity set rights this.rights = configuration.GetResourceSetRights(this.resourceSet); // Set page size this.pageSize = configuration.GetResourceSetPageSize(this.resourceSet); if (this.pageSize < 0) { throw new DataServiceException(500, Strings.DataService_SDP_PageSizeMustbeNonNegative(this.pageSize, this.Name)); } // Add QueryInterceptors this.readAuthorizationMethods = configuration.GetReadAuthorizationMethods(this.resourceSet); // Add ChangeInterceptors this.writeAuthorizationMethods = configuration.GetWriteAuthorizationMethods(this.resourceSet); #if DEBUG this.isReadOnly = true; #endif }
internal static void CheckResourceRights(ResourceSetWrapper container, EntitySetRights requiredRights) { if ((requiredRights & container.Rights) == EntitySetRights.None) { throw DataServiceException.CreateForbidden(); } }
/// <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); } 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.HttpMethodPatch, 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()); }
/// <summary>Checks whether this request has the specified reading rights.</summary> /// <param name="container">Container to check.</param> /// <param name="singleResult">Whether a single or multiple resources are requested.</param> /// <exception cref="DataServiceException">Thrown if <paramref name="singleResult"/> aren't available.</exception> internal static void CheckResourceRightsForRead(ResourceSetWrapper container, bool singleResult) { Debug.Assert(container != null, "container != null"); EntitySetRights requiredRights = singleResult ? EntitySetRights.ReadSingle : EntitySetRights.ReadMultiple; CheckResourceRights(container, requiredRights); }
public override KeyExpressions GetAllExistingKeysOfType(ResourceContainer resourceContainer, ResourceType resourceType) { if (!DataGenerator.Done) { return(DataGenerator.GetAllGeneratedKeys(resourceContainer, resourceType)); } bool rightsChanged = false; EntitySetRights oldRights = this.DataService.ConfigSettings.GetEntitySetAccessRule(resourceContainer.Name); if ((EntitySetRights.ReadMultiple & oldRights) == 0) { rightsChanged = true; this.DataService.ConfigSettings.SetEntitySetAccessRule(resourceContainer.Name, EntitySetRights.All); } KeyExpressions keys = SocketExceptionHandler.Execute <KeyExpressions>( () => GetAllExistingKeysBase(resourceContainer)); if (rightsChanged) { this.DataService.ConfigSettings.SetEntitySetAccessRule(resourceContainer.Name, oldRights); } if (resourceType == null) { return(keys); } return(new KeyExpressions(keys.Where(k => k.ResourceType.Equals(resourceType)))); }
internal EntitySetRights GetResourceSetRights(ResourceSet container) { EntitySetRights rightsForUnspecifiedResourceContainer; if (!this.resourceRights.TryGetValue(container.Name, out rightsForUnspecifiedResourceContainer)) { rightsForUnspecifiedResourceContainer = this.rightsForUnspecifiedResourceContainer; } return(rightsForUnspecifiedResourceContainer); }
/// <summary>Checks whether this request has the specified rights.</summary> /// <param name="container">Container to check.</param> /// <param name="requiredRights">Required rights.</param> /// <exception cref="DataServiceException">Thrown if <paramref name="requiredRights"/> aren't available.</exception> internal static void CheckResourceRights(ResourceSetWrapper container, EntitySetRights requiredRights) { Debug.Assert(container != null, "container != null"); Debug.Assert(requiredRights != EntitySetRights.None, "requiredRights != EntitySetRights.None"); if ((requiredRights & container.Rights) == 0) { throw DataServiceException.CreateForbidden(); } }
private static void AppendRight(EntitySetRights entitySetRights, EntitySetRights test, string name, StringBuilder builder) { if ((entitySetRights & test) != EntitySetRights.None) { if (builder.Length > 0) { builder.Append(", "); } builder.Append(name); } }
public void SetEntitySetAccessRule(string entityName, EntitySetRights entitySetRight) { if (entitySetRights.ContainsKey(entityName)) { entitySetRights[entityName] = entitySetRight; } else { entitySetRights.Add(entityName, entitySetRight); } }
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); }
/// <summary> /// Creates the wrapper from the given resource set for use in unit tests. /// </summary> /// <param name="resourceSet">resource set instance whose wrapper needs to get created.</param> /// <param name="rights">Optional rights for the set. Defaults to None.</param> /// <returns>Wrapper for the given resource set.</returns> internal static ResourceSetWrapper CreateForTests(ResourceSet resourceSet, EntitySetRights rights = EntitySetRights.None) { var resourceSetWrapper = new ResourceSetWrapper(resourceSet) { rights = rights, #if DEBUG isReadOnly = true #endif }; return(resourceSetWrapper); }
/// <summary> /// Appends the <paramref name="name"/> of a right if the <paramref name="test"/> right is enabled /// on <paramref name="entitySetRights"/>. /// </summary> /// <param name="entitySetRights">Rights to be checked.</param> /// <param name="test">Right being looked for.</param> /// <param name="name">Name of right to append.</param> /// <param name="builder">Comma-separated list of right names to append to.</param> private static void AppendRight(EntitySetRights entitySetRights, EntitySetRights test, string name, System.Text.StringBuilder builder) { Debug.Assert(builder != null, "builder != null"); if (0 != (entitySetRights & test)) { if (builder.Length > 0) { builder.Append(", "); } builder.Append(name); } }
public void SetEntitySetAccessRule(string name, EntitySetRights rights) { this.CheckNotSealed(); if (name == null) { throw System.Data.Services.Error.ArgumentNull("name"); } WebUtil.CheckResourceContainerRights(rights, "rights"); if (name == "*") { this.rightsForUnspecifiedResourceContainer = rights; } else { ResourceSet set; if (!this.provider.TryResolveResourceSet(name, out set) || (set == null)) { throw new ArgumentException(System.Data.Services.Strings.DataServiceConfiguration_ResourceSetNameNotFound(name), "name"); } this.resourceRights[set.Name] = rights; } }
internal DataServiceConfiguration(IDataServiceMetadataProvider provider) { this.provider = provider; this.resourceRights = new Dictionary <string, EntitySetRights>(EqualityComparer <string> .Default); this.serviceOperationRights = new Dictionary <string, ServiceOperationRights>(EqualityComparer <string> .Default); this.serviceActionRights = new Dictionary <string, ServiceActionRights>(EqualityComparer <string> .Default); this.pageSizes = new Dictionary <string, int>(EqualityComparer <string> .Default); this.rightsForUnspecifiedResourceContainer = EntitySetRights.None; this.rightsForUnspecifiedServiceOperation = ServiceOperationRights.None; this.rightsForUnspecifiedServiceAction = ServiceActionRights.None; this.knownTypes = new List <Type>(); this.maxBatchCount = 0x7fffffff; this.maxChangeSetCount = 0x7fffffff; this.maxExpandCount = 0x7fffffff; this.maxExpandDepth = 0x7fffffff; this.maxResultsPerCollection = 0x7fffffff; this.maxObjectCountOnInsert = 0x7fffffff; this.readAuthorizationMethods = new Dictionary <string, List <MethodInfo> >(EqualityComparer <string> .Default); this.writeAuthorizationMethods = new Dictionary <string, List <MethodInfo> >(EqualityComparer <string> .Default); this.accessEnabledResourceTypes = new HashSet <string>(EqualityComparer <string> .Default); this.dataServiceBehavior = new System.Data.Services.DataServiceBehavior(); this.typeConversion = true; }
internal DataServiceConfiguration(IDataServiceMetadataProvider provider) { this.provider = provider; this.resourceRights = new Dictionary<string, EntitySetRights>(EqualityComparer<string>.Default); this.serviceOperationRights = new Dictionary<string, ServiceOperationRights>(EqualityComparer<string>.Default); this.serviceActionRights = new Dictionary<string, ServiceActionRights>(EqualityComparer<string>.Default); this.pageSizes = new Dictionary<string, int>(EqualityComparer<string>.Default); this.rightsForUnspecifiedResourceContainer = EntitySetRights.None; this.rightsForUnspecifiedServiceOperation = ServiceOperationRights.None; this.rightsForUnspecifiedServiceAction = ServiceActionRights.None; this.knownTypes = new List<Type>(); this.maxBatchCount = 0x7fffffff; this.maxChangeSetCount = 0x7fffffff; this.maxExpandCount = 0x7fffffff; this.maxExpandDepth = 0x7fffffff; this.maxResultsPerCollection = 0x7fffffff; this.maxObjectCountOnInsert = 0x7fffffff; this.readAuthorizationMethods = new Dictionary<string, List<MethodInfo>>(EqualityComparer<string>.Default); this.writeAuthorizationMethods = new Dictionary<string, List<MethodInfo>>(EqualityComparer<string>.Default); this.accessEnabledResourceTypes = new HashSet<string>(EqualityComparer<string>.Default); this.dataServiceBehavior = new System.Data.Services.DataServiceBehavior(); this.typeConversion = true; }
public void SetEntitySetAccessRule(string name, EntitySetRights rights) { throw new NotImplementedException(); }
public void SetEntitySetAccessRule(string name, EntitySetRights rights) { Contract.Requires(name != null); }
/// <summary> /// Initializes a new <see cref="DataServiceConfiguration"/> with /// the specified <paramref name="provider"/>. /// </summary> /// <param name="provider">Non-null provider for this configuration.</param> internal DataServiceConfiguration(IDataServiceMetadataProvider provider) { WebUtil.CheckArgumentNull(provider, "provider"); this.provider = provider; this.resourceRights = new Dictionary<string, EntitySetRights>(EqualityComparer<string>.Default); this.serviceOperationRights = new Dictionary<string, ServiceOperationRights>(EqualityComparer<string>.Default); this.serviceActionRights = new Dictionary<string, ServiceActionRights>(EqualityComparer<string>.Default); this.pageSizes = new Dictionary<string, int>(EqualityComparer<string>.Default); this.rightsForUnspecifiedResourceContainer = EntitySetRights.None; this.rightsForUnspecifiedServiceOperation = ServiceOperationRights.None; this.rightsForUnspecifiedServiceAction = ServiceActionRights.None; this.knownTypes = new List<Type>(); this.maxBatchCount = Int32.MaxValue; this.maxChangeSetCount = Int32.MaxValue; this.maxExpandCount = Int32.MaxValue; this.maxExpandDepth = Int32.MaxValue; this.maxResultsPerCollection = Int32.MaxValue; this.maxObjectCountOnInsert = Int32.MaxValue; this.accessEnabledResourceTypes = new HashSet<string>(EqualityComparer<string>.Default); this.dataServiceBehavior = new DataServiceBehavior(); // default value is true since in V1, we always did the type conversion // and this configuration settings was introduced in V2 this.typeConversion = true; }
public void SetEntitySetAccessRule (string name, EntitySetRights rights) { throw new NotImplementedException (); }
public IQueryable <int> GetEntitySetAccessRule(string entityName) { EntitySetRights entitySetRights = configurationSettings.GetEntitySetAccessRule(entityName); return(new int[] { (int)entitySetRights }.AsQueryable()); }
/// <summary> /// Creates the wrapper from the given resource set for use in unit tests. /// </summary> /// <param name="resourceSet">resource set instance whose wrapper needs to get created.</param> /// <param name="rights">Optional rights for the set. Defaults to None.</param> /// <returns>Wrapper for the given resource set.</returns> internal static ResourceSetWrapper CreateForTests(ResourceSet resourceSet, EntitySetRights rights = EntitySetRights.None) { var resourceSetWrapper = new ResourceSetWrapper(resourceSet) { rights = rights, #if DEBUG isReadOnly = true #endif }; return resourceSetWrapper; }
public void SetEntitySetAccessRule(string name, EntitySetRights rights) { EntityAccessRules.Add(name, rights); }
/// <summary>Sets the permissions for the specified entity set resource.</summary> /// <param name="name">The Name of the entity set for which to set permissions.</param> /// <param name="rights">The Access rights to be granted to this resource, passed as an <see cref="T:Microsoft.OData.Service.EntitySetRights" /> value.</param> public void SetEntitySetAccessRule(string name, EntitySetRights rights) { this.CheckNotSealed(); if (name == null) { throw Error.ArgumentNull("name"); } WebUtil.CheckResourceContainerRights(rights, "rights"); if (name == "*") { this.rightsForUnspecifiedResourceContainer = rights; } else { ResourceSet container; if (!this.provider.TryResolveResourceSet(name, out container) || container == null) { throw new ArgumentException(Strings.DataServiceConfiguration_ResourceSetNameNotFound(name), "name"); } this.resourceRights[container.Name] = rights; } }
internal EntitySetRights GetResourceSetRights(ResourceSet container) { EntitySetRights rightsForUnspecifiedResourceContainer; if (!this.resourceRights.TryGetValue(container.Name, out rightsForUnspecifiedResourceContainer)) { rightsForUnspecifiedResourceContainer = this.rightsForUnspecifiedResourceContainer; } return rightsForUnspecifiedResourceContainer; }