예제 #1
0
    public static string?GetAllowedFor(this PropertyRoute route, PropertyAllowed requested)
    {
        if (!AuthLogic.IsEnabled || ExecutionMode.InGlobal)
        {
            return(null);
        }

        route = route.SimplifyToPropertyOrRoot();

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

            return(null);
        }
        else
        {
            PropertyAllowed paProperty = cache.GetAllowed(RoleEntity.Current, route);

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

            return(null);
        }
    }
예제 #2
0
        public static void Start(IApplicationBuilder app)
        {
            if (started)
            {
                return;
            }

            started = true;

            SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod());
            ReflectionServer.RegisterLike(typeof(QueryTokenEmbedded), () => UserAssetPermission.UserAssetsToXML.IsAuthorized() ||
                                          TypeAuthLogic.GetAllowed(typeof(UserQueryEntity)).MaxUI() > Entities.Authorization.TypeAllowedBasic.None ||
                                          TypeAuthLogic.GetAllowed(typeof(UserChartEntity)).MaxUI() > Entities.Authorization.TypeAllowedBasic.None
                                          );
            //EntityJsonConverter.DefaultPropertyRoutes.Add(typeof(QueryFilterEmbedded), PropertyRoute.Construct((UserQueryEntity e) => e.Filters.FirstEx()));
            //EntityJsonConverter.DefaultPropertyRoutes.Add(typeof(PinnedQueryFilterEmbedded), PropertyRoute.Construct((UserQueryEntity e) => e.Filters.FirstEx().Pinned));

            var pcs = SignumServer.WebEntityJsonConverterFactory.GetPropertyConverters(typeof(QueryTokenEmbedded));

            pcs.Add("token", new PropertyConverter
            {
                CustomWriteJsonProperty = (Utf8JsonWriter writer, WriteJsonPropertyContext ctx) =>
                {
                    var qte = (QueryTokenEmbedded)ctx.Entity;

                    writer.WritePropertyName(ctx.LowerCaseName);
                    JsonSerializer.Serialize(writer, qte.TryToken == null ? null : new QueryTokenTS(qte.TryToken, true), ctx.JsonSerializerOptions);
                },
                AvoidValidate          = true,
                CustomReadJsonProperty = (ref Utf8JsonReader reader, ReadJsonPropertyContext ctx) =>
                {
                    var result = JsonSerializer.Deserialize <object>(ref reader, ctx.JsonSerializerOptions);
                    //Discard
                }
            });
            pcs.Add("parseException", new PropertyConverter
            {
                CustomWriteJsonProperty = (Utf8JsonWriter writer, WriteJsonPropertyContext ctx) =>
                {
                    var qte = (QueryTokenEmbedded)ctx.Entity;

                    writer.WritePropertyName(ctx.LowerCaseName);
                    writer.WriteStringValue(qte.ParseException?.Message);
                },
                AvoidValidate          = true,
                CustomReadJsonProperty = (ref Utf8JsonReader reader, ReadJsonPropertyContext ctx) =>
                {
                    var result = reader.GetString();
                    //Discard
                }
            });
            pcs.GetOrThrow("tokenString").CustomWriteJsonProperty = (Utf8JsonWriter writer, WriteJsonPropertyContext ctx) =>
            {
                var qte = (QueryTokenEmbedded)ctx.Entity;

                writer.WritePropertyName(ctx.LowerCaseName);
                writer.WriteStringValue(qte.TryToken?.FullKey() ?? qte.TokenString);
            };
        }
예제 #3
0
        static bool manager_IsCreable(Type type)
        {
            if (!typeof(Entity).IsAssignableFrom(type))
            {
                return(true);
            }

            return(TypeAuthLogic.GetAllowed(type).MaxUI() == TypeAllowedBasic.Create);
        }
예제 #4
0
        public Lite <DashboardEntity>?Home()
        {
            if (TypeAuthLogic.GetAllowed(typeof(DashboardEntity)).MaxUI() == TypeAllowedBasic.None)
            {
                return(null);
            }

            var result = DashboardLogic.GetHomePageDashboard();

            return(result?.ToLite());
        }
예제 #5
0
        static bool manager_IsViewable(Type type, ModifiableEntity entity)
        {
            if (!typeof(Entity).IsAssignableFrom(type))
            {
                return(true);
            }

            var ident = (Entity)entity;

            if (ident == null || ident.IsNew)
            {
                return(TypeAuthLogic.GetAllowed(type).MaxUI() >= TypeAllowedBasic.Read);
            }

            return(ident.IsAllowedFor(TypeAllowedBasic.Read, inUserInterface: true));
        }
예제 #6
0
        static bool manager_IsReadOnly(Type type, ModifiableEntity entity)
        {
            if (!typeof(Entity).IsAssignableFrom(type))
            {
                return(false);
            }

            var ident = (Entity)entity;

            if (ident == null || ident.IsNew)
            {
                return(TypeAuthLogic.GetAllowed(type).MaxUI() < TypeAllowedBasic.Modify);
            }

            return(!ident.IsAllowedFor(TypeAllowedBasic.Modify, inUserInterface: true));
        }
예제 #7
0
    public override Func <PropertyRoute, PropertyAllowed, PropertyAllowed> GetCoerceValue(Lite <RoleEntity> role)
    {
        return((pr, a) =>
        {
            if (!TypeLogic.TypeToEntity.ContainsKey(pr.RootType))
            {
                return PropertyAllowed.Write;
            }

            TypeAllowedAndConditions aac = TypeAuthLogic.GetAllowed(role, pr.RootType);

            TypeAllowedBasic ta = aac.MaxUI();

            PropertyAllowed pa = ta.ToPropertyAllowed();

            return a < pa ? a : pa;
        });
    }
예제 #8
0
    public override Func <object, QueryAllowed, QueryAllowed> GetCoerceValue(Lite <RoleEntity> role)
    {
        return((queryName, allowed) =>
        {
            if (QueryAuthLogic.AvoidCoerce.Contains(queryName))
            {
                return allowed;
            }

            if (allowed == QueryAllowed.None)
            {
                return allowed;
            }

            var implementations = QueryLogic.Queries.GetEntityImplementations(queryName);

            return implementations.AllCanRead(t => TypeAuthLogic.GetAllowed(role, t)) ? allowed : QueryAllowed.None;
        });
    }
예제 #9
0
        private static void RegisterSaveButton <T>(string partialViewName, bool embedded)
            where T : ModifiableEntity
        {
            ButtonBarEntityHelper.RegisterEntityButtons <T>((ctx, entity) =>
            {
                if (TypeAuthLogic.GetAllowed(PackToRule.GetOrThrow(typeof(T))).MaxUI() >= TypeAllowedBasic.Modify)
                {
                    return new[]
                    {
                        new ToolBarButton(ctx.Prefix, partialViewName)
                        {
                            Text    = AuthMessage.Save.NiceToString(),
                            Style   = BootstrapStyle.Primary,
                            OnClick = embedded?
                                      Module["postDialog"](ctx.Url.Action("save" + partialViewName, "AuthAdmin"), ctx.Prefix):
                                      Module["submitPage"](ctx.Url.Action(partialViewName, "AuthAdmin"), ctx.Prefix),
                        }
                    }
                }
                ;

                return(new ToolBarButton[] { });
            });
        }
예제 #10
0
 public static void Start(IApplicationBuilder app)
 {
     SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod());
     ReflectionServer.RegisterLike(typeof(TreeEntity), () => Schema.Current.Tables.Keys.Where(p => typeof(TreeEntity).IsAssignableFrom(p)).Any(t => TypeAuthLogic.GetAllowed(t).MaxUI() > TypeAllowedBasic.None));
 }
예제 #11
0
        public static void Start(IApplicationBuilder app, Func <AuthTokenConfigurationEmbedded> tokenConfig, string hashableEncryptionKey)
        {
            SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod());

            AuthTokenServer.Start(tokenConfig, hashableEncryptionKey);

            ReflectionServer.GetContext = () => new
            {
                Culture = ReflectionServer.GetCurrentValidCulture(),
                Role    = UserEntity.Current == null ? null : RoleEntity.Current,
            };

            AuthLogic.OnRulesChanged += () => ReflectionServer.cache.Clear();

            if (TypeAuthLogic.IsStarted)
            {
                ReflectionServer.AddTypeExtension += (ti, t) =>
                {
                    if (typeof(Entity).IsAssignableFrom(t))
                    {
                        var ta = UserEntity.Current != null?TypeAuthLogic.GetAllowed(t) : null;

                        ti.Extension.Add("maxTypeAllowed", ta == null ? TypeAllowedBasic.None : ta.MaxUI());
                        ti.Extension.Add("minTypeAllowed", ta == null ? TypeAllowedBasic.None : ta.MinUI());
                        ti.RequiresEntityPack |= ta != null && ta.Conditions.Any();
                    }
                };


                EntityPackTS.AddExtension += ep =>
                {
                    var typeAllowed =
                        UserEntity.Current == null ? TypeAllowedBasic.None :
                        ep.entity.IsNew ? TypeAuthLogic.GetAllowed(ep.entity.GetType()).MaxUI() :
                        TypeAuthLogic.IsAllowedFor(ep.entity, TypeAllowedBasic.Write, true) ? TypeAllowedBasic.Write :
                        TypeAuthLogic.IsAllowedFor(ep.entity, TypeAllowedBasic.Read, true) ? TypeAllowedBasic.Read :
                        TypeAllowedBasic.None;

                    ep.extension.Add("typeAllowed", typeAllowed);
                };

                OperationController.AnyReadonly += (Lite <Entity>[] lites) =>
                {
                    return(lites.GroupBy(ap => ap.EntityType).Any(gr =>
                    {
                        var ta = TypeAuthLogic.GetAllowed(gr.Key);

                        if (ta.Min(inUserInterface: true) == TypeAllowedBasic.Write)
                        {
                            return false;
                        }

                        if (ta.Max(inUserInterface: true) <= TypeAllowedBasic.Read)
                        {
                            return true;
                        }

                        return giCountReadonly.GetInvoker(gr.Key)() > 0;
                    }));
                };
            }

            if (QueryAuthLogic.IsStarted)
            {
                ReflectionServer.AddTypeExtension += (ti, t) =>
                {
                    if (ti.QueryDefined)
                    {
                        ti.Extension.Add("queryAllowed", UserEntity.Current == null ? QueryAllowed.None : QueryAuthLogic.GetQueryAllowed(t));
                    }
                };

                ReflectionServer.AddFieldInfoExtension += (mi, fi) =>
                {
                    if (fi.DeclaringType !.Name.EndsWith("Query"))
                    {
                        mi.Extension.Add("queryAllowed", UserEntity.Current == null ? QueryAllowed.None : QueryAuthLogic.GetQueryAllowed(fi.GetValue(null) !));
                    }
                };
            }

            if (PropertyAuthLogic.IsStarted)
            {
                ReflectionServer.AddPropertyRouteExtension += (mi, pr) =>
                {
                    mi.Extension.Add("propertyAllowed", UserEntity.Current == null ? PropertyAllowed.None : pr.GetPropertyAllowed());
                };
            }

            if (OperationAuthLogic.IsStarted)
            {
                ReflectionServer.AddOperationExtension += (oits, oi, type) =>
                {
                    oits.Extension.Add("operationAllowed",
                                       UserEntity.Current == null ? false :
                                       OperationAuthLogic.GetOperationAllowed(oi.OperationSymbol, type, inUserInterface: true));
                };
            }

            if (PermissionAuthLogic.IsStarted)
            {
                ReflectionServer.AddFieldInfoExtension += (mi, fi) =>
                {
                    if (fi.FieldType == typeof(PermissionSymbol))
                    {
                        mi.Extension.Add("permissionAllowed",
                                         UserEntity.Current == null ? false :
                                         PermissionAuthLogic.IsAuthorized((PermissionSymbol)fi.GetValue(null) !));
                    }
                };
            }


            var piPasswordHash = ReflectionTools.GetPropertyInfo((UserEntity e) => e.PasswordHash);
            var pcs            = PropertyConverter.GetPropertyConverters(typeof(UserEntity));

            pcs.GetOrThrow("passwordHash").CustomWriteJsonProperty = ctx => { };
            pcs.Add("newPassword", new PropertyConverter
            {
                AvoidValidate           = true,
                CustomWriteJsonProperty = ctx => { },
                CustomReadJsonProperty  = ctx =>
                {
                    EntityJsonConverter.AssertCanWrite(ctx.ParentPropertyRoute.Add(piPasswordHash));

                    var password = (string)ctx.JsonReader.Value !;

                    var error = UserEntity.OnValidatePassword(password);
                    if (error != null)
                    {
                        throw new ApplicationException(error);
                    }

                    ((UserEntity)ctx.Entity).PasswordHash = Security.EncodePassword(password);
                }
            });
예제 #12
0
 QueryAllowed GetDefault(object key, Lite <RoleEntity> role)
 {
     return(QueryLogic.Queries.GetEntityImplementations(key).AllCanRead(t => TypeAuthLogic.GetAllowed(role, t)) ? QueryAllowed.Allow : QueryAllowed.None);
 }
예제 #13
0
        public static void Start(IApplicationBuilder app)
        {
            UserAssetServer.Start(app);

            SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod());

            CustomizeChartRequest();

            SignumServer.WebEntityJsonConverterFactory.AfterDeserilization.Register((ChartRequestModel cr) =>
            {
                if (cr.ChartScript != null)
                {
                    cr.GetChartScript().SynchronizeColumns(cr, null);
                }

                if (cr.QueryName != null)
                {
                    var qd = QueryLogic.Queries.QueryDescription(cr.QueryName);

                    if (cr.Columns != null)
                    {
                        foreach (var c in cr.Columns)
                        {
                            c.ParseData(cr, qd, SubTokensOptions.CanElement | SubTokensOptions.CanAggregate);
                        }
                    }
                }
            });

            SignumServer.WebEntityJsonConverterFactory.AfterDeserilization.Register((UserChartEntity uc) =>
            {
                if (uc.ChartScript != null)
                {
                    uc.GetChartScript().SynchronizeColumns(uc, null);
                }

                if (uc.Query != null)
                {
                    var qd = QueryLogic.Queries.QueryDescription(uc.Query.ToQueryName());
                    uc.ParseData(qd);
                }
            });

            UserChartEntity.SetConverters(
                query => QueryLogic.ToQueryName(query.Key),
                queryName => QueryLogic.GetQueryEntity(queryName));

            EntityPackTS.AddExtension += ep =>
            {
                if (ep.entity.IsNew || !ChartPermission.ViewCharting.IsAuthorized() || TypeAuthLogic.GetAllowed(typeof(UserChartEntity)).MaxDB() == TypeAllowedBasic.None)
                {
                    return;
                }

                var userCharts = UserChartLogic.GetUserChartsEntity(ep.entity.GetType());
                if (userCharts.Any())
                {
                    ep.extension.Add("userCharts", userCharts);
                }
            };
        }
예제 #14
0
 PropertyAllowed GetDefault(PropertyRoute key, Lite <RoleEntity> role)
 {
     return(TypeAuthLogic.GetAllowed(role, key.RootType).MaxUI().ToPropertyAllowed());
 }
예제 #15
0
        public static void Start(IApplicationBuilder app, Func <AuthTokenConfigurationEmbedded> tokenConfig, string hashableEncryptionKey)
        {
            SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod());

            AuthTokenServer.Start(tokenConfig, hashableEncryptionKey);

            ReflectionServer.GetContext = () => new
            {
                Culture = ReflectionServer.GetCurrentValidCulture(),
                Role    = UserEntity.Current == null ? null : RoleEntity.Current,
            };

            AuthLogic.OnRulesChanged += ReflectionServer.InvalidateCache;

            if (TypeAuthLogic.IsStarted)
            {
                ReflectionServer.TypeExtension += (ti, t) =>
                {
                    if (typeof(Entity).IsAssignableFrom(t))
                    {
                        if (UserEntity.Current == null)
                        {
                            return(null);
                        }

                        var ta = TypeAuthLogic.GetAllowed(t);

                        if (ta.MaxUI() == TypeAllowedBasic.None)
                        {
                            return(null);
                        }

                        ti.Extension.Add("maxTypeAllowed", ta.MaxUI());
                        ti.Extension.Add("minTypeAllowed", ta.MinUI());
                        ti.RequiresEntityPack |= ta.Conditions.Any();

                        return(ti);
                    }
                    else
                    {
                        if (t.HasAttribute <AllowUnathenticatedAttribute>())
                        {
                            return(ti);
                        }

                        if (UserEntity.Current == null)
                        {
                            return(null);
                        }

                        if (!AuthServer.IsNamespaceAllowed(t))
                        {
                            return(null);
                        }

                        return(ti);
                    }
                };


                EntityPackTS.AddExtension += ep =>
                {
                    var typeAllowed =
                        UserEntity.Current == null ? TypeAllowedBasic.None :
                        ep.entity.IsNew ? TypeAuthLogic.GetAllowed(ep.entity.GetType()).MaxUI() :
                        TypeAuthLogic.IsAllowedFor(ep.entity, TypeAllowedBasic.Write, true) ? TypeAllowedBasic.Write :
                        TypeAuthLogic.IsAllowedFor(ep.entity, TypeAllowedBasic.Read, true) ? TypeAllowedBasic.Read :
                        TypeAllowedBasic.None;

                    ep.extension.Add("typeAllowed", typeAllowed);
                };

                OperationController.AnyReadonly += (Lite <Entity>[] lites) =>
                {
                    return(lites.GroupBy(ap => ap.EntityType).Any(gr =>
                    {
                        var ta = TypeAuthLogic.GetAllowed(gr.Key);

                        if (ta.Min(inUserInterface: true) == TypeAllowedBasic.Write)
                        {
                            return false;
                        }

                        if (ta.Max(inUserInterface: true) <= TypeAllowedBasic.Read)
                        {
                            return true;
                        }

                        return giCountReadonly.GetInvoker(gr.Key)() > 0;
                    }));
                };
            }

            if (QueryAuthLogic.IsStarted)
            {
                ReflectionServer.TypeExtension += (ti, t) =>
                {
                    if (ti.QueryDefined)
                    {
                        var allowed = UserEntity.Current == null ? QueryAllowed.None : QueryAuthLogic.GetQueryAllowed(t);
                        if (allowed == QueryAllowed.None)
                        {
                            ti.QueryDefined = false;
                        }

                        ti.Extension.Add("queryAllowed", allowed);
                    }

                    return(ti);
                };

                ReflectionServer.FieldInfoExtension += (mi, fi) =>
                {
                    if (fi.DeclaringType !.Name.EndsWith("Query"))
                    {
                        var allowed = UserEntity.Current == null ? QueryAllowed.None : QueryAuthLogic.GetQueryAllowed(fi.GetValue(null) !);

                        if (allowed == QueryAllowed.None)
                        {
                            return(null);
                        }

                        mi.Extension.Add("queryAllowed", allowed);
                    }
                    return(mi);
                };
            }

            if (PropertyAuthLogic.IsStarted)
            {
                ReflectionServer.PropertyRouteExtension += (mi, pr) =>
                {
                    var allowed = UserEntity.Current == null?pr.GetAllowUnathenticated() : pr.GetPropertyAllowed();

                    if (allowed == PropertyAllowed.None)
                    {
                        return(null);
                    }

                    mi.Extension.Add("propertyAllowed", allowed);
                    return(mi);
                };

                SignumServer.WebEntityJsonConverterFactory.CanReadPropertyRoute += (pr, mod) =>
                {
                    var allowed = UserEntity.Current == null?pr.GetAllowUnathenticated() : pr.GetPropertyAllowed();

                    return(allowed == PropertyAllowed.None ? "Not allowed" : null);
                };

                SignumServer.WebEntityJsonConverterFactory.CanWritePropertyRoute += (pr, mod) =>
                {
                    var allowed = UserEntity.Current == null?pr.GetAllowUnathenticated() : pr.GetPropertyAllowed();

                    return(allowed == PropertyAllowed.Write ? null : "Not allowed to write property: " + pr.ToString());
                };
            }

            if (OperationAuthLogic.IsStarted)
            {
                ReflectionServer.OperationExtension += (oits, oi, type) =>
                {
                    var allowed = UserEntity.Current == null ? false :
                                  OperationAuthLogic.GetOperationAllowed(oi.OperationSymbol, type, inUserInterface: true);

                    if (!allowed)
                    {
                        return(null);
                    }

                    return(oits);
                };
            }

            if (PermissionAuthLogic.IsStarted)
            {
                ReflectionServer.FieldInfoExtension += (mi, fi) =>
                {
                    if (fi.FieldType == typeof(PermissionSymbol))
                    {
                        var allowed = UserEntity.Current == null ? false :
                                      PermissionAuthLogic.IsAuthorized((PermissionSymbol)fi.GetValue(null) !);

                        if (allowed == false)
                        {
                            return(null);
                        }
                    }

                    return(mi);
                };
            }

            var piPasswordHash = ReflectionTools.GetPropertyInfo((UserEntity e) => e.PasswordHash);
            var pcs            = SignumServer.WebEntityJsonConverterFactory.GetPropertyConverters(typeof(UserEntity));

            pcs.GetOrThrow("passwordHash").CustomWriteJsonProperty = (writer, ctx) => { };
            pcs.Add("newPassword", new PropertyConverter
            {
                AvoidValidate           = true,
                CustomWriteJsonProperty = (Utf8JsonWriter writer, WriteJsonPropertyContext ctx) => { },
                CustomReadJsonProperty  = (ref Utf8JsonReader reader, ReadJsonPropertyContext ctx) =>
                {
                    SignumServer.WebEntityJsonConverterFactory.AssertCanWrite(ctx.ParentPropertyRoute.Add(piPasswordHash), ctx.Entity);

                    var password = reader.GetString();

                    if (password == null)
                    {
                        ((UserEntity)ctx.Entity).PasswordHash = null;
                    }
                    else
                    {
                        var error = UserEntity.OnValidatePassword(password);
                        if (error != null)
                        {
                            throw new ApplicationException(error);
                        }

                        ((UserEntity)ctx.Entity).PasswordHash = Security.EncodePassword(password);
                    }
                }
            });

            if (TypeAuthLogic.IsStarted)
            {
                Omnibox.OmniboxServer.IsNavigable += type => TypeAuthLogic.GetAllowed(type).MaxUI() >= TypeAllowedBasic.Read;
            }

            if (SessionLogLogic.IsStarted)
            {
                AuthServer.UserLogged += (ActionContext ac, UserEntity user) =>
                {
                    Microsoft.AspNetCore.Http.HttpRequest re = ac.HttpContext.Request;
                    SessionLogLogic.SessionStart(
                        re.Host.ToString(),
                        re.Headers["User-Agent"].FirstOrDefault());
                }
            }
            ;

            SchemaMap.GetColorProviders += GetMapColors;
        }
예제 #16
0
 public static void Start(IApplicationBuilder app)
 {
     ReflectionServer.RegisterLike(typeof(TemplateTokenMessage), () =>
                                   TypeAuthLogic.GetAllowed(typeof(EmailTemplateEntity)).MaxUI() > Entities.Authorization.TypeAllowedBasic.None ||
                                   TypeAuthLogic.GetAllowed(typeof(WordTemplateEntity)).MaxUI() > Entities.Authorization.TypeAllowedBasic.None);
 }
예제 #17
0
        public static void Start(HttpConfiguration config, Func <AuthTokenConfigurationEmbedded> tokenConfig, string hashableEncryptionKey)
        {
            SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod());

            AuthTokenServer.Start(tokenConfig, hashableEncryptionKey);

            ReflectionServer.GetContext = () => new
            {
                Culture = ReflectionServer.GetCurrentValidCulture(),
                Role    = UserEntity.Current == null ? null : RoleEntity.Current,
            };

            AuthLogic.OnRulesChanged += () => ReflectionServer.cache.Clear();

            if (TypeAuthLogic.IsStarted)
            {
                ReflectionServer.AddTypeExtension += (ti, t) =>
                {
                    if (typeof(Entity).IsAssignableFrom(t))
                    {
                        ti.Extension.Add("typeAllowed", UserEntity.Current == null ? TypeAllowedBasic.None : TypeAuthLogic.GetAllowed(t).MaxUI());
                    }
                };
            }

            if (QueryAuthLogic.IsStarted)
            {
                ReflectionServer.AddTypeExtension += (ti, t) =>
                {
                    if (ti.QueryDefined)
                    {
                        ti.Extension.Add("queryAllowed", UserEntity.Current == null ? QueryAllowed.None : QueryAuthLogic.GetQueryAllowed(t));
                    }
                };

                ReflectionServer.AddFieldInfoExtension += (mi, fi) =>
                {
                    if (fi.DeclaringType.Name.EndsWith("Query"))
                    {
                        mi.Extension.Add("queryAllowed", UserEntity.Current == null ? QueryAllowed.None : QueryAuthLogic.GetQueryAllowed(fi.GetValue(null)));
                    }
                };
            }

            if (PropertyAuthLogic.IsStarted)
            {
                ReflectionServer.AddPropertyRouteExtension += (mi, pr) =>
                {
                    mi.Extension.Add("propertyAllowed", UserEntity.Current == null ? PropertyAllowed.None : pr.GetPropertyAllowed());
                };
            }

            if (OperationAuthLogic.IsStarted)
            {
                ReflectionServer.AddFieldInfoExtension += (mi, fi) =>
                {
                    if (fi.DeclaringType.Name.EndsWith("Operation"))
                    {
                        if (fi.GetValue(null) is IOperationSymbolContainer container)
                        {
                            mi.Extension.Add("operationAllowed",
                                             UserEntity.Current == null ? false
                                    : OperationAuthLogic.GetOperationAllowed(container.Symbol, inUserInterface: true));
                        }
                    }
                };
            }

            if (PermissionAuthLogic.IsStarted)
            {
                ReflectionServer.AddFieldInfoExtension += (mi, fi) =>
                {
                    if (fi.FieldType == typeof(PermissionSymbol))
                    {
                        mi.Extension.Add("permissionAllowed",
                                         UserEntity.Current == null
                                ? false
                                : PermissionAuthLogic.IsAuthorized((PermissionSymbol)fi.GetValue(null)));
                    }
                };
            }


            var piPasswordHash = ReflectionTools.GetPropertyInfo((UserEntity e) => e.PasswordHash);
            var pcs            = PropertyConverter.GetPropertyConverters(typeof(UserEntity));

            pcs.GetOrThrow("passwordHash").CustomWriteJsonProperty = ctx => { };
            pcs.Add("newPassword", new PropertyConverter
            {
                AvoidValidate           = true,
                CustomWriteJsonProperty = ctx => { },
                CustomReadJsonProperty  = ctx =>
                {
                    EntityJsonConverter.AssertCanWrite(ctx.ParentPropertyRoute.Add(piPasswordHash));

                    var password = (string)ctx.JsonReader.Value;

                    var error = UserEntity.OnValidatePassword(password);
                    if (error != null)
                    {
                        throw new ApplicationException(error);
                    }

                    ((UserEntity)ctx.Entity).PasswordHash = Security.EncodePassword(password);
                }
            });

            if (TypeAuthLogic.IsStarted)
            {
                Omnibox.OmniboxServer.IsNavigable += type => TypeAuthLogic.GetAllowed(type).MaxUI() >= TypeAllowedBasic.Read;
            }

            SchemaMap.GetColorProviders += GetMapColors;
        }
예제 #18
0
        public static void Start(IApplicationBuilder app)
        {
            TypeHelpServer.Start(app);
            SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod());
            ReflectionServer.OverrideIsNamespaceAllowed.Add(typeof(ExchangeVersion).Namespace !, () => TypeAuthLogic.GetAllowed(typeof(EmailSenderConfigurationEntity)).MaxUI() > TypeAllowedBasic.None);
            ReflectionServer.OverrideIsNamespaceAllowed.Add(typeof(SmtpDeliveryMethod).Namespace !, () => TypeAuthLogic.GetAllowed(typeof(EmailSenderConfigurationEntity)).MaxUI() > TypeAllowedBasic.None);


            TemplatingServer.Start(app);

            EntityJsonConverter.AfterDeserilization.Register((EmailTemplateEntity et) =>
            {
                if (et.Query != null)
                {
                    var qd = QueryLogic.Queries.QueryDescription(et.Query.ToQueryName());
                    et.ParseData(qd);
                }
            });

            QueryDescriptionTS.AddExtension += qd =>
            {
                object type = QueryLogic.ToQueryName(qd.queryKey);
                if (Schema.Current.IsAllowed(typeof(EmailTemplateEntity), true) == null)
                {
                    var templates = EmailTemplateLogic.GetApplicableEmailTemplates(type, null, EmailTemplateVisibleOn.Query);

                    if (templates.HasItems())
                    {
                        qd.Extension.Add("emailTemplates", templates);
                    }
                }
            };


            if (Schema.Current.Tables.ContainsKey(typeof(EmailSenderConfigurationEntity)))
            {
                var piPassword = ReflectionTools.GetPropertyInfo((SmtpNetworkDeliveryEmbedded e) => e.Password);
                var pcs        = PropertyConverter.GetPropertyConverters(typeof(SmtpNetworkDeliveryEmbedded));
                pcs.GetOrThrow("password").CustomWriteJsonProperty = ctx => { };
                pcs.Add("newPassword", new PropertyConverter
                {
                    AvoidValidate           = true,
                    CustomWriteJsonProperty = ctx => { },
                    CustomReadJsonProperty  = ctx =>
                    {
                        EntityJsonConverter.AssertCanWrite(ctx.ParentPropertyRoute.Add(piPassword));

                        var password = (string)ctx.JsonReader.Value !;

                        ((SmtpNetworkDeliveryEmbedded)ctx.Entity).Password = EmailSenderConfigurationLogic.EncryptPassword(password);
                    }
                });
예제 #19
0
    public static void Start(IApplicationBuilder app)
    {
        SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod());

        ReflectionServer.RegisterLike(typeof(DiffLogMessage), () => TimeMachinePermission.ShowTimeMachine.IsAuthorized() || TypeAuthLogic.GetAllowed(typeof(OperationLogEntity)).MaxUI() > TypeAllowedBasic.None);
    }