SecureUser.hpp 7.4 KB

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