How can I protect MVC Hangfire Dashboard












1














I'm using Visual Studio 2013 MVC, and I installed "Hangfire" to perform scheduled tasks. (http://hangfire.io/)



How can I protect the Web Monitoring UI page (http://localhost/Hangfire) with a password?



Thanks










share|improve this question



























    1














    I'm using Visual Studio 2013 MVC, and I installed "Hangfire" to perform scheduled tasks. (http://hangfire.io/)



    How can I protect the Web Monitoring UI page (http://localhost/Hangfire) with a password?



    Thanks










    share|improve this question

























      1












      1








      1







      I'm using Visual Studio 2013 MVC, and I installed "Hangfire" to perform scheduled tasks. (http://hangfire.io/)



      How can I protect the Web Monitoring UI page (http://localhost/Hangfire) with a password?



      Thanks










      share|improve this question













      I'm using Visual Studio 2013 MVC, and I installed "Hangfire" to perform scheduled tasks. (http://hangfire.io/)



      How can I protect the Web Monitoring UI page (http://localhost/Hangfire) with a password?



      Thanks







      c# visual-studio model-view-controller hangfire






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 19 '15 at 9:11









      IbrahimIbrahim

      1413




      1413
























          3 Answers
          3






          active

          oldest

          votes


















          0














          Let me give the entire code for a RestrictiveAuthorizationFilter:
          This way you can handle authorization however you desire.



          Assuming you have the OWINStartup class added.



          OWINStartup.cs



          using Owin;
          using Hangfire;
          using Hangfire.Dashboard;

          public class OWINStartup
          {
          public void Configuration(IAppBuilder app)
          {
          GlobalConfiguration.Configuration.UseSqlServerStorage("String");
          DashboardOptions options = new DashboardOptions()
          {
          AuthorizationFilters = new IAuthorizationFilter
          {
          new MyRestrictiveAuthorizationFilter()
          }
          };
          app.UseHangfireDashboard("/hangfire", options);
          }
          }


          RestrictiveAuthorizationFilter.cs



          using Hangfire.Dashboard;
          using System.Collections.Generic;
          using Microsoft.Owin;

          public class MyRestrictiveAuthorizationFilter : IAuthorizationFilter
          {
          public bool Authorize(IDictionary<string, object> owinEnvironment)
          {
          var context = new OwinContext(owinEnvironment);

          return context.Authentication.User.Identity.IsAuthenticated;
          }
          }


          Notice: using System.Collections.Generic;



          References:
          https://github.com/HangfireIO/Hangfire/issues/202



          https://media.readthedocs.org/pdf/hangfire/latest/hangfire.pdf (page 20)



          Hangfire.Dashboard.Authorization version: 2.1.0






          share|improve this answer





























            1














            Please take a look to the documentation



            In short.
            You can use already created authorization filters or implement your own



            using Hangfire.Dashboard;

            public class MyRestrictiveAuthorizationFilter : IAuthorizationFilter
            {
            public bool Authorize(IDictionary<string, object> owinEnvironment)
            {
            // In case you need an OWIN context, use the next line.
            var context = new OwinContext(owinEnvironment);
            return false;
            }
            }


            Additional information:



            Also you can take a look to the special package Hangfire.Dashboard.Authorization which contains the logic which you needed






            share|improve this answer























            • Perfect :) That's what I need. It works. Thanks a lot
              – Ibrahim
              Jan 20 '15 at 6:27



















            0














            Set this up in your Startup.Cs



              public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
            {
            //TODO
            app.UseHangfireDashboard("/hangfire", new DashboardOptions
            {
            Authorization = new { new MyAuthorizationFilter() }
            });
            app.UseHangfireDashboard();
            var options = new BackgroundJobServerOptions { WorkerCount = 1 };
            app.UseHangfireServer(options); }


            Create this class, it allows authenticated users to see the Dashboard



            public class MyAuthorizationFilter : IDashboardAuthorizationFilter
            {
            public bool Authorize(DashboardContext context)
            {
            var httpContext = context.GetHttpContext();

            // Allow all authenticated users to see the Dashboard (potentially dangerous).
            return httpContext.User.Identity.IsAuthenticated;
            }
            }





            share|improve this answer





















              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f28021135%2fhow-can-i-protect-mvc-hangfire-dashboard%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              Let me give the entire code for a RestrictiveAuthorizationFilter:
              This way you can handle authorization however you desire.



              Assuming you have the OWINStartup class added.



              OWINStartup.cs



              using Owin;
              using Hangfire;
              using Hangfire.Dashboard;

              public class OWINStartup
              {
              public void Configuration(IAppBuilder app)
              {
              GlobalConfiguration.Configuration.UseSqlServerStorage("String");
              DashboardOptions options = new DashboardOptions()
              {
              AuthorizationFilters = new IAuthorizationFilter
              {
              new MyRestrictiveAuthorizationFilter()
              }
              };
              app.UseHangfireDashboard("/hangfire", options);
              }
              }


              RestrictiveAuthorizationFilter.cs



              using Hangfire.Dashboard;
              using System.Collections.Generic;
              using Microsoft.Owin;

              public class MyRestrictiveAuthorizationFilter : IAuthorizationFilter
              {
              public bool Authorize(IDictionary<string, object> owinEnvironment)
              {
              var context = new OwinContext(owinEnvironment);

              return context.Authentication.User.Identity.IsAuthenticated;
              }
              }


              Notice: using System.Collections.Generic;



              References:
              https://github.com/HangfireIO/Hangfire/issues/202



              https://media.readthedocs.org/pdf/hangfire/latest/hangfire.pdf (page 20)



              Hangfire.Dashboard.Authorization version: 2.1.0






              share|improve this answer


























                0














                Let me give the entire code for a RestrictiveAuthorizationFilter:
                This way you can handle authorization however you desire.



                Assuming you have the OWINStartup class added.



                OWINStartup.cs



                using Owin;
                using Hangfire;
                using Hangfire.Dashboard;

                public class OWINStartup
                {
                public void Configuration(IAppBuilder app)
                {
                GlobalConfiguration.Configuration.UseSqlServerStorage("String");
                DashboardOptions options = new DashboardOptions()
                {
                AuthorizationFilters = new IAuthorizationFilter
                {
                new MyRestrictiveAuthorizationFilter()
                }
                };
                app.UseHangfireDashboard("/hangfire", options);
                }
                }


                RestrictiveAuthorizationFilter.cs



                using Hangfire.Dashboard;
                using System.Collections.Generic;
                using Microsoft.Owin;

                public class MyRestrictiveAuthorizationFilter : IAuthorizationFilter
                {
                public bool Authorize(IDictionary<string, object> owinEnvironment)
                {
                var context = new OwinContext(owinEnvironment);

                return context.Authentication.User.Identity.IsAuthenticated;
                }
                }


                Notice: using System.Collections.Generic;



                References:
                https://github.com/HangfireIO/Hangfire/issues/202



                https://media.readthedocs.org/pdf/hangfire/latest/hangfire.pdf (page 20)



                Hangfire.Dashboard.Authorization version: 2.1.0






                share|improve this answer
























                  0












                  0








                  0






                  Let me give the entire code for a RestrictiveAuthorizationFilter:
                  This way you can handle authorization however you desire.



                  Assuming you have the OWINStartup class added.



                  OWINStartup.cs



                  using Owin;
                  using Hangfire;
                  using Hangfire.Dashboard;

                  public class OWINStartup
                  {
                  public void Configuration(IAppBuilder app)
                  {
                  GlobalConfiguration.Configuration.UseSqlServerStorage("String");
                  DashboardOptions options = new DashboardOptions()
                  {
                  AuthorizationFilters = new IAuthorizationFilter
                  {
                  new MyRestrictiveAuthorizationFilter()
                  }
                  };
                  app.UseHangfireDashboard("/hangfire", options);
                  }
                  }


                  RestrictiveAuthorizationFilter.cs



                  using Hangfire.Dashboard;
                  using System.Collections.Generic;
                  using Microsoft.Owin;

                  public class MyRestrictiveAuthorizationFilter : IAuthorizationFilter
                  {
                  public bool Authorize(IDictionary<string, object> owinEnvironment)
                  {
                  var context = new OwinContext(owinEnvironment);

                  return context.Authentication.User.Identity.IsAuthenticated;
                  }
                  }


                  Notice: using System.Collections.Generic;



                  References:
                  https://github.com/HangfireIO/Hangfire/issues/202



                  https://media.readthedocs.org/pdf/hangfire/latest/hangfire.pdf (page 20)



                  Hangfire.Dashboard.Authorization version: 2.1.0






                  share|improve this answer












                  Let me give the entire code for a RestrictiveAuthorizationFilter:
                  This way you can handle authorization however you desire.



                  Assuming you have the OWINStartup class added.



                  OWINStartup.cs



                  using Owin;
                  using Hangfire;
                  using Hangfire.Dashboard;

                  public class OWINStartup
                  {
                  public void Configuration(IAppBuilder app)
                  {
                  GlobalConfiguration.Configuration.UseSqlServerStorage("String");
                  DashboardOptions options = new DashboardOptions()
                  {
                  AuthorizationFilters = new IAuthorizationFilter
                  {
                  new MyRestrictiveAuthorizationFilter()
                  }
                  };
                  app.UseHangfireDashboard("/hangfire", options);
                  }
                  }


                  RestrictiveAuthorizationFilter.cs



                  using Hangfire.Dashboard;
                  using System.Collections.Generic;
                  using Microsoft.Owin;

                  public class MyRestrictiveAuthorizationFilter : IAuthorizationFilter
                  {
                  public bool Authorize(IDictionary<string, object> owinEnvironment)
                  {
                  var context = new OwinContext(owinEnvironment);

                  return context.Authentication.User.Identity.IsAuthenticated;
                  }
                  }


                  Notice: using System.Collections.Generic;



                  References:
                  https://github.com/HangfireIO/Hangfire/issues/202



                  https://media.readthedocs.org/pdf/hangfire/latest/hangfire.pdf (page 20)



                  Hangfire.Dashboard.Authorization version: 2.1.0







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 17 '15 at 18:47









                  KickassKickass

                  650613




                  650613

























                      1














                      Please take a look to the documentation



                      In short.
                      You can use already created authorization filters or implement your own



                      using Hangfire.Dashboard;

                      public class MyRestrictiveAuthorizationFilter : IAuthorizationFilter
                      {
                      public bool Authorize(IDictionary<string, object> owinEnvironment)
                      {
                      // In case you need an OWIN context, use the next line.
                      var context = new OwinContext(owinEnvironment);
                      return false;
                      }
                      }


                      Additional information:



                      Also you can take a look to the special package Hangfire.Dashboard.Authorization which contains the logic which you needed






                      share|improve this answer























                      • Perfect :) That's what I need. It works. Thanks a lot
                        – Ibrahim
                        Jan 20 '15 at 6:27
















                      1














                      Please take a look to the documentation



                      In short.
                      You can use already created authorization filters or implement your own



                      using Hangfire.Dashboard;

                      public class MyRestrictiveAuthorizationFilter : IAuthorizationFilter
                      {
                      public bool Authorize(IDictionary<string, object> owinEnvironment)
                      {
                      // In case you need an OWIN context, use the next line.
                      var context = new OwinContext(owinEnvironment);
                      return false;
                      }
                      }


                      Additional information:



                      Also you can take a look to the special package Hangfire.Dashboard.Authorization which contains the logic which you needed






                      share|improve this answer























                      • Perfect :) That's what I need. It works. Thanks a lot
                        – Ibrahim
                        Jan 20 '15 at 6:27














                      1












                      1








                      1






                      Please take a look to the documentation



                      In short.
                      You can use already created authorization filters or implement your own



                      using Hangfire.Dashboard;

                      public class MyRestrictiveAuthorizationFilter : IAuthorizationFilter
                      {
                      public bool Authorize(IDictionary<string, object> owinEnvironment)
                      {
                      // In case you need an OWIN context, use the next line.
                      var context = new OwinContext(owinEnvironment);
                      return false;
                      }
                      }


                      Additional information:



                      Also you can take a look to the special package Hangfire.Dashboard.Authorization which contains the logic which you needed






                      share|improve this answer














                      Please take a look to the documentation



                      In short.
                      You can use already created authorization filters or implement your own



                      using Hangfire.Dashboard;

                      public class MyRestrictiveAuthorizationFilter : IAuthorizationFilter
                      {
                      public bool Authorize(IDictionary<string, object> owinEnvironment)
                      {
                      // In case you need an OWIN context, use the next line.
                      var context = new OwinContext(owinEnvironment);
                      return false;
                      }
                      }


                      Additional information:



                      Also you can take a look to the special package Hangfire.Dashboard.Authorization which contains the logic which you needed







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Jan 19 '15 at 16:30

























                      answered Jan 19 '15 at 14:53









                      Pavel NasovichPavel Nasovich

                      20317




                      20317












                      • Perfect :) That's what I need. It works. Thanks a lot
                        – Ibrahim
                        Jan 20 '15 at 6:27


















                      • Perfect :) That's what I need. It works. Thanks a lot
                        – Ibrahim
                        Jan 20 '15 at 6:27
















                      Perfect :) That's what I need. It works. Thanks a lot
                      – Ibrahim
                      Jan 20 '15 at 6:27




                      Perfect :) That's what I need. It works. Thanks a lot
                      – Ibrahim
                      Jan 20 '15 at 6:27











                      0














                      Set this up in your Startup.Cs



                        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
                      {
                      //TODO
                      app.UseHangfireDashboard("/hangfire", new DashboardOptions
                      {
                      Authorization = new { new MyAuthorizationFilter() }
                      });
                      app.UseHangfireDashboard();
                      var options = new BackgroundJobServerOptions { WorkerCount = 1 };
                      app.UseHangfireServer(options); }


                      Create this class, it allows authenticated users to see the Dashboard



                      public class MyAuthorizationFilter : IDashboardAuthorizationFilter
                      {
                      public bool Authorize(DashboardContext context)
                      {
                      var httpContext = context.GetHttpContext();

                      // Allow all authenticated users to see the Dashboard (potentially dangerous).
                      return httpContext.User.Identity.IsAuthenticated;
                      }
                      }





                      share|improve this answer


























                        0














                        Set this up in your Startup.Cs



                          public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
                        {
                        //TODO
                        app.UseHangfireDashboard("/hangfire", new DashboardOptions
                        {
                        Authorization = new { new MyAuthorizationFilter() }
                        });
                        app.UseHangfireDashboard();
                        var options = new BackgroundJobServerOptions { WorkerCount = 1 };
                        app.UseHangfireServer(options); }


                        Create this class, it allows authenticated users to see the Dashboard



                        public class MyAuthorizationFilter : IDashboardAuthorizationFilter
                        {
                        public bool Authorize(DashboardContext context)
                        {
                        var httpContext = context.GetHttpContext();

                        // Allow all authenticated users to see the Dashboard (potentially dangerous).
                        return httpContext.User.Identity.IsAuthenticated;
                        }
                        }





                        share|improve this answer
























                          0












                          0








                          0






                          Set this up in your Startup.Cs



                            public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
                          {
                          //TODO
                          app.UseHangfireDashboard("/hangfire", new DashboardOptions
                          {
                          Authorization = new { new MyAuthorizationFilter() }
                          });
                          app.UseHangfireDashboard();
                          var options = new BackgroundJobServerOptions { WorkerCount = 1 };
                          app.UseHangfireServer(options); }


                          Create this class, it allows authenticated users to see the Dashboard



                          public class MyAuthorizationFilter : IDashboardAuthorizationFilter
                          {
                          public bool Authorize(DashboardContext context)
                          {
                          var httpContext = context.GetHttpContext();

                          // Allow all authenticated users to see the Dashboard (potentially dangerous).
                          return httpContext.User.Identity.IsAuthenticated;
                          }
                          }





                          share|improve this answer












                          Set this up in your Startup.Cs



                            public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
                          {
                          //TODO
                          app.UseHangfireDashboard("/hangfire", new DashboardOptions
                          {
                          Authorization = new { new MyAuthorizationFilter() }
                          });
                          app.UseHangfireDashboard();
                          var options = new BackgroundJobServerOptions { WorkerCount = 1 };
                          app.UseHangfireServer(options); }


                          Create this class, it allows authenticated users to see the Dashboard



                          public class MyAuthorizationFilter : IDashboardAuthorizationFilter
                          {
                          public bool Authorize(DashboardContext context)
                          {
                          var httpContext = context.GetHttpContext();

                          // Allow all authenticated users to see the Dashboard (potentially dangerous).
                          return httpContext.User.Identity.IsAuthenticated;
                          }
                          }






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 13 '18 at 9:41









                          DamilareDamilare

                          45




                          45






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f28021135%2fhow-can-i-protect-mvc-hangfire-dashboard%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Bressuire

                              Vorschmack

                              Quarantine