00001 // OSB library ********************************************* -*- C++ -*- 00006 /* 00007 AUTHOR(S): Elangovan Angannan (aen) 00008 Stephan Broennimann (vb) 00009 00010 RCS information 00011 $Name: OSB_060808 $ 00012 $Revision: 1.27.2.1 $ 00013 00014 License 00015 OSB rating and billing library for communication networks 00016 Copyright (C) 2004, 2005, 2006 OSB systems 00017 00018 This file may be distributed and/or modify under the terms of the 00019 GNU General Public License (GPL) as published by the Free Software 00020 Foundation which is provided in the file LICENSE.GPL included in the 00021 packaging of this file. 00022 00023 The file is distributed in the hope that it will be useful, but WITHOUT 00024 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00025 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00026 for more details. 00027 00028 Holders of a OSB Commercial License may use this file under the terms 00029 and conditions of this commercial license. 00030 */ 00031 #ifndef _OSB_USER_H_ 00032 #define _OSB_USER_H_ 00033 00034 // ********************************************************************* 00035 // included header files 00036 // + standard includes 00037 #include <string> 00038 #include <list> 00039 #include <map> 00040 00041 // + local headers 00042 #include "osbid.h" 00043 #include "osbconst.h" 00044 00045 // ********************************************************************* 00046 // class declarations 00047 namespace OSB_LIB { 00048 class UserMgmtCfg; 00049 class UserGroup; 00050 } 00051 namespace OSB_DB { 00052 class OsbUserGw; 00053 class Session; 00054 }; 00055 00056 // ********************************************************************* 00057 // namespace extensions 00058 namespace OSB_LIB { 00059 00060 // ********************************************************************* 00061 // class declarations 00062 00063 // ********************************************************************* 00064 // type definitions 00065 00066 // ********************************************************************* 00067 // class definitions 00068 00079 class OsbUser { 00081 friend class OSB_DB::OsbUserGw; 00083 friend class UserMgmtCfg; 00084 00085 public: // Type definitions 00087 typedef Id<OsbUser> Oid; 00089 typedef std::map< ModuleId, Id<UserGroup> > Grants; 00090 00091 public: 00093 OsbUser(const Oid& oid = Oid()); 00094 00103 explicit OsbUser( 00104 const std::string& login, 00105 const std::string& password = "" 00106 ); 00107 00109 00110 const Oid& oid() const { return oid_; } 00111 const long objVs() const { return objVs_; } 00112 const std::string& loginName() const { return loginName_; } 00113 const std::string& password() const { return password_; } 00114 const std::string& name() const { return name_; } 00115 const std::string& email() const { return email_; } 00121 ModuleId defModule() const 00122 { 00123 return defModule_; 00124 } 00129 const Grants& grants() const; 00139 Id<UserGroup> userGroup(ModuleId module) const; 00141 00143 00144 00151 void setLoginName(const std::string& loginName); 00158 void setName(const std::string& name); 00165 void setEmail(const std::string& email); 00174 void setPassword( 00175 const std::string& newPw, 00176 const std::string& oldPw 00177 ); 00179 00181 00182 00190 void grant(const UserGroup& grp); 00191 00202 bool setDefModule(const ModuleId module); 00203 00212 void revoke(const ModuleId module); 00213 00219 void revokeAll(); 00221 00222 private: 00226 void setPw(const std::string& pw); 00233 bool checkPw(const std::string& password); 00234 00236 00237 00247 void read(const OSB_DB::Session& session); 00248 00257 bool login(const OSB_DB::Session& session); 00258 00271 void insert(const OSB_DB::Session& session); 00272 00282 void update(const OSB_DB::Session& session); 00283 00292 void remove(const OSB_DB::Session& session); 00294 00295 private: 00297 Oid oid_; 00299 long objVs_; 00301 std::string loginName_; 00303 std::string password_; 00305 std::string name_; 00307 std::string email_; 00309 Grants grants_; 00311 ModuleId defModule_; 00312 }; // class OsbUser 00313 00321 class Users { 00323 friend class UserMgmtCfg; 00325 friend class OSB_DB::OsbUserGw; 00326 public: 00331 typedef std::list<OsbUser> Cont; 00333 typedef Cont::const_iterator ConstIter; 00334 00335 public: 00337 Users(); 00338 public: 00340 bool empty() const; 00342 size_t size() const; 00344 ConstIter begin() const; 00346 ConstIter end() const; 00347 00355 const OsbUser& get(const OsbUser::Oid usrId) const; 00356 00358 void read(const OSB_DB::Session& session); 00360 bool usersRead() const; 00361 00362 private: 00370 void insert(const OsbUser& usr); 00371 00377 void remove(Cont::iterator usrIter); 00378 00380 Cont::iterator find(const OsbUser::Oid usrId); 00381 00382 private: 00384 Cont users_; 00386 bool usersRead_; 00387 }; // class Users 00388 } // namespace OSB_LIB 00389 #endif // #ifndef _OSB_USER_H_