示例#1
0
        static void AuthClient_UpdateCacheEvent()
        {
            var overrides = Server.Return((IPropertyAuthServer s) => s.OverridenProperties());

            propertyRules = new DefaultDictionary <PropertyRoute, PropertyAllowed>
                                (pr =>
            {
                if (!BasicPermission.AutomaticUpgradeOfProperties.IsAuthorized())
                {
                    return(TypeAuthClient.GetDefaultAllowed() ? PropertyAllowed.Modify : PropertyAllowed.None);
                }

                return(TypeAuthClient.GetAllowed(pr.RootType).MaxUI().ToPropertyAllowed());
            }, overrides);
        }
示例#2
0
        public static string GetAllowedFor(this PropertyRoute route, PropertyAllowed requested)
        {
            if (route.PropertyRouteType == PropertyRouteType.MListItems || route.PropertyRouteType == PropertyRouteType.LiteEntity)
            {
                return(GetAllowedFor(route.Parent, requested));
            }

            if (!typeof(Entity).IsAssignableFrom(route.RootType))
            {
                return(null);
            }

            if (route.PropertyRouteType == PropertyRouteType.Root || route.IsToStringProperty())
            {
                var typeAllowed = TypeAuthClient.GetAllowed(route.RootType).MaxUI().ToPropertyAllowed();
                if (typeAllowed < requested)
                {
                    return("Type {0} is set to {1} for {2}".FormatWith(route.RootType.NiceName(), typeAllowed, RoleEntity.Current));
                }

                return(null);
            }

            var propAllowed = GetPropertyAllowed(route);

            if (propAllowed < requested)
            {
                var typeAllowed = TypeAuthClient.GetAllowed(route.RootType).MaxUI().ToPropertyAllowed();

                if (typeAllowed < requested)
                {
                    return("Type {0} is set to {1} for {2}".FormatWith(route.RootType.NiceName(), typeAllowed, RoleEntity.Current));
                }

                return("Property {0} is set to {1} for {2}".FormatWith(route, propAllowed, RoleEntity.Current));
            }

            return(null);
        }
示例#3
0
        public static PropertyAllowed GetPropertyAllowed(this PropertyRoute route)
        {
            while (route.PropertyRouteType == PropertyRouteType.MListItems || route.PropertyRouteType == PropertyRouteType.LiteEntity)
            {
                route = route.Parent;
            }

            if (!typeof(Entity).IsAssignableFrom(route.RootType))
            {
                return(PropertyAllowed.Modify);
            }

            if (route.PropertyRouteType == PropertyRouteType.Root || route.IsToStringProperty())
            {
                return(TypeAuthClient.GetAllowed(route.RootType).MaxUI().ToPropertyAllowed());
            }

            var propAllowed = propertyRules.GetAllowed(route);

            var typeAllowed = TypeAuthClient.GetAllowed(route.RootType).MaxUI().ToPropertyAllowed();

            return(propAllowed < typeAllowed ? propAllowed : typeAllowed);
        }
示例#4
0
        public static void Start(bool types, bool property, bool queries, bool permissions, bool operations, bool defaultPasswordExpiresLogic)
        {
            if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                Server.Connecting += UpdateCache;

                if (types)
                {
                    TypeAuthClient.Start();
                }
                if (property)
                {
                    PropertyAuthClient.Start();
                }
                if (queries)
                {
                    QueryAuthClient.Start();
                }
                if (permissions)
                {
                    PermissionAuthClient.Start();
                }
                if (operations)
                {
                    OperationAuthClient.Start();
                }

                UpdateCache();

                Navigator.AddSetting(new EntitySettings <UserEntity> {
                    View = e => new User(), Icon = ImageLoader.GetImageSortName("user.png")
                });
                Navigator.AddSetting(new EntitySettings <RoleEntity> {
                    View = e => new Role(), Icon = ImageLoader.GetImageSortName("role.png")
                });

                if (defaultPasswordExpiresLogic)
                {
                    Navigator.AddSetting(new EntitySettings <PasswordExpiresIntervalEntity> {
                        View = e => new PasswordExpiresInterval()
                    });
                }

                OperationClient.AddSettings(new List <OperationSettings>()
                {
                    new EntityOperationSettings <UserEntity>(UserOperation.SetPassword)
                    {
                        IsVisible = e => false
                    },
                    new EntityOperationSettings <UserEntity>(UserOperation.SaveNew)
                    {
                        IsVisible = e => e.Entity.IsNew
                    },
                    new EntityOperationSettings <UserEntity>(UserOperation.Save)
                    {
                        IsVisible = e => !e.Entity.IsNew
                    }
                });

                SpecialOmniboxProvider.Register(new SpecialOmniboxAction("UpdateAuthCache",
                                                                         () => true,
                                                                         win =>
                {
                    UpdateCache();

                    MessageBox.Show(AuthMessage.AuthorizationCacheSuccessfullyUpdated.NiceToString());
                }));

                SpecialOmniboxProvider.Register(new SpecialOmniboxAction("DownloadAuthRules",
                                                                         () => BasicPermission.AdminRules.IsAuthorized(),
                                                                         win =>
                {
                    SaveFileDialog sfc = new SaveFileDialog()
                    {
                        FileName = "AuthRules.xml"
                    };
                    if (sfc.ShowDialog() == true)
                    {
                        var bytes = Server.Return((ILoginServer ls) => ls.DownloadAuthRules());

                        File.WriteAllBytes(sfc.FileName, bytes);
                    }
                }));
            }
        }