What is the principal ?

Estimated reading: 1 minute 193 views

In Visual-Guard, the “Principal” represents the currently authenticated and authorized user. Once a user is authenticated in runtime, you can access the current principal using runtime.Principal.

The Principal object provides a variety of properties that allow you to access information about the user’s roles, permissions, and groups. Here are some examples:

  • currentPrincipal.Roles: This property provides a list of roles granted to the user for the current application.
  • currentPrincipal.GetAllCurrentPermissions(): This method returns a list of permissions granted to the user for the current application.
  • currentPrincipal.ContextualGroups: This property provides a list of selectable contextual groups.
  • currentPrincipal.GrantedGroups: This property provides a list of groups which are directly assigned to users.
  • currentPrincipal.Groups: This property provides a list of groups which are directly assigned and also their descendant groups.
  • currentPrincipal.ProfileValues: This property gets a list of profile values for the current principal.

You can also change and save profile values for the principal. For example:

// Change profile values for principal
// where attributeId is propertyId of attribute
currentPrincipal.ProfileValues.SetValue(attributeId, 15);
currentPrincipal.ProfileValues.SetValue(attributeId, "HelloWorld");

// Save/update profile values for current principal
currentPrincipal.ProfileValues.Save();