internal static void CheckServiceOperationRights(ServiceOperationRights rights, string parameterName) { if ((rights < ServiceOperationRights.None) || (rights > (ServiceOperationRights.OverrideEntitySetRights | ServiceOperationRights.AllRead))) { 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 void CheckServiceOperationRights(OperationWrapper operation, bool singleResult) { if (operation.ResultKind != ServiceOperationResultKind.Void) { ServiceOperationRights requiredRights = singleResult ? ServiceOperationRights.ReadSingle : ServiceOperationRights.ReadMultiple; CheckServiceOperationRights(operation, requiredRights); } }
internal static void CheckServiceOperationRights(OperationWrapper operation, ServiceOperationRights requiredRights) { ServiceOperationRights serviceOperationRights = operation.ServiceOperationRights; if ((requiredRights & serviceOperationRights) == ServiceOperationRights.None) { throw DataServiceException.CreateForbidden(); } }
internal ServiceOperationRights GetServiceOperationRights(ServiceOperation serviceOperation) { ServiceOperationRights rightsForUnspecifiedServiceOperation; if (!this.serviceOperationRights.TryGetValue(serviceOperation.Name, out rightsForUnspecifiedServiceOperation)) { rightsForUnspecifiedServiceOperation = this.rightsForUnspecifiedServiceOperation; } return(rightsForUnspecifiedServiceOperation); }
public void SetServiceOperationAccessRule(string entityName, ServiceOperationRights serviceOperationRight) { if (serviceOperationRights.ContainsKey(entityName)) { serviceOperationRights[entityName] = serviceOperationRight; } else { serviceOperationRights.Add(entityName, serviceOperationRight); } }
/// <summary>Checks whether this request has the specified rights.</summary> /// <param name="operation">Operation to check.</param> /// <param name="requiredRights">Required rights.</param> /// <exception cref="DataServiceException">Thrown if <paramref name="requiredRights"/> aren't available.</exception> internal static void CheckServiceOperationRights(OperationWrapper operation, ServiceOperationRights requiredRights) { Debug.Assert(operation != null, "operation != null"); Debug.Assert(requiredRights != ServiceOperationRights.None, "requiredRights != EntitySetRights.None"); ServiceOperationRights effectiveRights = operation.ServiceOperationRights; if ((requiredRights & effectiveRights) == 0) { throw DataServiceException.CreateForbidden(); } }
public void SetServiceOperationAccessRule(string name, ServiceOperationRights rights) { this.CheckNotSealed(); if (name == null) { throw new ArgumentNullException("name"); } WebUtil.CheckServiceOperationRights(rights, "rights"); if (name == "*") { this.rightsForUnspecifiedServiceOperation = rights; } else { ServiceOperation operation; if (!this.provider.TryResolveServiceOperation(name, out operation) || (operation == null)) { throw new ArgumentException(System.Data.Services.Strings.DataServiceConfiguration_ServiceNameNotFound(name), "name"); } this.serviceOperationRights[operation.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; }
/// <summary> /// Apply the given configuration to the resource set. /// </summary> /// <param name="configuration">data service configuration instance.</param> /// <param name="provider">data service provider wrapper instance for accessibility validation.</param> public void ApplyConfiguration(DataServiceConfiguration configuration, DataServiceProviderWrapper provider) { #if DEBUG Debug.Assert(!this.isReadOnly, "Can only apply the configuration once."); #endif if (this.Kind == OperationKind.ServiceOperation) { this.serviceOperationRights = configuration.GetServiceOperationRights(this.ServiceOperation); } else { Debug.Assert(this.Kind == OperationKind.Action, "this.Kind == OperationKind.Action"); this.serviceActionRights = configuration.GetServiceActionRights(this.ServiceAction); } if ((this.Kind == OperationKind.ServiceOperation && (this.serviceOperationRights & ~ServiceOperationRights.OverrideEntitySetRights) != ServiceOperationRights.None) || (this.Kind == OperationKind.Action && this.serviceActionRights != Service.ServiceActionRights.None)) { if (this.operation.ResourceSet != null) { // If the result type is an entity type, we need to make sure its entity set is visible. // If the entity set is hidden, we need to make sure that we throw an exception. this.resourceSet = provider.TryResolveResourceSet(this.operation.ResourceSet.Name); if (this.resourceSet == null) { throw new InvalidOperationException(Strings.OperationWrapper_OperationResourceSetNotVisible(this.Name, this.operation.ResourceSet.Name)); } } else if (this.ResultSetPathExpression != null) { this.ResultSetPathExpression.InitializePathSegments(provider); } } #if DEBUG this.isReadOnly = true; #endif }
/// <summary> /// Apply the given configuration to the resource set. /// </summary> /// <param name="configuration">data service configuration instance.</param> /// <param name="provider">data service provider wrapper instance for accessibility validation.</param> public void ApplyConfiguration(DataServiceConfiguration configuration, DataServiceProviderWrapper provider) { #if DEBUG Debug.Assert(!this.isReadOnly, "Can only apply the configuration once."); #endif this.rights = configuration.GetServiceOperationRights(this.serviceOperation); if ((this.rights & ~ServiceOperationRights.OverrideEntitySetRights) != ServiceOperationRights.None) { if (this.serviceOperation.ResourceSet != null) { // If the result type is an entity type, we need to make sure its entity set is visible. // If the entity set is hidden, we need to make sure that we throw an exception. this.resourceSet = provider.TryResolveResourceSet(this.serviceOperation.ResourceSet.Name); if (this.resourceSet == null) { throw new InvalidOperationException(Strings.BaseServiceProvider_ServiceOperationTypeHasNoContainer(this.serviceOperation.Name, this.serviceOperation.ResultType.FullName)); } } } #if DEBUG this.isReadOnly = true; #endif }
public void SetServiceOperationAccessRule(string name, ServiceOperationRights rights) { ServiceOperationAccessRules.Add(name, rights); }
public void SetServiceOperationAccessRule(string name, ServiceOperationRights rights) { throw new NotImplementedException(); }
internal ServiceOperationRights GetServiceOperationRights(ServiceOperation serviceOperation) { ServiceOperationRights rightsForUnspecifiedServiceOperation; if (!this.serviceOperationRights.TryGetValue(serviceOperation.Name, out rightsForUnspecifiedServiceOperation)) { rightsForUnspecifiedServiceOperation = this.rightsForUnspecifiedServiceOperation; } return rightsForUnspecifiedServiceOperation; }
public void SetServiceOperationAccessRule(string name, ServiceOperationRights rights) { Contract.Requires(name != null); }
public void SetServiceOperationAccessRule (string name, ServiceOperationRights rights) { throw new NotImplementedException (); }
/// <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; }
/// <summary>Sets the permissions for the specified service operation.</summary> /// <param name="name">The name of the service operation for which to set permissions.</param> /// <param name="rights">The access rights to be granted to this resource, passed as a <see cref="T:Microsoft.OData.Service.ServiceOperationRights" /> value.</param> public void SetServiceOperationAccessRule(string name, ServiceOperationRights rights) { this.CheckNotSealed(); if (name == null) { throw new ArgumentNullException("name"); } WebUtil.CheckServiceOperationRights(rights, "rights"); if (name == "*") { this.rightsForUnspecifiedServiceOperation = rights; } else { ServiceOperation serviceOperation; if (!this.provider.TryResolveServiceOperation(name, out serviceOperation) || serviceOperation == null) { throw new ArgumentException(Strings.DataServiceConfiguration_ServiceNameNotFound(name), "name"); } this.serviceOperationRights[serviceOperation.Name] = rights; } }
public IQueryable <int> GetServiceOperationAccessRule(string entityName) { ServiceOperationRights serviceOperationRights = configurationSettings.GetServiceOperationAccessRule(entityName); return(new int[] { (int)serviceOperationRights }.AsQueryable()); }