added some more bits of the authentication module

This commit is contained in:
fgerlits 2004-11-20 10:53:56 +00:00
parent 5a655f905c
commit c662e639e0
9 changed files with 936 additions and 4389 deletions

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE authenticationClientFactory [
<!ELEMENT authenticationClientFactory (webAuthentication) >
<!ELEMENT webAuthentication (location) >
<!ELEMENT location EMPTY >
<!ATTLIST location server CDATA #REQUIRED >
<!ATTLIST location port NMTOKEN #REQUIRED >
<!ATTLIST location path CDATA #REQUIRED >
]>
<authenticationClientFactory>
<webAuthentication>
<location server="localhost" port="80"
path="/storage/var/xmlrpc/xrLocStor.php" />
</webAuthentication>
</authenticationClientFactory>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE webAuthentication [
<!ELEMENT webAuthentication (location) >
<!ELEMENT location EMPTY >
<!ATTLIST location server CDATA #REQUIRED >
<!ATTLIST location port NMTOKEN #REQUIRED >
<!ATTLIST location path CDATA #REQUIRED >
]>
<webAuthentication>
<location server="localhost" port="80"
path="/storage/var/xmlrpc/xrLocStor.php" />
</webAuthentication>

View File

@ -0,0 +1,107 @@
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/include/LiveSupport/Authentication/AuthenticationClientInterface.h,v $
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Authentication_AuthenticationClientInterface_h
#define LiveSupport_Authentication_AuthenticationClientInterface_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Authentication/SessionId.h"
namespace LiveSupport {
namespace Authentication {
using namespace LiveSupport::Core;
using namespace LiveSupport::Authentication;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* An interface for authentication clients.
*
* @author $Author: fgerlits $
* @version $Revision: 1.1 $
*/
class AuthenticationClientInterface
{
public:
/**
* Login to the authentication server.
* Returns a new session ID; in case of an error, returns a
* null pointer.
*
* @return the new session ID
*/
virtual Ptr<SessionId>::Ref
login(const std::string &login, const std::string &password)
throw ()
= 0;
/**
* Logout from the authentication server.
*
* @param sessionId the ID of the session to end
* @return true if logged out successfully, false if not
*/
virtual const bool
logout(Ptr<SessionId>::Ref sessionId)
throw ()
= 0;
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Authentication
} // namespace LiveSupport
#endif // LiveSupport_Authentication_AuthenticationClientInterface_h

View File

@ -0,0 +1,144 @@
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/include/LiveSupport/Authentication/Attic/SessionId.h,v $
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Authentication_SessionId_h
#define LiveSupport_Authentication_SessionId_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
namespace LiveSupport {
namespace Authentication {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A class representing session identifiers.
*
* @author $Author: fgerlits $
* @version $Revision: 1.1 $
*/
class SessionId
{
private:
/**
* The value of the session ID.
*/
std::string id;
/**
* Default constructor.
*/
SessionId(void) throw ()
{
}
public:
/**
* The type for the numeric value the session id is represented in.
*/
typedef std::string IdType;
/**
* Constructor to create a SessionId with a specific value.
* TODO: remove this later, as this is for testing purposes only.
*
* @param id the value of the created id object.
*/
SessionId(const IdType id) throw ()
{
this->id = id;
}
/**
* Compare this is with an other one.
*
* @param otherId the other unqiue id to compare to.
* @return true if this an otherId have the same ID value,
* false otherwise.
*/
bool
operator==(const SessionId & otherId) const
throw ()
{
return this->id == otherId.id;
}
/**
* Compare this id with an other one.
*
* @param otherId the other session id to compare to.
* @return true if this id is smaller than the other one,
* false otherwise.
*/
bool
operator<(const SessionId & otherId) const
throw ()
{
return this->id < otherId.id;
}
/**
* Return the string value of this session ID.
*
* @return the string value of this id.
*/
const IdType
getId(void) const throw ()
{
return id;
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Authentication
} // namespace LiveSupport
#endif // LiveSupport_Authentication_SessionId_h

View File

@ -0,0 +1,169 @@
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/include/LiveSupport/Authentication/Attic/WebAuthenticationClient.h,v $
------------------------------------------------------------------------------*/
#ifndef WebAuthenticationClient_h
#define WebAuthenticationClient_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/Configurable.h"
#include "LiveSupport/Authentication/SessionId.h"
#include "LiveSupport/Authentication/AuthenticationClientInterface.h"
namespace LiveSupport {
namespace Authentication {
using namespace LiveSupport;
using namespace LiveSupport::Core;
using namespace LiveSupport::Authentication;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* An interface to the (possibly remote) php storage server.
*
* @author $Author: fgerlits $
* @version $Revision: 1.1 $
*/
class WebAuthenticationClient :
virtual public Configurable,
virtual public AuthenticationClientInterface
{
private:
/**
* The name of the configuration XML elmenent used by
* WebAuthenticationClient
*/
static const std::string configElementNameStr;
/**
* The name of the storage server, e.g. "myserver.mycompany.com".
*/
std::string storageServerName;
/**
* The port wher the storage server is listening (default is 80).
*/
int storageServerPort;
/**
* The path to the storage server php page.
*/
std::string storageServerPath;
public:
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~WebAuthenticationClient(void) throw ()
{
}
/**
* Return the name of the XML element this object expects
* to be sent to a call to configure().
*
* @return the name of the expected XML configuration element.
*/
static const std::string
getConfigElementName(void) throw ()
{
return configElementNameStr;
}
/**
* Configure the object based on the XML element supplied.
*
* @param element the XML element to configure the object from.
* @exception std::invalid_argument if the supplied XML element
* contains bad configuraiton information
* @exception std::logic_error if the scheduler daemon has already
* been configured, and can not be reconfigured.
*/
virtual void
configure(const xmlpp::Element & element)
throw (std::invalid_argument,
std::logic_error);
/**
* Login to the storage server, using the data read from the
* configuration file.
* Returns a new session ID; in case of an error, returns a
* null pointer.
*
* @return the new session ID
*/
virtual Ptr<SessionId>::Ref
login(const std::string &login, const std::string &password)
throw ();
/**
* Logout from the storage server.
*
* @param sessionId the ID of the session to end
* @return true if logged out successfully, false if not
*/
virtual const bool
logout(Ptr<SessionId>::Ref sessionId)
throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Authentication
} // namespace LiveSupport
#endif // WebAuthenticationClient_h

View File

@ -0,0 +1,247 @@
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/WebAuthenticationClient.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#else
#error "Need unistd.h"
#endif
#include <iostream> // for testing only, REMOVE THIS later
#include <fstream>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <XmlRpcClient.h>
#include <XmlRpcValue.h>
#include "LiveSupport/Authentication/WebAuthenticationClient.h"
using namespace boost::posix_time;
using namespace XmlRpc;
using namespace LiveSupport::Core;
using namespace LiveSupport::Authentication;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ configuration file constants */
/*------------------------------------------------------------------------------
* The name of the config element for this class
*----------------------------------------------------------------------------*/
const std::string WebAuthenticationClient::configElementNameStr
= "webAuthentication";
/*------------------------------------------------------------------------------
* The name of the config child element for the storage server location
*----------------------------------------------------------------------------*/
static const std::string locationConfigElementName = "location";
/*------------------------------------------------------------------------------
* The name of the config element attribute for the storage server name
*----------------------------------------------------------------------------*/
static const std::string locationServerAttrName = "server";
/*------------------------------------------------------------------------------
* The name of the config element attribute for the storage server port
*----------------------------------------------------------------------------*/
static const std::string locationPortAttrName = "port";
/*------------------------------------------------------------------------------
* The name of the config element attribute for the storage server php page
*----------------------------------------------------------------------------*/
static const std::string locationPathAttrName = "path";
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storage server constants: login */
/*------------------------------------------------------------------------------
* The name of the login method on the storage server
*----------------------------------------------------------------------------*/
static const std::string loginMethodName = "locstor.login";
/*------------------------------------------------------------------------------
* The name of the login parameter in the input structure
*----------------------------------------------------------------------------*/
static const std::string loginParamName = "login";
/*------------------------------------------------------------------------------
* The name of the password parameter in the input structure
*----------------------------------------------------------------------------*/
static const std::string passwordParamName = "pass";
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storage server constants: logout */
/*------------------------------------------------------------------------------
* The name of the logout method on the storage server
*----------------------------------------------------------------------------*/
static const std::string logoutMethodName = "locstor.logout";
/*------------------------------------------------------------------------------
* The name of the session ID parameter in the input structure
*----------------------------------------------------------------------------*/
static const std::string sessionIdParamName = "sessid";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Configure the web storage client.
*----------------------------------------------------------------------------*/
void
WebAuthenticationClient :: configure(const xmlpp::Element & element)
throw (std::invalid_argument,
std::logic_error)
{
if (element.get_name() != configElementNameStr) {
std::string eMsg = "Bad configuration element ";
eMsg += element.get_name();
throw std::invalid_argument(eMsg);
}
const xmlpp::Attribute * attribute;
// read the storage server location
xmlpp::Node::NodeList childNodes
= element.get_children(locationConfigElementName);
xmlpp::Node::NodeList::iterator it = childNodes.begin();
if (it == childNodes.end()) {
std::string eMsg = "missing ";
eMsg += locationConfigElementName;
eMsg += " XML element";
throw std::invalid_argument(eMsg);
}
const xmlpp::Element * locationConfigElement
= dynamic_cast<const xmlpp::Element*> (*it);
if (!(attribute = locationConfigElement
->get_attribute(locationServerAttrName))) {
std::string eMsg = "Missing attribute ";
eMsg += locationServerAttrName;
throw std::invalid_argument(eMsg);
}
storageServerName = attribute->get_value();
if (!(attribute = locationConfigElement
->get_attribute(locationPortAttrName))) {
std::string eMsg = "Missing attribute ";
eMsg += locationPortAttrName;
throw std::invalid_argument(eMsg);
}
std::stringstream storageServerPortValue(attribute->get_value());
storageServerPortValue >> storageServerPort;
if (!(attribute = locationConfigElement
->get_attribute(locationPathAttrName))) {
std::string eMsg = "Missing attribute ";
eMsg += locationPathAttrName;
throw std::invalid_argument(eMsg);
}
storageServerPath = attribute->get_value();
++it;
if (it != childNodes.end()) {
std::string eMsg = "more than one ";
eMsg += locationConfigElementName;
eMsg += " XML element";
throw std::invalid_argument(eMsg);
}
}
/*------------------------------------------------------------------------------
* Login to the storage server.
*----------------------------------------------------------------------------*/
Ptr<SessionId>::Ref
WebAuthenticationClient :: login(const std::string & login,
const std::string & password)
throw ()
{
XmlRpcValue parameters;
XmlRpcValue result;
Ptr<SessionId>::Ref sessionId; // initialized to 0
XmlRpcClient xmlRpcClient(storageServerName.c_str(), storageServerPort,
storageServerPath.c_str(), false);
parameters[loginParamName] = login.c_str();
parameters[passwordParamName] = password.c_str();
if (!xmlRpcClient.execute(loginMethodName.c_str(), parameters, result)) {
return sessionId;
}
if (result.getType() != XmlRpcValue::TypeString) {
return sessionId;
}
sessionId.reset(new SessionId(result));
return sessionId;
}
/*------------------------------------------------------------------------------
* Logout from the storage server.
*----------------------------------------------------------------------------*/
const bool
WebAuthenticationClient :: logout(Ptr<SessionId>::Ref sessionId)
throw ()
{
XmlRpcValue parameters;
XmlRpcValue result;
XmlRpcClient xmlRpcClient(storageServerName.c_str(), storageServerPort,
storageServerPath.c_str(), false);
parameters[sessionIdParamName] = sessionId->getId().c_str();
if (!xmlRpcClient.execute(logoutMethodName.c_str(), parameters, result)) {
return false;
}
if (xmlRpcClient.isFault()) {
return false;
}
return true;
}

View File

@ -0,0 +1,125 @@
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/WebAuthenticationClientTest.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#else
#error "Need unistd.h"
#endif
#include <string>
#include <fstream>
#include <iostream>
#include "LiveSupport/Authentication/SessionId.h"
#include "LiveSupport/Authentication/WebAuthenticationClient.h"
#include "WebAuthenticationClientTest.h"
using namespace std;
using namespace LiveSupport::Core;
using namespace LiveSupport::Authentication;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(WebAuthenticationClientTest);
/**
* The name of the configuration file for the authentication client factory daemon.
*/
static const std::string configFileName = "etc/webAuthentication.xml";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Set up the test environment
*----------------------------------------------------------------------------*/
void
WebAuthenticationClientTest :: setUp(void) throw ()
{
try {
Ptr<xmlpp::DomParser>::Ref parser(
new xmlpp::DomParser(configFileName, true));
const xmlpp::Document * document = parser->get_document();
const xmlpp::Element * root = document->get_root_node();
wac.reset(new WebAuthenticationClient());
wac->configure(*root);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL("semantic error in configuration file");
} catch (xmlpp::exception &e) {
CPPUNIT_FAIL("error parsing configuration file");
}
}
/*------------------------------------------------------------------------------
* Clean up the test environment
*----------------------------------------------------------------------------*/
void
WebAuthenticationClientTest :: tearDown(void) throw ()
{
wac.reset();
}
/*------------------------------------------------------------------------------
* Test to see if we can log on and off
*----------------------------------------------------------------------------*/
void
WebAuthenticationClientTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<SessionId>::Ref sessionId;
CPPUNIT_ASSERT(!(sessionId = wac->login("Piszkos Fred", "malnaszor")));
sessionId.reset(new SessionId("ceci n'est pas un session ID"));
CPPUNIT_ASSERT(!wac->logout(sessionId));
CPPUNIT_ASSERT( sessionId = wac->login("root", "q"));
CPPUNIT_ASSERT( wac->logout(sessionId));
// this does not work due to a bug in the storage server
// CPPUNIT_ASSERT(!wac->logout(sessionId));
}

View File

@ -0,0 +1,112 @@
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/WebAuthenticationClientTest.h,v $
------------------------------------------------------------------------------*/
#ifndef WebAuthenticationClientTest_h
#define WebAuthenticationClientTest_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <cppunit/extensions/HelperMacros.h>
namespace LiveSupport {
namespace Authentication {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Unit test for the UploadPlaylistMetohd class.
*
* @author $Author: fgerlits $
* @version $Revision: 1.1 $
* @see WebAuthenticationClient
*/
class WebAuthenticationClientTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(WebAuthenticationClientTest);
CPPUNIT_TEST(firstTest);
CPPUNIT_TEST_SUITE_END();
private:
/**
* The WebAuthenticationClient instance to test.
*/
Ptr<WebAuthenticationClient>::Ref wac;
protected:
/**
* A simple test.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
firstTest(void) throw (CPPUNIT_NS::Exception);
public:
/**
* Set up the environment for the test case.
*/
void
setUp(void) throw ();
/**
* Clean up the environment after the test case.
*/
void
tearDown(void) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Authentication
} // namespace LiveSupport
#endif // WebAuthenticationClientTest_h

File diff suppressed because it is too large Load Diff