![]() |
|
|
Bdb packages | Design docs | Source docs | Guidelines | Recent releases |
|
Main Page Modules Namespace List Class Hierarchy Alphabetical List Compound List File List Compound Members File Members /BdbAccess/BdbAuth.cc
Go to the documentation of this file.00001 //-------------------------------------------------------------------------- 00002 // File and Version Information: 00003 // $Id: BdbAuth.cc,v 1.35 2002/06/21 18:30:18 ryd Exp $ 00004 // 00005 // Description: 00006 // This class provides an access to and management of the BaBar 00007 // Database athorization records. 00008 // 00009 // The class is implemented as a singleton. 00010 // 00011 // NOTE: This is a proxy class deffering the real authorization 00012 // requests to the BdbAuthFederation objects. 00013 // 00014 // Environment: 00015 // Software developed for the BaBar Detector at the SLAC B-Factory. 00016 // 00017 // Author List: 00018 // Igor A. Gaponenko Original Author 00019 // 00020 // History: 00021 // Copyright (C) 2001 Lawrence Berkeley Laboratory 00022 // 00023 //------------------------------------------------------------------------ 00024 00025 ///////////////////////// 00026 // This Class's Header // 00027 ///////////////////////// 00028 00029 #include "BdbAccess/BdbAuth.hh" 00030 00031 /////////////// 00032 // C Headers // 00033 /////////////// 00034 00035 ///////////////// 00036 // C++ Headers // 00037 ///////////////// 00038 00039 #include <iostream.h> 00040 #include <string> 00041 using std::string; 00042 #include <map> 00043 using std::map; 00044 00045 ///////////////////////////////// 00046 // Collaborating Class Headers // 00047 ///////////////////////////////// 00048 00049 #include "BdbAccess/BdbAuthFederation.hh" 00050 #include "BdbAccess/BdbAuthUsersItr.hh" 00051 #include "BdbAccess/BdbAuthGroupsItr.hh" 00052 00053 //////////////////////// 00054 // External functions // 00055 //////////////////////// 00056 00057 extern void BaBarObjyMessageHandler(char*); 00058 extern ooStatus BaBarObjyErrorHandler(ooErrorLevel, ooError&, ooHandle(ooObj)*, char*); 00059 00060 00061 ///////////////////////////////////////////////////////////////////////// 00062 // Local Macros, Typedefs, Structures, Unions and Forward Declarations // 00063 ///////////////////////////////////////////////////////////////////////// 00064 00065 static const char rcsid[] = "$Id: BdbAuth.cc,v 1.35 2002/06/21 18:30:18 ryd Exp $"; 00066 00067 00068 //////////////////////////////////// 00069 // Static Data Member Definitions // 00070 //////////////////////////////////// 00071 00072 BdbAuth* 00073 BdbAuth::_instance = 0; 00074 00075 //////////////////////// 00076 // Singleton Selector // 00077 //////////////////////// 00078 00079 BdbAuth* 00080 BdbAuth::instance( ) 00081 { 00082 if( 0 == _instance ) _instance = new BdbAuth( ); 00083 return _instance; 00084 } 00085 00086 //////////////// 00087 // Destructor // 00088 //////////////// 00089 00090 BdbAuth::~BdbAuth( ) 00091 { 00092 map<string, BdbAuthFederation*>::iterator theItr=_federation->begin(); 00093 while( theItr!=_federation->end()) { 00094 delete theItr->second; 00095 theItr++; 00096 } 00097 delete _federation; 00098 } 00099 00100 ///////////////// 00101 // Constructor // 00102 ///////////////// 00103 00104 BdbAuth::BdbAuth( ) 00105 { 00106 _federation = new map<string, BdbAuthFederation*>; 00107 } 00108 00109 /////////////// 00110 // Selectors // 00111 /////////////// 00112 00113 d_Boolean 00114 BdbAuth::isInitialized( BdbDomain::Domains theDomain ) 00115 { 00116 return federationInstance( )->isInitialized( theDomain ); 00117 } 00118 00119 d_Boolean 00120 BdbAuth::isAuthorized( BdbDomain::Domains theDomain, 00121 BdbDomain::AuthLevels theAuthLevel, 00122 const char* const theAuthName ) 00123 { 00124 return federationInstance( )->isAuthorized( theDomain, 00125 theAuthLevel, 00126 (const char*)theAuthName ); 00127 } 00128 00129 d_Boolean 00130 BdbAuth::isSystemManager( BdbDomain::Domains theDomain, 00131 const char* theUserName ) 00132 { 00133 return federationInstance( )->isSystemManager( theDomain, 00134 theUserName ); 00135 } 00136 00137 d_Boolean 00138 BdbAuth::isGroupManager( BdbDomain::Domains theDomain, 00139 const char* theUserName, 00140 const char* theGroupName ) 00141 { 00142 return federationInstance( )->isGroupManager( theDomain, 00143 theUserName, 00144 theGroupName ); 00145 } 00146 00147 d_Boolean 00148 BdbAuth::isGroupMember( BdbDomain::Domains theDomain, 00149 const char* theUserName, 00150 const char* theGroupName ) 00151 { 00152 return federationInstance( )->isGroupMember( theDomain, 00153 theUserName, 00154 theGroupName ); 00155 } 00156 00157 d_Boolean 00158 BdbAuth::isDomainMember( BdbDomain::Domains theDomain, 00159 const char* theUserName ) 00160 { 00161 return federationInstance( )->isDomainMember( theDomain, 00162 theUserName ); 00163 } 00164 00165 d_Boolean 00166 BdbAuth::isAccessAllowed( BdbDomain::Domains theDomain, 00167 const char* theUserName ) 00168 { 00169 return federationInstance( )->isAccessAllowed( theDomain, 00170 theUserName ); 00171 } 00172 00173 const char* 00174 BdbAuth::getUserDescription( BdbDomain::Domains theDomain, 00175 const char* theUserName ) 00176 { 00177 return federationInstance( )->getUserDescription( theDomain, 00178 theUserName ); 00179 } 00180 00181 const char* 00182 BdbAuth::getUserCreated( BdbDomain::Domains theDomain, 00183 const char* theUserName ) 00184 { 00185 return federationInstance( )->getUserCreated( theDomain, 00186 theUserName ); 00187 } 00188 00189 const char* 00190 BdbAuth::getGroupDescription( BdbDomain::Domains theDomain, 00191 const char* theGroupName ) 00192 { 00193 return federationInstance( )->getGroupDescription( theDomain, 00194 theGroupName ); 00195 } 00196 00197 const char* 00198 BdbAuth::getGroupCreated( BdbDomain::Domains theDomain, 00199 const char* theGroupName ) 00200 { 00201 return federationInstance( )->getGroupCreated( theDomain, 00202 theGroupName ); 00203 } 00204 00205 //////////////// 00206 // Operations // 00207 //////////////// 00208 00209 d_Boolean 00210 BdbAuth::initialize( BdbDomain::Domains theDomain ) 00211 { 00212 return federationInstance( )->initialize( theDomain ); 00213 } 00214 00215 d_Boolean 00216 BdbAuth::createUser( BdbDomain::Domains theDomain, 00217 BdbDomain::AuthLevels theAuthLevel, 00218 const char* theUserName, 00219 const char* theGroupName, 00220 const char* theDescription ) 00221 { 00222 return federationInstance( )->createUser( theDomain, 00223 theAuthLevel, 00224 theUserName, 00225 theGroupName, 00226 theDescription ); 00227 } 00228 00229 d_Boolean 00230 BdbAuth::deleteUser( BdbDomain::Domains theDomain, 00231 const char* theUserName ) 00232 { 00233 return federationInstance( )->deleteUser( theDomain, 00234 theUserName ); 00235 } 00236 00237 d_Boolean 00238 BdbAuth::createGroup( BdbDomain::Domains theDomain, 00239 const char* theGroupName, 00240 const char* theDescription ) 00241 { 00242 return federationInstance( )->createGroup( theDomain, 00243 theGroupName, 00244 theDescription ); 00245 } 00246 00247 d_Boolean 00248 BdbAuth::deleteGroup( BdbDomain::Domains theDomain, 00249 const char* theGroupName ) 00250 { 00251 return federationInstance( )->deleteGroup( theDomain, 00252 theGroupName ); 00253 } 00254 00255 d_Boolean 00256 BdbAuth::includeUser( BdbDomain::Domains theDomain, 00257 const char* theUserName, 00258 const char* theGroupName ) 00259 { 00260 return federationInstance( )->includeUser( theDomain, 00261 theUserName, 00262 theGroupName ); 00263 } 00264 00265 d_Boolean 00266 BdbAuth::excludeUser( BdbDomain::Domains theDomain, 00267 const char* theUserName, 00268 const char* theGroupName ) 00269 { 00270 return federationInstance( )->excludeUser( theDomain, 00271 theUserName, 00272 theGroupName ); 00273 } 00274 00275 d_Boolean 00276 BdbAuth::deleteDomain( BdbDomain::Domains theDomain ) 00277 { 00278 return federationInstance( )->deleteDomain( theDomain ); 00279 } 00280 00281 d_Boolean 00282 BdbAuth::setSystemManager( BdbDomain::Domains theDomain, 00283 const char* theUserName, 00284 d_Boolean onOff ) 00285 { 00286 return federationInstance( )->setSystemManager( theDomain, 00287 theUserName, 00288 onOff ); 00289 } 00290 00291 d_Boolean 00292 BdbAuth::setGroupManager( BdbDomain::Domains theDomain, 00293 const char* theUserName, 00294 const char* theGroupName, 00295 d_Boolean onOff ) 00296 { 00297 return federationInstance( )->setGroupManager( theDomain, 00298 theUserName, 00299 theGroupName, 00300 onOff ); 00301 } 00302 00303 //////////////////////////// 00304 // Transaction management // 00305 //////////////////////////// 00306 00307 void 00308 BdbAuth::startUpdate( ) 00309 { 00310 BdbApplicationOrDomain* theApp = BdbApplicationOrDomain::activeInstance( ); 00311 theApp->startUpdate( "Authorization" ); 00312 } 00313 00314 void 00315 BdbAuth::startRead( ) 00316 { 00317 BdbApplicationOrDomain* theApp = BdbApplicationOrDomain::activeInstance( ); 00318 theApp->startRead( "Authorization" ); 00319 } 00320 00321 void 00322 BdbAuth::abort( ) 00323 { 00324 BdbApplicationOrDomain* theApp = BdbApplicationOrDomain::activeInstance( ); 00325 theApp->abort( "Authorization" ); 00326 } 00327 00328 void 00329 BdbAuth::commit( ) 00330 { 00331 BdbApplicationOrDomain* theApp = BdbApplicationOrDomain::activeInstance( ); 00332 theApp->commit( "Authorization" ); 00333 } 00334 00335 /////////////////////// 00336 // Iterators factory // 00337 /////////////////////// 00338 00339 BdbAuthItr* 00340 BdbAuth::createUsersItr( BdbDomain::Domains theDomain ) 00341 { 00342 BdbAuthFederation* theAuthFederation = federationInstance( ); 00343 BdbAuthUsersItr* theItr = new BdbAuthUsersItr( theAuthFederation, 00344 theDomain ); 00345 if( !theItr->isValid( )) { 00346 00347 delete theItr; 00348 00349 error( theAuthFederation->getName( ).c_str(), 00350 theDomain, 00351 "Failed to setup a users iterator to iterate all users in the domain." ); 00352 00353 return 0; 00354 } 00355 return theItr; 00356 } 00357 00358 BdbAuthItr* 00359 BdbAuth::createUsersItr( BdbDomain::Domains theDomain, 00360 const char* theGroupName ) 00361 { 00362 BdbAuthFederation* theAuthFederation = federationInstance( ); 00363 BdbAuthUsersItr* theItr = new BdbAuthUsersItr( theAuthFederation, 00364 theDomain, 00365 theGroupName ); 00366 if( !theItr->isValid( )) { 00367 00368 delete theItr; 00369 00370 error( theAuthFederation->getName( ).c_str(), 00371 theDomain, 00372 "Failed to setup a users iterator to iterate all users in a group." ); 00373 00374 return 0; 00375 } 00376 return theItr; 00377 } 00378 00379 BdbAuthItr* 00380 BdbAuth::createGroupsItr( BdbDomain::Domains theDomain ) 00381 { 00382 BdbAuthFederation* theAuthFederation = federationInstance( ); 00383 BdbAuthGroupsItr* theItr = new BdbAuthGroupsItr( theAuthFederation, 00384 theDomain ); 00385 if( !theItr->isValid( )) { 00386 00387 delete theItr; 00388 00389 error( theAuthFederation->getName( ).c_str(), 00390 theDomain, 00391 "Failed to setup a users iterator to iterate all groups in the domain." ); 00392 00393 return 0; 00394 } 00395 return theItr; 00396 } 00397 00398 BdbAuthItr* 00399 BdbAuth::createGroupsItr( BdbDomain::Domains theDomain, 00400 const char* theUserName ) 00401 { 00402 BdbAuthFederation* theAuthFederation = federationInstance( ); 00403 BdbAuthGroupsItr* theItr = new BdbAuthGroupsItr( theAuthFederation, 00404 theDomain, 00405 theUserName ); 00406 if( !theItr->isValid( )) { 00407 00408 delete theItr; 00409 00410 error( theAuthFederation->getName( ).c_str(), 00411 theDomain, 00412 "Failed to setup a users iterator to iterate all groups a user is member of." ); 00413 00414 return 0; 00415 } 00416 return theItr; 00417 } 00418 00419 //////////////////////// 00420 // Messages reporting // 00421 //////////////////////// 00422 00423 void 00424 BdbAuth::message( const char* theBootFileName, 00425 BdbDomain::Domains theDomain, 00426 const char* theMessage ) 00427 { 00428 cout << "BdbAuth::message() " << theMessage << endl 00429 << " FEDERATION: " << theBootFileName << endl 00430 << " DOMAIN: " << BdbDomain::domainName( theDomain ) << endl; 00431 } 00432 00433 void 00434 BdbAuth::warning( const char* theBootFileName, 00435 BdbDomain::Domains theDomain, 00436 const char* theMessage ) 00437 { 00438 cout << "BdbAuth::warning() " << theMessage << endl 00439 << " FEDERATION: " << theBootFileName << endl 00440 << " DOMAIN: " << BdbDomain::domainName( theDomain ) << endl; 00441 } 00442 00443 void 00444 BdbAuth::error( const char* theBootFileName, 00445 BdbDomain::Domains theDomain, 00446 const char* theMessage ) 00447 { 00448 cout << "BdbAuth::error() " << theMessage << endl 00449 << " FEDERATION: " << theBootFileName << endl 00450 << " DOMAIN: " << BdbDomain::domainName( theDomain ) << endl; 00451 } 00452 00453 void 00454 BdbAuth::fatal( const char* theBootFileName, 00455 BdbDomain::Domains theDomain, 00456 const char* theMessage, 00457 int exitCode ) 00458 { 00459 cout << "BdbAuth::fatal() " << theMessage << endl 00460 << " FEDERATION: " << theBootFileName << endl 00461 << " DOMAIN: " << BdbDomain::domainName( theDomain ) << endl; 00462 00463 exit( exitCode ); 00464 } 00465 00466 /////////////////////////////////////// 00467 // Federations dictionary management // 00468 /////////////////////////////////////// 00469 00470 BdbAuthFederation* 00471 BdbAuth::federationInstance( ) 00472 { 00473 // Get the BOOT file name if possible. Use an empty string if not found. 00474 00475 const char* theBootFileName = ""; 00476 00477 BdbApplicationOrDomain* theApp = BdbApplicationOrDomain::activeInstance( ); 00478 if( 0 != theApp && 0 != theApp->bootName( )) { 00479 theBootFileName = theApp->bootName( ); 00480 } 00481 00482 // Locate/create a federation instance for that BOOT file name. 00483 00484 if( _federation->find( theBootFileName )==_federation->end()) { 00485 (*_federation)[theBootFileName] = new BdbAuthFederation( theBootFileName ); 00486 } 00487 00488 return (*_federation)[theBootFileName]; 00489 } 00490 00491 ///////////////// 00492 // End Of File // 00493 /////////////////
BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us
Page Owner: Jacek Becla
Last Update: October 04, 2002