PrincipalPermission Constructors

Definition

Initializes a new instance of the PrincipalPermission class.

Overloads

PrincipalPermission(PermissionState)

Initializes a new instance of the PrincipalPermission class with the specified PermissionState.

PrincipalPermission(String, String)

Initializes a new instance of the PrincipalPermission class for the specified name and role.

PrincipalPermission(String, String, Boolean)

Initializes a new instance of the PrincipalPermission class for the specified name, role, and authentication status.

PrincipalPermission(PermissionState)

Source:
PrincipalPermission.cs
Source:
PrincipalPermission.cs
Source:
PrincipalPermission.cs
Source:
PrincipalPermission.cs

Initializes a new instance of the PrincipalPermission class with the specified PermissionState.

public:
 PrincipalPermission(System::Security::Permissions::PermissionState state);
public PrincipalPermission (System.Security.Permissions.PermissionState state);
new System.Security.Permissions.PrincipalPermission : System.Security.Permissions.PermissionState -> System.Security.Permissions.PrincipalPermission
Public Sub New (state As PermissionState)

Parameters

state
PermissionState

One of the PermissionState values.

Exceptions

The state parameter is not a valid PermissionState.

Remarks

None matches only the unauthenticated principal (Name is the empty string (""), no Role, Authenticated is false). Unrestricted matches all principals (Name is null, Role is null).

Note

This constructor is included for consistency with the design of other permissions, but is not useful in practice.

Applies to

PrincipalPermission(String, String)

Source:
PrincipalPermission.cs
Source:
PrincipalPermission.cs
Source:
PrincipalPermission.cs
Source:
PrincipalPermission.cs

Initializes a new instance of the PrincipalPermission class for the specified name and role.

public:
 PrincipalPermission(System::String ^ name, System::String ^ role);
public PrincipalPermission (string name, string role);
new System.Security.Permissions.PrincipalPermission : string * string -> System.Security.Permissions.PrincipalPermission
Public Sub New (name As String, role As String)

Parameters

name
String

The name of the IPrincipal object's user.

role
String

The role of the IPrincipal object's user (for example, Administrator).

Examples

The following example requires the active principal to be an administrator. The name parameter is null, which enables any user who is an administrator to pass the demand.

Note In Windows Vista, User Account Control (UAC) determines the privileges of a user. If you are a member of the Built-in Administrators group, you are assigned two run-time access tokens: a standard user access token and an administrator access token. By default, you are in the standard user role. To execute the code that requires you to be an administrator, you must first elevate your privileges from standard user to administrator. You can do this when you start an application by right-clicking the application icon and indicating that you want to run as an administrator.

using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;
using namespace System::Security::Policy;
using namespace System::Security::Principal;

int main(array<System::String ^> ^args)
{
    System::String^ null;
    AppDomain::CurrentDomain->SetPrincipalPolicy(PrincipalPolicy::WindowsPrincipal);
    PrincipalPermission^ principalPerm = gcnew PrincipalPermission(null, "Administrators" );
      principalPerm->Demand();
      Console::WriteLine("Demand succeeded");
    return 0;
}
using System;
using System.Threading;
using System.Security.Permissions;
using System.Security.Principal;

class SecurityPrincipalDemo
{

    public static void Main()
    {
        AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
        PrincipalPermission principalPerm = new PrincipalPermission(null, "Administrators");
        principalPerm.Demand();
        Console.WriteLine("Demand succeeded.");
    }
}
Imports System.Threading
Imports System.Security.Permissions
Imports System.Security.Principal



Class SecurityPrincipalDemo


    Public Shared Sub Main()
        AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal)
        Dim principalPerm As New PrincipalPermission(Nothing, "Administrators")
        principalPerm.Demand()
        Console.WriteLine("Demand succeeded.")

    End Sub
End Class

Remarks

Both the name parameter and the role parameter must match for this permission to match the active IPrincipal and associated IIdentity. Set name to null to check for any user in a role.

Applies to

PrincipalPermission(String, String, Boolean)

Source:
PrincipalPermission.cs
Source:
PrincipalPermission.cs
Source:
PrincipalPermission.cs
Source:
PrincipalPermission.cs

Initializes a new instance of the PrincipalPermission class for the specified name, role, and authentication status.

public:
 PrincipalPermission(System::String ^ name, System::String ^ role, bool isAuthenticated);
public PrincipalPermission (string name, string role, bool isAuthenticated);
new System.Security.Permissions.PrincipalPermission : string * string * bool -> System.Security.Permissions.PrincipalPermission
Public Sub New (name As String, role As String, isAuthenticated As Boolean)

Parameters

name
String

The name of the IPrincipal object's user.

role
String

The role of the IPrincipal object's user (for example, Administrator).

isAuthenticated
Boolean

true to signify that the user is authenticated; otherwise, false.

Remarks

Both the name parameter and the role parameter must match for this permission to match the active IPrincipal and associated IIdentity.

Applies to