diff --git a/livesupport/products/scheduler/etc/scheduler-web.xml b/livesupport/products/scheduler/etc/scheduler-web.xml index d89a5e4cc..03888d0ad 100644 --- a/livesupport/products/scheduler/etc/scheduler-web.xml +++ b/livesupport/products/scheduler/etc/scheduler-web.xml @@ -1,8 +1,14 @@ + @@ -11,6 +17,22 @@ + + + + + + + + + + + + + + + @@ -19,11 +41,6 @@ - - - - - @@ -62,6 +79,8 @@ ]> + + + + + + + + + @@ -11,6 +17,22 @@ + + + + + + + + + + + + + + + @@ -54,6 +76,8 @@ ]> + + + + + + + + diff --git a/livesupport/products/scheduler/src/PlaylistEvent.cxx b/livesupport/products/scheduler/src/PlaylistEvent.cxx index fb216193d..77a07dfab 100644 --- a/livesupport/products/scheduler/src/PlaylistEvent.cxx +++ b/livesupport/products/scheduler/src/PlaylistEvent.cxx @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.5 $ + Version : $Revision: 1.6 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PlaylistEvent.cxx,v $ ------------------------------------------------------------------------------*/ @@ -46,6 +46,7 @@ #include "PlaylistEvent.h" +using namespace boost; using namespace LiveSupport::Core; using namespace LiveSupport::Scheduler; @@ -65,15 +66,19 @@ using namespace LiveSupport::Scheduler; * Constructor. *----------------------------------------------------------------------------*/ PlaylistEvent :: PlaylistEvent( + Ptr::Ref sessionId, Ptr::Ref audioPlayer, Ptr::Ref storage, Ptr::Ref scheduleEntry) throw () { + this->sessionId = sessionId; this->audioPlayer = audioPlayer; this->storage = storage; this->scheduleEntry = scheduleEntry; - this->sessionId.reset(new SessionId("dummy session ID")); + + // this init time is a wild guess, say 5 seconds should be enough + initTime.reset(new posix_time::time_duration(0, 0, 5, 0)); } diff --git a/livesupport/products/scheduler/src/PlaylistEvent.h b/livesupport/products/scheduler/src/PlaylistEvent.h index 468839782..29704e6aa 100644 --- a/livesupport/products/scheduler/src/PlaylistEvent.h +++ b/livesupport/products/scheduler/src/PlaylistEvent.h @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.5 $ + Version : $Revision: 1.6 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PlaylistEvent.h,v $ ------------------------------------------------------------------------------*/ @@ -40,6 +40,7 @@ #include "configure.h" #endif +#include "LiveSupport/Core/SessionId.h" #include "LiveSupport/Core/ScheduleEntry.h" #include "LiveSupport/Storage/StorageClientInterface.h" #include "LiveSupport/PlaylistExecutor/AudioPlayerInterface.h" @@ -69,7 +70,7 @@ using namespace LiveSupport::Storage; * A scheduled event for playing a playlist. * * @author $Author: maroy $ - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ */ class PlaylistEvent : public virtual ScheduledEventInterface { @@ -109,13 +110,15 @@ class PlaylistEvent : public virtual ScheduledEventInterface /** * Constructor. * + * @param sessionId the session id used to access the storage. * @param audioPlayer the audio player to play the playlist with. * @param storage the storage containing the playlist to play, * and all the related audio clips. * @param scheduleEntry the schedule entry this event is * playing. */ - PlaylistEvent(Ptr::Ref audioPlayer, + PlaylistEvent(Ptr::Ref sessionId, + Ptr::Ref audioPlayer, Ptr::Ref storage, Ptr::Ref scheduleEntry) throw (); diff --git a/livesupport/products/scheduler/src/PlaylistEventContainer.cxx b/livesupport/products/scheduler/src/PlaylistEventContainer.cxx index 955d50c7f..bbc60d518 100644 --- a/livesupport/products/scheduler/src/PlaylistEventContainer.cxx +++ b/livesupport/products/scheduler/src/PlaylistEventContainer.cxx @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PlaylistEventContainer.cxx,v $ ------------------------------------------------------------------------------*/ @@ -63,11 +63,13 @@ using namespace LiveSupport::Scheduler; * Constructor. *----------------------------------------------------------------------------*/ PlaylistEventContainer :: PlaylistEventContainer( + Ptr::Ref sessionId, Ptr::Ref storage, Ptr::Ref schedule, Ptr::Ref audioPlayer) throw () { + this->sessionId = sessionId; this->storage = storage; this->schedule = schedule; this->audioPlayer = audioPlayer; @@ -84,7 +86,7 @@ PlaylistEventContainer :: getNextEvent(Ptr::Ref when) throw () Ptr::Ref event; if (entry.get()) { - event.reset(new PlaylistEvent(audioPlayer, storage, entry)); + event.reset(new PlaylistEvent(sessionId, audioPlayer, storage, entry)); } return event; diff --git a/livesupport/products/scheduler/src/PlaylistEventContainer.h b/livesupport/products/scheduler/src/PlaylistEventContainer.h index aedbcf46c..0074c62f0 100644 --- a/livesupport/products/scheduler/src/PlaylistEventContainer.h +++ b/livesupport/products/scheduler/src/PlaylistEventContainer.h @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: fgerlits $ - Version : $Revision: 1.2 $ + Author : $Author: maroy $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PlaylistEventContainer.h,v $ ------------------------------------------------------------------------------*/ @@ -40,6 +40,7 @@ #include "configure.h" #endif +#include "LiveSupport/Core/SessionId.h" #include "LiveSupport/Storage/StorageClientInterface.h" #include "LiveSupport/PlaylistExecutor/AudioPlayerInterface.h" #include "LiveSupport/EventScheduler/EventContainerInterface.h" @@ -70,12 +71,18 @@ using namespace LiveSupport::Storage; /** * An event container holding the scheduled playlists. * - * @author $Author: fgerlits $ - * @version $Revision: 1.2 $ + * @author $Author: maroy $ + * @version $Revision: 1.3 $ */ class PlaylistEventContainer : public virtual EventContainerInterface { private: + /** + * The session id, passed on to PlaylistEvents, to access + * resources from the storage. + */ + Ptr::Ref sessionId; + /** * The storage containing the playlists to play. */ @@ -96,12 +103,15 @@ class PlaylistEventContainer : public virtual EventContainerInterface /** * Constructor. * + * @param sessionId the session id that will be accepted by + * calls to storage * @param storage the storage containing the playlist and related * audio clips * @param schedule the schedule to get the events from. * @param audioPlayer the audio player to play the playlists with. */ - PlaylistEventContainer(Ptr::Ref storage, + PlaylistEventContainer(Ptr::Ref sessionId, + Ptr::Ref storage, Ptr::Ref schedule, Ptr::Ref audioPlayer) throw (); diff --git a/livesupport/products/scheduler/src/PlaylistEventContainerTest.cxx b/livesupport/products/scheduler/src/PlaylistEventContainerTest.cxx index d3d2cfef2..29d5db316 100644 --- a/livesupport/products/scheduler/src/PlaylistEventContainerTest.cxx +++ b/livesupport/products/scheduler/src/PlaylistEventContainerTest.cxx @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.3 $ + Version : $Revision: 1.4 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PlaylistEventContainerTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -198,7 +198,10 @@ PlaylistEventContainerTest :: simpleTest(void) throw (CPPUNIT_NS::Exception) { Ptr::Ref container; - container.reset(new PlaylistEventContainer(storage, schedule, audioPlayer)); + container.reset(new PlaylistEventContainer(sessionId, + storage, + schedule, + audioPlayer)); // see that there are no events scheduled Ptr::Ref scheduledEvent; @@ -215,7 +218,10 @@ PlaylistEventContainerTest :: scheduleTest(void) throw (CPPUNIT_NS::Exception) { Ptr::Ref container; - container.reset(new PlaylistEventContainer(storage, schedule, audioPlayer)); + container.reset(new PlaylistEventContainer(sessionId, + storage, + schedule, + audioPlayer)); // schedule playlist 1 at 10 seconds from now Ptr::Ref playlistId(new UniqueId(1)); diff --git a/livesupport/products/scheduler/src/PlaylistEventTest.cxx b/livesupport/products/scheduler/src/PlaylistEventTest.cxx index b9d38555f..cc401787f 100644 --- a/livesupport/products/scheduler/src/PlaylistEventTest.cxx +++ b/livesupport/products/scheduler/src/PlaylistEventTest.cxx @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PlaylistEventTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -43,6 +43,7 @@ #include #include "LiveSupport/Core/TimeConversion.h" +#include "LiveSupport/Authentication/AuthenticationClientFactory.h" #include "LiveSupport/Storage/StorageClientFactory.h" #include "LiveSupport/PlaylistExecutor/AudioPlayerFactory.h" @@ -53,6 +54,7 @@ using namespace boost::posix_time; using namespace LiveSupport::Core; +using namespace LiveSupport::Authentication; using namespace LiveSupport::Storage; using namespace LiveSupport::PlaylistExecutor; using namespace LiveSupport::Scheduler; @@ -69,6 +71,12 @@ CPPUNIT_TEST_SUITE_REGISTRATION(PlaylistEventTest); */ static const std::string audioPlayerConfigFileName = "etc/audioPlayer.xml"; +/** + * The name of the configuration file for the authentication client factory. + */ +static const std::string authenticationClientConfigFileName = + "etc/authenticationClient.xml"; + /** * The name of the configuration file for the storage client */ @@ -104,6 +112,14 @@ PlaylistEventTest :: setUp(void) throw () storage = scf->getStorageClient(); + // get an authentication client + Ptr::Ref acf; + acf = AuthenticationClientFactory::getInstance(); + parser.reset(new xmlpp::DomParser(authenticationClientConfigFileName, + true)); + acf->configure(*(parser->get_document()->get_root_node())); + authentication = acf->getAuthenticationClient(); + } catch (std::invalid_argument &e) { std::cerr << e.what() << std::endl; CPPUNIT_FAIL("semantic error in configuration file"); @@ -115,6 +131,10 @@ PlaylistEventTest :: setUp(void) throw () audioPlayer->initialize(); duration.reset(new time_duration(seconds(30))); + + if (!(sessionId = authentication->login("root", "q"))) { + CPPUNIT_FAIL("could not log in to authentication server"); + } } @@ -129,6 +149,10 @@ PlaylistEventTest :: tearDown(void) throw () duration.reset(); storage.reset(); audioPlayer.reset(); + + authentication->logout(sessionId); + sessionId.reset(); + authentication.reset(); } @@ -150,7 +174,8 @@ PlaylistEventTest :: createTestEvent(void) throw () startTime, endTime)); - Ptr::Ref playlistEvent(new PlaylistEvent(audioPlayer, + Ptr::Ref playlistEvent(new PlaylistEvent(sessionId, + audioPlayer, storage, scheduleEntry)); diff --git a/livesupport/products/scheduler/src/PlaylistEventTest.h b/livesupport/products/scheduler/src/PlaylistEventTest.h index e456e54b3..29b6ca8b6 100644 --- a/livesupport/products/scheduler/src/PlaylistEventTest.h +++ b/livesupport/products/scheduler/src/PlaylistEventTest.h @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: fgerlits $ - Version : $Revision: 1.2 $ + Author : $Author: maroy $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PlaylistEventTest.h,v $ ------------------------------------------------------------------------------*/ @@ -42,6 +42,7 @@ #include +#include "LiveSupport/Authentication/AuthenticationClientInterface.h" #include "LiveSupport/Storage/StorageClientInterface.h" #include "LiveSupport/PlaylistExecutor/AudioPlayerInterface.h" @@ -53,6 +54,7 @@ using namespace boost::posix_time; using namespace LiveSupport; using namespace LiveSupport::Core; +using namespace LiveSupport::Authentication; using namespace LiveSupport::PlaylistExecutor; /* ================================================================ constants */ @@ -66,8 +68,8 @@ using namespace LiveSupport::PlaylistExecutor; /** * Unit test for the PlaylistEvent class * - * @author $Author: fgerlits $ - * @version $Revision: 1.2 $ + * @author $Author: maroy $ + * @version $Revision: 1.3 $ * @see PlaylistEvent */ class PlaylistEventTest : public CPPUNIT_NS::TestFixture @@ -94,6 +96,16 @@ class PlaylistEventTest : public CPPUNIT_NS::TestFixture */ Ptr::Ref duration; + /** + * An authentication client. + */ + Ptr::Ref authentication; + + /** + * A session ID from the authentication client login() method. + */ + Ptr::Ref sessionId; + /** * Create a playlist event for testing purposes. */ diff --git a/livesupport/products/scheduler/src/SchedulerDaemon.cxx b/livesupport/products/scheduler/src/SchedulerDaemon.cxx index 36916203b..fe67c4d23 100644 --- a/livesupport/products/scheduler/src/SchedulerDaemon.cxx +++ b/livesupport/products/scheduler/src/SchedulerDaemon.cxx @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: fgerlits $ - Version : $Revision: 1.14 $ + Author : $Author: maroy $ + Version : $Revision: 1.15 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/SchedulerDaemon.cxx,v $ ------------------------------------------------------------------------------*/ @@ -54,6 +54,7 @@ #include #include "LiveSupport/Db/ConnectionManagerFactory.h" +#include "LiveSupport/Authentication/AuthenticationClientFactory.h" #include "LiveSupport/Storage/StorageClientFactory.h" #include "LiveSupport/PlaylistExecutor/AudioPlayerFactory.h" #include "ScheduleFactory.h" @@ -89,6 +90,20 @@ static const std::string confElement = "scheduler"; */ static const std::string xmlRpcDaemonConfElement = "xmlRpcDaemon"; +/** + * The name of the config child element for the login and password + */ +static const std::string userConfigElementName = "user"; + +/** + * The name of the config element attribute for the login + */ +static const std::string userLoginAttrName = "login"; + +/** + * The name of the config element attribute for the password + */ +static const std::string userPasswordAttrName = "password"; /* =============================================== local function prototypes */ @@ -154,7 +169,27 @@ SchedulerDaemon :: configure(const xmlpp::Element & element) throw std::invalid_argument(eMsg); } - xmlpp::Node::NodeList nodes; + xmlpp::Node::NodeList nodes; + const xmlpp::Element * elem; + const xmlpp::Attribute * attribute; + + // read in the user data + std::string login; + std::string password; + + nodes = element.get_children(userConfigElementName); + if (nodes.size() < 1) { + throw std::invalid_argument("no user element"); + } + elem = dynamic_cast (*nodes.begin()); + if (!(attribute = elem->get_attribute(userLoginAttrName))) { + throw std::invalid_argument("missing login attribute"); + } + login = attribute->get_value(); + if (!(attribute = elem->get_attribute(userPasswordAttrName))) { + throw std::invalid_argument("missing password attribute"); + } + password = attribute->get_value(); // configure the ConnectionManagerFactory nodes = @@ -166,6 +201,16 @@ SchedulerDaemon :: configure(const xmlpp::Element & element) = ConnectionManagerFactory::getInstance(); cmf->configure( *((const xmlpp::Element*) *(nodes.begin())) ); + // configure the AuthenticationClientFactory + nodes = + element.get_children(AuthenticationClientFactory::getConfigElementName()); + if (nodes.size() < 1) { + throw std::invalid_argument("no authenticationClientFactory element"); + } + Ptr::Ref acf + = AuthenticationClientFactory::getInstance(); + acf->configure( *((const xmlpp::Element*) *(nodes.begin())) ); + // configure the StorageClientFactory nodes = element.get_children(StorageClientFactory::getConfigElementName()); if (nodes.size() < 1) { @@ -207,11 +252,20 @@ SchedulerDaemon :: configure(const xmlpp::Element & element) // do some initialization, using the configured objects + authentication = acf->getAuthenticationClient(); + try { + sessionId = authentication->login(login, password); + } catch (AuthenticationException &e) { + // TODO: mark error + std::cerr << "authentication problem: " << e.what() << std::endl; + } + audioPlayer = apf->getAudioPlayer(); Ptr::Ref eventContainer; Ptr::Ref granularity; - eventContainer.reset(new PlaylistEventContainer(scf->getStorageClient(), + eventContainer.reset(new PlaylistEventContainer(sessionId, + scf->getStorageClient(), sf->getSchedule(), audioPlayer)); // TODO: read granularity from config file @@ -223,6 +277,17 @@ SchedulerDaemon :: configure(const xmlpp::Element & element) } +/*------------------------------------------------------------------------------ + * Destructor. + *----------------------------------------------------------------------------*/ +SchedulerDaemon :: ~SchedulerDaemon(void) throw () +{ + if (authentication.get() && sessionId.get()) { + authentication->logout(sessionId); + } +} + + /*------------------------------------------------------------------------------ * Register our XML-RPC methods *----------------------------------------------------------------------------*/ diff --git a/livesupport/products/scheduler/src/SchedulerDaemon.h b/livesupport/products/scheduler/src/SchedulerDaemon.h index fc30c51fb..b67821712 100644 --- a/livesupport/products/scheduler/src/SchedulerDaemon.h +++ b/livesupport/products/scheduler/src/SchedulerDaemon.h @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: fgerlits $ - Version : $Revision: 1.12 $ + Author : $Author: maroy $ + Version : $Revision: 1.13 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/SchedulerDaemon.h,v $ ------------------------------------------------------------------------------*/ @@ -60,6 +60,8 @@ #include "LiveSupport/Core/Ptr.h" #include "LiveSupport/Core/Installable.h" #include "LiveSupport/Core/Configurable.h" +#include "LiveSupport/Core/SessionId.h" +#include "LiveSupport/Authentication/AuthenticationClientInterface.h" #include "LiveSupport/PlaylistExecutor/AudioPlayerInterface.h" #include "LiveSupport/EventScheduler/EventScheduler.h" #include "AddAudioClipToPlaylistMethod.h" @@ -90,6 +92,7 @@ namespace Scheduler { using namespace LiveSupport; using namespace LiveSupport::Core; +using namespace LiveSupport::Authentication; using namespace LiveSupport::PlaylistExecutor; /* ================================================================ constants */ @@ -112,9 +115,13 @@ using namespace LiveSupport::PlaylistExecutor; * *

  *  <scheduler>
+ *      <user login="userid" password="pwd" />
  *      <connectionManagerFactory>
  *          ...
  *      </connectionManagerFactory>
+ *      <authenticationClientFactory>
+ *          ...
+ *      </authenticationClientFactory>
  *      <storageClientFactory>
  *          ...
  *      </storageClientFactory>
@@ -130,20 +137,30 @@ using namespace LiveSupport::PlaylistExecutor;
  *  </scheduler>
  *  
* + * The user element holds creditentials for accessing the storage, + * configured below. + * * For details on the included elements, see the corresponding documentation * for XmlRpcDaemon, StorageClientFactory, ConnectionManagerFactory - * and ScheduleFactory. + * ScheduleFactory and AuthenticationClientFactory. * * The DTD for the above element is the following: * *

- *  <!ELEMENT scheduler (connectionManagerFactory,storageClientFactory,
- *                          scheduleFactory,playLogFactory,xmlRpcDaemon) >
+ *  <!ELEMENT scheduler (user,
+ *                       connectionManagerFactory,
+ *                       authenticationClientFactory,
+ *                       storageClientFactory,
+ *                       scheduleFactory,
+ *                       playLogFactory,
+ *                       audioPlayer,
+ *                       xmlRpcDaemon) >
  *  
* - * @author $Author: fgerlits $ - * @version $Revision: 1.12 $ + * @author $Author: maroy $ + * @version $Revision: 1.13 $ * @see ConnectionManagerFactory + * @see AuthenticationClientFactory * @see StorageClientFactory * @see ScheduleFactory * @see XmlRpcDaemon @@ -159,6 +176,16 @@ class SchedulerDaemon : public Installable, */ static Ptr::Ref schedulerDaemon; + /** + * The authentication client. + */ + Ptr::Ref authentication; + + /** + * The session id for the scheduler user. + */ + Ptr::Ref sessionId; + /** * The event scheduler. */ @@ -301,9 +328,7 @@ class SchedulerDaemon : public Installable, * Virtual destructor. */ virtual - ~SchedulerDaemon(void) throw () - { - } + ~SchedulerDaemon(void) throw (); /** * Return a pointer to the singleton instance of SchedulerDaemon.