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)

'Declaration
Public NotInheritable Class SecurityCallContext
'Usage
Dim instance As SecurityCallContext

public final class SecurityCallContext
public final class SecurityCallContext
Not applicable.

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
        Else
            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
        Else
            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

// Accept a constructor string.
/** @attribute ConstructionEnabled()
 */
public class EmployeeInformation extends 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;
	} //GetName

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

	// Get the employee's salary. Only the employee and managers can do this.
	public double GetSalary() throws System.UnauthorizedAccessException
	{
		if (SecurityCallContext.get_CurrentCall().get_DirectCaller().
			get_AccountName().Equals(accountName) 
			|| SecurityCallContext.get_CurrentCall().
			IsCallerInRole("Manager")) {
			return salary;
		}
		else {
			throw new UnauthorizedAccessException();
		}
	} //GetSalary

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

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 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

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