SecureUser.hpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 SECUREUSER_INCL
  14. #define SECUREUSER_INCL
  15. #include "seclib.hpp"
  16. //#include "MD5.hpp"
  17. class CSecureUser : public CInterface,
  18. implements ISecUser,
  19. implements ISecCredentials
  20. {
  21. private:
  22. StringBuffer m_realm;
  23. StringBuffer m_name;
  24. StringBuffer m_pw;
  25. StringBuffer m_encodedPw;
  26. authStatus m_authenticateStatus;
  27. StringBuffer m_fullname;
  28. StringBuffer m_firstname;
  29. StringBuffer m_lastname;
  30. unsigned m_userID;
  31. StringBuffer m_Fqdn;
  32. StringBuffer m_Peer;
  33. SecUserStatus m_status;
  34. Owned<IProperties> m_parameters;
  35. CriticalSection crit;
  36. public:
  37. IMPLEMENT_IINTERFACE
  38. CSecureUser(const char *name, const char *pw) :
  39. m_name(name), m_pw(pw), m_authenticateStatus(AS_UNKNOWN), m_userID(0), m_status(SecUserStatus_Unknown)
  40. {
  41. }
  42. virtual ~CSecureUser()
  43. {
  44. }
  45. //interface ISecUser
  46. const char * getName()
  47. {
  48. return m_name.str();
  49. }
  50. bool setName(const char * name)
  51. {
  52. m_name.clear().append(name);
  53. return true;
  54. }
  55. const char * getFullName()
  56. {
  57. return m_fullname.str();
  58. }
  59. bool setFullName(const char * name)
  60. {
  61. m_fullname.clear().append(name);
  62. return TRUE;
  63. }
  64. virtual const char * getFirstName()
  65. {
  66. return m_firstname.str();
  67. }
  68. virtual bool setFirstName(const char * fname)
  69. {
  70. if(fname != NULL)
  71. {
  72. m_firstname.clear().append(fname);
  73. }
  74. return true;
  75. }
  76. virtual const char * getLastName()
  77. {
  78. return m_lastname.str();
  79. }
  80. virtual bool setLastName(const char * lname)
  81. {
  82. if(lname != NULL)
  83. {
  84. m_lastname.clear().append(lname);
  85. }
  86. return true;
  87. }
  88. const char * getRealm()
  89. {
  90. return m_realm.str();
  91. }
  92. bool setRealm(const char * name)
  93. {
  94. m_realm.clear().append(name);
  95. return true;
  96. }
  97. const char * getFqdn()
  98. {
  99. return m_Fqdn.str();
  100. }
  101. bool setFqdn(const char * Fqdn)
  102. {
  103. m_Fqdn.clear().append(Fqdn);
  104. return true;
  105. }
  106. const char *getPeer()
  107. {
  108. return m_Peer.str();
  109. }
  110. bool setPeer(const char *Peer)
  111. {
  112. m_Peer.clear().append(Peer);
  113. return true;
  114. }
  115. virtual SecUserStatus getStatus()
  116. {
  117. return m_status;
  118. }
  119. virtual bool setStatus(SecUserStatus Status)
  120. {
  121. m_status = Status;
  122. return true;
  123. }
  124. ISecCredentials & credentials()
  125. {
  126. return *this;
  127. }
  128. void setProperty(const char* name, const char* value)
  129. {
  130. if (!m_parameters)
  131. m_parameters.setown(createProperties(false));
  132. m_parameters->setProp(name, value);
  133. }
  134. const char* getProperty(const char* name)
  135. {
  136. if (m_parameters)
  137. return m_parameters->queryProp(name);
  138. return NULL;
  139. }
  140. void setPropertyInt(const char* name, int value)
  141. {
  142. if (!m_parameters)
  143. m_parameters.setown(createProperties(false));
  144. m_parameters->setProp(name, value);
  145. }
  146. int getPropertyInt(const char* name)
  147. {
  148. if (m_parameters)
  149. return m_parameters->getPropInt(name);
  150. return 0;
  151. }
  152. //interface ISecCredentials
  153. bool setPassword(const char * pw)
  154. {
  155. m_pw.clear();
  156. m_pw.append(pw);
  157. return true;
  158. }
  159. const char* getPassword()
  160. {
  161. return m_pw.str();
  162. }
  163. bool addToken(unsigned type, void * data, unsigned length)
  164. {
  165. return false; //not supported yet
  166. }
  167. virtual unsigned getUserID()
  168. {
  169. return m_userID;
  170. }
  171. virtual CDateTime & getPasswordExpiration(CDateTime& expirationDate){ return expirationDate; }
  172. virtual bool setPasswordExpiration(CDateTime& expirationDate) { return true; }
  173. virtual int getPasswordDaysRemaining() {return scPasswordNeverExpires;}//never expires
  174. virtual authStatus getAuthenticateStatus() {return m_authenticateStatus;}
  175. virtual void setAuthenticateStatus(authStatus status){m_authenticateStatus = status;}
  176. virtual void copyTo(ISecUser& destination)
  177. {
  178. destination.setAuthenticateStatus(getAuthenticateStatus());
  179. destination.setName(getName());
  180. destination.setFullName(getFullName());
  181. destination.setFirstName(getFirstName());
  182. destination.setLastName(getLastName());
  183. destination.setRealm(getRealm());
  184. destination.setFqdn(getFqdn());
  185. destination.setPeer(getPeer());
  186. destination.credentials().setPassword(credentials().getPassword());
  187. CDateTime tmpTime;
  188. destination.setPasswordExpiration(getPasswordExpiration(tmpTime));
  189. destination.setStatus(getStatus());
  190. if(m_parameters.get()==NULL)
  191. return;
  192. CriticalBlock b(crit);
  193. Owned<IPropertyIterator> Itr = m_parameters->getIterator();
  194. Itr->first();
  195. while(Itr->isValid())
  196. {
  197. destination.setProperty(Itr->getPropKey(),m_parameters->queryProp(Itr->getPropKey()));
  198. Itr->next();
  199. }
  200. //addToken is not currently implemented....
  201. // DBGLOG("Copied name %s to %s",getName(),destination.getName());
  202. }
  203. ISecUser * clone()
  204. {
  205. //DBGLOG("Beginning of clone()");
  206. CSecureUser* newuser = new CSecureUser(m_name.str(), m_pw.str());
  207. //DBGLOG("Before copy to");
  208. if(newuser)
  209. copyTo(*newuser);
  210. //DBGLOG("After copy to");
  211. return newuser;
  212. }
  213. };
  214. #endif // SECUREUSER_INCL
  215. //end