/// \file /// \ingroup tutorial_http /// This program demonstrates access control to the THttpServer with digest methods. /// Authentication file auth.txt was generated with following shell commands: /// ~~~ /// [shell] htdigest -c auth.txt root guest /// typing password for guest account /// [shell] htdigest auth.txt root admin /// typing 'admin' as password for admin account /// ~~~ /// When macro started and opening in browser with url /// ~~~ /// http://localhost:8080 /// ~~~ /// User name and password will be requested. One should /// either specify guest account without password or /// admin account with password 'admin' /// /// User with guest account only can monitor histograms /// User with admin account see commands, which can be executed /// /// \macro_code /// /// \author Sergey Linev #include "TH1.h" #include "TH2.h" #include "TRandom3.h" #include "TSystem.h" #include "THttpServer.h" void http_cors() { // create histograms TH1D *hpx = new TH1D("hpx","This is the px distribution",100,-4,4); hpx->SetFillColor(48); hpx->SetDirectory(nullptr); hpx->FillRandom("gaus", 10000); if (gSystem->AccessPathName("auth.txt") != 0) { printf("Please start macro from directory where auth.txt file is available\n"); printf("It required to supply authentication information for the http server\n"); return; } // start http server auto serv = new THttpServer("http:8080?auth_file=auth.txt&auth_domain=root&cred_cors&cors=https://root.cern"); // register histogram serv->Register("/", hpx); // now in the browser type URL // https://root.cern/js/latest/?with_credentials&json=http://localhost:8080/hpx/root.json }