00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef UTILS_DOMETALKER_H
00025 #define UTILS_DOMETALKER_H
00026
00027 #include <davix/davix.hpp>
00028 #include "DavixPool.h"
00029 #include "DomeUtils.h"
00030 #include "cpp/authn.h"
00031
00032 #include <boost/property_tree/ptree.hpp>
00033
00034 namespace dmlite {
00035
00036 struct DomeCredentials {
00037
00038 std::string clientName;
00039
00040 std::string remoteAddress;
00041
00042 std::vector<std::string> groups;
00043
00044
00045
00046 std::string oidc_audience;
00047
00048 std::string oidc_issuer;
00049
00050 std::string oidc_scope;
00051
00052 bool oidc_authorized;
00053
00054 DomeCredentials(std::string cn, std::string ra, std::vector<std::string> gr) :
00055 clientName(cn), remoteAddress(ra), groups(gr), oidc_authorized(false) {}
00056
00057 DomeCredentials() : oidc_authorized(false) {}
00058 DomeCredentials(const SecurityContext *ctx) {
00059 if(ctx) {
00060
00061 clientName = ctx->credentials.clientName;
00062 if (!clientName.size())
00063 clientName = ctx->user.name;
00064
00065 remoteAddress = ctx->credentials.remoteAddress;
00066
00067
00068 for(size_t i = 0; i < ctx->groups.size(); i++) {
00069 groups.push_back(ctx->groups[i].name);
00070 }
00071
00072
00073
00074 oidc_audience = ctx->credentials.oidc_audience;
00075 oidc_issuer = ctx->credentials.oidc_issuer;
00076 oidc_scope = ctx->credentials.oidc_scope;
00077
00078
00079 }
00080 }
00081
00082
00083
00084
00085 };
00086
00087 enum DomeHttpCode {
00088 DOME_HTTP_OK = 200,
00089
00090 DOME_HTTP_BAD_REQUEST = 400,
00091 DOME_HTTP_DENIED = 403,
00092 DOME_HTTP_NOT_FOUND = 404,
00093 DOME_HTTP_CONFLICT = 409,
00094 DOME_HTTP_UNPROCESSABLE = 422,
00095
00096 DOME_HTTP_INTERNAL_SERVER_ERROR = 500,
00097 DOME_HTTP_INSUFFICIENT_STORAGE = 507
00098 };
00099
00100 int http_status(const DmException &e);
00101
00102 class DmStatus;
00103 int http_status(const DmStatus &e);
00104
00105 class DomeTalker {
00106 public:
00107 DomeTalker(DavixCtxPool &pool, const DomeCredentials &creds, std::string uri, std::string verb, std::string cmd);
00108 DomeTalker(DavixCtxPool &pool, std::string uri, std::string verb, std::string cmd);
00109 ~DomeTalker();
00110
00111 bool execute();
00112 bool execute(const boost::property_tree::ptree ¶ms);
00113 bool execute(const std::string &str);
00114 bool execute(const std::ostringstream &ss);
00115
00116
00117 bool execute(const std::string &key, const std::string &value);
00118
00119
00120 bool execute(const std::string &key1, const std::string &value1,
00121 const std::string &key2, const std::string &value2);
00122
00123
00124 bool execute(const std::string &key1, const std::string &value1,
00125 const std::string &key2, const std::string &value2,
00126 const std::string &key3, const std::string &value3);
00127
00128
00129 std::string err();
00130
00131
00132 int status();
00133
00134
00135 int dmlite_code();
00136
00137 const boost::property_tree::ptree& jresp();
00138 const std::string& response();
00139
00140 void setcommand(const DomeCredentials &creds, const char *verb, const char *cmd);
00141 protected:
00142
00143 static const char *reqTypes[12];
00144 int getXrdHttpReqIndex(const char *verb) {
00145 for (int i = 0; i < 12; i++) {
00146 if (!strcmp(verb, reqTypes[i])) return i;
00147 }
00148 return 0;
00149 }
00150
00151
00152
00153 void calcXrdHttpHashes(
00154 char *hash,
00155 const char *fn,
00156 int16_t request,
00157 const char *sslclientshortname,
00158 const char *sslclientvorg,
00159 const char *sslclienthost,
00160 const char *sslclientdn,
00161 time_t tim,
00162 const char *key);
00163
00164 int compareXrdHttpHashes(
00165 const char *h1,
00166 const char *h2);
00167 private:
00168 DavixCtxPool &pool_;
00169 DomeCredentials creds_;
00170 std::string uri_;
00171 std::string verb_;
00172 std::string cmd_;
00173
00174 std::string target_;
00175
00176 DavixGrabber grabber_;
00177 DavixStuff *ds_;
00178
00179 Davix::DavixError *err_;
00180 std::string response_;
00181 boost::property_tree::ptree json_;
00182 bool parsedJson_;
00183 int status_;
00184 };
00185
00186 }
00187 #endif