00001 /***************************************************************************** 00002 * Copyright (C) 2011 by Benjamin Hadorn (b_hadorn@bluewin.ch) 00003 ***************************************************************************** 00004 * Project : Zeus Base Library 00005 * Module : SecurityManager 00006 * Package : Zeus.ZeusBase.Security 00007 * Author : Benjamin Hadorn 00008 * Date : 27.12.2011 00009 * System : Zeus-Framework 00010 ***************************************************************************** 00011 * Licence: * 00012 * This library is free software; you can redistribute it and/or modify * 00013 * it under the terms of the GNU Lesser General Public License as * 00014 * published by the Free Software Foundation; either version * 00015 * 2.1 of the License, or (at your option) any later version. * 00016 * * 00017 * This library is distributed in the hope that it will be useful, * 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00020 * GNU Lesser General Public License for more details. * 00021 * * 00022 * You should have received a copy of the GNU Lesser General Public * 00023 * License along with this library; if not, write to the Free Software * 00024 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA * 00025 *****************************************************************************/ 00026 00027 /***************************************************************************** 00028 * Changes: 00029 * 27.12.2011 bha: created zeus 2.0 00030 *****************************************************************************/ 00031 00032 #ifndef SecurityManagerH 00033 #define SecurityManagerH 00034 00035 #include <zeusbase/System/ZObject.h> 00036 #include <zeusbase/System/ByteArray.hpp> 00037 #include <zeusbase/System/StringList.h> 00038 #include <zeusbase/System/StringMap.hpp> 00039 #include <zeusbase/Security/FingerPrint.h> 00040 #include <zeusbase/Security/Interfaces/ISecurityManager.hpp> 00041 00042 #define SecurityManager TSecurityManager::getInstance() 00043 00044 BEGIN_NAMESPACE_Zeus 00045 00046 class TCriticalSection; 00047 00048 /****************************************************************************/ 00052 /****************************************************************************/ 00053 zeusbase_class TSecurityManager : public TZObject, public ISecurityManager 00054 { 00055 public: 00056 //Delegation methods 00057 void setDelegationInterface(ISecurityManager& rFactory); 00058 void releaseDelegationInterface(); 00059 00060 //Singleton 00061 static TSecurityManager& getInstance(); 00062 00063 //Methods to seal the security manager 00064 Uint seal(); 00065 Retval unseal(Uint uiSealHandle); 00066 bool isSealed() const; 00067 00068 //Methods to manage and access the secure data base 00069 void setMaxFileSize(Int iMaxSize); 00070 Retval getModules(TStringList& rList); 00071 Retval loadRegistry(const IString& rFileName); 00072 Retval loadRegistry(const wchar_t* pwcFileName); 00073 Retval registerModule(const IString& rName, const IString& rPath); 00074 Retval unregisterModule(const IString& rName); 00075 Retval removeAllPlugins(); 00076 00077 bool eval(const TFingerPrint& rPrint) const; 00078 bool evalCodeModule(const IString& rName, const IString& rPath) const; 00079 00080 //Methods of ISecurityManager 00081 virtual bool MQUALIFIER isFunctionAllowed(Uint uiFunctionSecurityID) const; 00082 virtual Uint MQUALIFIER getUserSecurityID() const; 00083 virtual Retval MQUALIFIER setUserSecurityID(Uint uiUserID); 00084 virtual Retval MQUALIFIER attachSecurityPlugin(const IString& rPluginName, ISecurityPlugin& rPlugin); 00085 virtual Retval MQUALIFIER detachSecurityPlugin(const IString& rPluginName); 00086 virtual Retval MQUALIFIER getSecurityPlugin(const IString& rPluginName, ISecurityPlugin*& rpPlugin) const; 00087 virtual Retval MQUALIFIER requestUserSecurityIDChange(const IString& rPluginName, Uint& ruiUserID); 00088 00089 //Methods of IZUnknown 00090 MEMORY_MANAGER_DECL 00091 00092 protected: 00094 //Compiler problem on older version from microsoft 00095 #ifdef _MSC_VER 00096 public: 00097 #endif 00098 00099 00100 TSecurityManager(); 00101 virtual ~TSecurityManager(); 00102 00103 private: 00105 static TAutoPtr<TSecurityManager> m_ptrInstance; 00107 TAutoPtr<ISecurityManager> m_ptrDelegation; 00109 TStringMap<ISecurityPlugin*> m_mapPlugins; 00111 TStringMap<TFingerPrint*> m_mapReg; 00113 bool m_bLoaded; 00115 bool m_bChanged; 00117 TString m_strDataBaseName; 00119 Int m_iMaxFileSize; 00121 Uint m_uiUserSecurityID; 00123 Uint m_uiSealedHandle; 00125 TCriticalSection& m_rLock; 00126 00127 void closeRegistry(); 00128 void checkAndCreateNewDB(const IString& rFileName); 00129 }; 00130 00131 //INLINE METHODS 00132 /***************************************************************************/ 00135 /***************************************************************************/ 00136 inline /*static*/ TSecurityManager& TSecurityManager::getInstance() 00137 { 00138 return *m_ptrInstance; 00139 } 00140 00141 /***************************************************************************/ 00147 /***************************************************************************/ 00148 inline Retval TSecurityManager::loadRegistry(const wchar_t* pwcFileName) 00149 { 00150 return this->loadRegistry(TString(pwcFileName)); 00151 } 00152 00153 00154 END_NAMESPACE_Zeus 00155 #endif