Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
SecurityCallContext Class
Collapse the table of content
Expand the table of content

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 NotInheritable Class SecurityCallContext

The SecurityCallContext type exposes the following members.

Public propertyCallersGets a SecurityCallers object that describes the caller.
Public propertyStatic memberCurrentCallGets a SecurityCallContext object that describes the security call context.
Public propertyDirectCallerGets a SecurityIdentity object that describes the direct caller of this method.
Public propertyIsSecurityEnabledDetermines whether security checks are enabled in the current context.
Public propertyMinAuthenticationLevelGets the MinAuthenticationLevel value from the ISecurityCallContext collection in COM+.
Public propertyNumCallersGets the NumCallers value from the ISecurityCallContext collection in COM+.
Public propertyOriginalCallerGets a SecurityIdentity that describes the original caller.

Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodIsCallerInRoleVerifies that the direct caller is a member of the specified role.
Public methodIsUserInRoleVerifies that the specified user is in the specified role.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

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

    Inherits ServicedComponent

    ' The employee's user name and salary. 
    Private accountName As String 
    Private salary As Double = 0

    ' Get the employee's name. All users can call this method. 
    Public Function GetName() As String  
        Return accountName

    End Function 'GetName

    ' Set the employee's salary. Only managers can do this. 
    Public Sub SetSalary(ByVal ammount As Double) 
        If SecurityCallContext.CurrentCall.IsCallerInRole("Manager") Then
            salary = ammount
            Throw New UnauthorizedAccessException()
        End If 

    End Sub 'SetSalary

    ' Get the employee's salary. Only the employee and managers can do this. 
    Public Function GetSalary() As Double  
        If SecurityCallContext.CurrentCall.DirectCaller.AccountName = accountName OrElse SecurityCallContext.CurrentCall.IsCallerInRole("Manager") Then 
            Return salary
            Throw New UnauthorizedAccessException()
        End If 

    End Function 'GetSalary

    ' Use the constructor string. 
    ' This method is called when the object is instantiated. 
    Protected Overrides Sub Construct(ByVal constructorString As String) 
        accountName = constructorString

    End Sub 'Construct

End Class 'EmployeeInformation

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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