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