78
79
class RestrictTableFunctor :
79
public std::unary_function<plugin::Authorization *, bool>
80
public unary_function<plugin::Authorization *, bool>
81
const identifier::User &user_ctx;
82
identifier::Table &table;
82
const SecurityContext &user_ctx;
84
RestrictTableFunctor(const identifier::User &user_ctx_arg,
85
identifier::Table &table_arg) :
86
std::unary_function<plugin::Authorization *, bool>(),
86
RestrictTableFunctor(const SecurityContext &user_ctx_arg,
87
const string &schema_arg,
88
const string &table_arg) :
89
unary_function<plugin::Authorization *, bool>(),
87
90
user_ctx(user_ctx_arg),
91
95
inline result_type operator()(argument_type auth)
93
return auth->restrictTable(user_ctx, table);
97
return auth->restrictTable(user_ctx, schema, table);
97
101
class RestrictProcessFunctor :
98
public std::unary_function<plugin::Authorization *, bool>
102
public unary_function<plugin::Authorization *, bool>
100
const identifier::User &user_ctx;
101
const identifier::User &session_ctx;
104
const SecurityContext &user_ctx;
105
const SecurityContext &session_ctx;
103
RestrictProcessFunctor(const identifier::User &user_ctx_arg,
104
const identifier::User &session_ctx_arg) :
105
std::unary_function<plugin::Authorization *, bool>(),
107
RestrictProcessFunctor(const SecurityContext &user_ctx_arg,
108
const SecurityContext &session_ctx_arg) :
109
unary_function<plugin::Authorization *, bool>(),
106
110
user_ctx(user_ctx_arg),
107
111
session_ctx(session_ctx_arg)
116
class PruneSchemaFunctor :
117
public std::unary_function<identifier::Schema&, bool>
119
drizzled::identifier::User::const_shared_ptr user_ctx;
121
PruneSchemaFunctor(drizzled::identifier::User::const_shared_ptr user_ctx_arg) :
122
std::unary_function<identifier::Schema&, bool>(),
123
user_ctx(user_ctx_arg)
126
inline result_type operator()(argument_type auth)
128
return not plugin::Authorization::isAuthorized(user_ctx, auth, false);
132
120
} /* namespace */
134
bool plugin::Authorization::isAuthorized(identifier::User::const_shared_ptr user_ctx,
135
identifier::Schema::const_reference schema_identifier,
138
/* If we never loaded any authorization plugins, just return true */
139
if (authorization_plugins.empty())
142
/* Use find_if instead of foreach so that we can collect return codes */
143
std::vector<plugin::Authorization *>::const_iterator iter=
144
std::find_if(authorization_plugins.begin(),
145
authorization_plugins.end(),
146
RestrictDbFunctor(*user_ctx, schema_identifier));
150
* If iter is == end() here, that means that all of the plugins returned
151
* false, which means that that each of them believe the user is authorized
152
* to view the resource in question.
154
if (iter != authorization_plugins.end())
159
schema_identifier.getSQLPath(path);
161
my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),
162
user_ctx->username().c_str(),
163
user_ctx->address().c_str(),
171
bool plugin::Authorization::isAuthorized(drizzled::identifier::User::const_shared_ptr user_ctx,
172
identifier::Table &table,
175
/* If we never loaded any authorization plugins, just return true */
176
if (authorization_plugins.empty())
179
/* Use find_if instead of foreach so that we can collect return codes */
180
std::vector<plugin::Authorization *>::const_iterator iter=
181
std::find_if(authorization_plugins.begin(),
182
authorization_plugins.end(),
183
RestrictTableFunctor(*user_ctx, table));
186
* If iter is == end() here, that means that all of the plugins returned
187
* false, which means that that each of them believe the user is authorized
188
* to view the resource in question.
190
if (iter != authorization_plugins.end())
195
table.getSQLPath(path);
197
my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),
198
user_ctx->username().c_str(),
199
user_ctx->address().c_str(),
207
bool plugin::Authorization::isAuthorized(drizzled::identifier::User::const_shared_ptr user_ctx,
208
const Session *session,
211
return isAuthorized(*user_ctx, session, send_error);
214
bool plugin::Authorization::isAuthorized(drizzled::identifier::User::const_reference user_ctx,
215
const Session *session,
218
drizzled::identifier::User::const_shared_ptr session_ctx= session->user();
220
/* If we never loaded any authorization plugins, just return true */
221
if (authorization_plugins.empty())
224
/* Use find_if instead of foreach so that we can collect return codes */
225
std::vector<plugin::Authorization *>::const_iterator iter=
226
std::find_if(authorization_plugins.begin(),
227
authorization_plugins.end(),
228
RestrictProcessFunctor(user_ctx, *session_ctx));
122
bool plugin::Authorization::isAuthorized(const SecurityContext &user_ctx,
123
const string &schema,
126
/* If we never loaded any authorization plugins, just return true */
127
if (authorization_plugins.empty())
130
/* Use find_if instead of foreach so that we can collect return codes */
131
vector<plugin::Authorization *>::const_iterator iter=
132
find_if(authorization_plugins.begin(),
133
authorization_plugins.end(),
134
RestrictDbFunctor(user_ctx, schema));
137
* If iter is == end() here, that means that all of the plugins returned
138
* false, which means that that each of them believe the user is authorized
139
* to view the resource in question.
141
if (iter != authorization_plugins.end())
145
my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),
146
user_ctx.getUser().c_str(),
147
user_ctx.getIp().c_str(),
155
bool plugin::Authorization::isAuthorized(const SecurityContext &user_ctx,
156
const string &schema,
160
/* If we never loaded any authorization plugins, just return true */
161
if (authorization_plugins.empty())
164
/* Use find_if instead of foreach so that we can collect return codes */
165
vector<plugin::Authorization *>::const_iterator iter=
166
find_if(authorization_plugins.begin(),
167
authorization_plugins.end(),
168
RestrictTableFunctor(user_ctx, schema, table));
171
* If iter is == end() here, that means that all of the plugins returned
172
* false, which means that that each of them believe the user is authorized
173
* to view the resource in question.
175
if (iter != authorization_plugins.end())
179
my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),
180
user_ctx.getUser().c_str(),
181
user_ctx.getIp().c_str(),
189
bool plugin::Authorization::isAuthorized(const SecurityContext &user_ctx,
190
const Session *session,
193
const SecurityContext &session_ctx= session->getSecurityContext();
195
/* If we never loaded any authorization plugins, just return true */
196
if (authorization_plugins.empty())
199
/* Use find_if instead of foreach so that we can collect return codes */
200
vector<plugin::Authorization *>::const_iterator iter=
201
find_if(authorization_plugins.begin(),
202
authorization_plugins.end(),
203
RestrictProcessFunctor(user_ctx, session_ctx));
231
206
* If iter is == end() here, that means that all of the plugins returned