dmlite  0.6
authn.h
Go to the documentation of this file.
1 /// @file include/dmlite/cpp/authn.h
2 /// @brief Authentication API. Any sort of security check is plugin-specific.
3 /// @author Alejandro Álvarez Ayllón <aalvarez@cern.ch>
4 #ifndef DMLITE_CPP_AUTHN_H
5 #define DMLITE_CPP_AUTHN_H
6 
7 #include "dmlite/common/config.h"
8 #include "base.h"
9 #include "exceptions.h"
10 #include "utils/extensible.h"
11 
12 #include <string>
13 #include <vector>
14 
15 namespace dmlite {
16 
17  // Forward declarations.
18  class PluginManager;
19  class StackInstance;
20 
21  /// Security credentials. To be filled by the front-end.
23  std::string mech;
24  std::string clientName;
25  std::string remoteAddress;
26  std::string sessionId;
27 
28  std::vector<std::string> fqans;
29 
30  bool operator == (const SecurityCredentials&) const;
31  bool operator != (const SecurityCredentials&) const;
32  bool operator < (const SecurityCredentials&) const;
33  bool operator > (const SecurityCredentials&) const;
34  };
35 
36  /// User information.
37  /// To be filled by the Authn plugin with whichever data
38  /// it is needed. (i.e. uid for LCGDM Adapter)
39  /// To be used by other plugins whenever they need it.
40  /// IMPORTANT: This means plugins must be compatible with the Authn
41  /// put in charge of security.
42  struct UserInfo: public Extensible {
43  std::string name;
44 
45  bool operator == (const UserInfo&) const;
46  bool operator != (const UserInfo&) const;
47  bool operator < (const UserInfo&) const;
48  bool operator > (const UserInfo&) const;
49  };
50 
51  /// Group information
52  /// See UserInfo
53  struct GroupInfo: public Extensible {
54  std::string name;
55 
56  bool operator == (const GroupInfo&) const;
57  bool operator != (const GroupInfo&) const;
58  bool operator < (const GroupInfo&) const;
59  bool operator > (const GroupInfo&) const;
60  };
61 
62 
63  /// Security context. To be created by the Authn.
64  struct SecurityContext {
66 
68  const UserInfo& u,
69  std::vector<GroupInfo>& g):
70  credentials(c), user(u), groups(g) {}
71 
73 
75  std::vector<GroupInfo> groups;
76 
77  bool operator == (const SecurityContext&) const;
78  bool operator != (const SecurityContext&) const;
79  bool operator < (const SecurityContext&) const;
80  bool operator > (const SecurityContext&) const;
81  };
82 
83 
84 
85  /// User and group handling.
86  ///@note This is the only interface not inheriting from BaseInterface.
87  class Authn {
88  public:
89  /// Destructor
90  virtual ~Authn();
91 
92  /// String ID of the user DB implementation.
93  virtual std::string getImplId(void) const throw() = 0;
94 
95  /// Create a security context from the credentials.
96  /// @param cred The security credentials.
97  /// @return A newly created SecurityContext.
99 
100  /// Create a default security context.
101  /// @return A newly created SecurityContext.
103 
104  /// Create a new group.
105  /// @param groupName The group name.
106  /// @return The new group.
107  virtual GroupInfo newGroup(const std::string& groupName) ;
108 
109  /// Get a specific group.
110  /// @param groupName The group name.
111  /// @return The group.
112  virtual GroupInfo getGroup(const std::string& groupName) ;
113 
114  /// Get a specific group using an alternative key.
115  /// @param key The key name.
116  /// @param value They value to search for.
117  /// @return The group.
118  /// @note The implementation will throw an exception if the field
119  /// can not be used as key.
120  virtual GroupInfo getGroup(const std::string& key,
121  const boost::any& value) ;
122 
123  /// Get the group list.
124  virtual std::vector<GroupInfo> getGroups(void) ;
125 
126  /// Update group info. 'name' identify uniquely the group.
127  /// @param group The group metadata to update.
128  virtual void updateGroup(const GroupInfo& group) ;
129 
130  /// Delete a group.
131  virtual void deleteGroup(const std::string& groupName) ;
132 
133  /// Create a new user.
134  /// @param userName The user name.
135  /// @return The new user.
136  virtual UserInfo newUser(const std::string& userName) ;
137 
138  /// Get a specific user.
139  /// @param userName The user name.
140  /// @return The user.
141  virtual UserInfo getUser(const std::string& userName) ;
142 
143  /// Get a specific user using an alternative key.
144  /// @param key The key name.
145  /// @param value They value to search for.
146  /// @return The user.
147  /// @note The implementation will throw an exception if the field
148  /// can not be used as key.
149  virtual UserInfo getUser(const std::string& key,
150  const boost::any& value) ;
151 
152  /// Get the user list.
153  virtual std::vector<UserInfo> getUsers(void) ;
154 
155  /// Update user info. 'name' identify uniquely the user.
156  /// @param user The user metadata to update.
157  virtual void updateUser(const UserInfo& user) ;
158 
159  /// Delete a user.
160  virtual void deleteUser(const std::string& userName) ;
161 
162  /// Get the mapping of a user/group. Additionaly, new users and groups MAY
163  /// be created by the implementation.
164  /// @param userName The user name.
165  /// @param groupNames The different groups. Can be empty.
166  /// @param user Pointer to an UserInfo struct where to put the data.
167  /// @param groups Pointer to a vector where the group mapping will be put.
168  /// @note If groupNames is empty, grid mapfile will be used to retrieve the default group.
169  virtual void getIdMap(const std::string& userName,
170  const std::vector<std::string>& groupNames,
171  UserInfo* user,
172  std::vector<GroupInfo>* groups) ;
173  };
174 
175 
176  /// AuthnFactory
177  class AuthnFactory: public virtual BaseFactory {
178  public:
179  /// Destructor
180  virtual ~AuthnFactory();
181 
182  protected:
183  // Stack instance is allowed to instantiate Authn
184  friend class StackInstance;
185 
186  /// Children of AuthnFactory are allowed to instantiate too (decorator)
187  static Authn* createAuthn(AuthnFactory* factory,
188  PluginManager* pm) ;
189 
190  /// Instantiate a implementation of Authn
192  };
193 
194 };
195 
196 #endif // DMLITE_CPP_AUTH_H
dmlite::GroupInfo::operator==
bool operator==(const GroupInfo &) const
dmlite::SecurityCredentials::mech
std::string mech
Definition: authn.h:23
exceptions.h
Exceptions used by the API.
dmlite::Authn::~Authn
virtual ~Authn()
Destructor.
dmlite::SecurityContext::SecurityContext
SecurityContext(const SecurityCredentials &c, const UserInfo &u, std::vector< GroupInfo > &g)
Definition: authn.h:67
dmlite::BaseFactory
Base class for factories.
Definition: base.h:48
dmlite::GroupInfo::name
std::string name
Definition: authn.h:54
dmlite::Authn::getGroup
virtual GroupInfo getGroup(const std::string &key, const boost::any &value)
dmlite::Authn::getUser
virtual UserInfo getUser(const std::string &key, const boost::any &value)
dmlite::SecurityContext::credentials
SecurityCredentials credentials
Definition: authn.h:72
dmlite::UserInfo::operator!=
bool operator!=(const UserInfo &) const
extensible.h
Extensible types (hold metadata).
dmlite::Authn::getGroups
virtual std::vector< GroupInfo > getGroups(void)
Get the group list.
dmlite::SecurityCredentials::sessionId
std::string sessionId
Definition: authn.h:26
dmlite::Authn::updateGroup
virtual void updateGroup(const GroupInfo &group)
dmlite::UserInfo::operator==
bool operator==(const UserInfo &) const
dmlite::Authn::getUsers
virtual std::vector< UserInfo > getUsers(void)
Get the user list.
dmlite::Authn::deleteUser
virtual void deleteUser(const std::string &userName)
Delete a user.
dmlite::SecurityContext::operator<
bool operator<(const SecurityContext &) const
dmlite::GroupInfo
Definition: authn.h:53
dmlite::AuthnFactory::createAuthn
static Authn * createAuthn(AuthnFactory *factory, PluginManager *pm)
Children of AuthnFactory are allowed to instantiate too (decorator)
dmlite::UserInfo::operator>
bool operator>(const UserInfo &) const
base.h
Base interfaces.
dmlite::SecurityCredentials
Security credentials. To be filled by the front-end.
Definition: authn.h:22
dmlite::SecurityCredentials::operator==
bool operator==(const SecurityCredentials &) const
dmlite::UserInfo::operator<
bool operator<(const UserInfo &) const
dmlite::Authn::createSecurityContext
virtual SecurityContext * createSecurityContext(void)
dmlite::Authn::newGroup
virtual GroupInfo newGroup(const std::string &groupName)
dmlite::Extensible
Helpful typedef for KeyValue containers.
Definition: extensible.h:20
dmlite::SecurityContext::SecurityContext
SecurityContext()
Definition: authn.h:65
dmlite::AuthnFactory::createAuthn
virtual Authn * createAuthn(PluginManager *pm)
Instantiate a implementation of Authn.
dmlite::SecurityContext
Security context. To be created by the Authn.
Definition: authn.h:64
dmlite::SecurityContext::operator!=
bool operator!=(const SecurityContext &) const
dmlite::AuthnFactory
AuthnFactory.
Definition: authn.h:177
dmlite::StackInstance
Definition: dmlite.h:161
dmlite::SecurityCredentials::operator<
bool operator<(const SecurityCredentials &) const
dmlite::SecurityCredentials::operator!=
bool operator!=(const SecurityCredentials &) const
dmlite::SecurityCredentials::fqans
std::vector< std::string > fqans
Definition: authn.h:28
dmlite::Authn::getIdMap
virtual void getIdMap(const std::string &userName, const std::vector< std::string > &groupNames, UserInfo *user, std::vector< GroupInfo > *groups)
dmlite::Authn
Definition: authn.h:87
dmlite::PluginManager
CatalogInterface can only be instantiated through this class.
Definition: dmlite.h:42
dmlite::Authn::updateUser
virtual void updateUser(const UserInfo &user)
dmlite::Authn::deleteGroup
virtual void deleteGroup(const std::string &groupName)
Delete a group.
dmlite::Authn::getGroup
virtual GroupInfo getGroup(const std::string &groupName)
dmlite::Authn::getImplId
virtual std::string getImplId(void) const =0
String ID of the user DB implementation.
dmlite::SecurityContext::groups
std::vector< GroupInfo > groups
Definition: authn.h:75
dmlite::SecurityCredentials::clientName
std::string clientName
Definition: authn.h:24
dmlite::Authn::createSecurityContext
virtual SecurityContext * createSecurityContext(const SecurityCredentials &cred)
dmlite::SecurityContext::user
UserInfo user
Definition: authn.h:74
dmlite::SecurityCredentials::operator>
bool operator>(const SecurityCredentials &) const
dmlite::UserInfo::name
std::string name
Definition: authn.h:43
dmlite::SecurityContext::operator>
bool operator>(const SecurityContext &) const
dmlite::GroupInfo::operator<
bool operator<(const GroupInfo &) const
dmlite::GroupInfo::operator!=
bool operator!=(const GroupInfo &) const
dmlite
Namespace for the dmlite C++ API.
Definition: authn.h:15
dmlite::Authn::getUser
virtual UserInfo getUser(const std::string &userName)
dmlite::UserInfo
Definition: authn.h:42
dmlite::SecurityContext::operator==
bool operator==(const SecurityContext &) const
dmlite::SecurityCredentials::remoteAddress
std::string remoteAddress
Definition: authn.h:25
dmlite::Authn::newUser
virtual UserInfo newUser(const std::string &userName)
dmlite::GroupInfo::operator>
bool operator>(const GroupInfo &) const
dmlite::AuthnFactory::~AuthnFactory
virtual ~AuthnFactory()
Destructor.