31 #include <BESCatalog.h> 32 #include <BESCatalogList.h> 33 #include <BESCatalogUtils.h> 35 #include <TheBESKeys.h> 36 #include <BESInternalError.h> 37 #include <BESSyntaxUserError.h> 39 #include <BESForbiddenError.h> 41 #include "WhiteList.h" 54 WhiteList::get_white_list()
56 if (d_instance)
return d_instance;
61 WhiteList::WhiteList()
64 string key = REMOTE_ACCESS_WHITELIST;
67 throw BESInternalError(
string(
"The remote access whitelist, '")+REMOTE_ACCESS_WHITELIST
68 +
"' has not been configured.", __FILE__, __LINE__);
86 bool WhiteList::is_white_listed(
const std::string &url)
88 bool whitelisted =
false;
89 const string file_url(
"file://");
90 const string http_url(
"http://");
91 const string https_url(
"https://");
95 if (url.compare(0, file_url.size(), file_url) == 0 ) {
98 string file_path = url.substr(file_url.size());
99 BESDEBUG(
"bes",
"WhiteList::Is_Whitelisted() - file_path: "<< file_path << endl);
103 BESDEBUG(
"bes",
"WhiteList::Is_Whitelisted() - Found catalog: "<< bcat->
get_catalog_name() << endl);
106 string msg =
"OUCH! Unable to locate default catalog!";
107 BESDEBUG(
"bes",
"WhiteList::Is_Whitelisted() - " << msg << endl);
111 string catalog_root = bcat->
get_root();
112 BESDEBUG(
"bes",
"WhiteList::Is_Whitelisted() - Catalog root: "<< catalog_root << endl);
114 whitelisted = file_path.compare(0, catalog_root.size(), catalog_root) == 0;
115 BESDEBUG(
"bes",
"WhiteList::Is_Whitelisted() - Is_Whitelisted: "<< (whitelisted?
"true":
"false") << endl);
119 if (url.compare(0, http_url.size(), http_url) == 0
120 || url.compare(0, https_url.size(), https_url) == 0 ) {
122 vector<string>::const_iterator i = d_white_list.begin();
123 vector<string>::const_iterator e = d_white_list.end();
124 for (; i != e && !whitelisted; i++) {
125 if ((*i).length() <= url.length()) {
126 if (url.substr(0, (*i).length()) == (*i)) {
134 msg =
"WhiteList - ERROR! Unknown URL protocol! Only " + http_url +
", " + https_url +
", and " + file_url +
" are supported.";
135 BESDEBUG(
"bes", msg << endl);
virtual std::string get_catalog_name() const
Get the name for this catalog.
virtual std::string get_root() const =0
exception thrown if inernal error encountered
static TheBESKeys * TheKeys()
void get_values(const std::string &s, std::vector< std::string > &vals, bool &found)
Retrieve the values of a given key, if set.
Catalogs provide a hierarchical organization for data.
error thrown if the BES is not allowed to access the resource requested
Can a given URL be dereferenced given the BES's configuration?
static BESCatalogList * TheCatalogList()
Get the singleton BESCatalogList instance.