This documentation is archived and is not being maintained.

SecurityCallContext Class

Describes the chain of callers leading up to the current method call.

Namespace:  System.EnterpriseServices
Assembly:  System.EnterpriseServices (in System.EnterpriseServices.dll)

public sealed class SecurityCallContext

The following code example demonstrates the use of the SecurityCallContext class to interrogate the security context of calls to the methods of a ServicedComponent class.

// Accept a constructor string.
[ConstructionEnabled]

public class EmployeeInformation : ServicedComponent
{

    // The employee's user name and salary. 
    private string accountName;
    private double salary = 0;


    // Get the employee's name. All users can call this method. 
    public string GetName ()
    {
      return(accountName);
    }


    // Set the employee's salary. Only managers can do this. 
    public void SetSalary (double ammount)
    {
        if (SecurityCallContext.CurrentCall.IsCallerInRole("Manager"))
        {
            salary = ammount;
        }
        else
        {
            throw new UnauthorizedAccessException();
        }
    }


    // Get the employee's salary. Only the employee and managers can do this. 
    public double GetSalary ()
    {
        if ( SecurityCallContext.CurrentCall.DirectCaller.AccountName == accountName ||
             SecurityCallContext.CurrentCall.IsCallerInRole("Manager") )
        {
            return(salary);
        }
        else
        {
          throw new UnauthorizedAccessException();
        }
    }


    // Use the constructor string. 
    // This method is called when the object is instantiated. 
    protected override void Construct (string constructorString)
    {
        accountName = constructorString;
    }

}
// Accept a constructor string.
[ConstructionEnabled]

public __gc class EmployeeInformation : public ServicedComponent
{
    // The employee's user name and salary.
private:
    String* accountName;
    double salary;


    // Get the employee's name. All users can call this method.
public:
    String* GetName ()
    {
      return(accountName);
    }


    // Set the employee's salary. Only managers can do this.
public:
    void SetSalary (double ammount)
    {
        if (SecurityCallContext::CurrentCall->IsCallerInRole(S"Manager"))
        {
            salary = ammount;
        }
        else
        {
            throw new UnauthorizedAccessException();
        }
    }


    // Get the employee's salary. Only the employee and managers can do this.
public:
    double GetSalary ()
    {
        if ( SecurityCallContext::CurrentCall->DirectCaller->AccountName == accountName ||
             SecurityCallContext::CurrentCall->IsCallerInRole(S"Manager") )
        {
            return(salary);
        }
        else
        {
          throw new UnauthorizedAccessException();
        }
    }


    // Use the constructor string.
    // This method is called when the object is instantiated.
protected:
    void Construct (String* constructorString)
    {
        accountName = constructorString;
    }

};

System.Object
  System.EnterpriseServices.SecurityCallContext

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: