SecurityCallContext Class

Definition

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

C#
public sealed class SecurityCallContext
Inheritance
SecurityCallContext

Examples

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.

C#
// 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;
    }
}

Properties

Callers

Gets a SecurityCallers object that describes the caller.

CurrentCall

Gets a SecurityCallContext object that describes the security call context.

DirectCaller

Gets a SecurityIdentity object that describes the direct caller of this method.

IsSecurityEnabled

Determines whether security checks are enabled in the current context.

MinAuthenticationLevel

Gets the MinAuthenticationLevel value from the ISecurityCallContext collection in COM+.

NumCallers

Gets the NumCallers value from the ISecurityCallContext collection in COM+.

OriginalCaller

Gets a SecurityIdentity that describes the original caller.

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
IsCallerInRole(String)

Verifies that the direct caller is a member of the specified role.

IsUserInRole(String, String)

Verifies that the specified user is in the specified role.

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1