mirror of https://gitee.com/bigwinds/arangodb
reorganisation of directory tree structure
This commit is contained in:
parent
6706ef5332
commit
120f61423e
|
@ -1,6 +1,7 @@
|
|||
aclocal.m4
|
||||
autom4te.cache
|
||||
avocado
|
||||
BasicsC/local-configuration.h
|
||||
config/compile
|
||||
config/config.guess
|
||||
config/config.sub
|
||||
|
@ -17,3 +18,16 @@ Makefile.in
|
|||
*.o
|
||||
.svn
|
||||
*~
|
||||
js-*.h
|
||||
JsonParser/json-parser.c
|
||||
JsonParserX/JsonParserX.cpp
|
||||
JsonParserX/JsonParserX.h
|
||||
JsonParserX/JsonParserX.output
|
||||
JsonParserX/JsonScannerX.cpp
|
||||
JsonParserX/location.hh
|
||||
JsonParserX/position.hh
|
||||
JsonParserX/stack.hh
|
||||
V8/v8-json.cpp
|
||||
BasicsC/stamp-h1
|
||||
avocadodb
|
||||
libavocadodb.a
|
||||
|
|
|
@ -16,12 +16,3 @@ setup:
|
|||
@echo AUTOCONF
|
||||
@autoconf -I m4
|
||||
@echo auto system configured, proceed with configure
|
||||
|
||||
touch:
|
||||
test -f configure
|
||||
touch configure
|
||||
test -f aclocal.m4
|
||||
touch aclocal.m4
|
||||
test -f Makefile.in
|
||||
touch Makefile.in
|
||||
touch config/*
|
||||
|
|
262
Makefile.am
262
Makefile.am
|
@ -1,189 +1,89 @@
|
|||
################################################################################
|
||||
## Makefile.am for AvocadoDB
|
||||
################################################################################
|
||||
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
AM_CFLAGS =
|
||||
AM_CPPFLAGS = @BOOST_CPPFLAGS@ @LIBEV_CPPFLAGS@ @OPENSSL_CPPFLAGS@ @V8_CPPFLAGS@
|
||||
AM_LDFLAGS = @BOOST_LDFLAGS@ @LIBEV_LDFLAGS@ @OPENSSL_LDFLAGS@ @V8_LDFLAGS@
|
||||
AM_CPPFLAGS =
|
||||
AM_LDFLAGS =
|
||||
BUILT_SOURCES =
|
||||
LIBS = @BOOST_LIBS@ @LIBEV_LIBS@ @OPENSSL_LIBS@ @V8_LIBS@ -lreadline -ldl
|
||||
BUILD_H = $(top_srcdir)/build.h
|
||||
LIBS =
|
||||
|
||||
noinst_LIBRARIES = libavocadodb.a
|
||||
bin_PROGRAMS = avocadodb
|
||||
|
||||
################################################################################
|
||||
## avocado program
|
||||
## avocado
|
||||
################################################################################
|
||||
|
||||
bin_PROGRAMS = avocado
|
||||
include Makefile.files
|
||||
|
||||
################################################################################
|
||||
## FLEX
|
||||
################################################################################
|
||||
|
||||
if ENABLE_FLEX
|
||||
|
||||
@srcdir@/%.c: @srcdir@/%.l
|
||||
@top_srcdir@/config/flex-c.sh $(LEX) `dirname $@` `basename $^ .l`
|
||||
|
||||
else
|
||||
|
||||
@srcdir@/%.c: @srcdir@/%.l
|
||||
@echo '+---------------------------------------------------------------+'
|
||||
@echo '| WARNING: required FLEX version not found, cannot update files |'
|
||||
@echo '+---------------------------------------------------------------+'
|
||||
|
||||
endif
|
||||
|
||||
################################################################################
|
||||
## FLEX++
|
||||
################################################################################
|
||||
|
||||
if ENABLE_FLEX
|
||||
|
||||
@srcdir@/%.cpp: @srcdir@/%.ll
|
||||
@top_srcdir@/config/flex-c++.sh $(LEX) `dirname $@` `basename $^ .ll`
|
||||
|
||||
else
|
||||
|
||||
@srcdir@/%.cpp: @srcdir@/%.ll
|
||||
@echo '+---------------------------------------------------------------+'
|
||||
@echo '| WARNING: required FLEX version not found, cannot update files |'
|
||||
@echo '+---------------------------------------------------------------+'
|
||||
|
||||
endif
|
||||
|
||||
################################################################################
|
||||
## BISON
|
||||
################################################################################
|
||||
|
||||
if ENABLE_BISON
|
||||
|
||||
@srcdir@/%.cpp: @srcdir@/%.yy
|
||||
@top_srcdir@/config/bison-c.sh $(BISON) `dirname $@` `basename $^ .yy`
|
||||
|
||||
else
|
||||
|
||||
@srcdir@/%.cpp: @srcdir@/%.yy
|
||||
@echo '+----------------------------------------------------------------+'
|
||||
@echo '| WARNING: required BISON version not found, cannot update files |'
|
||||
@echo '+----------------------------------------------------------------+'
|
||||
|
||||
endif
|
||||
|
||||
################################################################################
|
||||
## BISON++
|
||||
################################################################################
|
||||
|
||||
if ENABLE_BISON
|
||||
|
||||
@srcdir@/%.cpp: @srcdir@/%.yy
|
||||
@top_srcdir@/config/bison-c++.sh $(BISON) `dirname $@` `basename $^ .yy`
|
||||
|
||||
else
|
||||
|
||||
@srcdir@/%.cpp: @srcdir@/%.yy
|
||||
@echo '+----------------------------------------------------------------+'
|
||||
@echo '| WARNING: required BISON version not found, cannot update files |'
|
||||
@echo '+----------------------------------------------------------------+'
|
||||
|
||||
endif
|
||||
|
||||
avocado_SOURCES = \
|
||||
Admin/ApplicationAdminServer.cpp \
|
||||
Admin/RestAdminBaseHandler.cpp \
|
||||
Admin/RestAdminFeConfigurationHandler.cpp \
|
||||
Admin/RestAdminLogHandler.cpp \
|
||||
Admin/RestBaseHandler.cpp \
|
||||
Admin/RestVersionHandler.cpp \
|
||||
ApplicationServer/ApplicationHttpServerImpl.cpp \
|
||||
ApplicationServer/ApplicationHttpsServerImpl.cpp \
|
||||
ApplicationServer/ApplicationServerDispatcherImpl.cpp \
|
||||
ApplicationServer/ApplicationServerImpl.cpp \
|
||||
ApplicationServer/ApplicationServerSchedulerImpl.cpp \
|
||||
BasicsC/associative.c \
|
||||
BasicsC/associative-multi.c \
|
||||
BasicsC/conversions.c \
|
||||
BasicsC/csv.c \
|
||||
BasicsC/error.c \
|
||||
BasicsC/files.c \
|
||||
BasicsC/hashes.c \
|
||||
BasicsC/init.c \
|
||||
BasicsC/json.c \
|
||||
BasicsC/locks-macos.c \
|
||||
BasicsC/locks-posix.c \
|
||||
BasicsC/logging.c \
|
||||
BasicsC/memory.c \
|
||||
Basics/ConditionLocker.cpp \
|
||||
Basics/ConditionVariable-posix.cpp \
|
||||
BasicsC/random.c \
|
||||
BasicsC/string-buffer.c \
|
||||
BasicsC/strings.c \
|
||||
BasicsC/structures.c \
|
||||
BasicsC/system-functions.c \
|
||||
BasicsC/system-windows.c \
|
||||
BasicsC/terminal-utils.c \
|
||||
BasicsC/terminal-utils-ncurses.c \
|
||||
BasicsC/threads-posix.c \
|
||||
BasicsC/vector.c \
|
||||
Basics/FileUtils.cpp \
|
||||
Basics/Initialise.cpp \
|
||||
Basics/Logger.cpp \
|
||||
Basics/LoggerData.cpp \
|
||||
Basics/LoggerInfo.cpp \
|
||||
Basics/LoggerStream.cpp \
|
||||
Basics/LoggerTiming.cpp \
|
||||
Basics/Mutex.cpp \
|
||||
Basics/MutexLocker.cpp \
|
||||
Basics/ProgramOptions.cpp \
|
||||
Basics/ProgramOptionsDescription.cpp \
|
||||
Basics/Random.cpp \
|
||||
Basics/ReadLocker.cpp \
|
||||
Basics/ReadUnlocker.cpp \
|
||||
Basics/ReadWriteLock.cpp \
|
||||
Basics/SocketUtils.cpp \
|
||||
Basics/StringUtils.cpp \
|
||||
Basics/Thread-posix.cpp \
|
||||
Basics/Timing.cpp \
|
||||
Basics/VariantArray.cpp \
|
||||
Basics/VariantBlob.cpp \
|
||||
Basics/VariantBoolean.cpp \
|
||||
Basics/VariantDate.cpp \
|
||||
Basics/VariantDatetime.cpp \
|
||||
Basics/VariantDouble.cpp \
|
||||
Basics/VariantFloat.cpp \
|
||||
Basics/VariantInt16.cpp \
|
||||
Basics/VariantInt32.cpp \
|
||||
Basics/VariantInt64.cpp \
|
||||
Basics/VariantInt8.cpp \
|
||||
Basics/VariantMatrix2.cpp \
|
||||
Basics/VariantNull.cpp \
|
||||
Basics/VariantObject.cpp \
|
||||
Basics/VariantString.cpp \
|
||||
Basics/VariantUInt16.cpp \
|
||||
Basics/VariantUInt32.cpp \
|
||||
Basics/VariantUInt64.cpp \
|
||||
Basics/VariantUInt8.cpp \
|
||||
Basics/VariantVector.cpp \
|
||||
Basics/WriteLocker.cpp \
|
||||
Basics/WriteUnlocker.cpp \
|
||||
Dispatcher/DispatcherImpl.cpp \
|
||||
Dispatcher/DispatcherQueue.cpp \
|
||||
Dispatcher/DispatcherThread.cpp \
|
||||
GeneralServer/GeneralFigures.cpp \
|
||||
GeoIndex/GeoIndex.c \
|
||||
HttpServer/HttpCommTask.cpp \
|
||||
HttpServer/HttpsAsyncCommTask.cpp \
|
||||
HttpServer/HttpsServerImpl.cpp \
|
||||
HttpServer/PathHandler.cpp \
|
||||
HttpServer/RedirectHandler.cpp \
|
||||
HttpServer/ServiceUnavailableHandler.cpp \
|
||||
JsonParser/json-parser.c \
|
||||
JsonParserX/JsonParserX.cpp \
|
||||
JsonParserX/JsonParserXDriver.cpp \
|
||||
JsonParserX/JsonScannerX.cpp \
|
||||
ProgramOptions/program-options.c \
|
||||
Rest/AddressPort.cpp \
|
||||
Rest/AnyServer.cpp \
|
||||
Rest/ApplicationHttpServer.cpp \
|
||||
Rest/ApplicationHttpsServer.cpp \
|
||||
Rest/ApplicationServer.cpp \
|
||||
Rest/ApplicationServerDispatcher.cpp \
|
||||
Rest/AsyncTask.cpp \
|
||||
Rest/ConnectionTask.cpp \
|
||||
RestHandler/RestActionHandler.cpp \
|
||||
RestHandler/RestDocumentHandler.cpp \
|
||||
RestHandler/RestSystemActionHandler.cpp \
|
||||
RestHandler/RestVocbaseBaseHandler.cpp \
|
||||
Rest/HttpHandler.cpp \
|
||||
Rest/HttpHandlerFactory.cpp \
|
||||
Rest/HttpRequest.cpp \
|
||||
Rest/HttpResponse.cpp \
|
||||
Rest/HttpsServer.cpp \
|
||||
Rest/Initialise.cpp \
|
||||
Rest/InputParser.cpp \
|
||||
Rest/Job.cpp \
|
||||
Rest/LibraryLoader.cpp \
|
||||
Rest/ListenTask.cpp \
|
||||
Rest/OutputGenerator.cpp \
|
||||
Rest/PeriodicTask.cpp \
|
||||
Rest/RestHandlerFactory.cpp \
|
||||
Rest/RestModel.cpp \
|
||||
Rest/RestServer.cpp \
|
||||
Rest/Scheduler.cpp \
|
||||
RestServer/ActionDispatcherThread.cpp \
|
||||
RestServer/avocado.cpp \
|
||||
RestServer/AvocadoHttpServer.cpp \
|
||||
RestServer/AvocadoServer.cpp \
|
||||
RestServer/JSLoader.cpp \
|
||||
RestServer/SystemActionDispatcherThread.cpp \
|
||||
Rest/SignalTask.cpp \
|
||||
Rest/SocketTask.cpp \
|
||||
Rest/SslInterface.cpp \
|
||||
Rest/Task.cpp \
|
||||
Rest/TimerTask.cpp \
|
||||
Rest/Url.cpp \
|
||||
ResultGenerator/HtmlResultGenerator.cpp \
|
||||
ResultGenerator/JsonResultGenerator.cpp \
|
||||
ResultGenerator/JsonXResultGenerator.cpp \
|
||||
ResultGenerator/PhpResultGenerator.cpp \
|
||||
ResultGenerator/ResultGenerator.cpp \
|
||||
ResultGenerator/XmlResultGenerator.cpp \
|
||||
Scheduler/SchedulerImpl.cpp \
|
||||
Scheduler/SchedulerLibev.cpp \
|
||||
Scheduler/SchedulerThread.cpp \
|
||||
SessionManager/Session.cpp \
|
||||
SessionManager/SessionHandler.cpp \
|
||||
ShapedJson/json-shaper.c \
|
||||
ShapedJson/shape-accessor.c \
|
||||
ShapedJson/shaped-json.c \
|
||||
UserManager/Role.cpp \
|
||||
UserManager/User.cpp \
|
||||
UserManager/UserHandler.cpp \
|
||||
UserManager/UsersHandler.cpp \
|
||||
V8/v8-actions.cpp \
|
||||
V8/v8-json.cpp \
|
||||
V8/v8-shell.cpp \
|
||||
V8/v8-utils.cpp \
|
||||
V8/v8-vocbase.cpp \
|
||||
VocBase/blob-collection.c \
|
||||
VocBase/collection.c \
|
||||
VocBase/compactor.c \
|
||||
VocBase/datafile.c \
|
||||
VocBase/document-collection.c \
|
||||
VocBase/headers.c \
|
||||
VocBase/index.c \
|
||||
VocBase/query.c \
|
||||
VocBase/result-set.c \
|
||||
VocBase/simple-collection.c \
|
||||
VocBase/synchroniser.c \
|
||||
VocBase/vocbase.c \
|
||||
VocBase/voc-shaper.c \
|
||||
# end of file list
|
||||
|
|
|
@ -1,202 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief session management
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2010-2011 triagens GmbH, Cologne, Germany
|
||||
///
|
||||
/// 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.
|
||||
///
|
||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Dr. Frank Celler
|
||||
/// @author Copyright 2011, triagens GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Session.h"
|
||||
|
||||
#include <Basics/Logger.h>
|
||||
#include <Basics/MutexLocker.h>
|
||||
#include <Basics/Random.h>
|
||||
|
||||
#include "UserManager/User.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace triagens::basics;
|
||||
using namespace triagens::admin;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// session registry
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
namespace {
|
||||
map<string, Session*> SessionRegistry;
|
||||
list<Session*> Sessions;
|
||||
}
|
||||
|
||||
namespace triagens {
|
||||
namespace admin {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// constants
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
string const Session::SID_CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
Mutex Session::lock;
|
||||
set<right_t> Session::_rights;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// static public methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
Session* Session::lookup (string const& sid) {
|
||||
map<string, Session*>::const_iterator i = SessionRegistry.find(sid);
|
||||
|
||||
if (i == SessionRegistry.end()) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
Session* session = i->second;
|
||||
|
||||
list<Session*>::iterator j = find(Sessions.begin(), Sessions.end(), session);
|
||||
|
||||
if (j != Sessions.end()) {
|
||||
Sessions.erase(j);
|
||||
}
|
||||
|
||||
Sessions.push_back(session);
|
||||
|
||||
return session;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Session* Session::create () {
|
||||
if (Sessions.size() > MAXIMAL_OPEN_SESSION) {
|
||||
Session* session = Sessions.front();
|
||||
|
||||
LOGGER_DEBUG << "too many admin sessions, throwing away '" << session->getSid() << "'";
|
||||
Sessions.pop_front();
|
||||
|
||||
remove(session);
|
||||
}
|
||||
|
||||
Random::UniformCharacter generator(SID_LENGTH, SID_CHARACTERS);
|
||||
|
||||
string sid = generator.random();
|
||||
|
||||
while (SessionRegistry.find(sid) != SessionRegistry.end()) {
|
||||
sid = generator.random();
|
||||
}
|
||||
|
||||
Session* session = new Session(sid);
|
||||
|
||||
SessionRegistry[sid] = session;
|
||||
Sessions.push_back(session);
|
||||
|
||||
LOGGER_DEBUG << "created admin session '" << session->getSid() << "'";
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Session::remove (Session* session) {
|
||||
LOGGER_DEBUG << "removing admin session '" << session->getSid() << "'";
|
||||
|
||||
SessionRegistry.erase(session->getSid());
|
||||
|
||||
list<Session*>::iterator j = find(Sessions.begin(), Sessions.end(), session);
|
||||
|
||||
if (j != Sessions.end()) {
|
||||
Sessions.erase(j);
|
||||
}
|
||||
|
||||
delete session;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// constructors and destructors
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
Session::Session (string const& sid)
|
||||
: _sid(sid), _user(0) {
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// public methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
bool Session::login (string const& username, string const& password, string& reason) {
|
||||
User* user = User::lookup(username);
|
||||
|
||||
if (user == 0) {
|
||||
reason = "unknown user '" + username + "'";
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ok = user->checkPassword(password);
|
||||
|
||||
if (! ok) {
|
||||
reason = "wrong password for user '" + username + "'";
|
||||
return false;
|
||||
}
|
||||
|
||||
_user = user;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Session::logout () {
|
||||
if (_user != 0) {
|
||||
_user = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Session::hasRight (right_t right) {
|
||||
if (_user == 0) {
|
||||
return _rights.find(right) != _rights.end();
|
||||
}
|
||||
else {
|
||||
return _user->hasRight(right);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Session::setAnonymousRights (vector<right_t> const& rights) {
|
||||
_rights.insert(rights.begin(), rights.end());
|
||||
}
|
||||
|
||||
|
||||
|
||||
set<right_t> const& Session::anonymousRights () {
|
||||
return _rights;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,169 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief session management
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2010-2011 triagens GmbH, Cologne, Germany
|
||||
///
|
||||
/// 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.
|
||||
///
|
||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Dr. Frank Celler
|
||||
/// @author Copyright 2011, triagens GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef TRIAGENS_BORNHOLM_SESSION_MANAGER_SESSION_H
|
||||
#define TRIAGENS_BORNHOLM_SESSION_MANAGER_SESSION_H 1
|
||||
|
||||
#include <BasicsC/Common.h>
|
||||
|
||||
#include <Admin/Right.h>
|
||||
#include <Basics/Mutex.h>
|
||||
|
||||
namespace triagens {
|
||||
namespace admin {
|
||||
class User;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief session management
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Session {
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief maximal number of open sessions
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static size_t const MAXIMAL_OPEN_SESSION = 10;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief length of session identifier
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static size_t const SID_LENGTH = 10;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief length of session characters
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static string const SID_CHARACTERS;
|
||||
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief access lock
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static basics::Mutex lock;
|
||||
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns a role by name
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static Session* lookup (string const& sid);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief creates a session
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static Session* create ();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief removes a session
|
||||
///
|
||||
/// Remove will also delete the session object.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool remove (Session*);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief sets a anonymous rights
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void setAnonymousRights (vector<right_t> const&);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief gets anonymous rights
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static set<right_t> const& anonymousRights ();
|
||||
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns the session identifier
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
string const& getSid () const {
|
||||
return _sid;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns the user of a session
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
User* getUser () const {
|
||||
return _user;
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief logs a user in
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool login (string const& username, string const& password, string& reason);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief logs a user out
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool logout ();
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief checks for a right
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool hasRight (right_t);
|
||||
|
||||
protected:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief creates a new sessions
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Session (string const& sid);
|
||||
|
||||
private:
|
||||
static set<right_t> _rights;
|
||||
|
||||
private:
|
||||
string const _sid;
|
||||
|
||||
User* _user;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,292 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief session handler
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2010-2011 triagens GmbH, Cologne, Germany
|
||||
///
|
||||
/// 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.
|
||||
///
|
||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Dr. Frank Celler
|
||||
/// @auther Martin Schoenert
|
||||
/// @author Copyright 2011, triagens GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "SessionHandler.h"
|
||||
|
||||
#include <Admin/ApplicationAdminServer.h>
|
||||
#include <Basics/MutexLocker.h>
|
||||
#include <Basics/VariantArray.h>
|
||||
#include <Basics/VariantBoolean.h>
|
||||
#include <Basics/VariantInt32.h>
|
||||
#include <Basics/VariantVector.h>
|
||||
#include <Rest/HttpRequest.h>
|
||||
#include <Rest/HttpResponse.h>
|
||||
|
||||
#include "SessionManager/Session.h"
|
||||
|
||||
#include "UserManager/Role.h"
|
||||
#include "UserManager/User.h"
|
||||
|
||||
using namespace triagens::basics;
|
||||
using namespace triagens::rest;
|
||||
|
||||
namespace triagens {
|
||||
namespace admin {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// constructors and destructors
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
SessionHandler::SessionHandler (HttpRequest* request, ApplicationAdminServer* server)
|
||||
: RestBaseHandler(request), _server(server) {
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// HttpHandler methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
HttpHandler::status_e SessionHandler::execute () {
|
||||
|
||||
// execute the request
|
||||
switch (request->requestType()) {
|
||||
case HttpRequest::HTTP_REQUEST_POST: return executePost();
|
||||
case HttpRequest::HTTP_REQUEST_GET: return executeGet();
|
||||
case HttpRequest::HTTP_REQUEST_PUT: return executePut();
|
||||
case HttpRequest::HTTP_REQUEST_DELETE: return executeDelete();
|
||||
|
||||
default:
|
||||
generateError(HttpResponse::METHOD_NOT_ALLOWED, "method not supported");
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// private methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
HttpHandler::status_e SessionHandler::executePost () {
|
||||
if (request->suffix().size() != 0) {
|
||||
generateError(HttpResponse::BAD, "expecting POST <prefix>/session");
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
// create a new session
|
||||
MUTEX_LOCKER(Session::lock);
|
||||
|
||||
Session* session = Session::create();
|
||||
|
||||
generateSession(session);
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HttpHandler::status_e SessionHandler::executeGet () {
|
||||
vector<string> const& suffix = request->suffix();
|
||||
|
||||
if (suffix.size() != 1) {
|
||||
generateError(HttpResponse::BAD, "expecting GET <prefix>/session/<sid>");
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
string const& sid = suffix[0];
|
||||
|
||||
// lookup an existing session
|
||||
MUTEX_LOCKER(Session::lock);
|
||||
|
||||
Session* session = Session::lookup(sid);
|
||||
|
||||
if (session != 0) {
|
||||
generateSession(session);
|
||||
}
|
||||
else {
|
||||
generateError(HttpResponse::NOT_FOUND, "unknown session");
|
||||
}
|
||||
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HttpHandler::status_e SessionHandler::executePut () {
|
||||
vector<string> const& suffix = request->suffix();
|
||||
|
||||
if (suffix.size() != 2) {
|
||||
generateError(HttpResponse::BAD, "expecting PUT <prefix>/session/<sid>/<method>");
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
string const& sid = suffix[0];
|
||||
string const& method = suffix[1];
|
||||
|
||||
// lookup an existing session
|
||||
MUTEX_LOCKER(Session::lock);
|
||||
|
||||
Session* session = Session::lookup(sid);
|
||||
|
||||
if (session != 0) {
|
||||
if (method == "login") {
|
||||
return executeLogin(session);
|
||||
}
|
||||
else if (method == "logout") {
|
||||
return executeLogout(session);
|
||||
}
|
||||
else if (method == "password") {
|
||||
return executePassword(session);
|
||||
}
|
||||
|
||||
generateError(HttpResponse::BAD, "unknown method '" + method + "'");
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
else {
|
||||
generateError(HttpResponse::NOT_FOUND, "unknown session");
|
||||
}
|
||||
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HttpHandler::status_e SessionHandler::executeDelete () {
|
||||
vector<string> const& suffix = request->suffix();
|
||||
|
||||
if (suffix.size() != 1) {
|
||||
generateError(HttpResponse::BAD, "expecting DELETE <prefix>/session/<sid>");
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
string const& sid = suffix[0];
|
||||
|
||||
// lookup an existing session
|
||||
MUTEX_LOCKER(Session::lock);
|
||||
|
||||
Session* session = Session::lookup(sid);
|
||||
bool removed = false;
|
||||
|
||||
if (session != 0) {
|
||||
removed = Session::remove(session);
|
||||
}
|
||||
|
||||
VariantArray* result = new VariantArray();
|
||||
result->add("removed", new VariantBoolean(removed));
|
||||
|
||||
generateResult(result);
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
HttpHandler::status_e SessionHandler::executeLogin (Session* session) {
|
||||
struct Description : public InputParser::ObjectDescription {
|
||||
Description () {
|
||||
attribute("user", user);
|
||||
attribute("password", password);
|
||||
}
|
||||
|
||||
string user;
|
||||
string password;
|
||||
} desc;
|
||||
|
||||
bool ok = parseBody(desc);
|
||||
|
||||
if (! ok) {
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
string reason;
|
||||
ok = session->login(desc.user, desc.password, reason);
|
||||
|
||||
if (! ok) {
|
||||
generateError(HttpResponse::UNAUTHORIZED, reason);
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
generateSession(session);
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HttpHandler::status_e SessionHandler::executeLogout (Session* session) {
|
||||
session->logout();
|
||||
|
||||
generateSession(session);
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HttpHandler::status_e SessionHandler::executePassword (Session* session) {
|
||||
User* user = session->getUser();
|
||||
|
||||
if (user == 0) {
|
||||
generateError(HttpResponse::BAD, "session has not bound to user");
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
struct Description : public InputParser::ObjectDescription {
|
||||
Description () {
|
||||
attribute("password", password);
|
||||
}
|
||||
|
||||
string password;
|
||||
} desc;
|
||||
|
||||
bool ok = parseBody(desc);
|
||||
|
||||
if (! ok) {
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
bool changed = user->changePassword(desc.password);
|
||||
|
||||
VariantArray* result = new VariantArray();
|
||||
result->add("changed", new VariantBoolean(changed));
|
||||
|
||||
generateResult(result);
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SessionHandler::generateSession (Session* session) {
|
||||
VariantArray* result = new VariantArray();
|
||||
result->add("sid", session->getSid());
|
||||
|
||||
User* user = session->getUser();
|
||||
|
||||
if (user != 0) {
|
||||
result->add("user", user->getName());
|
||||
}
|
||||
|
||||
VariantVector* r = new VariantVector();
|
||||
|
||||
set<right_t> const& rights = (user == 0) ? Session::anonymousRights() : user->getRole()->getRights();
|
||||
|
||||
for (set<right_t>::const_iterator i = rights.begin(); i != rights.end(); ++i) {
|
||||
r->add(new VariantInt32(*i));
|
||||
}
|
||||
|
||||
result->add("rights", r);
|
||||
|
||||
generateResult(result);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief session handler
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2010-2011 triagens GmbH, Cologne, Germany
|
||||
///
|
||||
/// 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.
|
||||
///
|
||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Dr. Frank Celler
|
||||
/// @auther Martin Schoenert
|
||||
/// @author Copyright 2010-2011, triAGENS GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef TRIAGENS_BORNHOLM_SESSION_MANAGER_SESSION_HANDLER_H
|
||||
#define TRIAGENS_BORNHOLM_SESSION_MANAGER_SESSION_HANDLER_H 1
|
||||
|
||||
#include <Admin/RestBaseHandler.h>
|
||||
|
||||
namespace triagens {
|
||||
namespace admin {
|
||||
class ApplicationAdminServer;
|
||||
class Session;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief session handler
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class SessionHandler : public RestBaseHandler {
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief static constructor
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static rest::HttpHandler* create (rest::HttpRequest* request, void* data) {
|
||||
return new SessionHandler(request, (ApplicationAdminServer*) data);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// {@inheritDoc}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool isDirect () {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// {@inheritDoc}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
status_e execute ();
|
||||
|
||||
protected:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief constructor
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SessionHandler (rest::HttpRequest* request, ApplicationAdminServer*);
|
||||
|
||||
private:
|
||||
status_e executePost ();
|
||||
status_e executeGet ();
|
||||
status_e executePut ();
|
||||
status_e executeDelete ();
|
||||
|
||||
status_e executeLogin (Session*);
|
||||
status_e executeLogout (Session*);
|
||||
status_e executePassword (Session*);
|
||||
|
||||
void generateSession (Session*);
|
||||
|
||||
private:
|
||||
ApplicationAdminServer* _server;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -5,19 +5,29 @@
|
|||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2010-2011 triagens GmbH, Cologne, Germany
|
||||
/// Copyright by triAGENS GmbH - All rights reserved.
|
||||
///
|
||||
/// 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
|
||||
/// The Programs (which include both the software and documentation)
|
||||
/// contain proprietary information of triAGENS GmbH; they are
|
||||
/// provided under a license agreement containing restrictions on use and
|
||||
/// disclosure and are also protected by copyright, patent and other
|
||||
/// intellectual and industrial property laws. Reverse engineering,
|
||||
/// disassembly or decompilation of the Programs, except to the extent
|
||||
/// required to obtain interoperability with other independently created
|
||||
/// software or as specified by law, is prohibited.
|
||||
///
|
||||
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
/// The Programs are not intended for use in any nuclear, aviation, mass
|
||||
/// transit, medical, or other inherently dangerous applications. It shall
|
||||
/// be the licensee's responsibility to take all appropriate fail-safe,
|
||||
/// backup, redundancy, and other measures to ensure the safe use of such
|
||||
/// applications if the Programs are used for such purposes, and triAGENS
|
||||
/// GmbH disclaims liability for any damages caused by such use of
|
||||
/// the Programs.
|
||||
///
|
||||
/// 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.
|
||||
/// This software is the confidential and proprietary information of
|
||||
/// triAGENS GmbH. You shall not disclose such confidential and
|
||||
/// proprietary information and shall use it only in accordance with the
|
||||
/// terms of the license agreement you entered into with triAGENS GmbH.
|
||||
///
|
||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
|
|
|
@ -1,121 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief role of a user
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2010-2011 triagens GmbH, Cologne, Germany
|
||||
///
|
||||
/// 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.
|
||||
///
|
||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Dr. Frank Celler
|
||||
/// @author Copyright 2011, triagens GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Role.h"
|
||||
|
||||
#include <Basics/Logger.h>
|
||||
#include <Basics/Mutex.h>
|
||||
#include <Basics/MutexLocker.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace triagens::basics;
|
||||
using namespace triagens::admin;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// role regestry
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
namespace {
|
||||
Mutex RoleLock;
|
||||
map<string, Role*> RoleRegistry;
|
||||
}
|
||||
|
||||
namespace triagens {
|
||||
namespace admin {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// static public methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
Role* Role::create (string const& name, right_t manage) {
|
||||
MUTEX_LOCKER(RoleLock);
|
||||
|
||||
map<string, Role*>::const_iterator i = RoleRegistry.find(name);
|
||||
|
||||
if (i != RoleRegistry.end()) {
|
||||
LOGGER_DEBUG << "user '" << name << "' already exists";
|
||||
return 0;
|
||||
}
|
||||
|
||||
Role* user = new Role(name, manage);
|
||||
|
||||
RoleRegistry[name] = user;
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Role* Role::lookup (string const& name) {
|
||||
MUTEX_LOCKER(RoleLock);
|
||||
|
||||
map<string, Role*>::const_iterator i = RoleRegistry.find(name);
|
||||
|
||||
if (i == RoleRegistry.end()) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return i->second;
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// constructors and destructors
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
Role::Role (string const& name, right_t manage)
|
||||
: _name(name), _rightToManage(manage) {
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// public methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void Role::addRight (right_t right) {
|
||||
_rights.insert(right);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Role::setRights (vector<right_t> const& rights) {
|
||||
_rights.clear();
|
||||
_rights.insert(rights.begin(), rights.end());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Role::removeRight (right_t right) {
|
||||
_rights.erase(right);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Role::clearRights () {
|
||||
_rights.clear();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,124 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief role of a user
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2010-2011 triagens GmbH, Cologne, Germany
|
||||
///
|
||||
/// 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.
|
||||
///
|
||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Dr. Frank Celler
|
||||
/// @author Copyright 2011, triagens GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef TRIAGENS_BORNHOLM_USER_MANAGER_ROLE_H
|
||||
#define TRIAGENS_BORNHOLM_USER_MANAGER_ROLE_H 1
|
||||
|
||||
#include <BasicsC/Common.h>
|
||||
|
||||
#include <Admin/Right.h>
|
||||
#include <Basics/Logger.h>
|
||||
|
||||
namespace triagens {
|
||||
namespace admin {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief role of a user
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Role : noncopyable {
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief creates a new role
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static Role* create (string const& name, right_t manage);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns a role by name
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static Role* lookup (string const& name);
|
||||
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief constructor
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Role (string const& name, right_t manage);
|
||||
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns the name of a role
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
string const& getName () const {
|
||||
return _name;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns the rights of a role
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
set<right_t> const& getRights () const {
|
||||
return _rights;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief adds a right to a role
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void addRight (right_t);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief sets the rights of a role
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void setRights (vector<right_t> const&);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief removes a right from a role
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void removeRight (right_t);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief clears all rights of a role
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void clearRights ();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns right required to manage this role
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
right_t rightToManage () {
|
||||
return _rightToManage;
|
||||
}
|
||||
|
||||
private:
|
||||
string const _name;
|
||||
set<right_t> _rights;
|
||||
right_t _rightToManage;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,309 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief a user
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2010-2011 triagens GmbH, Cologne, Germany
|
||||
///
|
||||
/// 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.
|
||||
///
|
||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Dr. Frank Celler
|
||||
/// @author Copyright 2011, triagens GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "User.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include <Basics/StringUtils.h>
|
||||
#include <Basics/FileUtils.h>
|
||||
#include <Basics/Logger.h>
|
||||
#include <Basics/Mutex.h>
|
||||
#include <Basics/MutexLocker.h>
|
||||
|
||||
#include "UserManager/Role.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace triagens::basics;
|
||||
using namespace triagens::admin;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// user registry
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
namespace {
|
||||
Mutex UserLock;
|
||||
map<string, User*> UserRegistry;
|
||||
string userDatabase;
|
||||
}
|
||||
|
||||
namespace triagens {
|
||||
namespace admin {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// static public methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
User* User::create (string const& name, Role* role) {
|
||||
MUTEX_LOCKER(UserLock);
|
||||
|
||||
map<string, User*>::const_iterator i = UserRegistry.find(name);
|
||||
|
||||
if (i != UserRegistry.end()) {
|
||||
LOGGER_DEBUG << "user '" << name << "' already exists";
|
||||
return 0;
|
||||
}
|
||||
|
||||
User* user = new User(name, role);
|
||||
|
||||
UserRegistry[name] = user;
|
||||
saveUser();
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
|
||||
User* User::lookup (string const& name) {
|
||||
MUTEX_LOCKER(UserLock);
|
||||
|
||||
map<string, User*>::const_iterator i = UserRegistry.find(name);
|
||||
|
||||
if (i == UserRegistry.end()) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return i->second;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool User::remove (User* user) {
|
||||
MUTEX_LOCKER(UserLock);
|
||||
|
||||
map<string, User*>::iterator i = UserRegistry.find(user->_name);
|
||||
|
||||
if (i == UserRegistry.end()) {
|
||||
LOGGER_DEBUG << "user '" << user->_name << "' is unknown";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (i->second != user) {
|
||||
LOGGER_WARNING << "user '" << user->_name << "' does not matched stored profile";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! user->hasRight(RIGHT_TO_BE_DELETED)) {
|
||||
LOGGER_WARNING << "user '" << user->_name << "' cannot be deleted";
|
||||
return false;
|
||||
}
|
||||
|
||||
UserRegistry.erase(i);
|
||||
saveUser();
|
||||
|
||||
// This is a simple user manager, we are not deleting any old users.
|
||||
// Otherwise we would need to create locks outside the "lookup" function
|
||||
// to avoid deleting the current user, or we would need to use smart
|
||||
// pointer or objects.
|
||||
|
||||
// delete user;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
vector<User*> User::users () {
|
||||
MUTEX_LOCKER(UserLock);
|
||||
|
||||
vector<User*> result;
|
||||
|
||||
for (map<string, User*>::const_iterator i = UserRegistry.begin(); i != UserRegistry.end(); ++i) {
|
||||
result.push_back(i->second);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool User::loadUser (string const& path) {
|
||||
userDatabase = path;
|
||||
bool found = true;
|
||||
|
||||
if (userDatabase.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! FileUtils::exists(userDatabase)) {
|
||||
ofstream* of = FileUtils::createOutput(userDatabase);
|
||||
|
||||
if (of == 0) {
|
||||
LOGGER_FATAL << "cannot create user database '" << userDatabase << "'";
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
*of << "# EMPTY USER DATABASE\n";
|
||||
|
||||
if (of->fail()) {
|
||||
LOGGER_FATAL << "cannot create user database '" << userDatabase << "'";
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
delete of;
|
||||
found = false;
|
||||
}
|
||||
|
||||
ifstream* is = FileUtils::createInput(userDatabase);
|
||||
|
||||
if (is == 0) {
|
||||
LOGGER_FATAL << "cannot read user database '" << userDatabase << "'";
|
||||
return false;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
string line;
|
||||
getline(*is, line);
|
||||
|
||||
if (is->eof()) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (is->fail()) {
|
||||
LOGGER_FATAL << "cannot read user database '" << userDatabase << "'";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (line.empty() || line[0] == '#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
vector<string> split = StringUtils::split(line, ';');
|
||||
|
||||
if (split.size() != 3) {
|
||||
LOGGER_FATAL << "corrupted user data '" << userDatabase << "'";
|
||||
return false;
|
||||
}
|
||||
|
||||
string const& name = split[2];
|
||||
Role* role = Role::lookup(name);
|
||||
|
||||
if (role == 0) {
|
||||
LOGGER_ERROR << "unknown role '" << name << "' in user database";
|
||||
continue;
|
||||
}
|
||||
|
||||
User* user = new User(split[0], role);
|
||||
user->changePassword(split[1]);
|
||||
|
||||
UserRegistry[name] = user;
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void User::saveUser () {
|
||||
if (userDatabase.empty()) {
|
||||
LOGGER_DEBUG << "no user database defined, cannot save data";
|
||||
return;
|
||||
}
|
||||
|
||||
string tmp = userDatabase + ".tmp";
|
||||
|
||||
if (FileUtils::exists(tmp)) {
|
||||
if (! FileUtils::remove(tmp)) {
|
||||
LOGGER_FATAL << "cannot remove the temporary user database '" << tmp << "'";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ofstream* of = FileUtils::createOutput(tmp);
|
||||
|
||||
if (of == 0) {
|
||||
LOGGER_FATAL << "cannot create the temporary user data '" << tmp << "'";
|
||||
return;
|
||||
}
|
||||
|
||||
for (map<string, User*>::const_iterator i = UserRegistry.begin(); i != UserRegistry.end(); ++i) {
|
||||
User* user = i->second;
|
||||
|
||||
*of << StringUtils::escape(user->_name, ";") << ";"
|
||||
<< StringUtils::escape(user->_password, ";") << ";"
|
||||
<< StringUtils::escape(user->_role->getName(), ";")
|
||||
<< "\n";
|
||||
|
||||
if (of->fail()) {
|
||||
LOGGER_FATAL << "cannot write the temporary user data '" << tmp << "'";
|
||||
delete of;
|
||||
FileUtils::remove(tmp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
delete of;
|
||||
|
||||
FileUtils::remove(userDatabase);
|
||||
|
||||
if (! FileUtils::rename(tmp, userDatabase)) {
|
||||
LOGGER_FATAL << "could not rename the temporary user database '" << tmp << "'";
|
||||
return;
|
||||
}
|
||||
|
||||
LOGGER_DEBUG << "wrote user database '" << userDatabase << "'";
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// constructors and destructors
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
User::User (string const& name, Role* role)
|
||||
: _name(name), _password(""), _role(role) {
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// public methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool User::changePassword (string const& password) {
|
||||
_password = password;
|
||||
saveUser();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool User::checkPassword (string const& password) {
|
||||
return _password == password;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool User::hasRight (right_t right) {
|
||||
if (_role == 0) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
set<right_t> const& rights = _role->getRights();
|
||||
|
||||
return rights.find(right) != rights.end();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,138 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief a user
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2010-2011 triagens GmbH, Cologne, Germany
|
||||
///
|
||||
/// 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.
|
||||
///
|
||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Dr. Frank Celler
|
||||
/// @author Copyright 2011, triagens GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef TRIAGENS_BORNHOLM_USER_MANAGER_USER_H
|
||||
#define TRIAGENS_BORNHOLM_USER_MANAGER_USER_H 1
|
||||
|
||||
#include <BasicsC/Common.h>
|
||||
|
||||
#include <Admin/Right.h>
|
||||
|
||||
namespace triagens {
|
||||
namespace admin {
|
||||
class Role;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief a user
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class User : noncopyable {
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief adds a new user
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static User* create (string const& name, Role*);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns a role by name
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static User* lookup (string const& name);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief removes a user
|
||||
///
|
||||
/// Remove will also delete the user object.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool remove (User*);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns a role by name
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static vector<User*> users ();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief loads the user database
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool loadUser (string const& file);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief saves the user database
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void saveUser ();
|
||||
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns the name of a user
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
string const& getName () const {
|
||||
return _name;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns the role of a user
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Role* getRole () const {
|
||||
return _role;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief changes the password of a user
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool changePassword (string const& password);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief checks the password of a user
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool checkPassword (string const& password);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief has right
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool hasRight (right_t);
|
||||
|
||||
protected:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief creates a new user
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
User (string const& name, Role*);
|
||||
|
||||
private:
|
||||
string const _name;
|
||||
string _password;
|
||||
Role* _role;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,236 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief user handler
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2010-2011 triagens GmbH, Cologne, Germany
|
||||
///
|
||||
/// 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.
|
||||
///
|
||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Dr. Frank Celler
|
||||
/// @author Copyright 2011, triagens GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "UserHandler.h"
|
||||
|
||||
#include <Admin/ApplicationAdminServer.h>
|
||||
#include <Basics/VariantArray.h>
|
||||
#include <Basics/VariantBoolean.h>
|
||||
#include <Basics/VariantInt32.h>
|
||||
#include <Basics/VariantVector.h>
|
||||
#include <Rest/HttpRequest.h>
|
||||
#include <Rest/HttpResponse.h>
|
||||
|
||||
#include "UserManager/User.h"
|
||||
#include "UserManager/Role.h"
|
||||
#include "SessionManager/Session.h"
|
||||
|
||||
using namespace triagens::basics;
|
||||
using namespace triagens::rest;
|
||||
|
||||
namespace triagens {
|
||||
namespace admin {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// constructors and destructors
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
UserHandler::UserHandler (HttpRequest* request, ApplicationAdminServer* server)
|
||||
: RestAdminBaseHandler(request), _server(server) {
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// HttpHandler methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
HttpHandler::status_e UserHandler::execute () {
|
||||
|
||||
// extract the username
|
||||
vector<string> const& suffix = request->suffix();
|
||||
|
||||
if (suffix.size() != 1) {
|
||||
generateError(HttpResponse::BAD, "expecting <prefix>/user/<username>");
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
string const& name = suffix[0];
|
||||
|
||||
// execute the request
|
||||
switch (request->requestType()) {
|
||||
case HttpRequest::HTTP_REQUEST_POST: return executePost(name);
|
||||
case HttpRequest::HTTP_REQUEST_GET: return executeGet(name);
|
||||
case HttpRequest::HTTP_REQUEST_PUT: return executePut(name);
|
||||
case HttpRequest::HTTP_REQUEST_DELETE: return executeDelete(name);
|
||||
|
||||
default:
|
||||
generateError(HttpResponse::METHOD_NOT_ALLOWED, "method not supported");
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// private methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
HttpHandler::status_e UserHandler::executePost (string const& name) {
|
||||
struct Description : public InputParser::ObjectDescription {
|
||||
Description () {
|
||||
attribute("role", role);
|
||||
attribute("password", password);
|
||||
}
|
||||
|
||||
string role;
|
||||
string password;
|
||||
} desc;
|
||||
|
||||
bool ok = parseBody(desc);
|
||||
|
||||
if (! ok) {
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
Role* role = Role::lookup(desc.role);
|
||||
|
||||
if (role == 0) {
|
||||
generateError(HttpResponse::NOT_FOUND, "role '" + desc.role + "' not found");
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
ok = hasRight(role->rightToManage());
|
||||
|
||||
if (! ok) {
|
||||
generateError(HttpResponse::UNAUTHORIZED, "no permission to create user with role '" + desc.role + "'");
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
User* user = User::create(name, role);
|
||||
|
||||
if (user == 0) {
|
||||
generateError(HttpResponse::UNAUTHORIZED, "cannot create user '" + name + "'");
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
user->changePassword(desc.password);
|
||||
|
||||
generateUser(user);
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HttpHandler::status_e UserHandler::executeGet (string const& name) {
|
||||
User* user = User::lookup(name);
|
||||
|
||||
if (user == 0) {
|
||||
generateError(HttpResponse::NOT_FOUND, "user '" + name + "' not found");
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
generateUser(user);
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HttpHandler::status_e UserHandler::executePut (string const& name) {
|
||||
if (! isSelf(name)) {
|
||||
generateError(HttpResponse::UNAUTHORIZED, "cannot manage password for user '" + name + "'");
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
User* user = User::lookup(name);
|
||||
|
||||
if (user == 0) {
|
||||
generateError(HttpResponse::NOT_FOUND, "user '" + name + "' not found");
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
struct Description : public InputParser::ObjectDescription {
|
||||
Description () {
|
||||
optional("password", password, hasPassword);
|
||||
}
|
||||
|
||||
bool hasPassword;
|
||||
string password;
|
||||
} desc;
|
||||
|
||||
bool ok = parseBody(desc);
|
||||
|
||||
if (! ok) {
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
bool changed = true;
|
||||
|
||||
if (desc.hasPassword) {
|
||||
changed = user->changePassword(desc.password);
|
||||
}
|
||||
|
||||
VariantArray* result = new VariantArray();
|
||||
result->add("changed", new VariantBoolean(changed));
|
||||
|
||||
generateResult(result);
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HttpHandler::status_e UserHandler::executeDelete (string const& name) {
|
||||
User* user = User::lookup(name);
|
||||
|
||||
bool removed = false;
|
||||
|
||||
if (user != 0) {
|
||||
bool ok = hasRight(user->getRole()->rightToManage());
|
||||
|
||||
if (! ok) {
|
||||
generateError(HttpResponse::UNAUTHORIZED,
|
||||
"no permission to create user with role '" + user->getRole()->getName() + "'");
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
removed = User::remove(user);
|
||||
}
|
||||
|
||||
VariantArray* result = new VariantArray();
|
||||
result->add("removed", new VariantBoolean(removed));
|
||||
|
||||
generateResult(result);
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void UserHandler::generateUser (User* user) {
|
||||
VariantArray* result = new VariantArray();
|
||||
result->add("role", user->getRole()->getName());
|
||||
result->add("name", user->getName());
|
||||
|
||||
set<right_t> const& rights = user->getRole()->getRights();
|
||||
|
||||
VariantVector* r = new VariantVector();
|
||||
|
||||
for (set<right_t>::const_iterator i = rights.begin(); i != rights.end(); ++i) {
|
||||
r->add(new VariantInt32(*i));
|
||||
}
|
||||
|
||||
result->add("rights", r);
|
||||
|
||||
generateResult(result);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief user handler
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2010-2011 triagens GmbH, Cologne, Germany
|
||||
///
|
||||
/// 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.
|
||||
///
|
||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Dr. Frank Celler
|
||||
/// @author Copyright 2011, triagens GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef TRIAGENS_BORNHOLM_USER_MANAGER_USER_HANDLER_H
|
||||
#define TRIAGENS_BORNHOLM_USER_MANAGER_USER_HANDLER_H 1
|
||||
|
||||
#include <Admin/RestAdminBaseHandler.h>
|
||||
|
||||
#include <Admin/Right.h>
|
||||
|
||||
namespace triagens {
|
||||
namespace admin {
|
||||
class ApplicationAdminServer;
|
||||
class User;
|
||||
class Session;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief user handler
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class UserHandler : public RestAdminBaseHandler {
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief static constructor
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static rest::HttpHandler* create (rest::HttpRequest* request, void* data) {
|
||||
return new UserHandler(request, (ApplicationAdminServer*) data);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// {@inheritDoc}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool isDirect () {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// {@inheritDoc}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
status_e execute ();
|
||||
|
||||
protected:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief constructor
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
UserHandler (rest::HttpRequest* request, ApplicationAdminServer*);
|
||||
|
||||
private:
|
||||
status_e executePost (string const& name);
|
||||
status_e executeGet (string const& name);
|
||||
status_e executePut (string const& name);
|
||||
status_e executeDelete (string const& name);
|
||||
|
||||
void generateUser (User*);
|
||||
|
||||
private:
|
||||
ApplicationAdminServer* _server;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,83 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief users handler
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2010-2011 triagens GmbH, Cologne, Germany
|
||||
///
|
||||
/// 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.
|
||||
///
|
||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Dr. Frank Celler
|
||||
/// @author Copyright 2011, triagens GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "UsersHandler.h"
|
||||
|
||||
#include <Admin/ApplicationAdminServer.h>
|
||||
#include <Basics/VariantArray.h>
|
||||
#include <Basics/VariantString.h>
|
||||
#include <Basics/VariantVector.h>
|
||||
#include <Rest/HttpRequest.h>
|
||||
|
||||
#include "UserManager/User.h"
|
||||
|
||||
using namespace triagens::basics;
|
||||
using namespace triagens::rest;
|
||||
|
||||
namespace triagens {
|
||||
namespace admin {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// constructors and destructors
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
UsersHandler::UsersHandler (HttpRequest* request, ApplicationAdminServer* server)
|
||||
: RestAdminBaseHandler(request), _server(server) {
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// HttpHandler methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
HttpHandler::status_e UsersHandler::execute () {
|
||||
vector<string> const& suffix = request->suffix();
|
||||
|
||||
if (suffix.size() != 0) {
|
||||
generateError(HttpResponse::BAD, "expecting GET <prefix>/users");
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
if (request->requestType() != HttpRequest::HTTP_REQUEST_GET) {
|
||||
generateError(HttpResponse::METHOD_NOT_ALLOWED, "expecting GET");
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
|
||||
vector<User*> users = User::users();
|
||||
|
||||
VariantArray* result = new VariantArray();
|
||||
VariantVector* list = new VariantVector();
|
||||
result->add("users", list);
|
||||
|
||||
for (vector<User*>::iterator i = users.begin(); i != users.end(); ++i) {
|
||||
list->add((*i)->getName());
|
||||
}
|
||||
|
||||
generateResult(result);
|
||||
return HANDLER_DONE;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief users handler
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2010-2011 triagens GmbH, Cologne, Germany
|
||||
///
|
||||
/// 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.
|
||||
///
|
||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Dr. Frank Celler
|
||||
/// @author Copyright 2011, triagens GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef TRIAGENS_BORNHOLM_USER_MANAGER_USERS_HANDLER_H
|
||||
#define TRIAGENS_BORNHOLM_USER_MANAGER_USERS_HANDLER_H 1
|
||||
|
||||
#include <Admin/RestAdminBaseHandler.h>
|
||||
|
||||
namespace triagens {
|
||||
namespace admin {
|
||||
class ApplicationAdminServer;
|
||||
class User;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief user handler
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class UsersHandler : public RestAdminBaseHandler {
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief static constructor
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static rest::HttpHandler* create (rest::HttpRequest* request, void* data) {
|
||||
return new UsersHandler(request, (ApplicationAdminServer*) data);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// {@inheritDoc}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool isDirect () {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// {@inheritDoc}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
status_e execute ();
|
||||
|
||||
protected:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief constructor
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
UsersHandler (rest::HttpRequest* request, ApplicationAdminServer*);
|
||||
|
||||
private:
|
||||
ApplicationAdminServer* _server;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
2
build.h
2
build.h
|
@ -1 +1 @@
|
|||
#define TRIAGENS_VERSION "0.0.6 (9800:9802)"
|
||||
#define TRIAGENS_VERSION "0.0.7"
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [ $# -lt 4 ]; then
|
||||
echo "usage: $0 <name> <guard-name> <build.h> <header1> ..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
NAME=$1
|
||||
shift
|
||||
|
||||
name=`echo $NAME | awk '{print tolower($1)}'`
|
||||
|
||||
GUARD=$1
|
||||
shift
|
||||
|
||||
BUILD=$1
|
||||
shift
|
||||
|
||||
echo "TRIAGENS_$GUARD" | tr "a-z" "A-Z" | awk '{print "#ifndef " $1}'
|
||||
echo "TRIAGENS_$GUARD" | tr "a-z" "A-Z" | awk '{print "#define " $1 " 1"}'
|
||||
echo ""
|
||||
echo "$*" | tr " " "\n" | sort | awk '$1 != "" {print "#include <" $1 ">"}'
|
||||
echo ""
|
||||
echo "namespace triagens {"
|
||||
echo " namespace $name {"
|
||||
echo " inline string version () {"
|
||||
echo " return " | tr -d "\n"
|
||||
cat $BUILD | sed -e 's:^.*"\(.*\)":"\1";:'
|
||||
echo " }"
|
||||
echo ""
|
||||
echo " inline string revision () {"
|
||||
echo " return \"\$Revision: $NAME " | tr -d "\n"
|
||||
echo `cat $BUILD | sed -e 's:.*"\(.*\)".*:\1:'` | tr -d "\n"
|
||||
echo ' (c) triAGENS GmbH $";'
|
||||
echo " }"
|
||||
echo " }"
|
||||
echo "}"
|
||||
echo ""
|
||||
echo "#endif"
|
18
configure.ac
18
configure.ac
|
@ -20,15 +20,24 @@ dnl CHECKS HOST, PROGRAMS, COMPILER, LIB, SYSTEM
|
|||
dnl ============================================================================
|
||||
|
||||
m4_include([m4/configure.basics])
|
||||
AC_PROG_RANLIB
|
||||
|
||||
m4_include([m4/configure.static])
|
||||
m4_include([m4/configure.32bit])
|
||||
m4_include([m4/configure.logging])
|
||||
m4_include([m4/configure.largefile])
|
||||
m4_include([m4/configure.threads])
|
||||
m4_include([m4/configure.flex-bison])
|
||||
m4_include([m4/configure.boost])
|
||||
m4_include([m4/configure.libev])
|
||||
m4_include([m4/configure.openssl])
|
||||
m4_include([m4/configure.v8])
|
||||
|
||||
m4_include([m4/external.boost])
|
||||
m4_include([m4/external.libev])
|
||||
m4_include([m4/external.math])
|
||||
m4_include([m4/external.ncurses])
|
||||
m4_include([m4/external.readline])
|
||||
m4_include([m4/external.openssl])
|
||||
m4_include([m4/external.v8])
|
||||
|
||||
CPPFLAGS="$CPPFLAGS -DGEO_TRIAGENS=1"
|
||||
|
||||
dnl ============================================================================
|
||||
dnl OUTPUT GENERATE FILES
|
||||
|
@ -38,6 +47,7 @@ BUILD_H="\$(top_srcdir)/build.h"
|
|||
AC_SUBST(BUILD_H)
|
||||
|
||||
AC_CONFIG_FILES([Makefile])
|
||||
AM_CONFIG_HEADER([BasicsC/local-configuration.h])
|
||||
AC_OUTPUT
|
||||
|
||||
dnl ============================================================================
|
||||
|
|
57
durham.h
57
durham.h
|
@ -1,57 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief storage engine
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2010-2011 triagens GmbH, Cologne, Germany
|
||||
///
|
||||
/// 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.
|
||||
///
|
||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Dr. Frank Celler
|
||||
/// @author Copyright 2011, triAGENS GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @mainpage
|
||||
///
|
||||
/// The Durham Storage Engine stores documents (aka objects or JSON documents)
|
||||
/// in datafiles within the filesystem. These documents are mapped into the
|
||||
/// process space using mmap. Instead of using JSON, BSON, or XML to store the
|
||||
/// documents a very concise representation, namely JSON Shapes, is used.
|
||||
/// This allows for verbose attributes name, while still being space efficient.
|
||||
/// Access to attributes can be precompiled and is therefore incredible fast.
|
||||
///
|
||||
/// @section Interface
|
||||
///
|
||||
/// The Store Engine groups documents into collections. Each
|
||||
/// collection can be accessed using queries. These queries can either
|
||||
/// be expressed using a @ref FluentInterface "fluent interface" (see
|
||||
/// @ref JavaScriptFuncIndex "Index of JavaScript Functions"), using
|
||||
/// the SQL-select operator find, or using UNQL.
|
||||
///
|
||||
/// @section DataStructures Data Structures
|
||||
///
|
||||
/// The key data structures are @ref ShapedJson "JSON Shapes". JSON Shapes
|
||||
/// allow the Durham Storage Engine to store documents in a very space
|
||||
/// efficient way.
|
||||
///
|
||||
/// @section CollectionsDatafiles Collections and Datafiles
|
||||
///
|
||||
/// All data is stored in datafiles. The internal structure of a datafile is
|
||||
/// described in @ref DurhamDatafiles "Datafiles". All datafiles of a set of
|
||||
/// documents are grouped together in a @ref DurhamCollections "Collection".
|
||||
////////////////////////////////////////////////////////////////////////////////
|
Loading…
Reference in New Issue