expressappframework-404204-getting-started-in-depth-tutorial-blazor-enable-additional-modules-use-the-security-system.md
This article explains how to implement the Security System in your application. The system applies the SecurityStrategyComplex security strategy. According to this strategy, application users have roles with different permission sets. For more information about permissions, see the following topic: Security (Access Control & Authentication).
The instructions below describe how to do the following:
The administrator has a full-access permission set. The user has a limited permission set. The administrator can create User objects and Role objects, specify Permissions for them, and then assign Roles to Users at runtime.
With AuthenticationStandard authentication type, the Security System uses the internal XAF authentication mechanism and stores user credentials in the application’s database. Users need to input their name and password in the login form before application startup.
Note
Before you proceed, take a moment to review this lesson:
In the MySolution.Module\BusinessObjects folder, create the ApplicationUser class. Replace the generated class declaration with the following code:
In the same manner, create the ApplicationUserLoginInfo class.
Go to the MySolution.Module\MySolutionDbContext file and add the following properties to DbSet:
Enable Standard Authentication in the platform-specific Startup files:
Expand the MySolution.Module project in the Solution Explorer and go to the DatabaseUpdate folder. Open the Updater.cs file and create the Administrator user in the ModuleUpdater.UpdateDatabaseAfterUpdateSchema method.
In the same manner, create a common user.
Create a common user role and specify its permissions. This user only has access to the current user object.
Optionally, you can configure your application to store user differences (individual user settings) in the database. Make the following changes in the MySolution.Blazor.Server\BlazorModule.cs (ASP.NET Core Blazor) and MySolution.Win\WinModule.cs (Windows Forms) files:
Run the application. Log in under Admin. Leave the password field empty (you did not specify the password when you created this user). When you click the Log In button, the user’s credentials are authenticated and the application runs.
Select the My Details item in the navigation control and see the Detail View.
Administrators and other users with Role creation permission can create roles at runtime.
Administrators and other users with User creation permission can create users at runtime.