Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members  

BDBSecurityPlugin.h

00001 /*
00002    Copyright (C) 2002 the Strongroom project
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The definition of the security module.
00010    @author Denis de Leeuw Duarte
00011 */
00012 
00013 
00014 
00015 #ifndef __BDBSECURITYPLUGIN_H_
00016 #define __BDBSECURITYPLUGIN_H_
00017 
00018 using namespace std;
00019 
00023 #define __SECDATAFILE "securitydb"
00024 
00025 
00026 #include <SecurityPlugin.h>
00027 #include <db_cxx.h>
00028 
00050 class BDBSecurityPlugin : public SecurityPlugin
00051 {
00052   typedef DbTxn transaction_t; 
00053   typedef struct 
00054   { 
00055     NumID userID;
00056     bool hasWritePermission;
00057     bool hasDeletePermission;
00058   } docperm_t;
00059 
00060  public:
00061     
00062   BDBSecurityPlugin( const Config &cfg );
00063   ~BDBSecurityPlugin();
00064 
00065   /* ======== Required by Plugin base class =======*/
00066 
00067   bool init();
00068 
00069   /* ==== Required by SecurityPlugin base class ====*/
00070 
00071   void getLoginChallenge( string username, string &challenge );
00072   bool hasReadPermission(NumID userid, NumID docid);
00073   bool hasWritePermission(NumID userid, NumID docid);
00074   bool hasDeletePermission( NumID userid, NumID docid );
00075   CoreError fileCreated(NumID userid, NumID docid, Permission permission);
00076   CoreError changeUserPermission(NumID userid, Permission permission, NumID adminid);
00077   CoreError changeFilePermission(NumID docid, Permission permission, NumID userid);
00078   CoreError filterSearchResults(QueryResult &queryResult);
00079   CoreError addUser( const UserProfile &userProfile, string challenge, string password, NumID &userid );
00080   CoreError delUser( NumID userid );
00081   CoreError login( string username, string challenge, string response, UserProfile &user );
00082   CoreError getUserProfile( NumID userid, UserProfile &userProfile );
00083   CoreError changeUserProfile( NumID userid, const UserProfile &userProfile );
00084   CoreError setPassword( NumID userid, string challenge, string oldPassword, string newPassword );
00085   CoreError clearPassword( NumID userid );
00086   CoreError listUsers( vector<NumID> &users );
00087 
00088   /* ===============================================*/
00089 
00090  private:
00091 
00092   /*
00093     Checks if the key exists in the system database. If not, it is created  and 
00094     initialized with the default value. This method is used during the 
00095     initialization process to ensure a meaningful system database. 
00096   */
00097   bool checkSysKeyOrSetDefault( const char *key, uint64_t defaultValue   );
00098 
00099   /*
00100     Creates a new BDB transaction and returns a handle to it. The transaction
00101     needs to be finished with commitTransaction() or abortTransaction() to 
00102     prevent a memory leak and/or deadlock.
00103    */
00104   transaction_t *startTransaction();
00105   
00106   /*
00107     Commits the transaction and frees it. 
00108    */
00109   void commitTransaction( transaction_t *transaction );
00110 
00111   /*
00112     Aborts the transaction and frees it.
00113    */
00114   void abortTransaction( transaction_t *transaction );
00115 
00116   /*
00117     Fetch a user's ID from the database. Returns true on success and false on failure.
00118     \param txn the transaction that guards the operation.
00119     \param username the name of the user
00120     \param userid the destination address of the fetched user-ID.
00121   */
00122   bool fetchUserID( transaction_t *txn, std::string username, NumID *userid );
00123 
00124   /*
00125     Fetch a user's profile from the database. Returns true on success and false on failure.
00126     \param txn the transaction that guards the operation.
00127     \param userid the ID of the user.
00128     \param xmlprofile the string object that will receive the XML user profile
00129   */
00130   bool fetchUserProfile( transaction_t *txn, NumID userid, std::string &xmlprofile );
00131 
00132   Db *usrTableHandle;
00133   Db *docTableHandle;
00134   Db *sysTableHandle;
00135   DbEnv *dbEnvHandle;
00136   bool _initialized;
00137 };
00138 
00139 /* Standard system database keys */
00140 
00141 static const char *key_highest_uid = "HIGHEST_UID";
00142 
00143 #endif /*_BDBSECURITYPLUGIN_H_*/

Generated on Wed Feb 18 13:45:55 2004 for strongroom by doxygen1.2.18