-
Notifications
You must be signed in to change notification settings - Fork 0
108 Security: User management. Typescript classes.
chempkovsky edited this page Jun 7, 2022
·
12 revisions
Security has two aspects: Authentication and Authorization
- Before this article, we used to generate typescript classes with
PhbkDbContext
-Dbcontext as a Wizard's Repo. - In the article 012.1 we generated Auxiliary classes. All information about created object was persisted in a Wizard's Repo of
PhbkDbContext
- Now,
aspnetchckdbcontext
will be used to generate the Typescript code. But theaspnetchckdbcontext
Repo does not contain information about the common classes that have already been created in the project. - Thus, our very first task is to import common classes info from
PhbkDbContext
-Repo inaspnetchckdbcontext
-Repo.- There is a
import common staff
-button on one of the page of JavaScript Wizard. But we do not recommend to use this functionality (it's under the development). - Instead, we will show how to copy/paste json fragment from
PhbkDbContext
-Repo inaspnetchckdbcontext
-Repo.
- There is a
- run Visual studio 2022
- open the
PhBkContext.PhBkContext.csproj.PhBkContext.Auth.aspnetchckdbcontext.json
-file, which is a Repo foraspnetchckdbcontext
- open the
PhBkContext.PhBkContext.csproj.PhBkContext.PhBk.PhbkDbContext.json
-file, which is a Repo forPhbkDbContext
- Note: you will find both files in the Solution folder.
- Format both files
- right click editor window and select
Format document
-menu item
- right click editor window and select
Click to show the picture
- Select
CommonStaffs
-section ofPhBkContext.PhBkContext.csproj.PhBkContext.PhBk.PhbkDbContext.json
-file and copy into the clipboard.
Click to show the picture
- Replace
"CommonStaffs": null
-line ofPhBkContext.PhBkContext.csproj.PhBkContext.PhBk.PhbkDbContext.json
-file with the clipboard selection.
Click to show the picture
- save
PhBkContext.PhBkContext.csproj.PhBkContext.Auth.aspnetchckdbcontext.json
-file - close both files
- right click
src/app
-folder of the Angular project and selectJavascript Wizard
-menu item - on the first page click
next
-button - on the second page
- select
PhBkContext.csproj
-project - select
aspnetchckdbcontext
-Dbcontext - click
next
-button
- select
- on the third page
- select
aspnetmodelView
in the combo - click
next
-button
- select
- on the fourth page
- click
batch processing
-button-
Batch actions
dialog will be shown
-
- click
- on Batch actions dialog run the scripts:
02040-AspNetAllInterfacesBatch.json
02041-AspNetAllWebApiServicesBatch.json
02042-AspNetAllSFormsBatch.json
02043-AspNetAllVformsBatch.json
02044-AspNetAllAformsBatch.json
02044-AspNetAllUformsBatch.json
02044-AspNetAllDformsBatch.json
02047-AspNetAllRvBatch.json
02048-AspNetAllRaBatch.json
02049-AspNetAllRuBatch.json
02050-AspNetAllRdBatch.json
02051-AspNetAllRlBatch.json
02052-AspNetAllRdlBatch.json
- After you finish
- open the
src\app\components\aspnetuser-view\aspnetuser-view-rdl.routing.module.ts
-file- the
children
-array is empty!!! - here is a fragment
- the
- open the
...
const routes: Routes = [
{
path: '',
component: AspnetuserViewRdlistComponent,
canActivate: [AppGlblSettingsServiceActivator],
children: [
//
// Info: Root Master View [aspnetuserView]
// Info: Detail View [aspnetuserrolesView]
//
//
//warning: for the View [aspnetuserrolesView] the component [02050-Rdl-lazy.routing.module.ts] has not been generated yet
//
//
// Info: Root Master View [aspnetuserView]
// Info: Detail View [aspnetusermaskView]
//
//
//warning: for the View [aspnetusermaskView] the component [02050-Rdl-lazy.routing.module.ts] has not been generated yet
//
]
}
];
...
- to fix this issue, run the following batch-scripts second time:
02042-AspNetAllSFormsBatch.json
02043-AspNetAllVformsBatch.json
02047-AspNetAllRvBatch.json
02051-AspNetAllRlBatch.json
02052-AspNetAllRdlBatch.json
-
Navigation paths
-
in the article 106 we generated Webapi services.
- Webapi service generated for
aspnetroleView
usesRoleManager<IdentityRole>
-class functionality-
RoleManager
can not return users for the given Role.
-
- Webapi service generated for
aspnetuserView
usesUserManager<IdentityUser>
-class functionality-
UserManager
can return roles for the given user
-
- Webapi service generated for
-
in the article 107 we regenerated entities and Dbcontext for production.
- The List of Entities consists of only two objects:
-
aspnetmodel
to persist all Views in the project -
aspnetrolemask
to persist triples (View, Role, Permission Bitmask)
-
- The List of Entities consists of only two objects:
-
As a result
- Webapi service generated for
aspnetusermaskView
returns read only data. - Webapi service generated for
aspnetuserpermsView
returns read only data. - The Rlform(Rflform) for
aspnetuserrolesView
can be used only as detail panel foraspnetuserView
-master Rlform(Rflform)
- Webapi service generated for
-
Navigation paths which make sense
-
aspnetuserView
-aspnetroleView
-aspnetrolemask
-
aspnetuserView
-aspnetusermaskView
-
aspnetroleView
-aspnetrolemask
-
aspnetmodelView
-aspnetrolemask
-
-
-
Rl
andRdl
navigation forms:- For our demo app we will generate
Routes
forRl
andRdl
navigation forms- Real app require only one type of forms (
Rdl
orRl
) -
Rdl
forms implement Add/Update/Delete/View item as popup dialogs -
Rl
forms implement Add/Update/Delete/View item as a separate navigation forms.
- Real app require only one type of forms (
- For our demo app we will generate
- right click
src/app
-folder of the Angular project and selectJavascript Wizard
-menu item - on the first page click
next
-button - on the second page
- select
PhBkContext.csproj
-project - select
aspnetchckdbcontext
-Dbcontext - click
next
-button
- select
- on the third page
- select
aspnetmodelView
in the combo - click
next
-button
- select
- on the fourth page
- select
01980-R-lazy.routes.ts
- click
next
-button
- select
- on the fifth page
- select
r-lazy.routes.ts.t4
- click
next
-button
- select
- copy generated code in the
app-routing.module.ts
-file - copy the following html in the
app.component.html
-file
<a mat-list-item [routerLink]="['aspnetmodelView']" routerLinkActive="active">List of aspnetmodels</a>
- on the fourth page
- select
02060-Rdl-lazy.routes.ts
- click
next
-button
- select
- on the fifth page
- select
rdl-lazy.routes.ts.t4
- click
next
-button
- select
- copy generated code in the
app-routing.module.ts
-file - copy the following html in the
app.component.html
-file
<a mat-list-item [routerLink]="['RDLaspnetmodelView']" routerLinkActive="active">List of aspnetmodels (Dlg)</a>
repeat the steps similar to those described for aspnetmodelView
repeat the steps similar to those described for aspnetmodelView
- We do not need generate Routes and menu items for the rest of the Views.
-
aspnetrolemaskView
is returned only for one selected role -
aspnetusermaskView
is returned only for one selected user- It is a dynamically generated data. It collects Roles assigned to the given User.
- Having the Roles along with Role Permission Masks it defines permission Masks for the given user.
-
aspnetuserpermsView
is returned only for one selected user.- It is a helper structure that is sent to the client after the user has logged in
-
aspnetuserrolesView
is returned only for one selected user. It does not return for one selected Role.
-