mirror of
https://github.com/arcan1s/queued.git
synced 2025-04-24 23:47:19 +00:00
implement auth for get option methods to hide sensetive settings
This commit is contained in:
parent
bfea1635f9
commit
bb0a3c43be
@ -55,21 +55,21 @@ void QueuedServer::init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_server->init(QueuedCoreAdaptor::getOption(
|
m_server->init(QueuedCoreAdaptor::getOption(
|
||||||
QueuedConfig::QueuedSettings::ServerTimeout)
|
QueuedConfig::QueuedSettings::ServerTimeout, "")
|
||||||
.get()
|
.get()
|
||||||
.toInt());
|
.toInt());
|
||||||
QString address = QueuedCoreAdaptor::getOption(
|
QString address = QueuedCoreAdaptor::getOption(
|
||||||
QueuedConfig::QueuedSettings::ServerAddress)
|
QueuedConfig::QueuedSettings::ServerAddress, "")
|
||||||
.get()
|
.get()
|
||||||
.toString();
|
.toString();
|
||||||
ushort port
|
ushort port = QueuedCoreAdaptor::getOption(
|
||||||
= QueuedCoreAdaptor::getOption(QueuedConfig::QueuedSettings::ServerPort)
|
QueuedConfig::QueuedSettings::ServerPort, "")
|
||||||
.get()
|
.get()
|
||||||
.toUInt();
|
.toUInt();
|
||||||
m_server->listen(QHostAddress(address), port);
|
m_server->listen(QHostAddress(address), port);
|
||||||
m_server->setMaxPendingConnections(
|
m_server->setMaxPendingConnections(
|
||||||
QueuedCoreAdaptor::getOption(
|
QueuedCoreAdaptor::getOption(
|
||||||
QueuedConfig::QueuedSettings::ServerMaxConnections)
|
QueuedConfig::QueuedSettings::ServerMaxConnections, "")
|
||||||
.get()
|
.get()
|
||||||
.toInt());
|
.toInt());
|
||||||
|
|
||||||
|
@ -50,7 +50,8 @@ QVariantHash QueuedTcpServerResponseHelperApi1::getData(
|
|||||||
break;
|
break;
|
||||||
case QueuedTcpServerResponseHelper::RequestPath::Option:
|
case QueuedTcpServerResponseHelper::RequestPath::Option:
|
||||||
if (_type == "GET")
|
if (_type == "GET")
|
||||||
output = QueuedTcpServerResponseHelperOption::getOption(_arg);
|
output
|
||||||
|
= QueuedTcpServerResponseHelperOption::getOption(_arg, _token);
|
||||||
else if (_type == "POST")
|
else if (_type == "POST")
|
||||||
output = QueuedTcpServerResponseHelperOption::setOption(_arg, _data,
|
output = QueuedTcpServerResponseHelperOption::setOption(_arg, _data,
|
||||||
_token);
|
_token);
|
||||||
|
@ -20,11 +20,12 @@
|
|||||||
|
|
||||||
|
|
||||||
QVariantHash
|
QVariantHash
|
||||||
QueuedTcpServerResponseHelperOption::getOption(const QString &_option)
|
QueuedTcpServerResponseHelperOption::getOption(const QString &_option,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Get option" << _option;
|
qCDebug(LOG_SERV) << "Get option" << _option;
|
||||||
|
|
||||||
auto res = QueuedCoreAdaptor::getOption(_option);
|
auto res = QueuedCoreAdaptor::getOption(_option, _token);
|
||||||
|
|
||||||
QVariantHash output;
|
QVariantHash output;
|
||||||
res.match(
|
res.match(
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
namespace QueuedTcpServerResponseHelperOption
|
namespace QueuedTcpServerResponseHelperOption
|
||||||
{
|
{
|
||||||
QVariantHash getOption(const QString &_option);
|
QVariantHash getOption(const QString &_option, const QString &_token);
|
||||||
QVariantHash setOption(const QString &_option, const QVariantHash &_value,
|
QVariantHash setOption(const QString &_option, const QVariantHash &_value,
|
||||||
const QString &_token);
|
const QString &_token);
|
||||||
};
|
};
|
||||||
|
@ -42,8 +42,8 @@ QueuedTcpServerResponseHelperPlugins::addPlugin(const QString &_name,
|
|||||||
|
|
||||||
QVariantHash QueuedTcpServerResponseHelperPlugins::listPlugins()
|
QVariantHash QueuedTcpServerResponseHelperPlugins::listPlugins()
|
||||||
{
|
{
|
||||||
auto res
|
auto res = QueuedCoreAdaptor::getOption(
|
||||||
= QueuedCoreAdaptor::getOption(QueuedConfig::QueuedSettings::Plugins);
|
QueuedConfig::QueuedSettings::Plugins, "");
|
||||||
|
|
||||||
QVariantHash output;
|
QVariantHash output;
|
||||||
res.match(
|
res.match(
|
||||||
|
@ -88,6 +88,20 @@ public:
|
|||||||
* @return ID in settings representation
|
* @return ID in settings representation
|
||||||
*/
|
*/
|
||||||
static QString internalId(const QueuedConfig::QueuedSettings _key);
|
static QString internalId(const QueuedConfig::QueuedSettings _key);
|
||||||
|
/**
|
||||||
|
* @brief check whether requested option is admin only
|
||||||
|
* @param _key
|
||||||
|
* key to search in
|
||||||
|
* @return true if this value is hidden for non-admins
|
||||||
|
*/
|
||||||
|
bool isAdmin(const QString &_key) const;
|
||||||
|
/**
|
||||||
|
* @brief check whether requested option is admin only
|
||||||
|
* @param _key
|
||||||
|
* key to search in
|
||||||
|
* @return true if this value is hidden for non-admins
|
||||||
|
*/
|
||||||
|
bool isAdmin(const QueuedConfig::QueuedSettings &_key) const;
|
||||||
/**
|
/**
|
||||||
* @brief set value
|
* @brief set value
|
||||||
* @param _key
|
* @param _key
|
||||||
|
@ -196,9 +196,11 @@ public:
|
|||||||
* @brief get value from advanced settings
|
* @brief get value from advanced settings
|
||||||
* @param _key
|
* @param _key
|
||||||
* key string
|
* key string
|
||||||
|
* @param _token
|
||||||
|
* user auth token
|
||||||
* @return option value or empty QVariant
|
* @return option value or empty QVariant
|
||||||
*/
|
*/
|
||||||
QueuedResult<QVariant> option(const QString &_key);
|
QueuedResult<QVariant> option(const QString &_key, const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief usage report
|
* @brief usage report
|
||||||
* @param _from
|
* @param _from
|
||||||
|
@ -194,16 +194,22 @@ sendUserPermissionRemove(const long long _id,
|
|||||||
* @brief get option
|
* @brief get option
|
||||||
* @param _property
|
* @param _property
|
||||||
* option name
|
* option name
|
||||||
|
* @param _token
|
||||||
|
* user auth token
|
||||||
* @return option value
|
* @return option value
|
||||||
*/
|
*/
|
||||||
QueuedResult<QVariant> getOption(const QString &_property);
|
QueuedResult<QVariant> getOption(const QString &_property,
|
||||||
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief get option
|
* @brief get option
|
||||||
* @param _property
|
* @param _property
|
||||||
* option name
|
* option name
|
||||||
|
* @param _token
|
||||||
|
* user auth token
|
||||||
* @return option value
|
* @return option value
|
||||||
*/
|
*/
|
||||||
QueuedResult<QVariant> getOption(const QueuedConfig::QueuedSettings _property);
|
QueuedResult<QVariant> getOption(const QueuedConfig::QueuedSettings _property,
|
||||||
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief performance report
|
* @brief performance report
|
||||||
* @param _from
|
* @param _from
|
||||||
|
@ -57,9 +57,11 @@ public slots:
|
|||||||
* @brief get advanced option
|
* @brief get advanced option
|
||||||
* @param property
|
* @param property
|
||||||
* property name
|
* property name
|
||||||
|
* @param token
|
||||||
|
* user auth token
|
||||||
* @return property value or empty if property not found
|
* @return property value or empty if property not found
|
||||||
*/
|
*/
|
||||||
QDBusVariant Option(const QString &property);
|
QDBusVariant Option(const QString &property, const QString &token);
|
||||||
/**
|
/**
|
||||||
* @brief get task property
|
* @brief get task property
|
||||||
* @param id
|
* @param id
|
||||||
|
@ -132,6 +132,7 @@ enum class QueuedSettings {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
QueuedSettings id;
|
QueuedSettings id;
|
||||||
QVariant defaultValue;
|
QVariant defaultValue;
|
||||||
|
bool isAdmin = true;
|
||||||
} QueuedSettingsField;
|
} QueuedSettingsField;
|
||||||
/**
|
/**
|
||||||
* @typedef QueuedSettingsDefaultMap
|
* @typedef QueuedSettingsDefaultMap
|
||||||
@ -142,20 +143,20 @@ typedef QHash<QString, QueuedSettingsField> QueuedSettingsDefaultMap;
|
|||||||
* @brief default settings map
|
* @brief default settings map
|
||||||
*/
|
*/
|
||||||
static const QueuedSettingsDefaultMap QueuedSettingsDefaults = {
|
static const QueuedSettingsDefaultMap QueuedSettingsDefaults = {
|
||||||
{"", {QueuedSettings::Invalid, QVariant()}},
|
{"", {QueuedSettings::Invalid, QVariant(), false}},
|
||||||
{"DatabaseInterval", {QueuedSettings::DatabaseInterval, 86400000}},
|
{"DatabaseInterval", {QueuedSettings::DatabaseInterval, 86400000, true}},
|
||||||
{"DatabaseVersion",
|
{"DatabaseVersion",
|
||||||
{QueuedSettings::DatabaseVersion, QueuedConfig::DATABASE_VERSION}},
|
{QueuedSettings::DatabaseVersion, QueuedConfig::DATABASE_VERSION, true}},
|
||||||
{"DefaultLimits", {QueuedSettings::DefaultLimits, "0\n0\n0\n0\n0"}},
|
{"DefaultLimits", {QueuedSettings::DefaultLimits, "0\n0\n0\n0\n0", false}},
|
||||||
{"KeepTasks", {QueuedSettings::KeepTasks, 0}},
|
{"KeepTasks", {QueuedSettings::KeepTasks, 0, false}},
|
||||||
{"KeepUsers", {QueuedSettings::KeepUsers, 0}},
|
{"KeepUsers", {QueuedSettings::KeepUsers, 0, false}},
|
||||||
{"OnExitAction", {QueuedSettings::OnExitAction, 2}},
|
{"OnExitAction", {QueuedSettings::OnExitAction, 2, false}},
|
||||||
{"Plugins", {QueuedSettings::Plugins, ""}},
|
{"Plugins", {QueuedSettings::Plugins, "", false}},
|
||||||
{"ServerAddress", {QueuedSettings::ServerAddress, ""}},
|
{"ServerAddress", {QueuedSettings::ServerAddress, "", false}},
|
||||||
{"ServerMaxConnections", {QueuedSettings::ServerMaxConnections, 30}},
|
{"ServerMaxConnections", {QueuedSettings::ServerMaxConnections, 30, false}},
|
||||||
{"ServerPort", {QueuedSettings::ServerPort, 8080}},
|
{"ServerPort", {QueuedSettings::ServerPort, 8080, false}},
|
||||||
{"ServerTimeout", {QueuedSettings::ServerTimeout, -1}},
|
{"ServerTimeout", {QueuedSettings::ServerTimeout, -1, false}},
|
||||||
{"TokenExpiration", {QueuedSettings::TokenExpiration, 30}},
|
{"TokenExpiration", {QueuedSettings::TokenExpiration, 30, false}},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -205,9 +205,11 @@ public:
|
|||||||
* @brief get value from advanced settings
|
* @brief get value from advanced settings
|
||||||
* @param _key
|
* @param _key
|
||||||
* key string
|
* key string
|
||||||
|
* @param _token
|
||||||
|
* user auth token
|
||||||
* @return option value or empty QVariant
|
* @return option value or empty QVariant
|
||||||
*/
|
*/
|
||||||
QueuedResult<QVariant> option(const QString &_key);
|
QueuedResult<QVariant> option(const QString &_key, const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief usage report
|
* @brief usage report
|
||||||
* @param _from
|
* @param _from
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <queued/Queued.h>
|
#include <queued/Queued.h>
|
||||||
|
#include <queued/QueuedStaticConfig.h>
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -139,6 +140,32 @@ QueuedAdvancedSettings::internalId(const QueuedConfig::QueuedSettings _key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn isAdmin
|
||||||
|
*/
|
||||||
|
bool QueuedAdvancedSettings::isAdmin(const QString &_key) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Check if admin option" << _key;
|
||||||
|
|
||||||
|
if ((_key.startsWith("Plugin.")) || (_key.startsWith("plugin.")))
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return QueuedConfig::QueuedSettingsDefaults[internalId(_key)].isAdmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn isAdmin
|
||||||
|
*/
|
||||||
|
bool QueuedAdvancedSettings::isAdmin(
|
||||||
|
const QueuedConfig::QueuedSettings &_key) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Check if admin option" << static_cast<int>(_key);
|
||||||
|
|
||||||
|
return QueuedConfig::QueuedSettingsDefaults[internalId(_key)].isAdmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn set
|
* @fn set
|
||||||
*/
|
*/
|
||||||
|
@ -186,11 +186,12 @@ QueuedResult<QString> QueuedCore::hashFromPassword(const QString &_password)
|
|||||||
/**
|
/**
|
||||||
* @fn option
|
* @fn option
|
||||||
*/
|
*/
|
||||||
QueuedResult<QVariant> QueuedCore::option(const QString &_key)
|
QueuedResult<QVariant> QueuedCore::option(const QString &_key,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Look for option" << _key;
|
qCDebug(LOG_LIB) << "Look for option" << _key;
|
||||||
|
|
||||||
return m_impl->option(_key);
|
return m_impl->option(_key, _token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -290,11 +290,12 @@ QueuedResult<bool> QueuedCoreAdaptor::sendUserPermissionRemove(
|
|||||||
/**
|
/**
|
||||||
* @fn getOption
|
* @fn getOption
|
||||||
*/
|
*/
|
||||||
QueuedResult<QVariant> QueuedCoreAdaptor::getOption(const QString &_property)
|
QueuedResult<QVariant> QueuedCoreAdaptor::getOption(const QString &_property,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get option" << _property;
|
qCDebug(LOG_DBUS) << "Get option" << _property;
|
||||||
|
|
||||||
QVariantList args = {_property};
|
QVariantList args = {_property, _token};
|
||||||
return sendRequest<QVariant>(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<QVariant>(QueuedConfig::DBUS_SERVICE,
|
||||||
QueuedConfig::DBUS_PROPERTY_PATH,
|
QueuedConfig::DBUS_PROPERTY_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, "Option", args);
|
QueuedConfig::DBUS_SERVICE, "Option", args);
|
||||||
@ -305,11 +306,12 @@ QueuedResult<QVariant> QueuedCoreAdaptor::getOption(const QString &_property)
|
|||||||
* @fn getOption
|
* @fn getOption
|
||||||
*/
|
*/
|
||||||
QueuedResult<QVariant>
|
QueuedResult<QVariant>
|
||||||
QueuedCoreAdaptor::getOption(const QueuedConfig::QueuedSettings _property)
|
QueuedCoreAdaptor::getOption(const QueuedConfig::QueuedSettings _property,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get option" << static_cast<int>(_property);
|
qCDebug(LOG_DBUS) << "Get option" << static_cast<int>(_property);
|
||||||
|
|
||||||
return getOption(QueuedAdvancedSettings::internalId(_property));
|
return getOption(QueuedAdvancedSettings::internalId(_property), _token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -333,11 +333,18 @@ QueuedCorePrivate::hashFromPassword(const QString &_password)
|
|||||||
/**
|
/**
|
||||||
* @fn option
|
* @fn option
|
||||||
*/
|
*/
|
||||||
QueuedResult<QVariant> QueuedCorePrivate::option(const QString &_key)
|
QueuedResult<QVariant> QueuedCorePrivate::option(const QString &_key,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Look for option" << _key;
|
qCDebug(LOG_LIB) << "Look for option" << _key;
|
||||||
|
|
||||||
return m_advancedSettings->get(_key);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||||
|
|
||||||
|
if ((isAdmin) || (!m_advancedSettings->isAdmin(_key)))
|
||||||
|
return m_advancedSettings->get(_key);
|
||||||
|
else
|
||||||
|
return QueuedError("Not allowed",
|
||||||
|
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,11 +56,12 @@ QueuedPropertyInterface::~QueuedPropertyInterface()
|
|||||||
/**
|
/**
|
||||||
* @fn Option
|
* @fn Option
|
||||||
*/
|
*/
|
||||||
QDBusVariant QueuedPropertyInterface::Option(const QString &property)
|
QDBusVariant QueuedPropertyInterface::Option(const QString &property,
|
||||||
|
const QString &token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get property" << property;
|
qCDebug(LOG_DBUS) << "Get property" << property;
|
||||||
|
|
||||||
return QueuedCoreAdaptor::toDBusVariant(m_core->option(property));
|
return QueuedCoreAdaptor::toDBusVariant(m_core->option(property, token));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -225,7 +225,8 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::OptionGet: {
|
case QueuedctlArgument::OptionGet: {
|
||||||
result = QueuedctlOption::getOption(args.at(1));
|
QString token = QueuedctlAuth::getToken(_cache, _user);
|
||||||
|
result = QueuedctlOption::getOption(args.at(1), token);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::OptionSet: {
|
case QueuedctlArgument::OptionSet: {
|
||||||
|
@ -38,12 +38,12 @@ QueuedctlOption::editOption(const QString &_option, const QVariant &_value,
|
|||||||
|
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult
|
QueuedctlCommon::QueuedctlResult
|
||||||
QueuedctlOption::getOption(const QString &_option)
|
QueuedctlOption::getOption(const QString &_option, const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Get option" << _option;
|
qCDebug(LOG_APP) << "Get option" << _option;
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult output;
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
auto res = QueuedCoreAdaptor::getOption(_option);
|
auto res = QueuedCoreAdaptor::getOption(_option, _token);
|
||||||
res.match(
|
res.match(
|
||||||
[&output](const QVariant &val) {
|
[&output](const QVariant &val) {
|
||||||
output.status = val.isValid();
|
output.status = val.isValid();
|
||||||
|
@ -27,7 +27,8 @@ namespace QueuedctlOption
|
|||||||
QueuedctlCommon::QueuedctlResult editOption(const QString &_option,
|
QueuedctlCommon::QueuedctlResult editOption(const QString &_option,
|
||||||
const QVariant &_value,
|
const QVariant &_value,
|
||||||
const QString &_token);
|
const QString &_token);
|
||||||
QueuedctlCommon::QueuedctlResult getOption(const QString &_option);
|
QueuedctlCommon::QueuedctlResult getOption(const QString &_option,
|
||||||
|
const QString &_token);
|
||||||
void parserGet(QCommandLineParser &_parser);
|
void parserGet(QCommandLineParser &_parser);
|
||||||
void parserSet(QCommandLineParser &_parser);
|
void parserSet(QCommandLineParser &_parser);
|
||||||
};
|
};
|
||||||
|
@ -39,8 +39,8 @@ QueuedctlPlugins::addPlugin(const QString &_plugin, const QString &_token)
|
|||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult QueuedctlPlugins::listPlugins()
|
QueuedctlCommon::QueuedctlResult QueuedctlPlugins::listPlugins()
|
||||||
{
|
{
|
||||||
auto res
|
auto res = QueuedCoreAdaptor::getOption(
|
||||||
= QueuedCoreAdaptor::getOption(QueuedConfig::QueuedSettings::Plugins);
|
QueuedConfig::QueuedSettings::Plugins, "");
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult output;
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
res.match(
|
res.match(
|
||||||
|
Loading…
Reference in New Issue
Block a user