00001 // OSB library ************************************************ -*- C++ -*- 00019 /* 00020 AUTHOR(S): Stephan Broennimann (vb) 00021 00022 RCS information 00023 $Name: OSB_060808 $ 00024 $Revision: 1.8 $ 00025 00026 License 00027 OSB rating and billing library for communication networks 00028 Copyright (C) 2004, 2005, 2006 OSB systems 00029 00030 This file may be distributed and/or modify under the terms of the 00031 GNU General Public License (GPL) as published by the Free Software 00032 Foundation which is provided in the file LICENSE.GPL included in the 00033 packaging of this file. 00034 00035 The file is distributed in the hope that it will be useful, but WITHOUT 00036 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00037 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00038 for more details. 00039 00040 Holders of a OSB Commercial License may use this file under the terms 00041 and conditions of this commercial license. 00042 */ 00043 #ifndef _OSBACCESS_H_ 00044 #define _OSBACCESS_H_ 00045 00046 // ************************************************************************ 00047 // included header files 00048 // + standard includes 00049 #include <list> 00050 #include <map> 00051 #include <string> 00052 00053 // + libraries 00054 00055 // + local headers 00056 #include "osbid.h" 00057 #include "osbconst.h" 00058 #include "osbutils.h" 00059 00060 // + class declarations 00061 namespace OSB_LIB { 00062 class UserGroup; 00063 } 00064 00065 namespace OSB_DB { 00066 class GrpAccessGw; 00067 class ModAccessGw; 00068 class Session; 00069 } 00070 00071 // ************************************************************************ 00072 // namespace extensions 00073 namespace OSB_LIB { 00074 00075 // ************************************************************************ 00076 // forward declarations 00077 00078 // ************************************************************************ 00079 // type definitions 00080 00081 // ************************************************************************ 00082 // class definitions 00097 class ModAccess { 00099 friend class OSB_DB::ModAccessGw; 00101 friend class UserMgmtCfg; 00102 public: 00104 typedef Id<ModAccess> Oid; 00105 00106 public: 00108 explicit ModAccess(const Oid& oid = Oid()); 00117 ModAccess( 00118 const ModuleId module, 00119 const Oid& parent = Oid() 00120 ); 00121 00122 public: 00124 ModuleId module() const; 00126 const Oid& oid() const; 00132 const Oid& parentId() const; 00134 const std::string& tag() const; 00135 00144 void read( 00145 const OSB_DB::Session& session 00146 ); 00147 00154 void setTag( 00155 const std::string& tag 00156 ); 00157 00158 private: // user management only 00168 void save( 00169 const OSB_DB::Session& session 00170 ); 00171 00179 void remove( 00180 const OSB_DB::Session& session 00181 ); 00182 00183 private: 00185 ModuleId module_; 00187 Oid oid_; 00189 Oid parent_; 00191 std::string tag_; 00192 }; // class ModAccess 00193 00197 class ModAccessMap { 00199 friend class OSB_DB::ModAccessGw; 00201 friend class UserMgmtCfg; 00202 public: 00204 typedef std::map<ModAccess::Oid, ModAccess> Entries; 00205 public: 00207 explicit ModAccessMap( 00208 const ModuleId module = mdUnknown 00209 ); 00210 00211 public: 00213 ModuleId module() const; 00214 00222 const ModAccess* find( 00223 const ModAccess::Oid& maId 00224 ) const; 00225 00234 const ModAccess& get( 00235 const ModAccess::Oid& maId 00236 ) const; 00237 00247 void accessRights( 00248 std::list<ModAccess>& dest, 00249 const ModAccess::Oid& parId = ModAccess::Oid() 00250 ) const; 00251 00259 void read(const OSB_DB::Session& session); 00260 00261 private: // for UserMgmtCfg only 00273 void check( 00274 const ModAccess& access 00275 ) const; 00276 00285 void insert( 00286 const ModAccess& access 00287 ); 00288 00289 private: 00291 ModuleId module_; 00293 Entries entries_; 00294 }; // class ModAccessMap 00295 00309 class GrpAccess { 00311 friend class OSB_DB::GrpAccessGw; 00313 friend class UserMgmtCfg; 00314 public: 00316 typedef Id<GrpAccess> Oid; 00318 typedef Id<UserGroup> GrpId; 00320 typedef Id<ModAccess> MaId; 00321 00322 public: 00324 explicit GrpAccess( 00325 const Oid& oid = Oid() 00326 ); 00334 GrpAccess( 00335 const GrpId& grpId, 00336 const Oid& parent = Oid() 00337 ); 00338 public: 00340 const Oid& oid() const; 00342 const GrpId& grpId() const; 00344 const MaId& maId() const; 00346 const Oid& parentId() const; 00348 const std::string& tag() const; 00349 00358 void read( 00359 const OSB_DB::Session& session 00360 ); 00361 00365 void setModAccess( 00366 const ModAccess& modAccess 00367 ); 00368 00369 private: // user management only 00382 void save( 00383 const OSB_DB::Session& session 00384 ); 00385 00393 void remove( 00394 const OSB_DB::Session& session 00395 ); 00396 00397 private: 00399 Oid oid_; 00401 GrpId grpId_; 00403 MaId maId_; 00405 Oid parent_; 00412 std::string tag_; 00413 }; // class GrpAccess 00414 00422 class GrpAccessMap { 00424 friend class OSB_DB::GrpAccessGw; 00426 friend class UserMgmtCfg; 00427 00428 public: 00430 explicit GrpAccessMap( 00431 const Id<UserGroup> grpId 00432 ); 00433 00434 public: 00441 class Key { 00442 public: 00446 explicit Key(const GrpAccess& grpAccess); 00451 Key( 00452 const GrpAccess::Oid& parentId, 00453 const std::string& accessTag 00454 ); 00455 00456 public: 00461 const GrpAccess::Oid& parentId() const; 00463 const std::string& accessTag() const; 00464 00466 bool operator<(const Key& rhs) const; 00467 00468 private: 00473 GrpAccess::Oid parent_; 00475 std::string accessTag_; 00476 }; // class Key 00477 00484 typedef std::map<Key, GrpAccess> Entries; 00485 00492 typedef std::list<Key> Path; 00493 00494 public: 00496 const Id<UserGroup>& grpId() const; 00505 const GrpAccess& get( 00506 const GrpAccess::Oid& gaId 00507 ) const; 00516 const GrpAccess& get(const Key& key) const; 00524 const GrpAccess* find(const Key& key) const; 00525 00535 void accessRights( 00536 std::list<GrpAccess>& dest, 00537 const GrpAccess::Oid& parId = GrpAccess::Oid() 00538 ) const; 00539 00547 void read(const OSB_DB::Session& session); 00548 00550 00551 00558 bool allowed( 00559 const std::string& rootTag 00560 ) const; 00562 00563 private: // UserGroup only 00565 00566 00577 void check( 00578 const GrpAccess& access 00579 ) const; 00580 00592 void insert( 00593 GrpAccess& access 00594 ); 00596 00597 private: 00599 GrpAccess* find(const Key& key); 00601 GrpAccess* find( 00602 const GrpAccess::Oid& gaId 00603 ); 00604 00605 private: 00607 Id<UserGroup> grpId_; 00609 Entries entries_; 00610 }; // class GrpAccessMap 00611 } // namespace OSB_LIB 00612 00613 // ************************************************************************ 00614 // inline definitions 00615 namespace OSB_LIB { 00616 } // namespace OSB_LIB 00617 #endif // #ifndef _OSBACCESS_H_