109 Security: All Views of the app - chempkovsky/CS82ANGULAR GitHub Wiki

Two aspects

Security has two aspects: Authentication and Authorization

Notes

  • in the article 104 we created the aspnetmodel-table. This table should be used to persist all Views of the application.
  • read the following article as reminder.
  • populating the aspnetmodel table with data can be time-consuming. On the other hand, it's easy to misspell a title or forget a View.
  • 30000-AllModelViews.sql-script can be used to generate the names along with Sql-code (and C# code) which inserts data in the database table.
    • JavaScript Wizard must be used to run the script.
    • The script must be run for each Dbcontext of the application.
  • There is no script for the Features. Thus, Features must be inserted by hands.

Steps required to accomplish the task

Run JavaScript Wizard
  • right click any subfolder of any project of the app.
    • for example, Controllers-folder of the PhBkControllers.csproj-project
  • select JavaScript Wizard-menu item

First page of the Wizard

  • click Next-button on the first page

Second page of the Wizard

  • select the project and Dbcontext for which to run the script
    • for example, PhBkContext.csproj-project and PhbkDbContext-dbcontext
  • click Next-button

Third page of the Wizard

  • select any View of the Dbcontext
    • for example, PhbkPhoneView
  • click Next-button

Fourth page of the Wizard

  • in Select Action Type-combo box, select 30000-AllModelViews.sql
  • click Next-button

Fifth page of the Wizard

  • select AllModelViews.sql.t4-template
  • inside Edit-window
    • modify the values for
      • int startFromId=...
      • string insertSql=...
      • string insertCode=...
  • click Next-button
Click to show the picture

project structure

Sixth page of the Wizard

  • copy fragment of the generated code in the clipboard.
Click to show the picture

project structure

Database Contexts

  • here is a list of Database Contexts of the app

    • PhbkDbContext-context of the PhBkContext.csproj-project
    • aspnetchckdbcontext-context of the PhBkContext.csproj-project
    • AspNetRegistrationDbContex-context of the PhBkContext.csproj-project. Do not generate. It repeats the Views of aspnetchckdbcontext.
    • LpEmpPhBkContext-context of the LpPhBkContext.csproj-project. Do not generate. It repeats the Views of PhbkDbContext.
    • LpPhbkDbContext-context of the LpPhBkContext.csproj-project. Do not generate. It repeats the Views of PhbkDbContext.
    • LpPhnPhBkContext-context of the LpPhBkContext.csproj-project. Do not generate. It repeats the Views of PhbkDbContext.
  • Here is a result. We will insert the generated code in the OnModelCreating-method of the aspnetchckdbcontext-context

    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 1, ModelName = "PhbkPhoneTypeView", ModelDescription="Phone Type" });
    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 2, ModelName = "PhbkEnterpriseView", ModelDescription="Enterprise" });
    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 3, ModelName = "PhbkDivisionView", ModelDescription="Division" });
    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 4, ModelName = "LpdDivisionView", ModelDescription="Division Name" });
    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 5, ModelName = "LprDivision01View", ModelDescription="Division Name ref01" });
    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 6, ModelName = "LprDivision02View", ModelDescription="Division Name ref02" });
    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 7, ModelName = "PhbkEmployeeView", ModelDescription="Employee" });
    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 8, ModelName = "LpdEmpLastNameView", ModelDescription="Last Name" });
    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 9, ModelName = "LpdEmpFirstNameView", ModelDescription="First Name" });
    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 10, ModelName = "LpdEmpSecondNameView", ModelDescription="Second Name" });
    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 11, ModelName = "LprEmployee01View", ModelDescription="Employee Dict Ref" });
    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 12, ModelName = "LprEmployee02View", ModelDescription="Employee Dict Ref" });
    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 13, ModelName = "PhbkPhoneView", ModelDescription="Phone" });
    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 14, ModelName = "LpdPhoneView", ModelDescription="Phone" });
    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 15, ModelName = "LprPhone01View", ModelDescription="Phone Dict Ref" });
    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 16, ModelName = "LprPhone02View", ModelDescription="Phone Dict Ref" });
    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 17, ModelName = "LprPhone03View", ModelDescription="Phone Dict Ref" });
    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 18, ModelName = "LprPhone04View", ModelDescription="Phone Dict Ref" });

    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 19, ModelName = "aspnetmodelView", ModelDescription="Model" });
    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 20, ModelName = "aspnetroleView", ModelDescription="Role" });
    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 21, ModelName = "aspnetrolemaskView", ModelDescription="Role Mask" });
    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 22, ModelName = "aspnetuserView", ModelDescription="User" });
    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 23, ModelName = "aspnetusermaskView", ModelDescription="User Mask" });
    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 24, ModelName = "aspnetuserpermsView", ModelDescription="User perm" });
    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 25, ModelName = "aspnetuserrolesView", ModelDescription="User Role" });

    // features
    modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 26, ModelName = "SimpleDictionaryFtrComponent", ModelDescription = "Simple feature" });

    ////////////////////////////////////////////// Roles //////////////////////////////////////////////
    for (int i = 1; i < 26; i++)
    {
      modelBuilder.Entity<aspnetrolemask>().HasData(new { RoleName = "AdminRole", RoleDescription = "AdminRole", ModelPkRef = i, Mask1 = true, Mask2 = true, Mask3 = true, Mask4 = true, Mask5 = true });
    }
    // features
    modelBuilder.Entity<aspnetrolemask>().HasData(new { RoleName = "AdminRole", RoleDescription = "AdminRole", ModelPkRef = 26, Mask1 = true, Mask2 = false, Mask3 = false, Mask4 = false, Mask5 = false });

    // 1 "PhbkPhoneTypeView"
    modelBuilder.Entity<aspnetrolemask>().HasData(new { RoleName = "GuestRole", RoleDescription = "GuestRole", ModelPkRef = 1, Mask1 = true, Mask2 = false, Mask3 = false, Mask4 = false, Mask5 = true });
    // 2 "PhbkEnterpriseView"
    modelBuilder.Entity<aspnetrolemask>().HasData(new { RoleName = "GuestRole", RoleDescription = "GuestRole", ModelPkRef = 2, Mask1 = true, Mask2 = false, Mask3 = false, Mask4 = false, Mask5 = false });
    // 3 "PhbkDivisionView"
    modelBuilder.Entity<aspnetrolemask>().HasData(new { RoleName = "GuestRole", RoleDescription = "GuestRole", ModelPkRef = 3, Mask1 = true, Mask2 = false, Mask3 = false, Mask4 = false, Mask5 = false });
    // 7 "PhbkEmployeeView"
    modelBuilder.Entity<aspnetrolemask>().HasData(new { RoleName = "GuestRole", RoleDescription = "GuestRole", ModelPkRef = 7, Mask1 = true, Mask2 = false, Mask3 = false, Mask4 = false, Mask5 = false });
    // 13 "PhbkPhoneView"
    modelBuilder.Entity<aspnetrolemask>().HasData(new { RoleName = "GuestRole", RoleDescription = "GuestRole", ModelPkRef = 13, Mask1 = true, Mask2 = false, Mask3 = false, Mask4 = false, Mask5 = false });
    // features
    modelBuilder.Entity<aspnetrolemask>().HasData(new { RoleName = "GuestRole", RoleDescription = "GuestRole", ModelPkRef = 26, Mask1 = true, Mask2 = false, Mask3 = false, Mask4 = false, Mask5 = false });
⚠️ **GitHub.com Fallback** ⚠️