QueryInterceptorAttribute Classe
Definição
O QueryInterceptorAttribute em um método anota-o como um interceptador de consulta no conjunto de entidades especificado.The QueryInterceptorAttribute on a method annotates it as a query interceptor on the specified entity set.
public ref class QueryInterceptorAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=true, Inherited=true)]
public sealed class QueryInterceptorAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=true, Inherited=true)>]
type QueryInterceptorAttribute = class
inherit Attribute
Public NotInheritable Class QueryInterceptorAttribute
Inherits Attribute
- Herança
- Atributos
Exemplos
O exemplo a seguir controla o acesso ao Customers conjunto de entidades.The following example controls access to the Customers entity set. Cada um Customer só pode ver Orders associado a isso Customer .Each Customer can only see Orders associated with that Customer.
[QueryInterceptor("Orders")]
public Expression<Func<Order, bool>> FilterOrders()
{
return o => o.Customer.Name == /* Current principal name. */;
}
// Insures that the user accessing the customer(s) has the appropriate
// rights as defined in the QueryRules object to access the customer
// resource(s).
[QueryInterceptor ("Customers")]
public Expression<Func<Customer, bool>> FilterCustomers()
{
return c => c.Name == /* Current principal name. */ &&
this.CurrentDataSource.QueryRules.Contains(
rule => rule.Name == c.Name &&
rule.CustomerAllowedToQuery == true
);
}
Comentários
A autorização e a validação no nível do conjunto de entidades são implementadas por métodos anotados com o QueryInterceptorAttribute .Entity set-level authorization and validation is implemented by methods annotated with the QueryInterceptorAttribute. O WCF Data Services não implementa políticas de segurança, mas, em vez disso, fornece a infraestrutura necessária para que os desenvolvedores de serviço escrevam suas próprias regras de segurança e validação de negócios.WCF Data Servicess do not implement security policies but instead provide the infrastructure required for service developers to write their own security rules and business validation.
A validação e o controle de acesso do conjunto de entidades são habilitados por meio de operações de consulta usando a composição de consulta.Entity set access control and validation is enabled through query operations by using query composition. Para controlar o acesso baseado em entidade, implemente um conjunto de método por entidade de acordo com as seguintes regras:To control entity-based access, implement a method-per-entity set according to the following rules:
O método deve ter escopo público e ser anotado com o QueryInterceptorAttribute , levando o nome de um conjunto de entidades como um parâmetro.The method must have public scope and be annotated with the QueryInterceptorAttribute, taking the name of a entity set as a parameter.
O método não deve aceitar nenhum parâmetro.The method must accept no parameters.
O método deve retornar uma expressão do tipo Expression<Func<T, bool>> que é o filtro a ser composto para o conjunto de entidades.The method must return an expression of type Expression<Func<T, bool>> that is the filter to be composed for the entity set.
Construtores
| QueryInterceptorAttribute(String) |
Inicializa uma nova instância da classe QueryInterceptorAttribute para o conjunto de entidades especificado pelo parâmetro |
Propriedades
| EntitySetName |
Obtém nome do conjunto de entidades que contém a entidade à qual o interceptador se aplica.Gets the name of the entity set that contains the entity to which the interceptor applies. |
| TypeId |
Quando implementado em uma classe derivada, obtém um identificador exclusivo para este Attribute.When implemented in a derived class, gets a unique identifier for this Attribute. (Herdado de Attribute) |
Métodos
| Equals(Object) |
Retorna um valor que indica se essa instância é igual a um objeto especificado.Returns a value that indicates whether this instance is equal to a specified object. (Herdado de Attribute) |
| GetHashCode() |
Retorna o código hash para a instância.Returns the hash code for this instance. (Herdado de Attribute) |
| GetType() |
Obtém o Type da instância atual.Gets the Type of the current instance. (Herdado de Object) |
| IsDefaultAttribute() |
Quando substituído em uma classe derivada, indica se o valor dessa instância é o valor padrão para a classe derivada.When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Herdado de Attribute) |
| Match(Object) |
Quando substituído em uma classe derivada, retorna um valor que indica se essa instância é igual a um objeto especificado.When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Herdado de Attribute) |
| MemberwiseClone() |
Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object. (Herdado de Object) |
| ToString() |
Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object. (Herdado de Object) |
Implantações explícitas de interface
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Mapeia um conjunto de nomes para um conjunto correspondente de identificadores de expedição.Maps a set of names to a corresponding set of dispatch identifiers. (Herdado de Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Recupera as informações de tipo para um objeto, que pode ser usado para obter as informações de tipo para uma interface.Retrieves the type information for an object, which can be used to get the type information for an interface. (Herdado de Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
Retorna o número de interfaces de informações do tipo que um objeto fornece (0 ou 1).Retrieves the number of type information interfaces that an object provides (either 0 or 1). (Herdado de Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Fornece acesso a propriedades e métodos expostos por um objeto.Provides access to properties and methods exposed by an object. (Herdado de Attribute) |