SecurityCallContext Klasa
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Opisuje łańcuch wywołań wywołujących prowadzących do bieżącego wywołania metody.
public ref class SecurityCallContext sealed
public sealed class SecurityCallContext
type SecurityCallContext = class
Public NotInheritable Class SecurityCallContext
- Dziedziczenie
-
SecurityCallContext
W poniższym przykładzie kodu pokazano użycie SecurityCallContext klasy do przesłuchania kontekstu zabezpieczeń wywołań do metod ServicedComponent klasy.
// 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
Callers |
SecurityCallers Pobiera obiekt opisujący obiekt wywołujący. |
Current |
SecurityCallContext Pobiera obiekt opisujący kontekst wywołania zabezpieczeń. |
Direct |
SecurityIdentity Pobiera obiekt opisujący obiekt wywołujący bezpośredni tej metody. |
Is |
Określa, czy kontrole zabezpieczeń są włączone w bieżącym kontekście. |
Min |
|
Num |
|
Original |
Pobiera element opisujący SecurityIdentity oryginalny obiekt wywołujący. |
Equals(Object) |
Określa, czy dany obiekt jest taki sam, jak bieżący obiekt. (Odziedziczone po Object) |
Get |
Służy jako domyślna funkcja skrótu. (Odziedziczone po Object) |
Get |
Type Pobiera wartość bieżącego wystąpienia. (Odziedziczone po Object) |
Is |
Sprawdza, czy obiekt wywołujący bezpośrednio jest członkiem określonej roli. |
Is |
Sprawdza, czy określony użytkownik znajduje się w określonej roli. |
Memberwise |
Tworzy płytkią kopię bieżącego Objectelementu . (Odziedziczone po Object) |
To |
Zwraca ciąg reprezentujący bieżący obiekt. (Odziedziczone po Object) |
Produkt | Wersje |
---|---|
.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 |
Opinia o produkcie .NET
.NET to projekt typu open source. Wybierz link, aby przekazać opinię: