Wolframe, 0.0.3

execContext.hpp
Go to the documentation of this file.
1 /************************************************************************
2 
3  Copyright (C) 2011 - 2014 Project Wolframe.
4  All rights reserved.
5 
6  This file is part of Project Wolframe.
7 
8  Commercial Usage
9  Licensees holding valid Project Wolframe Commercial licenses may
10  use this file in accordance with the Project Wolframe
11  Commercial License Agreement provided with the Software or,
12  alternatively, in accordance with the terms contained
13  in a written agreement between the licensee and Project Wolframe.
14 
15  GNU General Public License Usage
16  Alternatively, you can redistribute this file and/or modify it
17  under the terms of the GNU General Public License as published by
18  the Free Software Foundation, either version 3 of the License, or
19  (at your option) any later version.
20 
21  Wolframe is distributed in the hope that it will be useful,
22  but WITHOUT ANY WARRANTY; without even the implied warranty of
23  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  GNU General Public License for more details.
25 
26  You should have received a copy of the GNU General Public License
27  along with Wolframe. If not, see <http://www.gnu.org/licenses/>.
28 
29  If you have questions regarding the use of this file, please contact
30  Project Wolframe.
31 
32 ************************************************************************/
35 #ifndef _WOLFRAME_PROCESSOR_EXEC_CONTEXT_HPP_INCLUDED
36 #define _WOLFRAME_PROCESSOR_EXEC_CONTEXT_HPP_INCLUDED
38 #include "types/keymap.hpp"
41 
42 namespace _Wolframe {
43 namespace proc {
44 
48 {
49 public:
56 
59 
61  const AAAA::User* user() const {return m_user.get();}
64  void setUser( AAAA::User* u) {m_user.reset( u);}
65 
67  const AAAA::Authorizer* authorizer() const {return m_authorizer;}
70 
72  unsigned int defaultTimeout() const {return m_default_timeout;}
74  void setDefaultTimeout( unsigned int timeout_sec_) {m_default_timeout = timeout_sec_;}
75 
77  const char* socketIdentifier() const {return m_localEndpoint.get()?m_localEndpoint->config().socketIdentifier.c_str():0;}
79  const net::RemoteEndpoint* remoteEndpoint() const {return m_remoteEndpoint.get();}
81  const net::LocalEndpoint* localEndpoint() const {return m_localEndpoint.get();}
82 
85  const net::RemoteEndpointR& remoteEndpoint_,
86  const net::LocalEndpointR& localEndpoint_)
87  {
88  m_remoteEndpoint = remoteEndpoint_;
89  m_localEndpoint = localEndpoint_;
90  }
91 
93  bool hasCapability( const std::string& c) const
94  {
95  if (!m_localEndpoint.get()) return false;
96  return m_localEndpoint->config().hasCapability( c);
97  }
98 
101  {
102  return m_aaaaProvider?m_aaaaProvider->authenticator( client ):0;
103  }
106  {
107  return m_aaaaProvider?m_aaaaProvider->passwordChanger( *m_user.get(), client ):0;
108  }
109 
111  bool checkAuthorization( const std::string& funcname, const std::string& resource, std::string& errmsg, bool allowIfNotExists=false);
112 
115  {
118  };
121  {
122  static const char* ar[] = {"CONNECT","PASSWD"};
123  return ar[n];
124  }
125 
128  {
129  std::string errmsg;
130  return checkAuthorization( basicAuthorizationFunctionName(f), "", errmsg, true);
131  }
132 
134  db::Transaction* transaction( const std::string& name);
135 
137  void push_database( const std::string& dbname) {m_dbstack.push_back( dbname);}
139  void pop_database() {m_dbstack.pop_back();}
140 
141 private:
142  ExecContext( const ExecContext&); //... non copyable
143  void operator=( const ExecContext&); //... non copyable
144 
145 private:
150  unsigned int m_default_timeout;
153  std::vector<std::string> m_dbstack;
154 };
155 
156 }} //namespace
157 #endif
158 
AAAA::Authenticator * authenticator(const net::RemoteEndpoint &client) const
Get an authenticator.
Definition: execContext.hpp:100
Interface for all authorization mechanisms.
Definition: authorization.hpp:50
AAAA provider interface.
std::vector< std::string > m_dbstack
stack for implementing current database as scope
Definition: execContext.hpp:153
void setUser(AAAA::User *u)
Set the user instance.
Definition: execContext.hpp:64
void pop_database()
Restore the previous current transaction database.
Definition: execContext.hpp:139
db::Transaction * transaction(const std::string &name)
Create a new transaction object.
bool hasCapability(const std::string &c) const
Ask for a capability for this execution context.
Definition: execContext.hpp:93
Transaction interface.
Definition: transaction.hpp:52
virtual PasswordChanger * passwordChanger(const User &user, const net::RemoteEndpoint &client) const =0
Create an return a password changer object.
Smart pointer definition with the intention to hold sensitive data.
unsigned int m_default_timeout
default timeout
Definition: execContext.hpp:150
BasicAuthorizationFunction
Hardcoded basic authorization function enumeration.
Definition: execContext.hpp:114
const net::LocalEndpoint * localEndpoint() const
Get the local endpoint for authorization checks.
Definition: execContext.hpp:81
const AAAA::Authorizer * authorizer() const
Get the authorization instance interface.
Definition: execContext.hpp:67
bool checkAuthorization(const std::string &funcname, const std::string &resource, std::string &errmsg, bool allowIfNotExists=false)
Checks if a function tagged with AUTHORIZE( funcname, resource) is allowed to be executed.
Abstract class as processor provider interface.
Definition: procProviderInterface.hpp:81
void setAuthorizer(const AAAA::Authorizer *a)
Set the authorization instance interface.
Definition: execContext.hpp:69
virtual Authenticator * authenticator(const net::RemoteEndpoint &client) const =0
Create an return an authenticator object.
ExecContext()
Default Constructor.
Definition: execContext.hpp:51
types::SecureReference< AAAA::User > m_user
user instance
Definition: execContext.hpp:147
Password changer interface This the only interface to be used by the system. All other interfaces are...
Definition: passwordChanger.hpp:52
Execution context passed to functions for referencing resources and to define authorization dependend...
Definition: execContext.hpp:47
boost::shared_ptr< LocalEndpoint > LocalEndpointR
Definition: connectionEndpoint.hpp:163
const AAAA::User * user() const
Get the the user instance reference.
Definition: execContext.hpp:61
void setDefaultTimeout(unsigned int timeout_sec_)
Set the default timeout for read operations in seconds (0=forever)
Definition: execContext.hpp:74
net::RemoteEndpointR m_remoteEndpoint
remote end point of the connection
Definition: execContext.hpp:151
Data structure containing all login data of a user.
Definition: user.hpp:47
AAAA::PasswordChanger * passwordChanger(const net::RemoteEndpoint &client) const
Get a password changer.
Definition: execContext.hpp:105
Interface to processor provider for language bindings and database.
void operator=(const ExecContext &)
net::LocalEndpointR m_localEndpoint
local end point of the connection
Definition: execContext.hpp:152
ExecContext(const ProcessorProviderInterface *p, const AAAA::AAAAproviderInterface *a)
Constructor.
Definition: execContext.hpp:54
Definition: execContext.hpp:117
void setConnectionData(const net::RemoteEndpointR &remoteEndpoint_, const net::LocalEndpointR &localEndpoint_)
Set the socket identifier for authorization checks.
Definition: execContext.hpp:84
template for map with case insensitive key strings
const ProcessorProviderInterface * provider() const
Get the processor provider interface.
Definition: execContext.hpp:58
const P * get() const
Access content.
Definition: secureReference.hpp:59
bool checkAuthorization(BasicAuthorizationFunction f)
Checks authorization for a basic function.
Definition: execContext.hpp:127
const net::RemoteEndpoint * remoteEndpoint() const
Get the remote endpoint for authorization checks.
Definition: execContext.hpp:79
boost::shared_ptr< RemoteEndpoint > RemoteEndpointR
Definition: connectionEndpoint.hpp:208
void push_database(const std::string &dbname)
Declare the database 'dbname' as the current transaction database.
Definition: execContext.hpp:137
Remote connection endpoint.
Definition: connectionEndpoint.hpp:190
void reset(P *ptr_=0)
Recreate or dispose reference.
Definition: secureReference.hpp:65
static const char * basicAuthorizationFunctionName(BasicAuthorizationFunction n)
Get the name of a basic function.
Definition: execContext.hpp:120
const char * socketIdentifier() const
Get the socket identifier for authorization checks.
Definition: execContext.hpp:77
Definition: execContext.hpp:116
Provider interface to create AAAA related objects.
Definition: AAAAproviderInterface.hpp:51
const AAAA::AAAAproviderInterface * m_aaaaProvider
instance to query for an authenticator
Definition: execContext.hpp:149
Authenticator interface This the only interface to be used by the system. All other interfaces are in...
Definition: authenticator.hpp:56
const ProcessorProviderInterface * m_provider
processor provider interface
Definition: execContext.hpp:146
const AAAA::Authorizer * m_authorizer
instance to query for execution permission based on login data
Definition: execContext.hpp:148
unsigned int defaultTimeout() const
Get the default timeout for read operations in seconds.
Definition: execContext.hpp:72
Local connection endpoints.
Definition: connectionEndpoint.hpp:144