public bool Authorize(HttpContext context, DashboardQuartzOptions dashboardQuartzOptions)
        {
            bool isAuthenticated = context.User?.Identity?.IsAuthenticated ?? false;

            if (!isAuthenticated)
            {
                return(false);
            }
            string role = context.User.Claims.FirstOrDefault(o => o.Type.Equals(ClaimTypes.Role))?.Value;

            return(role != null && role.Equals("admin", StringComparison.OrdinalIgnoreCase));
        }
        public bool Authorize(HttpContext context, DashboardQuartzOptions dashboardQuartzOptions)
        {
            IPAddress remoteIp = context.Connection.RemoteIpAddress;

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

            if (IPAddress.IsLoopback(remoteIp))
            {
                return(true);
            }

            if (remoteIp == context.Connection.LocalIpAddress)
            {
                return(true);
            }

            return(false);
        }
        public void AddServices(IServiceCollection services)
        {
            var dashboardQuartzOptions = new DashboardQuartzOptions();

            _dashboardQuartzOptions?.Invoke(dashboardQuartzOptions);

            services.AddSingleton(dashboardQuartzOptions);

            services.AddAuthentication(dashboardQuartzOptions.AuthScheme)
            .AddCookie(dashboardQuartzOptions.AuthScheme, options =>
            {
                options.LoginPath = dashboardQuartzOptions.LoginPath;
            });

            services.Configure <RazorViewEngineOptions>(options =>
            {
                options.AreaViewLocationFormats.Clear();
                options.AreaViewLocationFormats.Add("/Dashboard/Views/{1}/{0}.cshtml");
                options.AreaViewLocationFormats.Add("/Dashboard/Views/Shared/{0}.cshtml");
                options.AreaViewLocationFormats.Add("/Views/Shared/{0}.cshtml");
            });

            services.AddTransient <ISchedulerManager, SchedulerManager>();

            services.ConfigureOptions(typeof(DashboardQuartzUiConfigureOptions));

            services.AddMvc().AddJsonOptions(options =>
            {
                options.SerializerSettings.ContractResolver      = new DefaultContractResolver(); //不改变参数大小写
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;  //忽略在对象图中找到的循环引用
                //options.SerializerSettings.Converters = new JsonConverter[]
                //{
                //    new HexLongConverter()
                //};
            }).SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            services.AddSignalR();
        }
Exemplo n.º 4
0
 public DashboardMiddeware(RequestDelegate next, DashboardQuartzOptions options)
 {
     _next    = next;
     _options = options;
 }