SecurityCallContext Kelas
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menjelaskan rantai penelepon menjelang panggilan metode saat ini.
public ref class SecurityCallContext sealed
public sealed class SecurityCallContext
type SecurityCallContext = class
Public NotInheritable Class SecurityCallContext
- Warisan
-
SecurityCallContext
Contoh
Contoh kode berikut menunjukkan penggunaan SecurityCallContext kelas untuk menginterogasi konteks keamanan panggilan ke metode ServicedComponent kelas.
// Accept a constructor string.
[ConstructionEnabled]
public ref class EmployeeInformation: public ServicedComponent
{
private:
// The employee's user name and salary.
String^ accountName;
double salary;
public:
// Get the employee's name. All users can call this method.
String^ GetName()
{
return (accountName);
}
// Set the employee's salary. Only managers can do this.
void SetSalary( double ammount )
{
if ( SecurityCallContext::CurrentCall->IsCallerInRole( "Manager" ) )
{
salary = ammount;
}
else
{
throw gcnew UnauthorizedAccessException;
}
}
// Get the employee's salary. Only the employee and managers can do this.
double GetSalary()
{
if ( SecurityCallContext::CurrentCall->DirectCaller->AccountName == accountName || SecurityCallContext::CurrentCall->IsCallerInRole( "Manager" ) )
{
return (salary);
}
else
{
throw gcnew UnauthorizedAccessException;
}
}
protected:
// Use the constructor string.
// This method is called when the object is instantiated.
virtual void Construct( String^ constructorString ) override
{
accountName = constructorString;
}
};
// 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 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
' 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
End Class
Properti
Callers |
SecurityCallers Mendapatkan objek yang menjelaskan pemanggil. |
CurrentCall |
SecurityCallContext Mendapatkan objek yang menjelaskan konteks panggilan keamanan. |
DirectCaller |
SecurityIdentity Mendapatkan objek yang menjelaskan pemanggil langsung dari metode ini. |
IsSecurityEnabled |
Menentukan apakah pemeriksaan keamanan diaktifkan dalam konteks saat ini. |
MinAuthenticationLevel |
|
NumCallers |
|
OriginalCaller |
Mendapatkan yang SecurityIdentity menggambarkan pemanggil asli. |
Metode
Equals(Object) |
Menentukan apakah objek yang ditentukan sama dengan objek saat ini. (Diperoleh dari Object) |
GetHashCode() |
Berfungsi sebagai fungsi hash default. (Diperoleh dari Object) |
GetType() |
Mendapatkan dari instans Type saat ini. (Diperoleh dari Object) |
IsCallerInRole(String) |
Memverifikasi bahwa penelepon langsung adalah anggota peran yang ditentukan. |
IsUserInRole(String, String) |
Memverifikasi bahwa pengguna yang ditentukan berada dalam peran yang ditentukan. |
MemberwiseClone() |
Membuat salinan dangkal dari saat ini Object. (Diperoleh dari Object) |
ToString() |
Mengembalikan string yang mewakili objek saat ini. (Diperoleh dari Object) |