C0.01 Security: Authorization. Turn On. Tests. (Wpf) - 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
        /* Uncomment to turn ON Authorization */
        IAspnetusermaskViewServicePermission ServicePermission = null;
        /* */
        protected void OnUserChangedNotification(object sender, string uname) {
            UserName = uname;
            /* Uncomment to turn ON Authorization */
            if (string.IsNullOrEmpty(uname))
            {
                GlblSettingsSrv.Permissions = GlblSettingsSrv.GetEmptyPermissions();
            } else
            {
                if(ServicePermission == null)
                {
                    ServicePermission = _containerProvider.Resolve<IAspnetusermaskViewServicePermission>();
                }
                Application.Current.Dispatcher.Invoke(async () =>
                {
                    IaspnetusermaskViewPage rslt = await ServicePermission.getcurrusermasks();
                    GlblSettingsSrv.Permissions = ServicePermission.src2array(rslt);
                });
            }
            _regionManager.Regions["MainContentRegion"].RemoveAll();
            /* */
        }

Step #3

  • run Dm04WebApp
  • run PrismDemoApp

Step #4

  • before login click "AdminRoles Feature"-navigation menu

picture

  • before login click any navigation aware component menu item. For instance, "Book Rdlist"-navigation menu

picture

picture

  • after login as [email protected] click any navigation aware component menu item. For instance, "Book Rdlist"-navigation menu

picture

  • 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).