GenericPrincipal Class

 

Represents a generic principal.

Namespace:   System.Security.Principal
Assembly:  mscorlib (in mscorlib.dll)

System::Object
  System.Security.Claims::ClaimsPrincipal
    System.Security.Principal::GenericPrincipal
      System.Web.Security::PassportPrincipal

[SerializableAttribute]
[ComVisibleAttribute(true)]
public ref class GenericPrincipal : ClaimsPrincipal

NameDescription
System_CAPS_pubmethodGenericPrincipal(IIdentity^, array<String^>^)

Initializes a new instance of the GenericPrincipal class from a user identity and an array of role names to which the user represented by that identity belongs.

NameDescription
System_CAPS_pubpropertyClaims

Gets a collection that contains all of the claims from all of the claims identities associated with this claims principal.(Inherited from ClaimsPrincipal.)

System_CAPS_protpropertyCustomSerializationData

(Inherited from ClaimsPrincipal.)

System_CAPS_pubpropertyIdentities

Gets a collection that contains all of the claims identities associated with this claims principal.(Inherited from ClaimsPrincipal.)

System_CAPS_pubpropertyIdentity

Gets the GenericIdentity of the user represented by the current GenericPrincipal.(Overrides ClaimsPrincipal::Identity.)

NameDescription
System_CAPS_pubmethodAddIdentities(IEnumerable<ClaimsIdentity^>^)

Adds the specified claims identities to this claims principal.(Inherited from ClaimsPrincipal.)

System_CAPS_pubmethodAddIdentity(ClaimsIdentity^)

Adds the specified claims identity to this claims principal.(Inherited from ClaimsPrincipal.)

System_CAPS_pubmethodClone()

Returns a copy of this instance.(Inherited from ClaimsPrincipal.)

System_CAPS_protmethodCreateClaimsIdentity(BinaryReader^)

Creates a new claims identity.(Inherited from ClaimsPrincipal.)

System_CAPS_pubmethodEquals(Object^)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodFindAll(Predicate<Claim^>^)

Retrieves all of the claims that are matched by the specified predicate.(Inherited from ClaimsPrincipal.)

System_CAPS_pubmethodFindAll(String^)

Retrieves all or the claims that have the specified claim type.(Inherited from ClaimsPrincipal.)

System_CAPS_pubmethodFindFirst(Predicate<Claim^>^)

Retrieves the first claim that is matched by the specified predicate.(Inherited from ClaimsPrincipal.)

System_CAPS_pubmethodFindFirst(String^)

Retrieves the first claim with the specified claim type.(Inherited from ClaimsPrincipal.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_protmethodGetObjectData(SerializationInfo^, StreamingContext)

Populates the SerializationInfo with data needed to serialize the current ClaimsPrincipal object.(Inherited from ClaimsPrincipal.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodHasClaim(Predicate<Claim^>^)

Determines whether any of the claims identities associated with this claims principal contains a claim that is matched by the specified predicate.(Inherited from ClaimsPrincipal.)

System_CAPS_pubmethodHasClaim(String^, String^)

Determines whether any of the claims identities associated with this claims principal contains a claim with the specified claim type and value.(Inherited from ClaimsPrincipal.)

System_CAPS_pubmethodIsInRole(String^)

Determines whether the current GenericPrincipal belongs to the specified role.(Overrides ClaimsPrincipal::IsInRole(String^).)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

System_CAPS_pubmethodWriteTo(BinaryWriter^)

(Inherited from ClaimsPrincipal.)

System_CAPS_protmethodWriteTo(BinaryWriter^, array<Byte>^)

(Inherited from ClaimsPrincipal.)

This class represents the roles of the current user.

The following example shows the use of members of the GenericPrincipal class.

using namespace System;
using namespace System::Security::Principal;

ref class GenericPrincipalMembers
{
public:
   [STAThread]
   static void Main()
   {
      // Retrieve a GenericPrincipal that is based on the current user's
      // WindowsIdentity.
      GenericPrincipal^ genericPrincipal = GetGenericPrincipal();

      // Retrieve the generic identity of the GenericPrincipal object.
      GenericIdentity^ principalIdentity =
         dynamic_cast<GenericIdentity^>(genericPrincipal->Identity);

      // Display the identity name and authentication type.
      if ( principalIdentity->IsAuthenticated )
      {
         Console::WriteLine( principalIdentity->Name );
         Console::WriteLine( L"Type:{0}",
            principalIdentity->AuthenticationType );
      }

      // Verify that the generic principal has been assigned the
      // NetworkUser role.
      if ( genericPrincipal->IsInRole( L"NetworkUser" ) )
      {
         Console::WriteLine( L"User belongs to the NetworkUser role." );
      }
      Console::WriteLine( L"The sample completed successfully; "
      L"press Enter to continue." );
      Console::ReadLine();
   }

private:
   // Create a generic principal based on values from the current
   // WindowsIdentity.
   static GenericPrincipal^ GetGenericPrincipal()
   {
      // Use values from the current WindowsIdentity to construct
      // a set of GenericPrincipal roles.
      WindowsIdentity^ windowsIdentity = WindowsIdentity::GetCurrent();
      array<String^>^roles = gcnew array<String^>(10);
      if ( windowsIdentity->IsAuthenticated )
      {

         // Add custom NetworkUser role.
         roles[ 0 ] = L"NetworkUser";
      }

      if ( windowsIdentity->IsGuest )
      {

         // Add custom GuestUser role.
         roles[ 1 ] = L"GuestUser";
      }

      if ( windowsIdentity->IsSystem )
      {

         // Add custom SystemUser role.
         roles[ 2 ] = L"SystemUser";
      }

      // Construct a GenericIdentity object based on the current Windows
      // identity name and authentication type.
      String^ authenticationType = windowsIdentity->AuthenticationType;
      String^ userName = windowsIdentity->Name;
      GenericIdentity^ genericIdentity = gcnew GenericIdentity(
         userName,authenticationType );

      // Construct a GenericPrincipal object based on the generic identity
      // and custom roles for the user.
      GenericPrincipal^ genericPrincipal = gcnew GenericPrincipal(
         genericIdentity,roles );

      return genericPrincipal;
   }
};

int main()
{
   GenericPrincipalMembers::Main();
}


Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: