public static void Start(IApplicationBuilder app, IWebHostEnvironment hostingEnvironment, Assembly mainAsembly) { Schema.Current.ApplicationName = hostingEnvironment.ContentRootPath; SignumControllerFactory.RegisterArea(typeof(EntitiesController)); SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod() !); ReflectionServer.Start(); ReflectionServer.RegisterLike(typeof(SearchMessage), () => UserHolder.Current != null); ReflectionServer.RegisterLike(typeof(PaginationMode), () => UserHolder.Current != null); ReflectionServer.OverrideIsNamespaceAllowed.Add(typeof(DayOfWeek).Namespace !, () => UserHolder.Current != null); ReflectionServer.OverrideIsNamespaceAllowed.Add(typeof(CollectionMessage).Namespace !, () => UserHolder.Current != null); }
public static void Start(IApplicationBuilder app) { SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod()); PropertyConverter.GetPropertyConverters(typeof(FilePathEmbedded)).Add("fullWebPath", new PropertyConverter() { CustomWriteJsonProperty = ctx => { var csp = (FilePathEmbedded)ctx.Entity; ctx.JsonWriter.WritePropertyName(ctx.LowerCaseName); ctx.JsonSerializer.Serialize(ctx.JsonWriter, csp.FullWebPath()); }, AvoidValidate = true, CustomReadJsonProperty = ctx => { var list = ctx.JsonSerializer.Deserialize(ctx.JsonReader); //Discard } }); var s = Schema.Current.Settings; ReflectionServer.AddPropertyRouteExtension += (mi, pr) => { var dft = s.FieldAttributes(pr)?.OfType <DefaultFileTypeAttribute>().SingleOrDefaultEx(); if (dft != null) { if (dft.FileTypeSymbol == null) { dft.FileTypeSymbol = SymbolLogic <FileTypeSymbol> .Symbols .Where(a => a.Key.After(".") == dft.SymbolName && (dft.SymbolContainer == null || dft.SymbolContainer == a.Key.Before("."))) .SingleEx( () => $"No FileTypeSymbol with name {dft.SymbolName} is registered", () => $"More than one FileTypeSymbol with name {dft.SymbolName} are registered. Consider desambiguating using symbolContainer argument in {pr}" ); } var alg = FileTypeLogic.GetAlgorithm(dft.FileTypeSymbol); mi.Extension.Add("defaultFileTypeInfo", new { key = dft.FileTypeSymbol.Key, onlyImages = alg.OnlyImages, maxSizeInBytes = alg.MaxSizeInBytes, }); } }; FilePathEntity.ToAbsolute = FilePathEmbedded.ToAbsolute = url => SignumCurrentContextFilter.Url !.Content(url); }
public static void Start(IApplicationBuilder app, params IOmniboxResultGenerator[] generators) { SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod()); QueryTokenJsonConverter.GetQueryTokenTS = qt => new QueryTokenTS(qt, true); QueryNameJsonConverter.GetQueryKey = qn => QueryUtils.GetKey(qn); OmniboxParser.Manager = new ReactOmniboxManager(); ReflectionServer.RegisterLike(typeof(OmniboxMessage), () => OmniboxPermission.ViewOmnibox.IsAuthorized()); foreach (var g in generators) { OmniboxParser.Generators.Add(g); } }
public static void Start(IApplicationBuilder app, IApplicationLifetime lifetime) { SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod()); lifetime.ApplicationStopping.Register(() => { if (SchedulerLogic.Running) { SchedulerLogic.StopScheduledTasks(); } SchedulerLogic.StopRunningTasks(); }); }
public static void Start(IApplicationBuilder app) { TypeHelpServer.Start(app); SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod()); TemplatingServer.Start(app); CustomizeFiltersModel(); EntityPackTS.AddExtension += ep => { if (ep.entity.IsNew || !WordTemplatePermission.GenerateReport.IsAuthorized()) { return; } var wordTemplates = WordTemplateLogic.TemplatesByEntityType.Value.TryGetC(ep.entity.GetType()); if (wordTemplates != null) { var applicable = wordTemplates.Where(a => a.IsApplicable(ep.entity)); if (applicable.HasItems()) { ep.extension.Add("wordTemplates", applicable.Select(a => a.ToLite()).ToList()); } } }; QueryDescriptionTS.AddExtension += qd => { object type = QueryLogic.ToQueryName(qd.queryKey); if (Schema.Current.IsAllowed(typeof(WordTemplateEntity), true) == null) { var templates = WordTemplateLogic.GetApplicableWordTemplates(type, null, WordTemplateVisibleOn.Query); if (templates.HasItems()) { qd.Extension.Add("wordTemplates", templates); } } }; EntityJsonConverter.AfterDeserilization.Register((WordTemplateEntity uq) => { if (uq.Query != null) { var qd = QueryLogic.Queries.QueryDescription(uq.Query.ToQueryName()); uq.ParseData(qd); } }); }
public static void Start(HttpConfiguration config, params IOmniboxResultGenerator[] generators) { SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod()); QueryTokenJsonConverter.GetQueryTokenTS = qt => new QueryTokenTS(qt, true); QueryNameJsonConverter.GetQueryKey = qn => QueryUtils.GetKey(qn); OmniboxParser.Manager = new ReactOmniboxManager(); ReflectionServer.RegisterLike(typeof(OmniboxMessage)); foreach (var g in generators) { OmniboxParser.Generators.Add(g); } }
public static void Start(HttpConfiguration config) { SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod()); EntityJsonConverter.AfterDeserilization.Register((PropertyRouteEntity wc) => { var route = PropertyRouteLogic.TryGetPropertyRouteEntity(wc.RootType, wc.Path); if (route != null) { wc.SetId(route.Id); wc.SetIsNew(false); wc.SetCleanModified(false); } }); }
public static void Start(IApplicationBuilder app) { TypeHelpServer.Start(app); SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod()); ReflectionServer.RegisterLike(typeof(DynamicViewMessage), () => UserEntity.Current != null); EntityJsonConverter.AfterDeserilization.Register((PropertyRouteEntity wc) => { var route = PropertyRouteLogic.TryGetPropertyRouteEntity(wc.RootType, wc.Path); if (route != null) { wc.SetId(route.Id); wc.SetIsNew(false); wc.SetCleanModified(false); } }); }
public static void Start(HttpConfiguration config, Assembly mainAsembly) { Schema.Current.ApplicationName = System.Web.Hosting.HostingEnvironment.ApplicationHost.GetPhysicalPath(); config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; config.Services.Replace(typeof(IHttpControllerSelector), new SignumControllerFactory(config, mainAsembly)); SignumControllerFactory.RegisterArea(typeof(EntitiesController)); // Web API configuration and services var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml"); config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType); //Signum converters config.Formatters.JsonFormatter.SerializerSettings.Do(s => { s.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; s.Formatting = Newtonsoft.Json.Formatting.Indented; s.Converters.Add(new LiteJsonConverter()); s.Converters.Add(new EntityJsonConverter()); s.Converters.Add(new MListJsonConverter()); s.Converters.Add(new StringEnumConverter()); s.Converters.Add(new ResultTableConverter()); s.Converters.Add(new TimeSpanConverter()); }); SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod()); // Web API routes config.MapHttpAttributeRoutes(); config.Services.Replace(typeof(IBodyModelValidator), new SignumBodyModelValidator()); config.Filters.Add(new SignumAuthenticationFilterAttribute()); config.Filters.Add(new SignumAuthorizationFilterAttribute()); config.Filters.Add(new SignumExceptionFilterAttribute()); config.Filters.Add(new VersionFilterAttribute()); ReflectionServer.Start(); }
public static void Start(IApplicationBuilder app) { UserAssetServer.Start(app); SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod()); SignumServer.WebEntityJsonConverterFactory.AfterDeserilization.Register((PredictorMainQueryEmbedded p) => { if (p.Query != null) { p.ParseData(); } }); SignumServer.WebEntityJsonConverterFactory.AfterDeserilization.Register((PredictorSubQueryEntity mc) => { if (mc.Query != null) { var qd = QueryLogic.Queries.QueryDescription(mc.Query.ToQueryName()); mc.ParseData(qd); } }); }
public static void Start(IApplicationBuilder app, IHostingEnvironment hostingEnvironment, Assembly mainAsembly) { Schema.Current.ApplicationName = hostingEnvironment.ContentRootPath; //app.Services.Replace(typeof(IHttpControllerSelector), new SignumControllerFactory(config, mainAsembly)); SignumControllerFactory.RegisterArea(typeof(EntitiesController)); SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod()); //// Web API configuration and services //var appXmlType = app.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml"); //app.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType); //// Web API routes //app.MapHttpAttributeRoutes(); //app.Services.Replace(typeof(IBodyModelValidator), new SignumBodyModelValidator()); ReflectionServer.Start(); }
public static void RegisterArea(Type clientType, string areaName = null, string controllerNamespace = null, string resourcesNamespace = null) { if (areaName == null) { areaName = clientType.Namespace.AfterLast('.'); } if (areaName.Start(1) == "/") { throw new SystemException("Invalid start character / in {0}".FormatWith(areaName)); } if (controllerNamespace == null) { controllerNamespace = clientType.Namespace; } if (resourcesNamespace == null) { resourcesNamespace = clientType.Namespace; } var assembly = clientType.Assembly; CompiledViews.RegisterArea(assembly, areaName); SignumControllerFactory.RegisterControllersIn(assembly, controllerNamespace, areaName); EmbeddedFilesRepository rep = new EmbeddedFilesRepository(assembly, "~/" + areaName + "/", resourcesNamespace); if (!rep.IsEmpty) { FileRepositoryManager.Register(rep); } }
public static void Start(HttpConfiguration config) { SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod()); ReflectionServer.RegisterLike(typeof(TemplateTokenMessage)); CustomizeFiltersModel(); EntityPackTS.AddExtension += ep => { if (ep.entity.IsNew || !WordTemplatePermission.GenerateReport.IsAuthorized()) { return; } var wordTemplates = WordTemplateLogic.TemplatesByEntityType.Value.TryGetC(ep.entity.GetType()); if (wordTemplates != null) { var applicable = wordTemplates.Where(a => a.IsApplicable(ep.entity)); if (applicable.HasItems()) { ep.Extension.Add("wordTemplates", applicable.Select(a => a.ToLite()).ToList()); } } }; QueryDescriptionTS.AddExtension += qd => { object type = QueryLogic.ToQueryName(qd.queryKey); var templates = WordTemplateLogic.GetApplicableWordTemplates(type, null, WordTemplateVisibleOn.Query); if (templates.HasItems()) { qd.Extension.Add("wordTemplates", templates); } }; }
public static void Start(HttpConfiguration config) { UserAssetServer.Start(config); SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod()); EntityJsonConverter.AfterDeserilization.Register((PredictorEntity p) => { if (p.Query != null) { var qd = DynamicQueryManager.Current.QueryDescription(p.Query.ToQueryName()); p.ParseData(qd); } }); EntityJsonConverter.AfterDeserilization.Register((PredictorMultiColumnEntity mc) => { if (mc.Query != null) { var qd = DynamicQueryManager.Current.QueryDescription(mc.Query.ToQueryName()); mc.ParseData(qd); } }); }
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; }
public static void Start(HttpConfiguration config) { SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod()); ReflectionServer.RegisterLike(typeof(ExcelMessage)); }
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); } }; }
public static void Start(IApplicationBuilder app) { SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod()); ReflectionServer.RegisterLike(typeof(ProfilerPermission), () => ProfilerPermission.ViewHeavyProfiler.IsAuthorized() || ProfilerPermission.ViewTimeTracker.IsAuthorized()); }
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)); }
public static void Start(HttpConfiguration config) { SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod()); }
public static void Start(IApplicationBuilder app) { ReflectionServer.RegisterLike(typeof(MapMessage), () => MapPermission.ViewMap.IsAuthorized()); SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod()); SchemaMap.GetColorProviders += () => new[] { new MapColorProvider { Name = "namespace", NiceName = MapMessage.Namespace.NiceToString(), }, }; SchemaMap.GetColorProviders += () => new[] { new MapColorProvider { Name = "entityKind", NiceName = typeof(EntityKind).Name, } }; SchemaMap.GetColorProviders += () => new[] { new MapColorProvider { Name = "columns", NiceName = MapMessage.Columns.NiceToString(), } }; SchemaMap.GetColorProviders += () => new[] { new MapColorProvider { Name = "entityData", NiceName = typeof(EntityData).Name, } }; SchemaMap.GetColorProviders += () => new[] { new MapColorProvider { Name = "rows", NiceName = MapMessage.Rows.NiceToString(), } }; if (Schema.Current.Tables.Any(a => a.Value.SystemVersioned != null)) { SchemaMap.GetColorProviders += () => new[] { new MapColorProvider { Name = "rows_history", NiceName = MapMessage.RowsHistory.NiceToString(), } }; } SchemaMap.GetColorProviders += () => new[] { new MapColorProvider { Name = "tableSize", NiceName = MapMessage.TableSize.NiceToString(), } }; if (Schema.Current.Tables.Any(a => a.Value.SystemVersioned != null)) { SchemaMap.GetColorProviders += () => new[] { new MapColorProvider { Name = "tableSize_history", NiceName = MapMessage.TableSizeHistory.NiceToString(), } }; } }
public static void Start(IApplicationBuilder app) { SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod()); SchemaMap.GetColorProviders += GetMapColors; }
public static void Start(HttpConfiguration config) { SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod()); HostingEnvironment.RegisterObject(new SchedulerStopper()); }
public static void Start(HttpConfiguration config) { SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod()); SchemaMap.GetColorProviders += GetMapColors; }
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; }
public static void Start(IApplicationBuilder app) { SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod()); SignumAuthenticationFilter.Authenticators.Insert(0, ApiKeyAuthenticator); }
public static void Start(IApplicationBuilder app) { SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod()); ReflectionServer.RegisterLike(typeof(DiffLogMessage)); }
public static void Start(IApplicationBuilder app) { SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod()); void RegisterFilePathEmbeddedProperty(string propertyName, Func <FilePathEmbedded, object?> getter) { SignumServer.WebEntityJsonConverterFactory.GetPropertyConverters(typeof(FilePathEmbedded)).Add(propertyName, new PropertyConverter() { CustomWriteJsonProperty = (Utf8JsonWriter writer, WriteJsonPropertyContext ctx) => { var fpe = (FilePathEmbedded)ctx.Entity; writer.WritePropertyName(ctx.LowerCaseName); JsonSerializer.Serialize(writer, getter(fpe), ctx.JsonSerializerOptions); }, AvoidValidate = true, CustomReadJsonProperty = (ref Utf8JsonReader reader, ReadJsonPropertyContext ctx) => { var obj = JsonSerializer.Deserialize <object>(ref reader); //Discard } }); } RegisterFilePathEmbeddedProperty("fullWebPath", fpe => fpe.FullWebPath()); RegisterFilePathEmbeddedProperty("entityId", fpe => fpe.EntityId.Object); RegisterFilePathEmbeddedProperty("mListRowId", fpe => fpe.MListRowId?.Object); RegisterFilePathEmbeddedProperty("propertyRoute", fpe => fpe.PropertyRoute); RegisterFilePathEmbeddedProperty("rootType", fpe => fpe.RootType); var s = Schema.Current.Settings; ReflectionServer.PropertyRouteExtension += (mi, pr) => { var dft = s.FieldAttributes(pr)?.OfType <DefaultFileTypeAttribute>().SingleOrDefaultEx(); if (dft != null) { if (dft.FileTypeSymbol == null) { dft.FileTypeSymbol = SymbolLogic <FileTypeSymbol> .Symbols .Where(a => a.Key.After(".") == dft.SymbolName && (dft.SymbolContainer == null || dft.SymbolContainer == a.Key.Before("."))) .SingleEx( () => $"No FileTypeSymbol with name {dft.SymbolContainer}.{dft.SymbolName} is registered", () => $"More than one FileTypeSymbol with name {dft.SymbolContainer}.{dft.SymbolName} are registered. Consider desambiguating using symbolContainer argument in {pr}" ); } var alg = FileTypeLogic.GetAlgorithm(dft.FileTypeSymbol); mi.Extension.Add("defaultFileTypeInfo", new { key = dft.FileTypeSymbol.Key, onlyImages = alg.OnlyImages, maxSizeInBytes = alg.MaxSizeInBytes, }); } return(mi); }; FilePathEntity.ToAbsolute = FilePathEmbedded.ToAbsolute = url => SignumCurrentContextFilter.Url == null?Content(url) : SignumCurrentContextFilter.Url !.Content(url); ReflectionServer.RegisterLike(typeof(FileMessage), () => true); }
public static void Start(IApplicationBuilder app) { SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod()); }
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); } });