~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/simple_user_policy/module.cc

  • 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:
19
19
 
20
20
#include "config.h"
21
21
 
22
 
#include <string>
23
 
 
24
 
#include "drizzled/plugin/authorization.h"
25
 
#include "drizzled/security_context.h"
26
 
 
 
22
#include <drizzled/plugin/authorization.h>
 
23
 
 
24
#include "policy.h"
27
25
 
28
26
using namespace drizzled;
29
27
 
30
 
namespace authz
31
 
{
32
 
 
33
 
class Authz :
34
 
  public plugin::Authorization
35
 
{
36
 
public:
37
 
  Authz() :
38
 
    plugin::Authorization("test authz")
39
 
  { }
40
 
 
41
 
  /* I told you it was a silly plugin.
42
 
    If the db name is authz_no and the user is authz, then it's blocked
43
 
    If it's anything else, it's approved
44
 
  */
45
 
  virtual bool restrictSchema(const SecurityContext &user_ctx,
46
 
                              const std::string &db)
47
 
  {
48
 
    if (db == "authz_no" and user_ctx.getUser() == "authz")
49
 
      return true;
50
 
    return false;
51
 
  }
52
 
 
53
 
  virtual bool restrictProcess(const SecurityContext &user_ctx,
54
 
                               const SecurityContext &session_ctx)
55
 
  {
56
 
    if (user_ctx.getUser() == session_ctx.getUser())
57
 
      return false;
58
 
    if (user_ctx.getUser() == "authz")
59
 
      return true;
60
 
    return false;
61
 
  }
62
 
};
63
 
 
64
 
Authz *authz= NULL;
 
28
namespace simple_user_policy
 
29
{
65
30
 
66
31
static int init(plugin::Context &context)
67
32
{
68
 
  authz= new Authz();
69
 
  context.add(authz);
 
33
  context.add(new Policy);
70
34
  return 0;
71
35
}
72
36
 
73
 
} /* namespace authz */
 
37
} /* namespace simple_user_policy */
74
38
 
75
 
DRIZZLE_PLUGIN(authz::init, NULL);
 
39
DRIZZLE_PLUGIN(simple_user_policy::init, NULL);