zoukankan      html  css  js  c++  java
  • .net 5.0 中 CrystalQuartz 增加授权校验

    我的环境是 .net 5.0 在 但是应该是所有版本的 CrystalQuartz  都通用这个思路.
     
    public static class ApplicationBuilderExtensions
        {
            public static void UseCrystalQuartzAuthenticate(
                this IApplicationBuilder app,
                Func<object> schedulerProvider,
                CrystalQuartzOptions options)
            {
                ISchedulerProvider provider = new FuncSchedulerProvider(schedulerProvider);
    
                CrystalQuartzOptions actualOptions = options ?? new CrystalQuartzOptions();
    
                string text = actualOptions.Path ?? "/quartz";
    
                var optionsVal = new Options(actualOptions.TimelineSpan, SchedulerEngineProviders.SchedulerEngineResolvers, actualOptions.LazyInit, actualOptions.CustomCssUrl, ".net 5");
    
    
                EndpointRoutingApplicationBuilderExtensions.UseEndpoints(app, routes =>
                {
                    // 新增一个 app
                    RunningApplication runningApplication = new CrystalQuartzPanelApplication(provider, optionsVal).Run();
    
                    routes.Map(text, async delegate (HttpContext httpContext)
                    {
                        AuthenticateResult authenticate = await AuthenticationHttpContextExtensions.AuthenticateAsync(httpContext);
                        IRequest request = new AspNetCoreRequest(httpContext.Request.Query, httpContext.Request.HasFormContentType ? httpContext.Request.Form : null);
                        IResponseRenderer responseRenderer = new AspNetCoreResponseRenderer(httpContext);
                        if (authenticate.Succeeded)
                        {
                            runningApplication.Handle(request, responseRenderer);
                        }
                        else
                        {
                            responseRenderer.Render(new Response("text/html", 200, p => { p.Write(System.Text.Encoding.UTF8.GetBytes("no login")); }));
                        }
                    });
                });
            }
        }

    app.UseCrystalQuartz 替换成我们自己的 app.UseCrystalQuartzAuthenticate

    原理就是修改中间件,把他的中间件换成我们自己写的,在数据处理之前校验下身份信息.

    也可以简单点,直接弄个控制器,

    记录完毕,主要给自己看,如果能对你也有帮助,那也是极好的~

  • 相关阅读:
    小程序文档
    display: flex;
    时间戳格式化
    transition-分栏按钮动画
    animation与transition区别
    放大镜
    原生js实现瀑布流效果
    Javascript获取数组中最大和最小值
    scss基础
    C/C++ XMPP/Jabber 客户端类库对比/点评 (转)
  • 原文地址:https://www.cnblogs.com/xywy/p/14119153.html
Copyright © 2011-2022 走看看