~posulliv/drizzle/optimizer-style-cleanup

« back to all changes in this revision

Viewing changes to drizzled/plugin/authorization.h

  • Committer: Padraig O'Sullivan
  • Date: 2010-03-15 14:05:26 UTC
  • mfrom: (1237.9.99 staging)
  • Revision ID: osullivan.padraig@gmail.com-20100315140526-opbgwdwn6tfecdkq
MergeĀ fromĀ trunk.

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
 *  Definitions required for Authorization plugin
 
5
 *
 
6
 *  Copyright (C) 2010 Monty Taylor
 
7
 *
 
8
 *  This program is free software; you can redistribute it and/or modify
 
9
 *  it under the terms of the GNU General Public License as published by
 
10
 *  the Free Software Foundation; version 2 of the License.
 
11
 *
 
12
 *  This program is distributed in the hope that it will be useful,
 
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 *  GNU General Public License for more details.
 
16
 *
 
17
 *  You should have received a copy of the GNU General Public License
 
18
 *  along with this program; if not, write to the Free Software
 
19
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
20
 */
 
21
 
 
22
#ifndef DRIZZLED_PLUGIN_AUTHORIZATION_H
 
23
#define DRIZZLED_PLUGIN_AUTHORIZATION_H
 
24
 
 
25
#include "drizzled/plugin.h"
 
26
#include "drizzled/plugin/plugin.h"
 
27
#include "drizzled/security_context.h"
 
28
#include "drizzled/table_identifier.h"
 
29
 
 
30
#include <string>
 
31
#include <set>
 
32
 
 
33
namespace drizzled
 
34
{
 
35
 
 
36
namespace plugin
 
37
{
 
38
 
 
39
class Authorization : public Plugin
 
40
{
 
41
  Authorization();
 
42
  Authorization(const Authorization &);
 
43
  Authorization& operator=(const Authorization &);
 
44
public:
 
45
  explicit Authorization(std::string name_arg)
 
46
    : Plugin(name_arg, "Authorization")
 
47
  {}
 
48
  virtual ~Authorization() {}
 
49
 
 
50
  /**
 
51
   * Should we restrict the current user's access to this schema?
 
52
   *
 
53
   * @param Current security context
 
54
   * @param Database to check against
 
55
   *
 
56
   * @returns true if the user cannot access the schema
 
57
   */
 
58
  virtual bool restrictSchema(const SecurityContext &user_ctx,
 
59
                              const std::string &schema)= 0;
 
60
 
 
61
  /**
 
62
   * Should we restrict the current user's access to this table?
 
63
   *
 
64
   * @param Current security context
 
65
   * @param Database to check against
 
66
   * @param Table to check against
 
67
   *
 
68
   * @returns true if the user cannot access the table
 
69
   */
 
70
  virtual bool restrictTable(const SecurityContext &user_ctx,
 
71
                             const std::string &schema,
 
72
                             const std::string &table);
 
73
 
 
74
  /**
 
75
   * Should we restrict the current user's access to see this process?
 
76
   *
 
77
   * @param Current security context
 
78
   * @param Database to check against
 
79
   * @param Table to check against
 
80
   *
 
81
   * @returns true if the user cannot see the process
 
82
   */
 
83
  virtual bool restrictProcess(const SecurityContext &user_ctx,
 
84
                               const SecurityContext &session_ctx);
 
85
 
 
86
  /** Server API method for checking schema authorization */
 
87
  static bool isAuthorized(const SecurityContext &user_ctx,
 
88
                           const std::string &schema,
 
89
                           bool send_error= true);
 
90
 
 
91
  /** Server API method for checking table authorization */
 
92
  static bool isAuthorized(const SecurityContext &user_ctx,
 
93
                           const std::string &schema,
 
94
                           const std::string &table,
 
95
                           bool send_error= true);
 
96
 
 
97
  /** Server API method for checking process authorization */
 
98
  static bool isAuthorized(const SecurityContext &user_ctx,
 
99
                           const Session *session,
 
100
                           bool send_error= true);
 
101
 
 
102
  /**
 
103
   * Server API helper method for applying authorization tests
 
104
   * to a set of schema names (for use in the context of getSchemaNames
 
105
   */
 
106
  static void pruneSchemaNames(const SecurityContext &user_ctx,
 
107
                               std::set<std::string> &set_of_names);
 
108
  
 
109
  /**
 
110
   * Standard plugin system registration hooks
 
111
   */
 
112
  static bool addPlugin(plugin::Authorization *auth);
 
113
  static void removePlugin(plugin::Authorization *auth);
 
114
 
 
115
};
 
116
 
 
117
inline bool Authorization::restrictTable(const SecurityContext &user_ctx,
 
118
                                         const std::string &schema,
 
119
                                         const std::string &)
 
120
{
 
121
  return restrictSchema(user_ctx, schema);
 
122
}
 
123
 
 
124
inline bool Authorization::restrictProcess(const SecurityContext &,
 
125
                                           const SecurityContext &)
 
126
{
 
127
  return false;
 
128
}
 
129
 
 
130
} /* namespace plugin */
 
131
 
 
132
} /* namespace drizzled */
 
133
 
 
134
#endif /* DRIZZLED_PLUGIN_AUTHORIZATION_H */