示例#1
0
        /// <summary>
        /// Create.
        /// </summary>
        /// <param name="permissionsSetupProvider">
        /// The provider for a <see cref="PermissionsSetup"/> instance.
        /// </param>
        public AccessMapper(IPermissionsSetupProvider permissionsSetupProvider)
        {
            if (permissionsSetupProvider == null)
            {
                throw new ArgumentNullException(nameof(permissionsSetupProvider));
            }

            var permissionsSetup = permissionsSetupProvider.Load();

            rolesAccessRightsByCodeName           = new Dictionary <string, AccessRight>();
            dispositionTypeAccessRightsByCodeName = new Dictionary <string, AccessRight>();

            foreach (var assignment in permissionsSetup.PermissionAssignments)
            {
                CombineToAccessRightsMap(rolesAccessRightsByCodeName, assignment.Roles, assignment);

                CombineToAccessRightsMap(dispositionTypeAccessRightsByCodeName, assignment.DispositionTypes, assignment);
            }

            defaultRolesForAuthenticated =
                permissionsSetup.DefaultRolesForAuthenticated.Select(r => r.CodeName).ToArray();

            defaultRolesForAnonymous =
                permissionsSetup.DefaultRolesForAnonymous.Select(r => r.CodeName).ToArray();
        }
        /// <summary>
        /// Create.
        /// </summary>
        /// <param name="permissionsSetupProvider">
        /// The provider for a <see cref="PermissionsSetup"/> instance.
        /// </param>
        public AccessResolver(IPermissionsSetupProvider permissionsSetupProvider)
        {
            if (permissionsSetupProvider == null)
            {
                throw new ArgumentNullException(nameof(permissionsSetupProvider));
            }

            lazyAccessMapper = new Lazy <AccessMapper>(() => new AccessMapper(permissionsSetupProvider), true);

            rolesAccessRightsCache =
                new MRUCache <EquatableReadOnlyBag <string>, AccessRight>(
                    CombineAccessRightOfRoles,
                    RolesAccessRightsCacheSize);

            dispositionTypesAccessRightsCache =
                new MRUCache <EquatableReadOnlyBag <string>, AccessRight>(
                    CombineAccessRightOfDispositionTypes,
                    DispositionTypesAccessRightsCacheSize);
        }