Commit 78fd719a authored by Steven Murray's avatar Steven Murray
Browse files

Added AdminHost and AdminUser

parent 91435669
#include "AdminHost.hpp"
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
cta::AdminHost::AdminHost():
m_creationTime(time(NULL)) {
}
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
cta::AdminHost::AdminHost(
const std::string &name,
const UserIdentity &creator,
const std::string &comment):
m_name(name),
m_creationTime(time(NULL)),
m_creator(creator),
m_comment(comment) {
}
//------------------------------------------------------------------------------
// getName
//------------------------------------------------------------------------------
const std::string &cta::AdminHost::getName() const throw() {
return m_name;
}
//------------------------------------------------------------------------------
// getCreationTime
//------------------------------------------------------------------------------
time_t cta::AdminHost::getCreationTime() const throw() {
return m_creationTime;
}
//------------------------------------------------------------------------------
// getCreator
//------------------------------------------------------------------------------
const cta::UserIdentity &cta::AdminHost::getCreator()
const throw() {
return m_creator;
}
//------------------------------------------------------------------------------
// getComment
//------------------------------------------------------------------------------
const std::string &cta::AdminHost::getComment() const throw() {
return m_comment;
}
#pragma once
#include "UserIdentity.hpp"
#include <string>
namespace cta {
/**
* Class representing a administration host.
*/
class AdminHost {
public:
/**
* Constructor.
*/
AdminHost();
/**
* Constructor.
*
* @param name The network name of the administration host.
* @param creator The identity of the user that created the administration host.
* @param comment The comment describing the administration host.
*/
AdminHost(
const std::string &name,
const UserIdentity &creator,
const std::string &comment);
/**
* Returns the network name of the administration host.
*
* @return The network name of the administration host.
*/
const std::string &getName() const throw();
/**
* Returns the time when the administration host was created.
*
* @return The time when the administration host was created.
*/
time_t getCreationTime() const throw();
/**
* Returns the identity of the user that created the administration host.
*
* @return The identity of the user that created the administration host.
*/
const UserIdentity &getCreator() const throw();
/**
* Returns the comment describing the administration host.
*
* @return The comment describing the administration host.
*/
const std::string &getComment() const throw();
private:
/**
* The network name of the administration host.
*/
std::string m_name;
/**
* The time when the administration host was created.
*/
time_t m_creationTime;
/**
* The identity of the user that created the administration host.
*/
UserIdentity m_creator;
/**
* Comment describing the administration host.
*/
std::string m_comment;
}; // class AdminHost
} // namespace cta
#include "AdminUser.hpp"
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
cta::AdminUser::AdminUser():
m_creationTime(time(NULL)) {
}
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
cta::AdminUser::AdminUser(
const UserIdentity &user,
const UserIdentity &creator,
const std::string &comment):
m_user(user),
m_creationTime(time(NULL)),
m_creator(creator),
m_comment(comment) {
}
//------------------------------------------------------------------------------
// getUser
//------------------------------------------------------------------------------
const cta::UserIdentity &cta::AdminUser::getUser() const throw() {
return m_user;
}
//------------------------------------------------------------------------------
// getCreationTime
//------------------------------------------------------------------------------
time_t cta::AdminUser::getCreationTime() const throw() {
return m_creationTime;
}
//------------------------------------------------------------------------------
// getCreator
//------------------------------------------------------------------------------
const cta::UserIdentity &cta::AdminUser::getCreator()
const throw() {
return m_creator;
}
//------------------------------------------------------------------------------
// getComment
//------------------------------------------------------------------------------
const std::string &cta::AdminUser::getComment() const throw() {
return m_comment;
}
#pragma once
#include "UserIdentity.hpp"
#include <string>
namespace cta {
/**
* Class representing an administrator.
*/
class AdminUser {
public:
/**
* Constructor.
*/
AdminUser();
/**
* Constructor.
*
* @param user The identity of the administrator.
* @param creator The identity of the user that created the administrator.
* @param comment The comment describing the administrator.
*/
AdminUser(
const UserIdentity &user,
const UserIdentity &creator,
const std::string &comment);
/**
* Returns the identity of the administrator.
*
* @return The identity of the administrator.
*/
const UserIdentity &getUser() const throw();
/**
* Returns the time when the administrator was created.
*
* @return The time when the administrator was created.
*/
time_t getCreationTime() const throw();
/**
* Returns the identity of the user that created the administrator.
*
* @return The identity of the user that created the administrator.
*/
const UserIdentity &getCreator() const throw();
/**
* Returns the comment describing the administrator.
*
* @return The comment describing the administrator.
*/
const std::string &getComment() const throw();
private:
/**
* The identity of the administrator.
*/
UserIdentity m_user;
/**
* The time when the administrator was created.
*/
time_t m_creationTime;
/**
* The identity of the user that created the administrator.
*/
UserIdentity m_creator;
/**
* Comment describing the administrator.
*/
std::string m_comment;
}; // class AdminUser
} // namespace cta
cmake_minimum_required (VERSION 2.6)
set (CLIENT_LIB_SRC_FILES
AdminHost.cpp
AdminUser.cpp
ArchiveJob.cpp
DirectoryEntry.cpp
DirectoryIterator.cpp
......
#pragma once
#include "AdminHost.hpp"
#include "AdminUser.hpp"
#include "ArchiveJob.hpp"
#include "DirectoryIterator.hpp"
#include "LogicalLibrary.hpp"
......@@ -31,29 +33,32 @@ public:
*
* @param requester The identity of the user requesting the creation of the
* administrator.
* @param adminUser The identity of the administrator.
* @param user The identity of the administrator.
* @param comment The comment describing the sministrator.
*/
virtual void createAdminUser(
const SecurityIdentity &requester,
const UserIdentity &adminUser) = 0;
const UserIdentity &user,
const std::string &comment) = 0;
/**
* Deletes the specified administrator.
*
* @param requester The identity of the user requesting the deletion of the
* administrator.
* @param adminUser The identity of the administrator.
* @param user The identity of the administrator.
*/
virtual void deleteAdminUser(
const SecurityIdentity &requester,
const UserIdentity &adminUser) = 0;
const UserIdentity &user) = 0;
/**
* Returns the current list of administrators.
* Returns the current list of administrators in lexicographical order.
*
* @param requester The identity of the user requesting the list.
* @return The current list of administrators in lexicographical order.
*/
virtual std::list<UserIdentity> getAdminUsers(const SecurityIdentity &requester)
virtual std::list<AdminUser> getAdminUsers(const SecurityIdentity &requester)
const = 0;
/**
......@@ -61,29 +66,33 @@ public:
*
* @param requester The identity of the user requesting the creation of the
* administration host.
* @param adminHost The network name of the administration host.
* @param hostName The network name of the administration host.
* @param comment The comment describing the administration host.
*/
virtual void createAdminHost(
const SecurityIdentity &requester,
const std::string &adminHost) = 0;
const std::string &hostName,
const std::string &comment) = 0;
/**
* Deletes the specified administration host.
*
* @param requester The identity of the user requesting the deletion of the
* administration host.
* @param adminHost The network name of the administration host.
* @param hostName The network name of the administration host.
* @param comment The comment describing the administration host.
*/
virtual void deleteAdminHost(
const SecurityIdentity &requester,
const std::string &adminHost) = 0;
const std::string &hostName) = 0;
/**
* Returns the current list of administration hosts.
* Returns the current list of administration hosts in lexicographical order.
*
* @param requester The identity of the user requesting the list.
* @return The current list of administration hosts in lexicographical order.
*/
virtual std::list<std::string> getAdminHosts(const SecurityIdentity &requester)
virtual std::list<AdminHost> getAdminHosts(const SecurityIdentity &requester)
const = 0;
/**
......
......@@ -23,24 +23,25 @@ cta::MockMiddleTierAdmin::~MockMiddleTierAdmin() throw() {
//------------------------------------------------------------------------------
void cta::MockMiddleTierAdmin::createAdminUser(
const SecurityIdentity &requester,
const UserIdentity &adminUser) {
checkAdminUserDoesNotAlreadyExist(adminUser);
m_db.adminUsers.push_back(adminUser);
const UserIdentity &user,
const std::string &comment) {
checkAdminUserDoesNotAlreadyExist(user);
AdminUser adminUser(user, requester.user, comment);
m_db.adminUsers[user.uid] = adminUser;
}
//------------------------------------------------------------------------------
// checkAdminUserDoesNotAlreadyExist
//------------------------------------------------------------------------------
void cta::MockMiddleTierAdmin::checkAdminUserDoesNotAlreadyExist(
const UserIdentity &adminUser) {
for(std::list<UserIdentity>::const_iterator itor = m_db.adminUsers.begin();
itor != m_db.adminUsers.end(); itor++) {
if(adminUser.uid == itor->uid) {
std::ostringstream message;
message << "Administrator with uid " << adminUser.uid <<
" already exists";
throw(Exception(message.str()));
}
const UserIdentity &user) const {
std::map<uint32_t, AdminUser>::const_iterator itor =
m_db.adminUsers.find(user.uid);
if(itor != m_db.adminUsers.end()) {
std::ostringstream message;
message << "Administrator with uid " << user.uid <<
" already exists";
throw(Exception(message.str()));
}
}
......@@ -49,10 +50,10 @@ void cta::MockMiddleTierAdmin::checkAdminUserDoesNotAlreadyExist(
//------------------------------------------------------------------------------
void cta::MockMiddleTierAdmin::deleteAdminUser(
const SecurityIdentity &requester,
const UserIdentity &adminUser) {
for(std::list<UserIdentity>::iterator itor = m_db.adminUsers.begin();
const UserIdentity &user) {
for(std::map<uint32_t, AdminUser>::iterator itor = m_db.adminUsers.begin();
itor != m_db.adminUsers.end(); itor++) {
if(adminUser.uid == itor->uid) {
if(user.uid == itor->first) {
m_db.adminUsers.erase(itor);
return;
}
......@@ -60,16 +61,21 @@ void cta::MockMiddleTierAdmin::deleteAdminUser(
// Reaching this point means the administrator to be deleted does not exist
std::ostringstream message;
message << "Administration with uid " << adminUser.uid << " does not exist";
message << "Administration with uid " << user.uid << " does not exist";
throw Exception(message.str());
}
//------------------------------------------------------------------------------
// getAdminUsers
//------------------------------------------------------------------------------
std::list<cta::UserIdentity> cta::MockMiddleTierAdmin::getAdminUsers(
std::list<cta::AdminUser> cta::MockMiddleTierAdmin::getAdminUsers(
const SecurityIdentity &requester) const {
return m_db.adminUsers;
std::list<cta::AdminUser> users;
for(std::map<uint32_t, AdminUser>::const_iterator itor =
m_db.adminUsers.begin(); itor != m_db.adminUsers.end(); itor++) {
users.push_back(itor->second);
}
return users;
}
//------------------------------------------------------------------------------
......@@ -77,23 +83,24 @@ std::list<cta::UserIdentity> cta::MockMiddleTierAdmin::getAdminUsers(
//------------------------------------------------------------------------------
void cta::MockMiddleTierAdmin::createAdminHost(
const SecurityIdentity &requester,
const std::string &adminHost) {
checkAdminHostDoesNotAlreadyExist(adminHost);
m_db.adminHosts.push_back(adminHost);
const std::string &hostName,
const std::string &comment) {
checkAdminHostDoesNotAlreadyExist(hostName);
AdminHost adminHost(hostName, requester.user, comment);
m_db.adminHosts[hostName] = adminHost;
}
//------------------------------------------------------------------------------
// checkAdminHostDoesNotAlreadyExist
//------------------------------------------------------------------------------
void cta::MockMiddleTierAdmin::checkAdminHostDoesNotAlreadyExist(
const std::string &adminHost) {
for(std::list<std::string>::const_iterator itor = m_db.adminHosts.begin();
itor != m_db.adminHosts.end(); itor++) {
if(adminHost == *itor) {
std::ostringstream message;
message << "Administration host " << adminHost << " already exists";
throw(Exception(message.str()));
}
const std::string &hostName) const {
std::map<std::string, AdminHost>::const_iterator itor =
m_db.adminHosts.find(hostName);
if(itor != m_db.adminHosts.end()) {
std::ostringstream message;
message << "Administration host " << hostName << " already exists";
throw(Exception(message.str()));
}
}
......@@ -102,10 +109,10 @@ void cta::MockMiddleTierAdmin::checkAdminHostDoesNotAlreadyExist(
//------------------------------------------------------------------------------
void cta::MockMiddleTierAdmin::deleteAdminHost(
const SecurityIdentity &requester,
const std::string &adminHost) {
for(std::list<std::string>::iterator itor = m_db.adminHosts.begin();
const std::string &hostName) {
for(std::map<std::string, AdminHost>::iterator itor = m_db.adminHosts.begin();
itor != m_db.adminHosts.end(); itor++) {
if(adminHost == *itor) {
if(hostName == itor->first) {
m_db.adminHosts.erase(itor);
return;
}
......@@ -114,16 +121,21 @@ void cta::MockMiddleTierAdmin::deleteAdminHost(
// Reaching this point means the administration host to be deleted does not
// exist
std::ostringstream message;
message << "Administration host " << adminHost << " does not exist";
message << "Administration host " << hostName << " does not exist";
throw Exception(message.str());
}
//------------------------------------------------------------------------------
// getAdminHosts
//------------------------------------------------------------------------------
std::list<std::string> cta::MockMiddleTierAdmin::getAdminHosts(
std::list<cta::AdminHost> cta::MockMiddleTierAdmin::getAdminHosts(
const SecurityIdentity &requester) const {
return m_db.adminHosts;
std::list<cta::AdminHost> hosts;
for(std::map<std::string, AdminHost>::const_iterator itor =
m_db.adminHosts.begin(); itor != m_db.adminHosts.end(); itor++) {
hosts.push_back(itor->second);
}
return hosts;
}
//------------------------------------------------------------------------------
......@@ -276,14 +288,45 @@ void cta::MockMiddleTierAdmin::createLogicalLibrary(
const SecurityIdentity &requester,
const std::string &name,
const std::string &comment) {
checkLogicalLibraryDoesNotAlreadyExist(name);
LogicalLibrary logicalLibrary(name, requester.user, comment);
m_db.libraries[name] = logicalLibrary;
}
//------------------------------------------------------------------------------
// checkLogicalLibraryDoesNotAlreadyExist
//------------------------------------------------------------------------------
void cta::MockMiddleTierAdmin::checkLogicalLibraryDoesNotAlreadyExist(
const std::string &name) const {
std::map<std::string, LogicalLibrary>::const_iterator itor =
m_db.libraries.find(name);
if(itor != m_db.libraries.end()) {
std::ostringstream message;
message << "Logical library " << name << " already exists";
throw(Exception(message.str()));
}
}
//------------------------------------------------------------------------------
// deleteLogicalLibrary
//------------------------------------------------------------------------------
void cta::MockMiddleTierAdmin::deleteLogicalLibrary(
const SecurityIdentity &requester,
const std::string &name) {
for(std::map<std::string, LogicalLibrary>::iterator itor =
m_db.libraries.begin(); itor != m_db.libraries.end();
itor++) {
if(name == itor->first) {
m_db.libraries.erase(itor);
return;
}
}
// Reaching this point means the logical library to be deleted does not
// exist
std::ostringstream message;
message << "Logical library " << name << " does not exist";
throw Exception(message.str());
}
//------------------------------------------------------------------------------
......@@ -292,5 +335,11 @@ void cta::MockMiddleTierAdmin::deleteLogicalLibrary(
std::list<cta::LogicalLibrary> cta::MockMiddleTierAdmin::getLogicalLibraries(
const SecurityIdentity &requester) const {
std::list<LogicalLibrary> libraries;
for(std::map<std::string, LogicalLibrary>::const_iterator itor =
m_db.libraries.begin(); itor != m_db.libraries.end();
itor++) {
libraries.push_back(itor->second);
}
return libraries;
}
......@@ -28,58 +28,64 @@ public:
*
* @param requester The identity of the user requesting the creation of the
* administrator.
* @param adminUser The identity of the administrator.
* @param user The identity of the administrator.
* @param comment The comment describing te administator.
*/
void createAdminUser(
const SecurityIdentity &requester,
const UserIdentity &adminUser);
const UserIdentity &user,
const std::string &comment);
/**
* Deletes the specified administrator.
*
* @param requester The identity of the user requesting the deletion of the
* administrator.
* @param adminUser The identity of the administrator.
* @param user The identity of the administrator.
*/
void deleteAdminUser(
const SecurityIdentity &requester,
const UserIdentity &adminUser);
const UserIdentity &user);
/**
* Returns the current list of administrators.
* Returns the current list of administrators in lexicographical order.
*
* @param requester The identity of the user requesting the list.
* @return The current list of administrators in lexicographical order.
*/
std::list<UserIdentity> getAdminUsers(const SecurityIdentity &requester) const;
std::list<AdminUser> getAdminUsers(const SecurityIdentity &requester) const;
/**
* Creates the specified administration host.
*
* @param requester The identity of the user requesting the creation of the
* administration host.
* @param adminHost The network name of the administration host.
* @param hostName The network name of the administration host.
* @param comment T