SecurityResourceList.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*##############################################################################
  2. Copyright (C) 2011 HPCC Systems.
  3. All rights reserved. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ############################################################################## */
  14. #ifndef SECRESOURCELIST_INCL
  15. #define SECRESOURCELIST_INCL
  16. #include "seclib.hpp"
  17. #include <map>
  18. #include <string>
  19. class CSecurityResourceList : public CInterface,
  20. implements ISecResourceList
  21. {
  22. private:
  23. bool m_complete;
  24. StringAttr m_name;
  25. IArrayOf<ISecResource> m_rlist;
  26. std::map<std::string, Linked<ISecResource> > m_rmap;
  27. public:
  28. IMPLEMENT_IINTERFACE
  29. CSecurityResourceList(const char *name) : m_complete(0)
  30. {
  31. m_name.set(name);
  32. }
  33. void setAuthorizationComplete(bool value)
  34. {
  35. m_complete=value;
  36. }
  37. IArrayOf<ISecResource>& getResourceList()
  38. {
  39. return m_rlist;
  40. }
  41. //interface ISecResourceList : extends IInterface
  42. bool isAuthorizationComplete()
  43. {
  44. return m_complete;
  45. }
  46. ISecResourceList * clone()
  47. {
  48. ISecResourceList* _newList = new CSecurityResourceList(m_name.get());
  49. if(!_newList)
  50. return NULL;
  51. copyTo(*_newList);
  52. return _newList;
  53. }
  54. void clear()
  55. {
  56. m_rmap.clear();
  57. m_rlist.kill();
  58. }
  59. bool copyTo(ISecResourceList& destination)
  60. {
  61. ForEachItemIn(x, m_rlist)
  62. {
  63. CSecurityResource* res = (CSecurityResource*)(&(m_rlist.item(x)));
  64. if(res)
  65. destination.addResource(res->clone());
  66. }
  67. return true;
  68. }
  69. ISecResource* addResource(const char * name)
  70. {
  71. if(!name || !*name)
  72. return NULL;
  73. ISecResource* resource = m_rmap[name];
  74. if(resource == NULL)
  75. {
  76. resource = new CSecurityResource(name);
  77. m_rlist.append(*resource);
  78. m_rmap[name].set(resource);
  79. }
  80. return resource;
  81. }
  82. void addResource(ISecResource* resource)
  83. {
  84. if(resource == NULL)
  85. return;
  86. const char* name = resource->getName();
  87. if(!name || !*name)
  88. return;
  89. ISecResource* r = m_rmap[name];
  90. if(r == NULL)
  91. {
  92. m_rlist.append(*resource);
  93. m_rmap[name].set(resource);
  94. }
  95. else
  96. resource->Release();
  97. }
  98. bool addCustomResource(const char * name, const char * config)
  99. {
  100. return false;
  101. }
  102. ISecResource * getResource(const char * Resource)
  103. {
  104. if(!Resource || !*Resource)
  105. return NULL;
  106. ISecResource* r = m_rmap[Resource];
  107. if(r)
  108. return LINK(r);
  109. else
  110. return NULL;
  111. }
  112. virtual int count()
  113. {
  114. return m_rlist.length();
  115. }
  116. virtual const char* getName()
  117. {
  118. return m_name.get();
  119. }
  120. virtual ISecResource * queryResource(unsigned seq)
  121. {
  122. if(seq < m_rlist.length())
  123. return &(m_rlist.item(seq));
  124. else
  125. return NULL;
  126. }
  127. ISecPropertyIterator * getPropertyItr()
  128. {
  129. return new ArrayIIteratorOf<IArrayOf<struct ISecResource>, ISecProperty, ISecPropertyIterator>(m_rlist);
  130. }
  131. virtual ISecProperty* findProperty(const char* name)
  132. {
  133. if(!name || !*name)
  134. return NULL;
  135. return m_rmap[name];
  136. }
  137. StringBuffer& toString(StringBuffer& s)
  138. {
  139. s.appendf("name=%s, count=%d.", m_name.get(), count());
  140. for (int i=0; i<count(); i++)
  141. {
  142. s.appendf("\nItem %d: ",i+1);
  143. queryResource(i)->toString(s);
  144. }
  145. return s;
  146. }
  147. };
  148. #endif // SECRESOURCELIST_INCL
  149. //end