internal static void CheckServiceActionRights(ServiceActionRights rights, string parameterName) { if ((rights < ServiceActionRights.None) || (rights > ServiceActionRights.Invoke)) { 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 ServiceActionRights GetServiceActionRights(ServiceAction serviceAction) { ServiceActionRights rightsForUnspecifiedServiceAction; if (!this.serviceActionRights.TryGetValue(serviceAction.Name, out rightsForUnspecifiedServiceAction)) { rightsForUnspecifiedServiceAction = this.rightsForUnspecifiedServiceAction; } return(rightsForUnspecifiedServiceAction); }
public void SetServiceActionAccessRule(string name, ServiceActionRights rights) { this.CheckNotSealed(); WebUtil.CheckStringArgumentNullOrEmpty(name, "name"); WebUtil.CheckServiceActionRights(rights, "rights"); if (name == "*") { this.rightsForUnspecifiedServiceAction = rights; } else { this.serviceActionRights[name] = rights; } }
/// <summary>Sets the permissions for the specified service action.</summary> /// <param name="name">The name of the service action for which to set permissions.</param> /// <param name="rights">The access rights to be granted to this action, passed as a <see cref="T:Microsoft.OData.Service.ServiceActionRights" /> value.</param> public void SetServiceActionAccessRule(string name, ServiceActionRights rights) { this.CheckNotSealed(); WebUtil.CheckStringArgumentNullOrEmpty(name, "name"); WebUtil.CheckServiceActionRights(rights, "rights"); if (name == "*") { this.rightsForUnspecifiedServiceAction = rights; } else { // We initialize the service configuration before the action provider can be // loaded. We will not validate the service action names to make sure they // actually exist in the action provider. this.serviceActionRights[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> /// 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 ServiceActionRights GetServiceActionRights(ServiceAction serviceAction) { ServiceActionRights rightsForUnspecifiedServiceAction; if (!this.serviceActionRights.TryGetValue(serviceAction.Name, out rightsForUnspecifiedServiceAction)) { rightsForUnspecifiedServiceAction = this.rightsForUnspecifiedServiceAction; } return rightsForUnspecifiedServiceAction; }