ResourcePermissionBase Clase

Definición

Advertencia: Obsoleto

Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}

Permite el control de los permisos de seguridad de acceso del código.Allows control of code access security permissions.

public ref class ResourcePermissionBase abstract : System::Security::CodeAccessPermission, System::Security::Permissions::IUnrestrictedPermission
public abstract class ResourcePermissionBase : System.Security.CodeAccessPermission, System.Security.Permissions.IUnrestrictedPermission
[System.Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public abstract class ResourcePermissionBase : System.Security.CodeAccessPermission, System.Security.Permissions.IUnrestrictedPermission
[System.Serializable]
public abstract class ResourcePermissionBase : System.Security.CodeAccessPermission, System.Security.Permissions.IUnrestrictedPermission
type ResourcePermissionBase = class
    inherit CodeAccessPermission
    interface IUnrestrictedPermission
[<System.Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
type ResourcePermissionBase = class
    inherit CodeAccessPermission
    interface IUnrestrictedPermission
[<System.Serializable>]
type ResourcePermissionBase = class
    inherit CodeAccessPermission
    interface IUnrestrictedPermission
Public MustInherit Class ResourcePermissionBase
Inherits CodeAccessPermission
Implements IUnrestrictedPermission
Herencia
ResourcePermissionBase
Derivado
Atributos
Implementaciones

Ejemplos

En el ejemplo siguiente se hereda de la ResourcePermissionBase clase.The following example inherits from the ResourcePermissionBase class. se implementan cuatro tipos de constructores.4 kinds of constructors are implemented. En el ejemplo también se proporciona una implementación de una clase denominada MailslotPermissionEntry .The example also provides an implementation of a class called MailslotPermissionEntry. La PermissionAccessType propiedad se establece de forma privada en el tipo de MailslotPermissionEntry .The PermissionAccessType property is then privately set to the type of MailslotPermissionEntry. La TagNames propiedad está establecida de forma privada en "Name" y "Machine".The TagNames property is set privately to "Name" and "Machine".

#using <System.dll>

using namespace System;
using namespace System::Security::Permissions;
using namespace System::Collections;

[Flags]

public enum class MailslotPermissionAccess
{
   None = 0,
   Send = 1 << 1,
   Receive = 1 << 2 | MailslotPermissionAccess::Send
};


[Serializable]
public ref class MailslotPermissionEntry
{
private:
   String^ name;
   String^ machineName;
   MailslotPermissionAccess permissionAccess;

internal:
   MailslotPermissionEntry( ResourcePermissionBaseEntry^ baseEntry )
   {
      this->permissionAccess = (MailslotPermissionAccess)baseEntry->PermissionAccess;
      this->name = baseEntry->PermissionAccessPath[ 0 ]->ToString();
      this->machineName = baseEntry->PermissionAccessPath[ 1 ]->ToString();
   }

   ResourcePermissionBaseEntry^ GetBaseEntry()
   {
      array<String^>^newStrings = {this->Name,this->MachineName};
      ResourcePermissionBaseEntry^ baseEntry = gcnew ResourcePermissionBaseEntry( (int)(this->PermissionAccess),newStrings );
      return baseEntry;
   }

public:
   MailslotPermissionEntry( MailslotPermissionAccess permissionAccess, String^ name, String^ machineName )
   {
      this->permissionAccess = permissionAccess;
      this->name = name;
      this->machineName = machineName;
   }

   property String^ Name 
   {
      String^ get()
      {
         return this->name;
      }
   }

   property String^ MachineName 
   {
      String^ get()
      {
         return this->machineName;
      }
   }

   property MailslotPermissionAccess PermissionAccess 
   {
      MailslotPermissionAccess get()
      {
         return this->permissionAccess;
      }
   }
};


[Serializable]
public ref class MailslotPermission: public ResourcePermissionBase
{
private:
   ArrayList^ innerCollection;
   void SetNames()
   {
      this->PermissionAccessType = MailslotPermissionAccess::typeid;
      array<String^>^newStrings = {"Name","Machine"};
      this->TagNames = newStrings;
   }


internal:
   void AddPermissionAccess( MailslotPermissionEntry^ entry )
   {
      ResourcePermissionBase::AddPermissionAccess( entry->GetBaseEntry() );
   }

   void Clear()
   {
      ResourcePermissionBase::Clear();
   }

   void RemovePermissionAccess( MailslotPermissionEntry^ entry )
   {
      ResourcePermissionBase::RemovePermissionAccess( entry->GetBaseEntry() );
   }


public:
   MailslotPermission()
   {
      SetNames();
   }

   MailslotPermission( PermissionState state )
      : ResourcePermissionBase( state )
   {
      SetNames();
   }

   MailslotPermission( MailslotPermissionAccess permissionAccess, String^ name, String^ machineName )
   {
      SetNames();
      this->AddPermissionAccess( gcnew MailslotPermissionEntry( permissionAccess,name,machineName ) );
   }

   MailslotPermission( array<MailslotPermissionEntry^>^permissionAccessEntries )
   {
      SetNames();
      if ( permissionAccessEntries == nullptr )
            throw gcnew ArgumentNullException( "permissionAccessEntries" );

      for ( int index = 0; index < permissionAccessEntries->Length; ++index )
         this->AddPermissionAccess( permissionAccessEntries[ index ] );
   }

   property ArrayList^ PermissionEntries 
   {
      ArrayList^ get()
      {
         if ( this->innerCollection == nullptr )
                  this->innerCollection = gcnew ArrayList;

         this->innerCollection->InsertRange( 0, safe_cast<ICollection^>(ResourcePermissionBase::GetPermissionEntries()) );
         return this->innerCollection;
      }
   }
};
using System;
using System.Security.Permissions;
using System.Collections;

[Serializable()]
public class MailslotPermission: ResourcePermissionBase
{

    private ArrayList innerCollection;

    public MailslotPermission()
    {
        SetNames();
    }

    public MailslotPermission(PermissionState state):base(state)
    {
        SetNames();
    }

    public MailslotPermission(MailslotPermissionAccess permissionAccess, string name, string machineName)
    {
        SetNames();
        this.AddPermissionAccess(new MailslotPermissionEntry(permissionAccess, name, machineName));
    }

    public MailslotPermission(MailslotPermissionEntry[] permissionAccessEntries)
    {
        SetNames();
        if (permissionAccessEntries == null)
            throw new ArgumentNullException("permissionAccessEntries");

        for (int index = 0; index < permissionAccessEntries.Length; ++index)
            this.AddPermissionAccess(permissionAccessEntries[index]);
    }

    public ArrayList PermissionEntries
    {
        get
        {
            if (this.innerCollection == null)
                this.innerCollection = new ArrayList();
            this.innerCollection.InsertRange(0,base.GetPermissionEntries());

            return this.innerCollection;
        }
    }

    internal void AddPermissionAccess(MailslotPermissionEntry entry)
    {
        base.AddPermissionAccess(entry.GetBaseEntry());
    }

    internal new void Clear()
    {
        base.Clear();
    }

    internal void RemovePermissionAccess(MailslotPermissionEntry entry)
    {
        base.RemovePermissionAccess(entry.GetBaseEntry());
    }

    private void SetNames()
    {
        this.PermissionAccessType = typeof(MailslotPermissionAccess);
        this.TagNames = new string[]{"Name","Machine"};
    }
}

[Flags]
public enum MailslotPermissionAccess
{
    None = 0,
    Send = 1 << 1,
    Receive = 1 << 2 | Send,
}

[Serializable()]
public class MailslotPermissionEntry
{
    private string name;
    private string machineName;
    private MailslotPermissionAccess permissionAccess;

    public MailslotPermissionEntry(MailslotPermissionAccess permissionAccess, string name, string machineName)
    {
        this.permissionAccess = permissionAccess;
        this.name = name;
        this.machineName = machineName;
    }

    internal MailslotPermissionEntry(ResourcePermissionBaseEntry baseEntry)
    {
        this.permissionAccess = (MailslotPermissionAccess)baseEntry.PermissionAccess;
        this.name = baseEntry.PermissionAccessPath[0];
        this.machineName = baseEntry.PermissionAccessPath[1];
    }

    public string Name
    {
        get
        {
            return this.name;
        }
    }

    public string MachineName
    {
        get
        {
            return this.machineName;
        }
    }

    public MailslotPermissionAccess PermissionAccess
    {
        get
        {
            return this.permissionAccess;
        }
    }

    internal ResourcePermissionBaseEntry GetBaseEntry()
    {
        ResourcePermissionBaseEntry baseEntry = new ResourcePermissionBaseEntry((int)this.PermissionAccess, new string[] {this.Name,this.MachineName});
        return baseEntry;
    }
}
Imports System.Security.Permissions
Imports System.Collections

<Serializable()> Public Class MailslotPermission
    Inherits ResourcePermissionBase

    Private innerCollection As ArrayList


    Public Sub New()
        SetNames()
    End Sub


    Public Sub New(ByVal state As PermissionState)
        MyBase.New(state)
        SetNames()
    End Sub


    Public Sub New(ByVal permissionAccess As MailslotPermissionAccess, ByVal name As String, ByVal machineName1 As String)
        SetNames()
        Me.AddPermissionAccess(New MailslotPermissionEntry(permissionAccess, name, machineName1))
    End Sub


    Public Sub New(ByVal permissionAccessEntries() As MailslotPermissionEntry)
        SetNames()
        If permissionAccessEntries Is Nothing Then
            Throw New ArgumentNullException("permissionAccessEntries")
        End If
        Dim index As Integer

        While index < permissionAccessEntries.Length
            Me.AddPermissionAccess(permissionAccessEntries(index))
        End While
    End Sub

    Public ReadOnly Property PermissionEntries() As ArrayList
        Get
            If Me.innerCollection Is Nothing Then
                Me.innerCollection = New ArrayList()
            End If
            Me.innerCollection.InsertRange(0, MyBase.GetPermissionEntries())

            Return Me.innerCollection
        End Get
    End Property


    Friend Overloads Sub AddPermissionAccess(ByVal entry As MailslotPermissionEntry)
        MyBase.AddPermissionAccess(entry.GetBaseEntry())
    End Sub


    Friend Shadows Sub Clear()
        MyBase.Clear()
    End Sub


    Friend Overloads Sub RemovePermissionAccess(ByVal entry As MailslotPermissionEntry)
        MyBase.RemovePermissionAccess(entry.GetBaseEntry())
    End Sub


    Private Sub SetNames()
        Me.PermissionAccessType = GetType(MailslotPermissionAccess)
        Me.TagNames = New String() {"Name", "Machine"}
    End Sub
End Class

<Flags()> Public Enum MailslotPermissionAccess
    None = 0
    Send = 2
    Receive = 4 Or Send
End Enum 'MailslotPermissionAccess

<Serializable()> Public Class MailslotPermissionEntry
    Private nameVar As String
    Private machineNameVar As String
    Private permissionAccessVar As MailslotPermissionAccess


    Public Sub New(ByVal permissionAccess As MailslotPermissionAccess, ByVal name As String, ByVal machineName1 As String)
        Me.permissionAccessVar = permissionAccess
        Me.nameVar = name
        Me.machineNameVar = machineName1
    End Sub


    Friend Sub New(ByVal baseEntry As ResourcePermissionBaseEntry)
        Me.permissionAccessVar = CType(baseEntry.PermissionAccess, MailslotPermissionAccess)
        Me.nameVar = baseEntry.PermissionAccessPath(0)
        Me.machineNameVar = baseEntry.PermissionAccessPath(1)
    End Sub


    Public ReadOnly Property Name() As String
        Get
            Return Me.nameVar
        End Get
    End Property


    Public ReadOnly Property MachineName() As String
        Get
            Return Me.machineNameVar
        End Get
    End Property


    Public ReadOnly Property PermissionAccess() As MailslotPermissionAccess
        Get
            Return Me.permissionAccessVar
        End Get
    End Property


    Friend Function GetBaseEntry() As ResourcePermissionBaseEntry
        Dim baseEntry As New ResourcePermissionBaseEntry(CInt(Me.PermissionAccess), New String() {Me.Name, Me.MachineName})
        Return baseEntry
    End Function 'GetBaseEntry


End Class

Comentarios

Nota

La ResourcePermissionBase clase compara las cadenas mediante las reglas de ordenación ordinal y omite las mayúsculas y minúsculas de las cadenas que se comparan.The ResourcePermissionBase class compares strings using ordinal sort rules and ignores the case of the strings being compared.

Notas a los implementadores

Al heredar de ResourcePermissionBase , debe proporcionar al menos tres constructores, establecer dos propiedades y proporcionar una tercera propiedad.When you inherit from ResourcePermissionBase, you must provide at least three constructors, set two properties, and provide a third property. Los constructores necesarios son: un constructor sin parámetros, uno que toma PermissionState como parámetro y tantas como sea necesario para tomar los valores de las propiedades.The required constructors are: a parameterless constructor, one that takes a PermissionState as a parameter, and as many as needed that take values for the properties. Las propiedades que se deben establecer son PermissionAccessType y TagNames .The properties that need to be set are PermissionAccessType and TagNames. La tercera propiedad que se necesita es aquella que devuelve las entradas de permiso.The third property that is needed is one that returns the permission entries. Para obtener un ejemplo de una implementación de esta clase, vea PerformanceCounterPermission .For an example of an implementation of this class, see PerformanceCounterPermission. En PerformanceCounterPermission , la TagNames propiedad se establece de forma privada en "Machine" y "Category", la PermissionAccessType propiedad se establece de forma privada en el tipo de PerformanceCounterPermissionAccess y la PermissionEntries propiedad devuelve las entradas de permiso.In PerformanceCounterPermission, the TagNames property is set privately to "Machine" and "Category", the PermissionAccessType property is privately set to the type of PerformanceCounterPermissionAccess, and the PermissionEntries property returns the permission entries.

Constructores

ResourcePermissionBase()

Inicializa una nueva instancia de la clase ResourcePermissionBase.Initializes a new instance of the ResourcePermissionBase class.

ResourcePermissionBase(PermissionState)

Inicializa una nueva instancia de la clase ResourcePermissionBase con el nivel de acceso a los recursos especificado en el momento de la creación.Initializes a new instance of the ResourcePermissionBase class with the specified level of access to resources at creation.

Campos

Any

Especifica el carácter que se va a utilizar para representar cualquier carácter comodín.Specifies the character to be used to represent the any wildcard character.

Local

Especifica el carácter que se va a utilizar para representar una referencia local.Specifies the character to be used to represent a local reference.

Propiedades

PermissionAccessType

Obtiene o establece un valor de enumeración que describe los tipos de acceso que se está asignando al recurso.Gets or sets an enumeration value that describes the types of access that you are giving the resource.

TagNames

Obtiene o establece una matriz de cadenas que identifican el recurso que se va a proteger.Gets or sets an array of strings that identify the resource you are protecting.

Métodos

AddPermissionAccess(ResourcePermissionBaseEntry)

Agrega una entrada de permiso al permiso.Adds a permission entry to the permission.

Assert()

Declara que el código de llamada puede tener acceso al recurso protegido por una demanda de permiso a través del código que llama a este método, incluso si los autores de la llamada situados en una posición más alta de la pila no tienen permiso para tener acceso al recurso.Declares that the calling code can access the resource protected by a permission demand through the code that calls this method, even if callers higher in the stack have not been granted permission to access the resource. El uso de Assert() puede crear problemas de seguridad.Using Assert() can create security issues.

(Heredado de CodeAccessPermission)
Clear()

Borra el permiso de las entradas de permiso agregadas.Clears the permission of the added permission entries.

Copy()

Crea y devuelve una copia idéntica del objeto de permiso actual.Creates and returns an identical copy of the current permission object.

Demand()

Fuerza a un SecurityException en tiempo de ejecución si todos los autores de llamada situados en la parte superior de la pila de llamadas no disponen del permiso especificado por la instancia actual.Forces a SecurityException at run time if all callers higher in the call stack have not been granted the permission specified by the current instance.

(Heredado de CodeAccessPermission)
Deny()
Obsoleto.
Obsoleto.

Impide que los autores de la llamada situados en la posición más alta de la pila de llamadas usen el código que llama a este método para tener acceso al recurso especificado por la instancia actual.Prevents callers higher in the call stack from using the code that calls this method to access the resource specified by the current instance.

(Heredado de CodeAccessPermission)
Equals(Object)

Determina si el objeto CodeAccessPermission especificado es igual al objeto CodeAccessPermission actual.Determines whether the specified CodeAccessPermission object is equal to the current CodeAccessPermission.

(Heredado de CodeAccessPermission)
FromXml(SecurityElement)

Reconstruye un objeto de seguridad con un estado especificado a partir de codificación XML.Reconstructs a security object with a specified state from an XML encoding.

GetHashCode()

Obtiene un código hash para el objeto CodeAccessPermission que es adecuado para su uso en algoritmos hash y estructuras de datos como una tabla hash.Gets a hash code for the CodeAccessPermission object that is suitable for use in hashing algorithms and data structures such as a hash table.

(Heredado de CodeAccessPermission)
GetPermissionEntries()

Devuelve una matriz con los objetos ResourcePermissionBaseEntry agregados a este permiso.Returns an array of the ResourcePermissionBaseEntry objects added to this permission.

GetType()

Obtiene el Type de la instancia actual.Gets the Type of the current instance.

(Heredado de Object)
Intersect(IPermission)

Crea y devuelve un objeto de permiso que es la intersección entre el objeto de permiso actual y un objeto de permiso de destino.Creates and returns a permission object that is the intersection of the current permission object and a target permission object.

IsSubsetOf(IPermission)

Determina si el objeto de permiso actual es un subconjunto del permiso especificado.Determines whether the current permission object is a subset of the specified permission.

IsUnrestricted()

Obtiene un valor que indica si el permiso no tiene restricciones.Gets a value indicating whether the permission is unrestricted.

MemberwiseClone()

Crea una copia superficial del Object actual.Creates a shallow copy of the current Object.

(Heredado de Object)
PermitOnly()

Impide que los llamadores situados más arriba en la pila de llamadas usen el código que llama a este método para tener acceso a todos los recursos excepto al recurso especificado por la instancia actual.Prevents callers higher in the call stack from using the code that calls this method to access all resources except for the resource specified by the current instance.

(Heredado de CodeAccessPermission)
RemovePermissionAccess(ResourcePermissionBaseEntry)

Quita una entrada de permiso del permiso.Removes a permission entry from the permission.

ToString()

Crea y devuelve una representación de cadena del objeto de permiso actual.Creates and returns a string representation of the current permission object.

(Heredado de CodeAccessPermission)
ToXml()

Crea y devuelve una codificación XML del objeto de seguridad y de su estado actual.Creates and returns an XML encoding of the security object and its current state.

Union(IPermission)

Crea un objeto de permiso que combina el objeto de permiso actual y el objeto de permiso de destino.Creates a permission object that combines the current permission object and the target permission object.

Implementaciones de interfaz explícitas

IPermission.Demand()

Produce una SecurityException en tiempo de ejecución si no se cumple el requisito de seguridad.Throws a SecurityException at run time if the security requirement is not met.

(Heredado de CodeAccessPermission)
IStackWalk.Assert()

Afirma que el código de llamada puede tener acceso al recurso identificado por el objeto de permiso actual, incluso si los autores de la llamada situados en una posición más alta de la pila no tienen permiso para tener acceso al recurso.Asserts that the calling code can access the resource identified by the current permission object, even if callers higher in the stack have not been granted permission to access the resource.

(Heredado de CodeAccessPermission)
IStackWalk.Demand()

Determina en tiempo de ejecución si a todos los autores de llamada de la pila de llamadas se les ha concedido el permiso especificado por el objeto de permiso actual.Determines at run time whether all callers in the call stack have been granted the permission specified by the current permission object.

(Heredado de CodeAccessPermission)
IStackWalk.Deny()

Hace que cada Demand() del objeto actual que pase por el código de llamada produzca un error.Causes every Demand() for the current object that passes through the calling code to fail.

(Heredado de CodeAccessPermission)
IStackWalk.PermitOnly()

Hace que cada elemento Demand() para todos los objetos excepto el actual que pasan por el código de llamada genere un error, incluso si se ha concedido permiso de acceso al código situado más arriba en la pila de llamadas para otros recursos.Causes every Demand() for all objects except the current one that pass through the calling code to fail, even if code higher in the call stack has been granted permission to access other resources.

(Heredado de CodeAccessPermission)

Se aplica a