SecurityResourceList.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef SECRESOURCELIST_INCL
  14. #define SECRESOURCELIST_INCL
  15. #include "seclib.hpp"
  16. #include <map>
  17. #include <string>
  18. class CSecurityResourceList : public CInterface,
  19. implements ISecResourceList
  20. {
  21. private:
  22. bool m_complete;
  23. StringAttr m_name;
  24. IArrayOf<ISecResource> m_rlist;
  25. std::map<std::string, Linked<ISecResource> > m_rmap;
  26. public:
  27. IMPLEMENT_IINTERFACE
  28. CSecurityResourceList(const char *name) : m_complete(0)
  29. {
  30. m_name.set(name);
  31. }
  32. void setAuthorizationComplete(bool value)
  33. {
  34. m_complete=value;
  35. }
  36. IArrayOf<ISecResource>& getResourceList()
  37. {
  38. return m_rlist;
  39. }
  40. //interface ISecResourceList : extends IInterface
  41. bool isAuthorizationComplete()
  42. {
  43. return m_complete;
  44. }
  45. ISecResourceList * clone()
  46. {
  47. ISecResourceList* _newList = new CSecurityResourceList(m_name.get());
  48. if(!_newList)
  49. return NULL;
  50. copyTo(*_newList);
  51. return _newList;
  52. }
  53. void clear()
  54. {
  55. m_rmap.clear();
  56. m_rlist.kill();
  57. }
  58. bool copyTo(ISecResourceList& destination)
  59. {
  60. ForEachItemIn(x, m_rlist)
  61. {
  62. CSecurityResource* res = (CSecurityResource*)(&(m_rlist.item(x)));
  63. if(res)
  64. destination.addResource(res->clone());
  65. }
  66. return true;
  67. }
  68. ISecResource* addResource(const char * name)
  69. {
  70. if(!name || !*name)
  71. return NULL;
  72. ISecResource* resource = m_rmap[name];
  73. if(resource == NULL)
  74. {
  75. resource = new CSecurityResource(name);
  76. m_rlist.append(*resource);
  77. m_rmap[name].set(resource);
  78. }
  79. return resource;
  80. }
  81. void addResource(ISecResource* resource)
  82. {
  83. if(resource == NULL)
  84. return;
  85. const char* name = resource->getName();
  86. if(!name || !*name)
  87. return;
  88. ISecResource* r = m_rmap[name];
  89. if(r == NULL)
  90. {
  91. m_rlist.append(*resource);
  92. m_rmap[name].set(resource);
  93. }
  94. else
  95. resource->Release();
  96. }
  97. bool addCustomResource(const char * name, const char * config)
  98. {
  99. return false;
  100. }
  101. ISecResource * getResource(const char * Resource)
  102. {
  103. if(!Resource || !*Resource)
  104. return NULL;
  105. ISecResource* r = m_rmap[Resource];
  106. if(r)
  107. return LINK(r);
  108. else
  109. return NULL;
  110. }
  111. virtual int count()
  112. {
  113. return m_rlist.length();
  114. }
  115. virtual const char* getName()
  116. {
  117. return m_name.get();
  118. }
  119. virtual ISecResource * queryResource(unsigned seq)
  120. {
  121. if(seq < m_rlist.length())
  122. return &(m_rlist.item(seq));
  123. else
  124. return NULL;
  125. }
  126. ISecPropertyIterator * getPropertyItr()
  127. {
  128. return new ArrayIIteratorOf<IArrayOf<struct ISecResource>, ISecProperty, ISecPropertyIterator>(m_rlist);
  129. }
  130. virtual ISecProperty* findProperty(const char* name)
  131. {
  132. if(!name || !*name)
  133. return NULL;
  134. return m_rmap[name];
  135. }
  136. StringBuffer& toString(StringBuffer& s)
  137. {
  138. s.appendf("name=%s, count=%d.", m_name.get(), count());
  139. for (int i=0; i<count(); i++)
  140. {
  141. s.appendf("\nItem %d: ",i+1);
  142. queryResource(i)->toString(s);
  143. }
  144. return s;
  145. }
  146. };
  147. #endif // SECRESOURCELIST_INCL
  148. //end