~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/simple_user_policy/policy.h

  • Committer: Monty Taylor
  • Date: 2010-04-15 19:14:53 UTC
  • mto: This revision was merged to the branch mainline in revision 1476.
  • Revision ID: mordred@inaugust.com-20100415191453-ril2x8qdo78fny9w
Replaced test_authz with a plugin implementing a hard-coded simple
multi-tennancy policy. The policy describes:
- A root user exists which can do anything
- A user may only see a schema that is named the same has his user name
- A user may see data_dictionary and information_schema (data_dictionary
  required for show databases to work)

This way, we can more clearly test the results of the authorization
interface while providing an optional plugin that is actually useful to some
human.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2010 Monty Taylor <mordred@inaugust.com>
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
 
 
21
#ifndef PLUGINS_SIMPLE_USER_POLICY_POLICY_H
 
22
#define PLUGINS_SIMPLE_USER_POLICY_POLICY_H
 
23
 
 
24
#include <iostream>
 
25
 
 
26
#include <drizzled/plugin/authorization.h>
 
27
 
 
28
namespace simple_user_policy
 
29
{
 
30
 
 
31
class Policy :
 
32
  public drizzled::plugin::Authorization
 
33
{
 
34
public:
 
35
  Policy() :
 
36
    drizzled::plugin::Authorization("Simple User Policy")
 
37
  { }
 
38
 
 
39
  virtual bool restrictSchema(const drizzled::SecurityContext &user_ctx,
 
40
                              drizzled::SchemaIdentifier &db);
 
41
 
 
42
  virtual bool restrictProcess(const drizzled::SecurityContext &user_ctx,
 
43
                               const drizzled::SecurityContext &session_ctx);
 
44
};
 
45
 
 
46
inline bool Policy::restrictSchema(const drizzled::SecurityContext &user_ctx,
 
47
                                   drizzled::SchemaIdentifier &schema)
 
48
{
 
49
  if ((user_ctx.getUser() == "root")
 
50
      || schema.compare("data_dictionary")
 
51
      || schema.compare("information_schema"))
 
52
    return false;
 
53
  return not schema.compare(user_ctx.getUser());
 
54
}
 
55
 
 
56
inline bool Policy::restrictProcess(const drizzled::SecurityContext &user_ctx,
 
57
                                    const drizzled::SecurityContext &session_ctx)
 
58
{
 
59
  if (user_ctx.getUser() == "root")
 
60
    return false;
 
61
  return user_ctx.getUser() != session_ctx.getUser();
 
62
}
 
63
 
 
64
} /* namespace simple_user_policy */
 
65
 
 
66
#endif /* PLUGINS_SIMPLE_USER_POLICY_POLICY_H */