A6 Security: Authorization (Entities and DBContext) (Xamarin) - chempkovsky/CS2WPF-and-CS2XAMARIN GitHub Wiki

Two aspects

Notes

Creating Developer Edition of Entities for Authorization

Creating Developer Edition of DbContext for Authorization

Two aspects

Security has two aspects: Authentication and Authorization

Notes

  • In the article A4.03 we mentioned permission storage.
    • Except that, we need the User interface for managing user data. To generate the Typescript classes we need the View-declarations.
      • Again, we can define Views only after declaring Entities and DBContext.
      • Thus, before creating views, we need a temporary explicit declaration of some entities defined by Microsoft IdentityDbContext. After generating the Views we must delete temporary entities.
      • Another aspect is permission storage entities. Some of permission storage entities must reference role-entity to persist (permission bitmask, role) pairs.
  • As a result, we need to generate Entities and DBContext twice.
    • first time, for modeling
    • second time, for production
  • In this article we will show how to generate Entities and DBContext for modeling.
    • Next time, after creating the code for the Views, we will regenerate the Entities and DBContext for production.

Creating Developer Edition of Entities for Authorization

  • Step 1: Right click "AspNetMaskSecurity"-folder of Dm01Entity-project and select "Wpf form Wizard".
  • Step 2: On the first page (invitation page) click "next"-button.
  • Step 3: On the second page of the dialog the developer should select existing DbContext file.
    • Select:
      • Dm02Context (project)
      • LitDbContext (context)

picture

  • Step 4: On the third page, select "==Context==" and click "Next"-button

picture

  • Step 5: On the fourth page, click "patch processing"-button. "Batch action" dialog will be shown.

picture

  • Step 6: In "Batch action" dialog, select "00140-AspNetEntitiesDev.Xamarin.json"-script and click start-button. Make sure that "Errors"-panel is empty and close the Wizard.

Creating Developer Edition of DbContext for Authorization

  • Step 1: Right click "AspNetMaskSecurity"-folder of Dm02Context-project and select "Wpf form Wizard".
  • Repeat steps 2-5 of the Creating Developer Edition of Entities for Authorization paragraph
  • Step 6: In "Batch action" dialog, select "00150-AspNetDbContextDev.Xamarin.json"-script and click start-button. Make sure that "Errors"-panel is empty and close the Wizard.

Note 1:

As a result you will obtain the following C# files

  • aspnetmodel.cs
  • aspnetrole.cs [dummy(mock) class]
  • aspnetrolemask.cs
  • aspnetuser.cs [dummy(mock) class]
  • aspnetusermask.cs [dummy(mock) class]
  • aspnetuserperms.cs
  • aspnetuserroles.cs [dummy(mock) class]

and one Db context C# file

  • aspnetchckdbcontext.cs [generated with 00150-AspNetDbContextDev.Xamarin.json-batch]

Note 2:

Except 00150-AspNetDbContextDev.Xamarin.json there is another script: 00160-AspNetDbContextProd.Xamarin.json. The last script must be executed right after defining generating ViewModels(or DTO).

Note 3:

  • Some of the objects have been marked as dummy(mock) class. Here is a list.
    • 00400-aspnetrole.cs [dummy(mock) class]
    • 00410-aspnetuser.cs [dummy(mock) class]
    • 00420-aspnetuserroles.cs [dummy(mock) class]
    • 00430-aspnetusermask.cs [dummy(mock) class]

After generating ViewModels(or DTO) these four classes should be removed from the project.