123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- /*##############################################################################
- HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- ############################################################################## */
- #ifndef SECUREUSER_INCL
- #define SECUREUSER_INCL
- #include "seclib.hpp"
- //#include "MD5.hpp"
- class CSecureUser : public CInterface,
- implements ISecUser,
- implements ISecCredentials
- {
- private:
- StringBuffer m_realm;
- StringBuffer m_name;
- StringBuffer m_pw;
- StringBuffer m_encodedPw;
- authStatus m_authenticateStatus;
- StringBuffer m_fullname;
- StringBuffer m_firstname;
- StringBuffer m_lastname;
- unsigned m_userID;
- StringBuffer m_Fqdn;
- StringBuffer m_Peer;
- SecUserStatus m_status;
- Owned<IProperties> m_parameters;
- CriticalSection crit;
- public:
- IMPLEMENT_IINTERFACE
- CSecureUser(const char *name, const char *pw) :
- m_name(name), m_pw(pw), m_authenticateStatus(AS_UNKNOWN), m_userID(0), m_status(SecUserStatus_Unknown)
- {
- }
- virtual ~CSecureUser()
- {
- }
- //interface ISecUser
- const char * getName()
- {
- return m_name.str();
- }
-
- bool setName(const char * name)
- {
- m_name.clear().append(name);
- return true;
- }
-
- const char * getFullName()
- {
- return m_fullname.str();
- }
-
- bool setFullName(const char * name)
- {
- m_fullname.clear().append(name);
- return TRUE;
- }
- virtual const char * getFirstName()
- {
- return m_firstname.str();
- }
- virtual bool setFirstName(const char * fname)
- {
- if(fname != NULL)
- {
- m_firstname.clear().append(fname);
- }
- return true;
- }
- virtual const char * getLastName()
- {
- return m_lastname.str();
- }
- virtual bool setLastName(const char * lname)
- {
- if(lname != NULL)
- {
- m_lastname.clear().append(lname);
- }
- return true;
- }
- const char * getRealm()
- {
- return m_realm.str();
- }
- bool setRealm(const char * name)
- {
- m_realm.clear().append(name);
- return true;
- }
- const char * getFqdn()
- {
- return m_Fqdn.str();
- }
- bool setFqdn(const char * Fqdn)
- {
- m_Fqdn.clear().append(Fqdn);
- return true;
- }
- const char *getPeer()
- {
- return m_Peer.str();
- }
- bool setPeer(const char *Peer)
- {
- m_Peer.clear().append(Peer);
- return true;
- }
- virtual SecUserStatus getStatus()
- {
- return m_status;
- }
- virtual bool setStatus(SecUserStatus Status)
- {
- m_status = Status;
- return true;
- }
- ISecCredentials & credentials()
- {
- return *this;
- }
- void setProperty(const char* name, const char* value)
- {
- if (!m_parameters)
- m_parameters.setown(createProperties(false));
- m_parameters->setProp(name, value);
- }
- const char* getProperty(const char* name)
- {
- if (m_parameters)
- return m_parameters->queryProp(name);
- return NULL;
- }
- void setPropertyInt(const char* name, int value)
- {
- if (!m_parameters)
- m_parameters.setown(createProperties(false));
- m_parameters->setProp(name, value);
- }
- int getPropertyInt(const char* name)
- {
- if (m_parameters)
- return m_parameters->getPropInt(name);
- return 0;
- }
-
- //interface ISecCredentials
- bool setPassword(const char * pw)
- {
- m_pw.clear();
- m_pw.append(pw);
- return true;
- }
- const char* getPassword()
- {
- return m_pw.str();
- }
- bool addToken(unsigned type, void * data, unsigned length)
- {
- return false; //not supported yet
- }
- virtual unsigned getUserID()
- {
- return m_userID;
- }
- virtual CDateTime & getPasswordExpiration(CDateTime& expirationDate){ return expirationDate; }
- virtual bool setPasswordExpiration(CDateTime& expirationDate) { return true; }
- virtual int getPasswordDaysRemaining() {return scPasswordNeverExpires;}//never expires
- virtual authStatus getAuthenticateStatus() {return m_authenticateStatus;}
- virtual void setAuthenticateStatus(authStatus status){m_authenticateStatus = status;}
- virtual void copyTo(ISecUser& destination)
- {
- destination.setAuthenticateStatus(getAuthenticateStatus());
- destination.setName(getName());
- destination.setFullName(getFullName());
- destination.setFirstName(getFirstName());
- destination.setLastName(getLastName());
- destination.setRealm(getRealm());
- destination.setFqdn(getFqdn());
- destination.setPeer(getPeer());
- destination.credentials().setPassword(credentials().getPassword());
- CDateTime tmpTime;
- destination.setPasswordExpiration(getPasswordExpiration(tmpTime));
- destination.setStatus(getStatus());
- if(m_parameters.get()==NULL)
- return;
- CriticalBlock b(crit);
- Owned<IPropertyIterator> Itr = m_parameters->getIterator();
- Itr->first();
- while(Itr->isValid())
- {
- destination.setProperty(Itr->getPropKey(),m_parameters->queryProp(Itr->getPropKey()));
- Itr->next();
- }
- //addToken is not currently implemented....
- // DBGLOG("Copied name %s to %s",getName(),destination.getName());
- }
- ISecUser * clone()
- {
- //DBGLOG("Beginning of clone()");
- CSecureUser* newuser = new CSecureUser(m_name.str(), m_pw.str());
- //DBGLOG("Before copy to");
- if(newuser)
- copyTo(*newuser);
- //DBGLOG("After copy to");
- return newuser;
- }
- };
- #endif // SECUREUSER_INCL
- //end
|