XRootD
Loading...
Searching...
No Matches
XrdMacaroonsHandler.hh
Go to the documentation of this file.
2
3#include <memory>
4#include <stdexcept>
5#include <string>
6#include <vector>
7
9class XrdOucEnv;
10class XrdOucStream;
11class XrdSecEntity;
12
13namespace Macaroons {
14
15enum LogMask {
16 Debug = 0x01,
17 Info = 0x02,
18 Warning = 0x04,
19 Error = 0x08,
20 All = 0xff
21};
22
23class Handler : public XrdHttpExtHandler {
24public:
25 Handler(XrdSysError *log, const char *config, XrdOucEnv *myEnv,
26 XrdAccAuthorize *chain) :
27 m_max_duration(86400),
28 m_chain(chain),
29 m_log(log)
30 {
31 AuthzBehavior behavior;
32 if (!Config(config, myEnv, m_log, m_location, m_secret, m_max_duration, behavior))
33 {
34 throw std::runtime_error("Macaroon handler config failed.");
35 }
36 }
37
43
44 virtual ~Handler();
45
46 virtual bool MatchesPath(const char *verb, const char *path) override;
47 virtual int ProcessReq(XrdHttpExtReq &req) override;
48
49 virtual int Init(const char *cfgfile) override {return 0;}
50
51 // Static configuration method; made static to allow Authz object to reuse
52 // this code.
53 static bool Config(const char *config, XrdOucEnv *env, XrdSysError *log,
54 std::string &location, std::string &secret, ssize_t &max_duration,
55 AuthzBehavior &behavior);
56
57private:
58 std::string GenerateID(const std::string &, const XrdSecEntity &, const std::string &, const std::vector<std::string> &, const std::string &);
59 std::string GenerateActivities(const XrdHttpExtReq &, const std::string &) const;
60
61 int ProcessOAuthConfig(XrdHttpExtReq &req);
62 int ProcessTokenRequest(XrdHttpExtReq& req);
63 int GenerateMacaroonResponse(XrdHttpExtReq& req, const std::string &response, const std::vector<std::string> &, ssize_t validity, bool oauth_response);
64
65 static bool xsecretkey(XrdOucStream &Config, XrdSysError *log, std::string &secret);
66 static bool xsitename(XrdOucStream &Config, XrdSysError *log, std::string &location);
67 static bool xtrace(XrdOucStream &Config, XrdSysError *log);
68 static bool xmaxduration(XrdOucStream &Config, XrdSysError *log, ssize_t &max_duration);
69
70 ssize_t m_max_duration;
71 XrdAccAuthorize *m_chain;
72 XrdSysError *m_log;
73 std::string m_location;
74 std::string m_secret;
75};
76
77} // namespace Macaroons
static bool Config(const char *config, XrdOucEnv *env, XrdSysError *log, std::string &location, std::string &secret, ssize_t &max_duration, AuthzBehavior &behavior)
Handler(XrdSysError *log, const char *config, XrdOucEnv *myEnv, XrdAccAuthorize *chain)
virtual int Init(const char *cfgfile) override
Initializes the external request handler.
virtual bool MatchesPath(const char *verb, const char *path) override
Tells if the incoming path is recognized as one of the paths that have to be processed.
virtual int ProcessReq(XrdHttpExtReq &req) override
XrdHttpExtHandler()
Constructor.