C0.02 Security: Authorization. Turn On. Tests. (Xamarin) - chempkovsky/CS2WPF-and-CS2XAMARIN GitHub Wiki
Instructions
Step #1
- open
CommonServicesPrismModule\AppGlblSettingsSrvc\AppGlblSettingsService.cs
-file
- find
GetViewModelMask()
and GetDashBrdMask()
-methods
- remove or comment the first line in the body of each method:
public int GetViewModelMask(string vwModel) {
// return 15; // delete this line when vwModels is ready
if (Permissions == null) return 0;
int pk = 0;
if (!Views.TryGetValue(vwModel, out pk)) return 0;
int rid = pk / 7;
if (rid >= (Permissions.Count() - 3)) return 0;
int sft = (pk - rid * 7) * 4;
int rslt = Permissions[rid];
if (sft > 0)
{
rslt >>= sft;
}
return rslt;
}
public int GetDashBrdMask(string dshBrd)
{
// return 1; // delete this line when dshBrds is ready
if (Dashboards == null) return 0;
int pk = 0;
if (!Dashboards.TryGetValue(dshBrd, out pk)) return 0;
int rid = pk / 31;
if (rid >= (Permissions.Count() - 14)) return 0;
int sft = (pk - rid * 31);
int rslt = Permissions[rid + 14];
if (sft > 0)
{
rslt >>= sft;
}
return rslt;
}
- rebuild CommonServicesPrismModule-project
Step #2
- open
PrismDemoApp\ViewModels\MainWindowViewModel.cs
-file
- uncomment
ServicePermission
-var
- uncomment the body of
OnUserChangedNotification()
-method
private async void OnUserChangedNotification(object sender, string uname)
{
/* Uncomment to turn ON Authorization */
if (string.IsNullOrEmpty(uname))
{
(sender as IAppGlblSettingsService).Permissions = (sender as IAppGlblSettingsService).GetEmptyPermissions();
(sender as IAppGlblSettingsService).NavigateTo("HomePage");
return;
}
else
{
IAspnetusermaskViewServicePermission ServicePermission = _containerProvider.Resolve<IAspnetusermaskViewServicePermission>();
await MainThread.InvokeOnMainThreadAsync(async () =>
{
IaspnetusermaskViewPage rslt = await ServicePermission.getcurrusermasks();
(sender as IAppGlblSettingsService).Permissions = ServicePermission.src2array(rslt);
(sender as IAppGlblSettingsService).NavigateTo("HomePage");
});
return;
}
/* */
// (sender as IAppGlblSettingsService).NavigateTo("HomePage");
}
Step #3
- run Dm04WebApp
- run PrismDemoApp
Step #4
- before login click "AdminRoles Feature"-navigation menu
- before login click any navigation aware component menu item. For instance, "Book Rdlist"-navigation menu
- after login as [email protected] click any navigation aware component menu item. For instance, "Book Rdlist"-navigation menu
- log in as [email protected] and make sure that "Delete"-action is unavailable (for features and for navigation aware components).
- log in as [email protected] and make sure that only "Select"-action is available (for features and for navigation aware components).