1 #ifndef IRODS_PLUGIN_BASE_HPP
2 #define IRODS_PLUGIN_BASE_HPP
6 #include <boost/function.hpp>
126 std::stringstream msg;
127 msg <<
"empty operation [" << _op <<
"]";
137 template<
typename... types_t>
139 const std::string& _op,
144 std::stringstream msg;
145 msg <<
"empty operation [" << _op <<
"]";
153 template<
typename... types_t>
156 const std::string& _operation_name,
167 adapted_func_type adapted_fcn = [
this, &_operation_name](
plugin_context& _ctx, std::string* _out_param, types_t... _t) {
170 fcn_t& fcn = boost::any_cast< fcn_t& >(
operations_[ _operation_name ] );
171 error ret = fcn( _ctx, _t... );
176 std::string out_param;
180 memset( &rei, 0,
sizeof( rei ) );
187 rule_engine_context_manager_type re_ctx_mgr(
re_plugin_globals->global_re_mgr, &rei);
191 error finally_err = invoke_policy_enforcement_point(re_ctx_mgr,
196 forward<types_t>(_t)...);
197 if (!finally_err.
ok()) {
203 error pre_err = invoke_policy_enforcement_point(
209 std::forward<types_t>(_t)...);
213 out_param =
"error="+std::to_string(pre_err.
code()) +
";message="+pre_err.
result();
216 error except_err = invoke_policy_enforcement_point(
222 std::forward<types_t>(_t)...);
224 if(!except_err.
ok()) {
231 to_return_op_err = adapted_fcn(ctx, &out_param, forward<types_t>(_t)...);
233 if(!to_return_op_err.
ok()) {
235 out_param =
"error="+std::to_string(to_return_op_err.
code()) +
";message="+to_return_op_err.
result();
237 error except_err = invoke_policy_enforcement_point(
243 forward<types_t>(_t)...);
245 if(!except_err.
ok()) {
249 return to_return_op_err;
253 error post_err = invoke_policy_enforcement_point(
259 forward<types_t>(_t)...);
262 out_param =
"error="+std::to_string(post_err.
code()) +
";message="+post_err.
result();
265 error except_err = invoke_policy_enforcement_point(
271 forward<types_t>(_t)...);
273 if(!except_err.
ok()) {
280 return to_return_op_err;
283 return to_return_op_err;
285 return adapted_fcn( ctx, &out_param, forward<types_t>(_t)... );
288 catch (
const boost::bad_any_cast&) {
289 std::string msg(
"failed for call - " );
290 msg += _operation_name;
296 template<
typename T >
299 return ASSERT_PASS( ret,
"Failed to get property for auth plugin." );
303 template<
typename T >
306 return ASSERT_PASS( ret,
"Failed to set property in the auth plugin." );
347 template<
typename... types_t>
348 error invoke_policy_enforcement_point(
349 rule_engine_context_manager_type _re_ctx_mgr,
351 std::string* _out_param,
352 const std::string& _operation_name,
353 const std::string& _class,
361 std::string rule_name = ns +
"pep_" + _operation_name +
"_" + _class;
364 if (_re_ctx_mgr.rule_exists(rule_name, ret).ok() && ret) {
365 error op_err = _re_ctx_mgr.exec_rule(rule_name,
instance_name_, _ctx, _out_param, std::forward<types_t>(_t)...);
368 rodsLog(
LOG_DEBUG,
"%s-pep rule [%s] failed with error code [%d]", _class.c_str(), rule_name.c_str(), op_err.
code());
369 saved_op_err = op_err;
372 skip_op_err = op_err;
374 if (_class !=
"pre") {
375 rodsLog(
LOG_WARNING,
"RULE_ENGINE_SKIP_OPERATION (%d) incorrectly returned from PEP [%s]! "
376 "RULE_ENGINE_SKIP_OPERATION should only be returned from pre-PEPs!",
382 rodsLog(
LOG_DEBUG10,
"Rule [%s] passes regex test, but does not exist", rule_name.c_str());
387 if (!saved_op_err.
ok()) {
402 typedef boost::shared_ptr<plugin_base>
plugin_ptr;
405 #endif // IRODS_PLUGIN_BASE_HPP