다음을 통해 공유


RequiresRoleAttribute 클래스

DomainOperationEntry를 호출할 수 있는 역할 집합을 지정합니다.

네임스페이스: System.ServiceModel.DomainServices.Server
어셈블리: system.servicemodel.domainservices.server.dll의 System.ServiceModel.DomainServices.Server

사용법

‘사용 방법
Dim instance As RequiresRoleAttribute

구문

‘선언
<AttributeUsageAttribute(AttributeTargets.Class Or AttributeTargets.Method Or AttributeTargets.Property Or AttributeTargets.Field, AllowMultiple:=True, Inherited:=True)> _
Public NotInheritable Class RequiresRoleAttribute
    Inherits AuthorizationAttribute
[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Field, AllowMultiple=true, Inherited=true)] 
public sealed class RequiresRoleAttribute : AuthorizationAttribute
[AttributeUsageAttribute(AttributeTargets::Class|AttributeTargets::Method|AttributeTargets::Property|AttributeTargets::Field, AllowMultiple=true, Inherited=true)] 
public ref class RequiresRoleAttribute sealed : public AuthorizationAttribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Field, AllowMultiple=true, Inherited=true) */ 
public final class RequiresRoleAttribute extends AuthorizationAttribute
AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Field, AllowMultiple=true, Inherited=true) 
public final class RequiresRoleAttribute extends AuthorizationAttribute

예제

다음 예제에서는 GetCustomers 메서드에 RequiresRoleAttribute 특성이 적용된 도메인 서비스를 보여 줍니다.

<EnableClientAccess()>  _
Public Class AdventureWorksDomainService
    Inherits LinqToEntitiesDomainService(Of AdventureWorksLT_DataEntities)

    <RequiresRole("Managers")> _
    Public Function GetCustomers() As IQueryable(Of Customer)
        Return Me.ObjectContext.Customers
    End Function
    
    Public Function GetProducts() As IQueryable(Of Product)
        Return Me.ObjectContext.Products
    End Function

    <RequiresAuthentication()> _
    Public Function GetSalesOrderHeaders() As IQueryable(Of SalesOrderHeader)
        Return Me.ObjectContext.SalesOrderHeaders
    End Function
End Class
[EnableClientAccess()]
public class AdventureWorksDomainService : LinqToEntitiesDomainService<AdventureWorksLT_DataEntities>
{
    [RequiresRole("Managers")]
    public IQueryable<Customer> GetCustomers()
    {
        return this.ObjectContext.Customers;
    }
 
    public IQueryable<Product> GetProducts()
    {
        return this.ObjectContext.Products;
    }

    [RequiresAuthentication()]
    public IQueryable<SalesOrderHeader> GetSalesOrderHeaders()
    {
        return this.ObjectContext.SalesOrderHeaders;
    }
}

설명

도메인 메서드에 RequiresRoleAttribute를 적용하면 지정된 역할 중 하나에 속하는 인증된 사용자에게만 작업 액세스 권한이 부여됩니다. 전체 도메인 서비스 클래스에 RequiresRoleAttribute를 적용하면 지정된 역할에 속하는 인증된 사용자만 도메인 작업을 수행할 수 있게 됩니다. RequiresRoleAttribute는 사용자가 인증 기준에 맞지 않을 경우 메서드가 실행되지 못하게 합니다. 사용자가 필요한 역할의 멤버가 아닌 상태에서 도메인 작업을 호출하면 해당 작업에서 예외가 반환됩니다. 도메인 작업을 호출하기 전에 클라이언트 프로젝트에서 생성되는 User 개체의 IsInRole 메서드를 확인하면 이러한 상황을 방지할 수 있습니다.

RIA Services는 사용자를 인증해야 함을 나타내기 위해 RequiresAuthenticationAttribute도 제공합니다. AuthorizationAttribute에서 파생되는 클래스를 구현하고 IsAuthorized 메서드를 재정의하면 사용자 지정된 권한 부여 요구 사항을 제공할 수 있습니다. 자세한 내용은 How to: Create a Custom Authorization Attribute를 참조하십시오.

상속 계층

System.Object
   System.Attribute
     System.ComponentModel.DataAnnotations.AuthorizationAttribute
      System.ServiceModel.DomainServices.Server.RequiresRoleAttribute

스레드 보안

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 모든 인스턴스 멤버는 스레드로부터 안전하지 않을 수 있습니다.

플랫폼

개발 플랫폼

Windows XP Home Edition, Windows XP Professional, Windows Server 2003 , Windows Server 2008 및 Windows 2000

대상 플랫폼

Change History

참고 항목

참조

RequiresRoleAttribute 멤버
System.ServiceModel.DomainServices.Server 네임스페이스