diff --git a/.gear/gpui.spec b/.gear/gpui.spec index 0c3dc9e5e..4fccb0d2c 100644 --- a/.gear/gpui.spec +++ b/.gear/gpui.spec @@ -96,7 +96,10 @@ LD_PRELOAD=%buildroot%_libdir/gpui/plugins/libadministrative-templates-plugin.so %_libdir/gpui/plugins/libreg-plugin.so %_libdir/gpui/plugins/libspol-plugin.so %_libdir/gpui/plugins/libpol-plugin.so +%_libdir/gpui/plugins/libsdml-plugin.so +%_libdir/gpui/plugins/libsdmx-plugin.so %_libdir/gpui/plugins/libscripts-plugin.so +%_libdir/gpui/plugins/libsecurity-plugin.so %_libdir/gpui/plugins/libsmb-storage-plugin.so diff --git a/.gitignore b/.gitignore index 7d527cca2..d67416102 100644 --- a/.gitignore +++ b/.gitignore @@ -86,5 +86,7 @@ src/plugins/cmtl/schema/*.cpp src/plugins/cmtl/schema/*.h src/plugins/cmtx/schema/*.cpp src/plugins/cmtx/schema/*.h +src/plugins/security/schema/*.cpp +src/plugins/security/schema/*.h *.translations.qrc src/core/version.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a61bff8d..0a1d2c9b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,10 @@ execute_process( OUTPUT_VARIABLE GPUI_GEAR_VERSION WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + string(REPLACE "." ";" GEAR_VERSION_LIST ${GPUI_GEAR_VERSION}) list(GET GEAR_VERSION_LIST 0 GPUI_VERSION_MAJOR) list(GET GEAR_VERSION_LIST 1 GPUI_VERSION_MINOR) diff --git a/src/io/CMakeLists.txt b/src/io/CMakeLists.txt index b2a8e511a..fc48a77a0 100644 --- a/src/io/CMakeLists.txt +++ b/src/io/CMakeLists.txt @@ -1,6 +1,8 @@ find_package(Qt5 COMPONENTS Core REQUIRED) set(HEADERS + basefile.h + basefile.inl genericfile.h genericfile.inl genericreader.h diff --git a/src/io/basefile.h b/src/io/basefile.h new file mode 100644 index 000000000..c048aee56 --- /dev/null +++ b/src/io/basefile.h @@ -0,0 +1,66 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2023 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#ifndef GPUI_BASEFILE_H +#define GPUI_BASEFILE_H + +#include "io.h" + +#include "genericfile.h" +#include "policyfileformat.h" + +#include + +namespace io { + template + class BaseFilePrivate; + + template + class GPUI_IO_EXPORT BaseFile : public GenericFile, PolicyFileFormat>> + { + public: + BaseFile(); + + ~BaseFile(); + + void add(std::shared_ptr resources); + + void remove(std::shared_ptr resources); + + std::vector> getAll(); + + size_t count(); + + std::shared_ptr get(const size_t index); + + private: + BaseFile(const BaseFile&) = delete; // copy ctor + BaseFile(BaseFile&&) = delete; // move ctor + BaseFile& operator=(const BaseFile&) = delete; // copy assignment + BaseFile& operator=(BaseFile&&) = delete; // move assignment + + private: + BaseFilePrivate* const d; + }; +} + +#include "basefile.inl" + +#endif // GPUI_BASEFILE_H diff --git a/src/io/basefile.inl b/src/io/basefile.inl new file mode 100644 index 000000000..cebb793ac --- /dev/null +++ b/src/io/basefile.inl @@ -0,0 +1,112 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2023 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#include + +namespace io +{ + +template +class BaseFilePrivate +{ +public: + std::vector> definitions = {}; +}; + +/*! + * \class BaseFile BaseFile.h + * \brief The BaseFile class represents a policy file. + * \ingroup io + * + * The BaseFile class provides a container for definitions. + */ +template +BaseFile::BaseFile() + : GenericFile>() + , d(new BaseFilePrivate()) +{} + +template +BaseFile::~BaseFile() +{ + delete d; +} + +/*! + * \brief BaseFile::addPolicyDefinitions Adds definitions to the file. + * \param policyDefinitions Policy definitions to add. + */ +template +void BaseFile::add(std::shared_ptr definitions) +{ + d->definitions.emplace_back(definitions); +} + +/*! + * \brief BaseFile::removePolicyDefinitions Removes policy definitions from the file. + * \param policyDefinitions Policy definitions to remove. + */ +template +void BaseFile::remove(std::shared_ptr definitions) +{ + d->definitions.erase(std::remove_if(d->definitions.begin(), + d->definitions.end(), + [definitions](std::shared_ptr currentPolicy) { + return currentPolicy == definitions; + })); +} + +/*! + * \brief BaseFile::getAllPolicyDefinitions Returns all definitions from the file. + * \return + */ +template +std::vector> BaseFile::getAll() +{ + return d->definitions; +} + +/*! + * \brief BaseFile::policyDefinitionsCount Return number of definitions in current file. + * \return Amount of policy definitions in current file. + */ +template +size_t BaseFile::count() +{ + return d->definitions.size(); +} + +/*! + * \brief BaseFile::getPolicyDefinitions Returns a definition by index. + * \param index Index of a definitions. + * \return If definitions are found than returns definitions otherwise retruns null pointer. + */ +template +std::shared_ptr BaseFile::get(const size_t index) +{ + if (index < d->definitions.size()) + { + return d->definitions[index]; + } + + return std::shared_ptr(nullptr); +} + +} // namespace io diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index 46c90129c..0151e13ee 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -25,6 +25,9 @@ add_subdirectory(ini) add_subdirectory(pol) add_subdirectory(preferences) add_subdirectory(reg) +add_subdirectory(sdml) +add_subdirectory(sdmx) add_subdirectory(scripts) +add_subdirectory(security) add_subdirectory(spol) add_subdirectory(storage) diff --git a/src/plugins/scripts/scriptstreemodel.cpp b/src/plugins/scripts/scriptstreemodel.cpp index 674b520ac..011407e95 100644 --- a/src/plugins/scripts/scriptstreemodel.cpp +++ b/src/plugins/scripts/scriptstreemodel.cpp @@ -86,7 +86,9 @@ void ScriptsTreeModel::populateModel() machineNamespace->setProperty(ScriptsFolderItem::CATEGORY, true); auto machineSystemSettings = insertItem(machineNamespace); + auto machineSystemUuid = QUuid("{123e4567-e89b-12d3-a456-426652340010}"); machineSystemSettings->setDisplayName(QObject::tr("System settings").toStdString()); + machineSystemSettings->setProperty(ScriptsFolderItem::NODE_ID, machineSystemUuid); machineSystemSettings->setProperty(ScriptsFolderItem::PARENT_ID, machineUuid); machineSystemSettings->setProperty(ScriptsFolderItem::HELP_MSG, QObject::tr("System settings for computer").toStdString()); @@ -110,7 +112,9 @@ void ScriptsTreeModel::populateModel() userNamespace->setProperty(ScriptsFolderItem::CATEGORY, true); auto userSystemSetting = insertItem(userNamespace); + auto userSystemUuid = QUuid("{123e4567-e89b-12d3-a456-426652340011}"); userSystemSetting->setDisplayName(QObject::tr("System settings").toStdString()); + userSystemSetting->setProperty(ScriptsFolderItem::NODE_ID, userSystemUuid); userSystemSetting->setProperty(ScriptsFolderItem::PARENT_ID, userUuid); userSystemSetting->setProperty(ScriptsFolderItem::HELP_MSG, QObject::tr("System settings for user").toStdString()); diff --git a/src/plugins/sdml/CMakeLists.txt b/src/plugins/sdml/CMakeLists.txt new file mode 100644 index 000000000..da9c07dd8 --- /dev/null +++ b/src/plugins/sdml/CMakeLists.txt @@ -0,0 +1,24 @@ +find_package(GPUI COMPONENTS core io REQUIRED) +include_directories(${GPUI_INCLUDE_DIRS}) + +find_package(Qt5 COMPONENTS Core REQUIRED) + +set(PLUGIN_NAME "sdml-plugin") + +set(HEADERS + sdmlformat.h +) + +set(SOURCES + sdmlformat.cpp + sdmlplugin.cpp +) + +set(SOURCES ${SOURCES} ${HEADERS}) + +add_gpui_plugin(${PLUGIN_NAME} ${SOURCES}) +target_link_libraries(${PLUGIN_NAME} Qt5::Core) +target_link_libraries(${PLUGIN_NAME} ${GPUI_LIBRARIES}) +target_link_libraries(${PLUGIN_NAME} policy-common) +target_link_libraries(${PLUGIN_NAME} security_static_xsd_library) +target_link_libraries(${PLUGIN_NAME} xerces-c) diff --git a/src/plugins/sdml/sdmlformat.cpp b/src/plugins/sdml/sdmlformat.cpp new file mode 100644 index 000000000..5cf9786de --- /dev/null +++ b/src/plugins/sdml/sdmlformat.cpp @@ -0,0 +1,474 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2023 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#include "sdmlformat.h" + +#include "../security/schema/security.h" + +#include "../security/model/presentation/securitypresentationresources.h" + +#include "../common/exceptionhandler.h" + +namespace gpui +{ + +template +inline void assign_if_exists(TOutput &output, const TInput &input) +{ + if (input.present()) + { + output = input.get(); + } +} + +class XsdCheckBoxAdapter : public security::CheckBox +{ +private: + typedef ::GroupPolicy::SecurityDefinitions::CheckBox CheckBox; + +public: + XsdCheckBoxAdapter(const CheckBox &widget) + : security::CheckBox() + { + this->defaultChecked = widget.defaultChecked(); + + assign_if_exists(this->postfix, widget.postfix()); + } + + static std::shared_ptr create(const CheckBox &widget) + { + return std::make_shared(widget); + } +}; + +class XsdComboBoxAdapter : public security::ComboBox +{ +private: + typedef ::GroupPolicy::SecurityDefinitions::ComboBox ComboBox; + +public: + XsdComboBoxAdapter(const ComboBox &widget) + : security::ComboBox() + { + this->refId = widget.refId(); + assign_if_exists(this->postfix, widget.postfix()); + + assign_if_exists(this->defaultValue, widget.defaultChecked()); + + for (const auto& suggestionText : widget.suggestion()) + { + this->suggestion.emplace_back(suggestionText); + } + } + + static std::shared_ptr create(const ComboBox &widget) + { + return std::make_shared(widget); + } +}; + +class XsdDecimalTextBoxAdapter : public security::DecimalTextBox +{ +private: + typedef ::GroupPolicy::SecurityDefinitions::DecimalTextBox DecimalTextBox; + +public: + XsdDecimalTextBoxAdapter(const DecimalTextBox &widget) + : security::DecimalTextBox() + { + this->spinBox = widget.spin(); + assign_if_exists(this->defaultValue, widget.defaultValue()); + assign_if_exists(this->spinStep, widget.spinStep()); + assign_if_exists(this->postfix, widget.postfix()); + } + + static std::shared_ptr create(const DecimalTextBox &widget) + { + return std::make_shared(widget); + } +}; + +class XsdDropdownListAdapter : public security::DropdownList +{ +private: + typedef ::GroupPolicy::SecurityDefinitions::DropdownList DropdownList; + +public: + XsdDropdownListAdapter(const DropdownList &widget) + : security::DropdownList() + { + Q_UNUSED(widget); + // TODO: Implement. + } + + static std::shared_ptr create(const DropdownList &widget) + { + return std::make_shared(widget); + } +}; + +class XsdListBoxAdapter : public security::ListBox +{ +private: + typedef ::GroupPolicy::SecurityDefinitions::ListBox ListBox; + +public: + XsdListBoxAdapter(const ListBox &widget) + : security::ListBox() + { + assign_if_exists(this->postfix, widget.postfix()); + } + + static std::shared_ptr create(const ListBox &widget) + { + return std::make_shared(widget); + } +}; + +class XsdLongDecimalTextBoxAdapter : public security::LongDecimalTextBox +{ +private: + typedef ::GroupPolicy::SecurityDefinitions::LongDecimalTextBox LongDecimalTextBox; + +public: + XsdLongDecimalTextBoxAdapter(const LongDecimalTextBox &widget) + : security::LongDecimalTextBox() + { + this->spinBox = widget.spin(); + assign_if_exists(this->defaultValue, widget.defaultValue()); + assign_if_exists(this->spinStep, widget.spinStep()); + assign_if_exists(this->postfix, widget.postfix()); + } + + static std::shared_ptr create(const LongDecimalTextBox &widget) + { + return std::make_shared(widget); + } +}; + +class XsdMultiTextBoxAdapter : public security::MultiTextBox +{ +private: + typedef ::GroupPolicy::SecurityDefinitions::MultiTextBox MultiTextBox; + +public: + XsdMultiTextBoxAdapter(const MultiTextBox &widget) + : security::MultiTextBox() + { +// this->defaultHeight = widget.defaultHeight(); + this->refId = widget.refId(); +// this->showAsDialog = widget.showAsDialog(); + } + + static std::shared_ptr create(const MultiTextBox &widget) + { + return std::make_shared(widget); + } +}; + +class XsdTextBoxAdapter : public security::TextBox +{ +private: + typedef ::GroupPolicy::SecurityDefinitions::TextBox TextBox; + +public: + XsdTextBoxAdapter(const TextBox &widget) + : security::TextBox() + { + if (widget.defaultValue().present()) + { + this->defaultValue = widget.defaultValue().get(); + } + this->label = widget.label(); + this->refId = widget.refId(); + } + + static std::shared_ptr create(const TextBox &widget) + { + return std::make_shared(widget); + } +}; + +class XsdTextAdapter : public security::Text +{ +private: + typedef ::GroupPolicy::SecurityDefinitions::TextElement TextElement; + +public: + XsdTextAdapter(const TextElement &widget) + : security::Text() + { + this->refId = widget.id(); + + // TODO: Implement. + } + + static std::shared_ptr create(const TextElement &string) + { + return std::make_shared(string); + } +}; + +class XsdLdapSearchDialogAdapter : public security::LdapSearchDialog +{ +private: + typedef ::GroupPolicy::SecurityDefinitions::LdapSearchDialog LdapSearchDialog; + +public: + XsdLdapSearchDialogAdapter(const LdapSearchDialog &widget) + : security::LdapSearchDialog() + { + this->refId = widget.refId(); + + assign_if_exists(this->postfix, widget.postfix()); + assign_if_exists(this->dn, widget.dn()); + assign_if_exists(this->filter, widget.filter()); + assign_if_exists(this->addLabel, widget.addLabel()); + assign_if_exists(this->removeLabel, widget.removeLabel()); + assign_if_exists(this->title, widget.title()); + } + + static std::shared_ptr create(const LdapSearchDialog &string) + { + return std::make_shared(string); + } +}; + +class XsdRadioButtonAdapter : public security::RadioButton +{ +private: + typedef ::GroupPolicy::SecurityDefinitions::RadioButton RadioButton; + +public: + XsdRadioButtonAdapter(const RadioButton& widget) + : security::RadioButton() + { + this->refId = widget.refId(); + + assign_if_exists(this->defaultChecked, widget.defaultChecked()); + } + + static std::shared_ptr create(const RadioButton &radioButton) + { + return std::make_shared(radioButton); + } +}; + +class XsdGroupBoxAdapter : public security::GroupBox +{ +private: + typedef ::GroupPolicy::SecurityDefinitions::GroupBox GroupBox; + +public: + XsdGroupBoxAdapter(const GroupBox& widget) + : security::GroupBox() + { + this->refId = widget.refId(); + + assign_if_exists(this->label, widget.label()); + + assign_if_exists(this->hasCheckBox, widget.hasCheckBox()); + + assign_if_exists(this->defaultChecked, widget.defaultChecked()); + + assign_if_exists(this->hasBorder, widget.hasBorder()); + } + + static std::shared_ptr create(const GroupBox &groupBox) + { + return std::make_shared(groupBox); + } +}; + +template +void adapt_widgets(const SequenceType &sequence, + std::map> &widgets) +{ + for (const auto &adaptee : sequence) + { + auto adaptedElement = AdapterType::create(adaptee); + + widgets[adaptee.refId()] = std::move(adaptedElement); + } +} + +class XsdResourcesAdapter : public security::SecurityPresentationResources +{ +private: + typedef ::GroupPolicy::SecurityDefinitions::SecurityPresentationResources SecurityPresentationResources; + +public: + XsdResourcesAdapter(const SecurityPresentationResources &resources) + : security::SecurityPresentationResources() + { + this->description = resources.description(); + this->displayName = resources.displayName(); + + if (resources.resources().stringTable().present()) + { + for (const auto &string : resources.resources().stringTable()->string()) + { + this->stringTable[string.id()] = string; + } + } + + if (resources.resources().presentationTable().present()) + { + for (const auto &presentation : resources.resources().presentationTable()->presentation()) + { + Q_UNUSED(presentation); + + auto securityPresentation = std::make_shared(); + auto &widgetsVector = securityPresentation->widgets; + + this->presentationTable.emplace_back(presentation.id(), securityPresentation); + + const xercesc::DOMNode *n = presentation._node(); + assert(n->getNodeType() == xercesc::DOMNode::ELEMENT_NODE); + const xercesc::DOMElement *re = static_cast(n); + + for (n = re->getFirstChild(); n != 0; n = n->getNextSibling()) + { + if (n->getNodeType() == xercesc::DOMNode::ELEMENT_NODE) + { + auto elementNode = static_cast(n); + auto elementType = QString::fromStdU16String(elementNode->getTagName()); + if (elementType.compare("checkBox") == 0) + { + auto checkBox = std::make_unique<::GroupPolicy::SecurityDefinitions::CheckBox>(*elementNode); + auto widget = XsdCheckBoxAdapter::create(*checkBox); + widgetsVector.emplace_back(checkBox->refId(), widget); + } + else if (elementType.compare("comboBox") == 0) + { + auto comboBox = std::make_unique<::GroupPolicy::SecurityDefinitions::ComboBox>(*elementNode); + auto widget = XsdComboBoxAdapter::create(*comboBox); + widgetsVector.emplace_back(comboBox->refId(), widget); + } + else if (elementType.compare("decimalTextBox") == 0) + { + auto decimalTextBox = std::make_unique<::GroupPolicy::SecurityDefinitions::DecimalTextBox>( + *elementNode); + auto widget = XsdDecimalTextBoxAdapter::create(*decimalTextBox); + widgetsVector.emplace_back(decimalTextBox->refId(), widget); + } + else if (elementType.compare("dropdownList") == 0) + { + auto dropdownList = std::make_unique<::GroupPolicy::SecurityDefinitions::DropdownList>( + *elementNode); + auto widget = XsdDropdownListAdapter::create(*dropdownList); +// widgetsVector.emplace_back(dropdownList->refId(), widget); + } + else if (elementType.compare("listBox") == 0) + { + auto listBox = std::make_unique<::GroupPolicy::SecurityDefinitions::ListBox>(*elementNode); + auto widget = XsdListBoxAdapter::create(*listBox); + widgetsVector.emplace_back(listBox->refId(), widget); + } + else if (elementType.compare("longDecimalTextBox") == 0) + { + auto longDecimalTextBox + = std::make_unique<::GroupPolicy::SecurityDefinitions::LongDecimalTextBox>(*elementNode); + auto widget = XsdLongDecimalTextBoxAdapter::create(*longDecimalTextBox); + widgetsVector.emplace_back(longDecimalTextBox->refId(), widget); + } + else if (elementType.compare("multiTextBox") == 0) + { + auto multiTextBox = std::make_unique<::GroupPolicy::SecurityDefinitions::MultiTextBox>( + *elementNode); + auto widget = XsdMultiTextBoxAdapter::create(*multiTextBox); + widgetsVector.emplace_back(multiTextBox->refId(), widget); + } + else if (elementType.compare("textBox") == 0) + { + auto textBox = std::make_unique<::GroupPolicy::SecurityDefinitions::TextBox>(*elementNode); + auto widget = XsdTextBoxAdapter::create(*textBox); + widgetsVector.emplace_back(textBox->refId(), widget); + } + else if (elementType.compare("text") == 0) + { + auto text = std::make_unique<::GroupPolicy::SecurityDefinitions::Comment>(*elementNode); + // TODO: Implement. + } + else if (elementType.compare("ldapSearchDialog") == 0) + { + auto ldapSearch = std::make_unique<::GroupPolicy::SecurityDefinitions::LdapSearchDialog>(*elementNode); + auto widget = XsdLdapSearchDialogAdapter::create(*ldapSearch); + widgetsVector.emplace_back(ldapSearch->refId(), widget); + } + else if (elementType.compare("radioButton") == 0) + { + auto radioButton = std::make_unique<::GroupPolicy::SecurityDefinitions::RadioButton>(*elementNode); + auto widget = XsdRadioButtonAdapter::create(*radioButton); + widgetsVector.emplace_back(radioButton->refId(), widget); + } + else if (elementType.compare("groupBox") == 0) + { + auto groupBox = std::make_unique<::GroupPolicy::SecurityDefinitions::GroupBox>(*elementNode); + auto widget = XsdGroupBoxAdapter::create(*groupBox); + widgetsVector.emplace_back(groupBox->refId(), widget); + } + } + } + } + } + } + + static std::shared_ptr create(const SecurityPresentationResources &resources) + { + return std::make_shared(resources); + } +}; + +SdmlFormat::SdmlFormat() + : io::PolicyFileFormat("sdml") +{ +} + +bool SdmlFormat::read(std::istream &input, SdmlFile *file) +{ + Q_UNUSED(input); + + std::unique_ptr<::GroupPolicy::SecurityDefinitions::SecurityPresentationResources> securityDefinitions; + auto operation = [&]() { + securityDefinitions = GroupPolicy::SecurityDefinitions::securityPresentationResources(input, + ::xsd::cxx::tree::flags::dont_validate + | ::xsd::cxx::tree::flags::keep_dom + | ::xsd::cxx::tree::flags::own_dom); + + auto securityPresentation = XsdResourcesAdapter::create(*securityDefinitions); + + file->add(securityPresentation); + }; + + auto errorHandler = [&](const std::string &error) { this->setErrorString(error); }; + + return ExceptionHandler::handleOperation(operation, errorHandler); +} + +bool SdmlFormat::write(std::ostream &output, SdmlFile *file) +{ + Q_UNUSED(output); + Q_UNUSED(file); + + return false; +} + +} diff --git a/src/plugins/sdml/sdmlformat.h b/src/plugins/sdml/sdmlformat.h new file mode 100644 index 000000000..a3e450afa --- /dev/null +++ b/src/plugins/sdml/sdmlformat.h @@ -0,0 +1,50 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2023 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#ifndef GPUI_SDML_FORMAT_H +#define GPUI_SDML_FORMAT_H + +#include "../../../src/core/common.h" + +#include "../../../src/io/basefile.h" +#include "../../../src/io/policyfileformat.h" +#include "../../../src/io/policyresourcesfile.h" + +namespace security +{ + class SecurityPresentationResources; +} + +namespace gpui +{ +typedef io::BaseFile SdmlFile; + +class GPUI_SYMBOL_EXPORT SdmlFormat : public io::PolicyFileFormat +{ +public: + SdmlFormat(); + + bool read(std::istream &input, SdmlFile *file) override; + + bool write(std::ostream &output, SdmlFile *file) override; +}; +} // namespace gpui + +#endif // GPUI_SDML_FORMAT_H diff --git a/src/plugins/sdml/sdmlplugin.cpp b/src/plugins/sdml/sdmlplugin.cpp new file mode 100644 index 000000000..5b352e19e --- /dev/null +++ b/src/plugins/sdml/sdmlplugin.cpp @@ -0,0 +1,38 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2023 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#include "../../core/plugin.h" + +#include "sdmlformat.h" + +namespace gpui +{ +class SdmlPlugin : public Plugin +{ +public: + SdmlPlugin() + : Plugin("sdml") + { + GPUI_REGISTER_PLUGIN_CLASS(typeid(io::PolicyFileFormat).name(), SdmlFormat); + } +}; +} // namespace gpui + +GPUI_EXPORT_PLUGIN(adml, gpui::SdmlPlugin) diff --git a/src/plugins/sdmx/CMakeLists.txt b/src/plugins/sdmx/CMakeLists.txt new file mode 100644 index 000000000..11a334c60 --- /dev/null +++ b/src/plugins/sdmx/CMakeLists.txt @@ -0,0 +1,24 @@ +find_package(GPUI COMPONENTS core io REQUIRED) +include_directories(${GPUI_INCLUDE_DIRS}) + +find_package(Qt5 COMPONENTS Core REQUIRED) + +set(PLUGIN_NAME "sdmx-plugin") + +set(HEADERS + sdmxformat.h +) + +set(SOURCES + sdmxformat.cpp + sdmxplugin.cpp +) + +set(SOURCES ${SOURCES} ${HEADERS}) + +add_gpui_plugin(${PLUGIN_NAME} ${SOURCES}) +target_link_libraries(${PLUGIN_NAME} Qt5::Core) +target_link_libraries(${PLUGIN_NAME} ${GPUI_LIBRARIES}) +target_link_libraries(${PLUGIN_NAME} policy-common) +target_link_libraries(${PLUGIN_NAME} security_static_xsd_library) +target_link_libraries(${PLUGIN_NAME} xerces-c) diff --git a/src/plugins/sdmx/sdmxformat.cpp b/src/plugins/sdmx/sdmxformat.cpp new file mode 100644 index 000000000..792a18dea --- /dev/null +++ b/src/plugins/sdmx/sdmxformat.cpp @@ -0,0 +1,352 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2023 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#include "sdmxformat.h" + +#include "../security/schema/security.h" +#include "../security/model/sdmx/securitydefinitions.h" + +#include "../common/exceptionhandler.h" + +namespace gpui +{ + +template +inline void assign_if_exists(TOutput &output, const TInput &input) +{ + if (input.present()) + { + output = input.get(); + } +} + +template +void adapter_base(security::SecurityElement *output, const ElementType &input) +{ + output->refId = input.id(); + + if (input.clientExtension().present()) + { + output->clientExtension = QUuid(input.clientExtension().get().c_str()); + } + + output->propertyName = input.propertyName(); +} + +template +void decimal_adapter_base(TOutput *output, const TInput &input) +{ + adapter_base(output, input); + + assign_if_exists(output->maxValue, input.maxValue()); + assign_if_exists(output->minValue, input.minValue()); + output->required = input.required(); + output->soft = input.soft(); + output->storeAsText = input.storeAsText(); + + output->propertyName = input.propertyName(); +} + +template +void adapt_elements(const SequenceType &sequence, std::vector> &elements) +{ + for (const auto &adaptee : sequence) + { + auto adaptedElement = AdapterType::create(adaptee); + + elements.push_back(std::move(adaptedElement)); + } +} + +class XsdBooleanElementAdapter : public security::BooleanElement +{ +private: + typedef ::GroupPolicy::SecurityDefinitions::BooleanElement BooleanElement; + +public: + XsdBooleanElementAdapter(const BooleanElement &element) + { + adapter_base(this, element); + + this->propertyName = element.propertyName(); + } + + static std::unique_ptr create(const BooleanElement &element) + { + return std::make_unique(element); + } +}; + +class XsdDecimalElementAdapter : public security::DecimalElement +{ +private: + typedef ::GroupPolicy::SecurityDefinitions::DecimalElement DecimalElement; + +public: + XsdDecimalElementAdapter(const DecimalElement &element) { decimal_adapter_base(this, element); } + + static std::unique_ptr create(const DecimalElement &element) + { + return std::make_unique(element); + } +}; + +class XsdEnumElementAdapter : public security::EnumerationElement +{ +private: + typedef ::GroupPolicy::SecurityDefinitions::EnumerationElement EnumElement; + +public: + XsdEnumElementAdapter(const EnumElement &element) + { + adapter_base(this, element); + + this->propertyName = element.propertyName(); + + this->required = element.required(); + +// for (auto &item : element.) +// { +// if (item.value().decimal().present()) +// { +// this->items.push_back( +// std::make_pair(item.displayName(), +// std::make_unique(item.value().decimal().get().value()))); +// } + +// if (item.value().longDecimal().present()) +// { +// this->items.push_back(std::make_pair(item.displayName(), +// std::make_unique( +// item.value().longDecimal().get().value()))); +// } + +// if (item.value().string().present()) +// { +// this->items.push_back( +// std::make_pair(item.displayName(), +// std::make_unique(item.value().string().get()))); +// } +// } + } + + static std::unique_ptr create(const EnumElement &element) + { + return std::make_unique(element); + } +}; + +class XsdListElementAdapter : public security::ListElement +{ +private: + typedef ::GroupPolicy::SecurityDefinitions::ListElement ListElement; + +public: + XsdListElementAdapter(const ListElement &element) + { + adapter_base(this, element); + + assign_if_exists(this->valuePrefix, element.valuePrefix()); + + this->additive = element.additive(); + + this->expandable = element.expandable(); + + this->explicitValue = element.explicitValue(); + } + + static std::unique_ptr create(const ListElement &element) + { + return std::make_unique(element); + } +}; + +class XsdTextElementAdapter : public security::TextElement +{ +private: + typedef ::GroupPolicy::SecurityDefinitions::TextElement TextElement; + +public: + XsdTextElementAdapter(const TextElement &element) + { + adapter_base(this, element); + + this->propertyName = element.propertyName(); + + this->required = element.required(); + + this->maxLength = element.maxLength(); + + this->soft = element.soft(); + } + + static std::unique_ptr create(const TextElement &element) + { + return std::make_unique(element); + } +}; + +class XsdLongDecimalElementAdapter : public security::LongDecimalElement +{ +private: + typedef ::GroupPolicy::SecurityDefinitions::LongDecimalElement LongDecimalElement; + +public: + XsdLongDecimalElementAdapter(const LongDecimalElement &element) { decimal_adapter_base(this, element); } + + static std::unique_ptr create(const LongDecimalElement &element) + { + return std::make_unique(element); + } +}; + +class XsdMultiTextElementAdapter : public security::MultiTextElement +{ +private: + typedef ::GroupPolicy::SecurityDefinitions::MultiTextElement MultiTextElement; + +public: + XsdMultiTextElementAdapter(const MultiTextElement &element) + { + adapter_base(this, element); + + this->propertyName = element.propertyName(); + } + + static std::unique_ptr create(const MultiTextElement &element) + { + return std::make_unique(element); + } +}; + +class XsdSecurityAdapter : public security::SecurityDefinition +{ +private: + typedef ::GroupPolicy::SecurityDefinitions::SecurityDefinition SecurityDefinition; + +public: + XsdSecurityAdapter(const SecurityDefinition &definition) + : security::SecurityDefinition() + { + this->name = definition.name(); + this->displayName = definition.displayName(); + + assign_if_exists(this->explainText, definition.explainText()); + + if (definition.parentCategory().present()) + { + this->parentCategory = definition.parentCategory()->ref(); + } + + std::string propertyNameLocal{}; + std::string sectionNameLocal = definition.sectionName(); + + assign_if_exists(propertyNameLocal, definition.propertyName()); + + std::string presentationName{}; + assign_if_exists(presentationName, definition.presentation()); + + this->presentation = std::make_unique(presentationName); + this->propertyName = std::make_unique(propertyNameLocal); + this->sectionName = std::make_unique(sectionNameLocal); + } + + static std::shared_ptr create(const SecurityDefinition &element) + { + return std::make_shared(element); + } +}; + +class XsdSecurityDefinitionsAdapter : public security::SecurityDefinitions +{ +private: + typedef ::GroupPolicy::SecurityDefinitions::SecurityDefinitions SecurityDefinitions; + +public: + XsdSecurityDefinitionsAdapter(const SecurityDefinitions &definitions) + : security::SecurityDefinitions() + { + assign_if_exists(this->revision, definitions.revision()); + assign_if_exists(this->schemaVersion, definitions.schemaVersion()); + + for (const auto& securityElement : definitions.security()->securityDefinition()) + { + auto ourSecurity = XsdSecurityAdapter::create(securityElement); + + if (securityElement.elements().present()) + { + adapt_elements(securityElement.elements()->boolean(), ourSecurity->elements); + + adapt_elements(securityElement.elements()->decimal(), ourSecurity->elements); + + adapt_elements(securityElement.elements()->enum_(), ourSecurity->elements); + + adapt_elements(securityElement.elements()->text(), ourSecurity->elements); + + adapt_elements(securityElement.elements()->list(), ourSecurity->elements); + + adapt_elements(securityElement.elements()->longDecimal(), ourSecurity->elements); + + adapt_elements(securityElement.elements()->multiText(), ourSecurity->elements); + } + + this->security.push_back(ourSecurity); + } + } + + static std::shared_ptr create(const SecurityDefinitions &element) + { + return std::make_shared(element); + } +}; + +SdmxFormat::SdmxFormat() + : io::PolicyFileFormat("sdmx") +{ +} + +bool SdmxFormat::read(std::istream &input, SdmxFile *file) +{ + Q_UNUSED(file); + + std::unique_ptr<::GroupPolicy::SecurityDefinitions::SecurityDefinitions> securityDefinitions; + auto operation = [&]() { + securityDefinitions = GroupPolicy::SecurityDefinitions::securityDefinitions(input, + ::xsd::cxx::tree::flags::dont_validate); + + auto security = XsdSecurityDefinitionsAdapter::create(*securityDefinitions); + + file->add(security); + }; + + auto errorHandler = [&](const std::string &error) { this->setErrorString(error); }; + + return ExceptionHandler::handleOperation(operation, errorHandler); +} + +bool SdmxFormat::write(std::ostream &output, SdmxFile *file) +{ + Q_UNUSED(output); + Q_UNUSED(file); + + return false; +} + +} diff --git a/src/plugins/sdmx/sdmxformat.h b/src/plugins/sdmx/sdmxformat.h new file mode 100644 index 000000000..41ca48ae9 --- /dev/null +++ b/src/plugins/sdmx/sdmxformat.h @@ -0,0 +1,50 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2023 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#ifndef GPUI_SDMX_FORMAT_H +#define GPUI_SDMX_FORMAT_H + +#include "../../../src/core/common.h" + +#include "../../../src/io/basefile.h" +#include "../../../src/io/policyfileformat.h" +#include "../../../src/io/policyresourcesfile.h" + +namespace security +{ + class SecurityDefinitions; +} + +namespace gpui +{ +typedef io::BaseFile SdmxFile; + +class GPUI_SYMBOL_EXPORT SdmxFormat : public io::PolicyFileFormat +{ +public: + SdmxFormat(); + + bool read(std::istream &input, SdmxFile *file) override; + + bool write(std::ostream &output, SdmxFile *file) override; +}; +} // namespace gpui + +#endif // GPUI_SDMX_FORMAT_H diff --git a/src/plugins/sdmx/sdmxplugin.cpp b/src/plugins/sdmx/sdmxplugin.cpp new file mode 100644 index 000000000..8ff3b3ea4 --- /dev/null +++ b/src/plugins/sdmx/sdmxplugin.cpp @@ -0,0 +1,38 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2023 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#include "../../core/plugin.h" + +#include "sdmxformat.h" + +namespace gpui +{ +class SdmxPlugin : public Plugin +{ +public: + SdmxPlugin() + : Plugin("sdmx") + { + GPUI_REGISTER_PLUGIN_CLASS(typeid(io::PolicyFileFormat).name(), SdmxFormat); + } +}; +} // namespace gpui + +GPUI_EXPORT_PLUGIN(adml, gpui::SdmxPlugin) diff --git a/src/plugins/security/CMakeLists.txt b/src/plugins/security/CMakeLists.txt new file mode 100644 index 000000000..71eaf6329 --- /dev/null +++ b/src/plugins/security/CMakeLists.txt @@ -0,0 +1,109 @@ +find_package(Qt5 COMPONENTS Widgets Qml LinguistTools REQUIRED) + +find_package(GPUI COMPONENTS core io REQUIRED) + +set(PLUGIN_NAME security-plugin) +set(PLUGIN_STATIC_LIBRARY security_static) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTOUIC ON) + +include_directories(${CMAKE_SOURCE_DIR}/src) + +add_subdirectory(schema) + +set(HEADERS + model/bundle/securitybundle.h + model/presentation/category.h + model/presentation/checkbox.h + model/presentation/combobox.h + model/presentation/comment.h + model/presentation/dataelementcontent.h + model/presentation/dataelement.h + model/presentation/decimaltextbox.h + model/presentation/dropdownlist.h + model/presentation/groupbox.h + model/presentation/ldapsearchdialog.h + model/presentation/listbox.h + model/presentation/longdecimaltextbox.h + model/presentation/multitextbox.h + model/presentation/presentationelements.h + model/presentation/radiobutton.h + model/presentation/securitydescriptoreditor.h + model/presentation/securitypresentation.h + model/presentation/securitypresentationresources.h + model/presentation/textbox.h + model/presentation/text.h + model/sdmx/booleanelement.h + model/sdmx/decimalelement.h + model/sdmx/decimaltype.h + model/sdmx/enumerationelement.h + model/sdmx/listelement.h + model/sdmx/longdecimalelement.h + model/sdmx/longdecimaltype.h + model/sdmx/multitextelement.h + model/sdmx/securitydefinition.h + model/sdmx/securitydefinitions.h + model/sdmx/securityelement.h + model/sdmx/securityelements.h + model/sdmx/security.h + model/sdmx/securityitem.h + model/sdmx/securityvalue.h + model/sdmx/securityvaluelist.h + model/sdmx/textelement.h + model/ui/presentationbuilder.h + model/ui/securityproxymodel.h + model/ui/securitywidget.h + model/ui/ldapsearchlistwidget.h + model/ui/browseldapdialog.h +) + +set(SOURCES + model/bundle/securitybundle.cpp + model/ui/presentationbuilder.cpp + model/ui/securityproxymodel.cpp + model/ui/securitywidget.cpp + model/ui/ldapsearchlistwidget.cpp + model/ui/browseldapdialog.cpp +) + +set(UI_FORMS + model/ui/securitywidget.ui + model/ui/ldapsearchlistwidget.ui + model/ui/browseldapdialog.ui +) + +set(PLUGIN_HEADERS + securitysnapin.h +) + +set(PLUGIN_SOURCES + securityplugin.cpp + securitysnapin.cpp +) + +file(GLOB_RECURSE TS_FILES ${CMAKE_CURRENT_SOURCE_DIR} *.ts) + +set_source_files_properties(${TS_FILES} PROPERTIES OUTPUT_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}) + +add_translation(QM_FILES ${TS_FILES}) + +add_translation_resource(RESOURCES_SRC "security" ${QM_FILES}) + +qt5_add_resources(LIB_RESOURCES ${RESOURCES_SRC} ${ICON_RESOURCES}) + +set(PLUGIN_SOURCES ${PLUGIN_SOURCES} ${PLUGIN_HEADERS}) + +set(SOURCES ${SOURCES} ${HEADERS} ${UI_FORMS}) + +add_library(${PLUGIN_STATIC_LIBRARY} STATIC ${SOURCES}) +target_link_libraries(${PLUGIN_STATIC_LIBRARY} Qt5::Core Qt5::Widgets) +target_link_libraries(${PLUGIN_STATIC_LIBRARY} ${GPUI_LIBRARIES}) + +target_link_libraries(${PLUGIN_STATIC_LIBRARY} security_static_xsd_library) +target_link_libraries(${PLUGIN_STATIC_LIBRARY} xerces-c) + +add_gpui_plugin(${PLUGIN_NAME} ${PLUGIN_SOURCES} ${LIB_RESOURCES}) +target_link_libraries(${PLUGIN_NAME} ${PLUGIN_STATIC_LIBRARY}) diff --git a/src/plugins/security/model/bundle/securitybundle.cpp b/src/plugins/security/model/bundle/securitybundle.cpp new file mode 100644 index 000000000..bf09d1cbb --- /dev/null +++ b/src/plugins/security/model/bundle/securitybundle.cpp @@ -0,0 +1,569 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2023 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#include "securitybundle.h" + +#include +#include +#include +#include + +#include "../administrative_templates/bundle/itemtype.h" +#include "../administrative_templates/bundle/policyroles.h" + +#include "../sdmx/security.h" + +#include "../../../src/core/pluginstorage.h" + +#include "../../../src/plugins/sdml/sdmlformat.h" +#include "../../../src/plugins/sdmx/sdmxformat.h" + +#include +#include +#include + +#include "../sdmx/securitydefinitions.h" +#include "../presentation/securitypresentationresources.h" +#include "../presentation/securitypresentation.h" + +using namespace model::bundle; + +namespace security +{ + +struct CategoryStorage +{ + QStandardItem *machineItem = nullptr; + QStandardItem *userItem = nullptr; + Category category = {}; + std::string fileName = {}; +}; + +struct SecurityStorage +{ + SecurityType type = security::SecurityType::Machine; + std::string category = {}; + std::string fileName = {}; + QStandardItem *item = nullptr; +}; + +class SecurityBundlePrivate +{ +public: + std::unique_ptr treeModel = nullptr; + QStandardItem *rootMachineItem = nullptr; + QStandardItem *rootUserItem = nullptr; + std::vector items = {}; + std::map supportedOnMap = {}; + QStringList languageDirectoryPaths = {}; + std::vector unassignedItems = {}; + std::map categoryItemMap = {}; +}; + +template +std::unique_ptr loadPolicies(const QString &pluginName, const QFileInfo &fileName) +{ + std::unique_ptr policies; + + TFormat *format = gpui::PluginStorage::instance()->createPluginClass(pluginName); + + if (!format) + { + return policies; + } + + std::ifstream file; + + file.open(fileName.absoluteFilePath().toStdString(), std::ifstream::in); + + if (file.good()) + { + policies = std::make_unique(); + + if (!format->read(file, policies.get())) + { + qWarning() << fileName.fileName() + " " + QString::fromStdString(format->getErrorString()); + } + } + + file.close(); + + delete format; + + return policies; +} + +QString SecurityBundle::constructFileName(const QFileInfo &fileName) +{ + QString sdmlFileName = fileName.fileName(); + sdmlFileName.replace(sdmlFileName.length() - 4, 4, "sdml"); + for (const auto &path : d->languageDirectoryPaths) + { + QDir admlDir(path); + if (admlDir.isEmpty()) + { + continue; + } + + for (const auto &file : admlDir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot)) + { + if (file.fileName().toLower().compare(sdmlFileName.toLower()) == 0) + { + return file.absoluteFilePath(); + } + } + } + + return sdmlFileName; +} + +std::string findStringById(const std::string &id, const std::unique_ptr &resource) +{ + if (id.length() < 10 || id.compare(0, 9, "$(string.") != 0) + { + return id; + } + std::string pureId = id.substr(9, id.length() - 10); + for (auto ¤tResource : resource->getAll()) + { + auto search = currentResource->stringTable.find(pureId); + if (search != currentResource->stringTable.end()) + { + return search->second; + } + } + + return pureId; +} + +std::shared_ptr findPresentationById( + const std::string &id, const std::unique_ptr &resource) +{ + if (id.length() < 16 || id.compare(0, 15, "$(presentation.") != 0) + { + return nullptr; + } + std::string pureId = id.substr(15, id.length() - 16); + for (auto ¤tResource : resource->getAll()) + { + auto &table = currentResource->presentationTable; + + auto search = std::find_if(table.begin(), table.end(), [pureId](auto& element) + { + return pureId.compare(element.first) == 0; + }); + + if (search != table.end()) + { + return search->second; + } + } + + return nullptr; +} + +void handlePresentation(const std::shared_ptr &presentation, + const std::shared_ptr &policy, + const std::unique_ptr<::gpui::SdmlFile> &policyResources) +{ + Q_UNUSED(presentation); + Q_UNUSED(policy); + Q_UNUSED(policyResources); + // TODO: Implement. +} + +SecurityBundle::SecurityBundle() + : d(new SecurityBundlePrivate()) +{ +} + +SecurityBundle::~SecurityBundle() +{ + delete d; +} + +std::unique_ptr SecurityBundle::loadFolder(const std::string &path, const std::string &language) +{ + d->treeModel = std::make_unique(); + + QStandardItem *rootItem = d->treeModel->invisibleRootItem(); + QStandardItem *visibleRootItem = createItem(QObject::tr("[Local Group Policy]"), + "text-x-generic-template", + QObject::tr("Local group policies"), + ItemType::ITEM_TYPE_CATEGORY, + SecurityType::Both, + false); + visibleRootItem->setData(QUuid("{123e4567-e89b-12d3-a456-426652340003}"), model::bundle::CURRENT_UUID); + + rootItem->appendRow(visibleRootItem); + + QStandardItem *machineItem = createItem(QObject::tr("Machine"), + "computer", + QObject::tr("Machine level policies"), + ItemType::ITEM_TYPE_CATEGORY, + SecurityType::Machine, + false); + machineItem->setData(QUuid("{123e4567-e89b-12d3-a456-426652340003}"), model::bundle::PARENT_UUID); + machineItem->setData(QUuid("{123e4567-e89b-12d3-a456-426652340000}"), model::bundle::CURRENT_UUID); + QStandardItem *machineSystemSettingsItem = createItem(QObject::tr("System settings"), + "folder", + QObject::tr("System settings for computer"), + ItemType::ITEM_TYPE_CATEGORY, + SecurityType::Machine, + false); + machineSystemSettingsItem->setData(QUuid("{123e4567-e89b-12d3-a456-426652340000}"), model::bundle::PARENT_UUID); + machineSystemSettingsItem->setData(QUuid("{123e4567-e89b-12d3-a456-426652340010}"), model::bundle::CURRENT_UUID); + machineItem->appendRow(machineSystemSettingsItem); + d->rootMachineItem = createItem(QObject::tr("Security Settings"), + "folder", + QObject::tr("Machine level security settings"), + ItemType::ITEM_TYPE_CATEGORY, + SecurityType::User, + false); + machineSystemSettingsItem->appendRow(d->rootMachineItem); + + QStandardItem *userItem = createItem(QObject::tr("User"), + "user-home", + QObject::tr("User level policies"), + ItemType::ITEM_TYPE_CATEGORY, + SecurityType::User, + false); + userItem->setData(QUuid("{123e4567-e89b-12d3-a456-426652340003}"), model::bundle::PARENT_UUID); + userItem->setData(QUuid("{123e4567-e89b-12d3-a456-426652340001}"), model::bundle::CURRENT_UUID); + QStandardItem *userSystemSettingsItem = createItem(QObject::tr("System settings"), + "folder", + QObject::tr("System settings for user"), + ItemType::ITEM_TYPE_CATEGORY, + SecurityType::User, + false); + userSystemSettingsItem->setData(QUuid("{123e4567-e89b-12d3-a456-426652340001}"), model::bundle::PARENT_UUID); + userSystemSettingsItem->setData(QUuid("{123e4567-e89b-12d3-a456-426652340011}"), model::bundle::CURRENT_UUID); + userItem->appendRow(userSystemSettingsItem); + d->rootUserItem = createItem(QObject::tr("Security Settings"), + "folder", + QObject::tr("User level security settings"), + ItemType::ITEM_TYPE_CATEGORY, + SecurityType::User, + false); + userSystemSettingsItem->appendRow(d->rootUserItem); + + visibleRootItem->appendRow(machineItem); + visibleRootItem->appendRow(userItem); + + const QDir dir(path.c_str()); + const QFileInfoList files = dir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot); + const QFileInfoList directories = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); + + const QString qLanguage = QString::fromStdString(language).toLower(); + + d->languageDirectoryPaths.clear(); + + for (const QFileInfo &subDir : directories) + { + if (subDir.fileName().toLower().endsWith(qLanguage)) + { + d->languageDirectoryPaths.append(subDir.absoluteFilePath()); + } + } + + for (const QFileInfo &file : files) + { + if (file.fileName().toLower().endsWith(".sdmx")) + { + loadSdmxAndSdml(file); + } + } + + rearrangeTreeItems(); + assignSupportedOn(); + + removeEmptyItems(); + + return std::move(d->treeModel); +} + +bool SecurityBundle::loadSdmxAndSdml(const QFileInfo &sdmxFileName) +{ + auto securityDefinitions + = loadPolicies>("sdmx", sdmxFileName); + if (!securityDefinitions.get()) + { + return false; + } + + QString admlFileName = constructFileName(sdmxFileName); + auto policyResources + = loadPolicies<::gpui::SdmlFile, io::PolicyFileFormat<::gpui::SdmlFile>>("sdml", admlFileName); + if (!policyResources.get()) + { + return false; + } + + std::string fileName = sdmxFileName.fileName().toStdString(); + + for (auto &definition : securityDefinitions->getAll()) + { + for (auto &category : definition->categories) + { + auto categoryName = category->name + "." + fileName; + + QString displayName = QString::fromStdString(findStringById(category->displayName, policyResources)); + QString explainText = QString::fromStdString(findStringById(category->explainText, policyResources)); + + d->categoryItemMap[categoryName].machineItem = createItem(displayName, + "folder", + explainText, + ItemType::ITEM_TYPE_CATEGORY, + SecurityType::Machine, + false); + d->categoryItemMap[categoryName].userItem = createItem(displayName, + "folder", + explainText, + ItemType::ITEM_TYPE_CATEGORY, + SecurityType::User, + false); + d->categoryItemMap[categoryName].category = *category; + d->categoryItemMap[categoryName].fileName = fileName; + + d->categoryItemMap[category->name].machineItem = d->categoryItemMap[categoryName].machineItem; + d->categoryItemMap[category->name].userItem = d->categoryItemMap[categoryName].userItem; + + if (category->parentCategory.size() == 0) + { + d->rootUserItem->appendRow(d->categoryItemMap[categoryName].userItem); + d->rootMachineItem->appendRow(d->categoryItemMap[categoryName].machineItem); + } + } + + for (auto &policy : definition->security) + { + + QString displayName = QString::fromStdString(findStringById(policy->displayName, policyResources)); + QString explainText = QString::fromStdString(findStringById(policy->explainText, policyResources)); + + auto policyItem = createItem(displayName, + "text-x-generic", + explainText, + ItemType::ITEM_TYPE_POLICY, + policy->securityType, + false); + + SecurityStorage container; + container.category = policy->parentCategory; + container.item = policyItem; + container.type = policy->securityType; + container.fileName = sdmxFileName.fileName().toStdString(); + + if (policy->presentation) + { + auto presentation = findPresentationById(*policy->presentation.get(), policyResources); + if (presentation) + { + policyItem->setData(QVariant::fromValue(presentation), PolicyRoles::PRESENTATION); + handlePresentation(presentation, policy, policyResources); + } + } + + policyItem->setData(QVariant::fromValue(policy), PolicyRoles::POLICY); + + d->unassignedItems.push_back(container); + } + } + + return true; +} + +void SecurityBundle::rearrangeTreeItems() +{ + for (const auto &entry : d->categoryItemMap) + { + assignParentCategory(entry.second.category.parentCategory, + entry.second.machineItem, + entry.second.userItem, + entry.second.fileName); + } + + for (const auto &item : d->unassignedItems) + { + if (item.type == SecurityType::User) + { + assignParentCategory(item.category, nullptr, item.item, item.fileName); + } + else if (item.type == SecurityType::Machine) + { + assignParentCategory(item.category, item.item, nullptr, item.fileName); + } + else + { + item.item->setData(static_cast(SecurityType::Machine), PolicyRoles::POLICY_TYPE); + QStandardItem *copyItem = createItem(item.item->text(), + "text-x-generic", + item.item->data(PolicyRoles::EXPLAIN_TEXT).value(), + ItemType::ITEM_TYPE_POLICY, + SecurityType::User, + true); + copyItem->setData(item.item->data(PolicyRoles::SUPPORTED_ON), PolicyRoles::SUPPORTED_ON); + copyItem->setData(item.item->data(PolicyRoles::PRESENTATION), PolicyRoles::PRESENTATION); + copyItem->setData(item.item->data(PolicyRoles::POLICY), PolicyRoles::POLICY); + assignParentCategory(item.category, item.item, copyItem, item.fileName); + } + } +} + +void SecurityBundle::assignParentCategory(const std::string &rawCategory, + QStandardItem *machineItem, + QStandardItem *userItem, + const std::string &fileName) +{ + std::string parentCategory = rawCategory; + std::string::size_type position = parentCategory.find(':'); + if (position != std::string::npos) + { + parentCategory = parentCategory.substr(position + 1); + } + + std::string parentCategoryWithFilename = parentCategory + "." + fileName; + + auto search = d->categoryItemMap.find(parentCategoryWithFilename); + if (search != d->categoryItemMap.end()) + { + if (machineItem) + { + if (!machineItem->data(PolicyRoles::POLICY_WIDGET + 1).value()) + { + search->second.machineItem->appendRow(machineItem); + machineItem->setData(true, PolicyRoles::POLICY_WIDGET + 1); + } + } + if (userItem) + { + if (!userItem->data(PolicyRoles::POLICY_WIDGET + 1).value()) + { + search->second.userItem->appendRow(userItem); + userItem->setData(true, PolicyRoles::POLICY_WIDGET + 1); + } + } + } + else if ((search = d->categoryItemMap.find(parentCategory)) != d->categoryItemMap.end()) + { + if (machineItem) + { + if (!machineItem->data(PolicyRoles::POLICY_WIDGET + 1).value()) + { + search->second.machineItem->appendRow(machineItem); + machineItem->setData(true, PolicyRoles::POLICY_WIDGET + 1); + } + } + if (userItem) + { + if (!userItem->data(PolicyRoles::POLICY_WIDGET + 1).value()) + { + search->second.userItem->appendRow(userItem); + userItem->setData(true, PolicyRoles::POLICY_WIDGET + 1); + } + } + } + else if (rawCategory.size() > 0) + { + qWarning() << "Unable to find parent category: " << rawCategory.c_str() << fileName.c_str(); + if (machineItem) + { + if (!machineItem->data(PolicyRoles::POLICY_WIDGET + 1).value()) + { + d->rootMachineItem->appendRow(machineItem); + machineItem->setData(true, PolicyRoles::POLICY_WIDGET + 1); + } + } + + if (userItem) + { + if (!userItem->data(PolicyRoles::POLICY_WIDGET + 1).value()) + { + d->rootUserItem->appendRow(userItem); + userItem->setData(true, PolicyRoles::POLICY_WIDGET + 1); + } + } + } +} + +QStandardItem *SecurityBundle::createItem(const QString &displayName, + const QString &iconName, + const QString &explainText, + const uint itemType, + const SecurityType securityType, + const bool alreadyInserted) +{ + QStandardItem *categoryItem = new QStandardItem(displayName.trimmed()); + categoryItem->setIcon(QIcon::fromTheme(iconName)); + categoryItem->setFlags(categoryItem->flags() & (~Qt::ItemIsEditable)); + categoryItem->setData(explainText, PolicyRoles::EXPLAIN_TEXT); + categoryItem->setData(itemType, PolicyRoles::ITEM_TYPE); + categoryItem->setData(static_cast(securityType), PolicyRoles::POLICY_TYPE); + categoryItem->setData(alreadyInserted, PolicyRoles::POLICY_WIDGET + 1); + + d->items.push_back(categoryItem); + + return categoryItem; +} + +void SecurityBundle::assignSupportedOn() +{ +} + +void SecurityBundle::removeEmptyItems() +{ + iterateModelAndRemoveEmptyFolders(d->treeModel.get(), d->rootMachineItem->index()); + iterateModelAndRemoveEmptyFolders(d->treeModel.get(), d->rootUserItem->index()); +} + +void SecurityBundle::iterateModelAndRemoveEmptyFolders(QAbstractItemModel *model, + const QModelIndex &parent) +{ + for (int r = 0; r < model->rowCount(parent); ++r) + { + QModelIndex index = model->index(r, 0, parent); + QVariant data = model->data(index, PolicyRoles::ITEM_TYPE); + + qDebug() << "Folder " << model->data(index) << " has children: " << model->hasChildren(index) + << " type: " << data; + + if (model->hasChildren(index)) + { + iterateModelAndRemoveEmptyFolders(model, index); + } + else + { + if (data == 0) + { + qDebug() << "Deleted folder " << model->data(index); + + model->removeRow(index.row(), index.parent()); + + iterateModelAndRemoveEmptyFolders(model, index.parent()); + } + } + } +} + +} + +Q_DECLARE_METATYPE(std::shared_ptr<::security::SecurityPresentation>) +Q_DECLARE_METATYPE(std::shared_ptr<::security::SecurityDefinition>) + diff --git a/src/plugins/security/model/bundle/securitybundle.h b/src/plugins/security/model/bundle/securitybundle.h new file mode 100644 index 000000000..e427b7476 --- /dev/null +++ b/src/plugins/security/model/bundle/securitybundle.h @@ -0,0 +1,86 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2023 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#ifndef GPUI_SECURITY_BUNDLE_H +#define GPUI_SECURITY_BUNDLE_H + +#include +#include + +#include "../sdmx/security.h" + +class QFileInfo; +class QString; +class QStandardItem; +class QStandardItemModel; +class QAbstractItemModel; +class QModelIndex; + +namespace security +{ + +class SecurityBundlePrivate; + +class SecurityBundle +{ +public: + SecurityBundle(); + ~SecurityBundle(); + + std::unique_ptr loadFolder(const std::string &path, const std::string &language); + +private: + SecurityBundle(const SecurityBundle &) = delete; // copy ctor + SecurityBundle(SecurityBundle &&) = delete; // move ctor + SecurityBundle &operator=(const SecurityBundle &) = delete; // copy assignment + SecurityBundle &operator=(SecurityBundle &&) = delete; // move assignment + +private: + SecurityBundlePrivate *d { nullptr }; + +private: + bool loadSdmxAndSdml(const QFileInfo &sdmxFileName); + + QString constructFileName(const QFileInfo &fileName); + + + void rearrangeTreeItems(); + void assignParentCategory(const std::string &rawCategory, + QStandardItem *machineItem, + QStandardItem *userItem, + const std::string &fileName); + + QStandardItem *createItem(const QString &displayName, + const QString &iconName, + const QString &explainText, + const uint itemType, + const SecurityType securityType, + const bool alreadyInserted); + + void assignSupportedOn(); + + void removeEmptyItems(); + + void iterateModelAndRemoveEmptyFolders(QAbstractItemModel *model, const QModelIndex &parent); +}; + +} // namespace security + +#endif // GPUI_SECURITY_BUNDLE_H diff --git a/src/plugins/security/model/presentation/category.h b/src/plugins/security/model/presentation/category.h new file mode 100644 index 000000000..dfea87610 --- /dev/null +++ b/src/plugins/security/model/presentation/category.h @@ -0,0 +1,73 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_CATEGORY_H +#define SECURITY_CATEGORY_H + +#include +#include + +namespace security +{ + +/*! + * \class Category + * \brief A grouping of security definitions. + * + * \ingroup model + * \ingroup presentation + */ +class Category +{ +public: + /*! + * \brief name Specifies a logical name to use for a specific supported application and revision. + */ + std::string name{}; + + /*! + * \brief displayName The reference to the category text string located in the string table of the .sdml file. + */ + std::string displayName{}; + + /*! + * \brief keywords Contains index words that could be used to search for elements. + */ + std::vector keywords{}; + + /*! + * \brief seeAlso Reference to another element that may be related. + */ + std::vector seeAlso{}; + + /*! + * \brief explainText Explain or Help text associated with a specific category. + */ + std::string explainText{}; + + /*! + * \brief parentCategory Reference to parent of the current category. + */ + std::string parentCategory{}; +}; + +} // of namespace security + +#endif // SECURITY_CATEGORY_H diff --git a/src/plugins/security/model/presentation/checkbox.h b/src/plugins/security/model/presentation/checkbox.h new file mode 100644 index 000000000..43e4f429e --- /dev/null +++ b/src/plugins/security/model/presentation/checkbox.h @@ -0,0 +1,48 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_CHECKBOX_H +#define SECURITY_CHECKBOX_H + +#include "dataelementcontent.h" + +namespace security +{ + +/*! + * \class CheckBox + * \brief Represents a checkbox display element.\nCan be associated with a BooleanElement. + * + * \ingroup security + * \ingroup presentation + */ +class CheckBox: public DataElementContent +{ +public: + + /*! + * \brief If checkbox should be initially checked upon creation. + */ + bool defaultChecked { false }; +}; + +} // of namespace security + +#endif // SECURITY_CHECKBOX_H diff --git a/src/plugins/security/model/presentation/combobox.h b/src/plugins/security/model/presentation/combobox.h new file mode 100644 index 000000000..4ea22dc1a --- /dev/null +++ b/src/plugins/security/model/presentation/combobox.h @@ -0,0 +1,66 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_COMBOBOX_H +#define SECURITY_COMBOBOX_H + +#include "dataelementcontent.h" + +#include +#include + +namespace security +{ + +/*! + \class ComboBox + * \brief Represents a combobox display element with default/suggested entries. + * + * \ingroup security + * \ingroup presentation + */ +class ComboBox: public DataElementContent +{ +public: + /*! + * \brief label Text associated with the input box to provide prompt text. + */ + std::string label {}; + + /*! + * \brief defaultValue Specifies a default value. This can be used for either string or numeric data. + */ + std::string defaultValue {}; + + /*! + * \brief suggestions A suggested value to be placed in the drop-down list. + * Multiple suggestion elements result in multiple suggestions. + */ + std::vector suggestion {}; + + /*! + * \brief noSort If elements should be sorted. + */ + bool noSort { false }; +}; + +} // of namespace security + +#endif // SECURITY_COMBOBOX_H diff --git a/src/plugins/security/model/presentation/comment.h b/src/plugins/security/model/presentation/comment.h new file mode 100644 index 000000000..c7c165b28 --- /dev/null +++ b/src/plugins/security/model/presentation/comment.h @@ -0,0 +1,56 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_COMMENT_H +#define SECURITY_COMMENT_H + +#include "dataelement.h" + +#include + +namespace security +{ + +/*! + * \class Comment + * \brief Represents a comment display element. + * + * \ingroup security + * \ingroup presentation + */ +class Comment: public DataElement +{ +public: + + /*! + * \brief text Text of the comment. + */ + std::string text; + + /*! + * \brief image Image that can be incorporated into comment. + */ + std::string image; + +}; + +} // of namespace security + +#endif // SECURITY_COMMENT_H diff --git a/src/plugins/security/model/presentation/dataelement.h b/src/plugins/security/model/presentation/dataelement.h new file mode 100644 index 000000000..0f02f7bfe --- /dev/null +++ b/src/plugins/security/model/presentation/dataelement.h @@ -0,0 +1,48 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_DATA_ELEMENT_H +#define SECURITY_DATA_ELEMENT_H + +#include + +namespace security +{ + +/*! + * \class DataElement + * \brief Represents base of simple graphical elements. + * + * \ingroup security + * \ingroup presentation + */ +class DataElement +{ +public: + + /*! + * \brief refId A reference Id. + */ + std::string refId {}; +}; + +} // of namespace security + +#endif // SECURITY_DATA_ELEMENT_H diff --git a/src/plugins/security/model/presentation/dataelementcontent.h b/src/plugins/security/model/presentation/dataelementcontent.h new file mode 100644 index 000000000..a9808a50e --- /dev/null +++ b/src/plugins/security/model/presentation/dataelementcontent.h @@ -0,0 +1,57 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_DATA_ELEMENT_CONTENT_H +#define SECURITY_DATA_ELEMENT_CONTENT_H + +#include + +namespace security +{ + +/*! + \class DataElementContent + * \brief The DataElementContent class base class for graphical element such as combobox or radio-button. + * + * \ingroup security + * \ingroup presentation + */ +class DataElementContent +{ +public: + /*! + * \brief value An initial value of graphical element. + */ + std::string value{}; + + /*! + * \brief refId A reference Id. + */ + std::string refId{}; + + /*! + * \brief postfix A description that follows graphical element. + */ + std::string postfix{}; +}; + +} // of namespace security + +#endif // SECURITY_DATA_ELEMENT_CONTENT_H diff --git a/src/plugins/security/model/presentation/decimaltextbox.h b/src/plugins/security/model/presentation/decimaltextbox.h new file mode 100644 index 000000000..3c56c3c62 --- /dev/null +++ b/src/plugins/security/model/presentation/decimaltextbox.h @@ -0,0 +1,59 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_DECIMAL_TEXTBOX_H +#define SECURITY_DECIMAL_TEXTBOX_H + +#include "dataelementcontent.h" + +namespace security +{ + +/*! + * \class DecimalTextBox + * \brief Represents a text box with or without a spin control for entering decimal numbers. + * + * \ingroup security + * \ingroup presentation + */ +class DecimalTextBox: public DataElementContent +{ +public: + + /*! + * \brief defaultValue + */ + uint32_t defaultValue {0}; + + /*! + * \brief spinBox + */ + bool spinBox { false }; + + /*! + * \brief spinStep + */ + uint32_t spinStep {1}; + +}; + +} // of namespace security + +#endif // SECURITY_DECIMAL_TEXTBOX_H diff --git a/src/plugins/security/model/presentation/dropdownlist.h b/src/plugins/security/model/presentation/dropdownlist.h new file mode 100644 index 000000000..f2610a3a4 --- /dev/null +++ b/src/plugins/security/model/presentation/dropdownlist.h @@ -0,0 +1,68 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_DROPDOWNLIST_H +#define SECURITY_DROPDOWNLIST_H + +#include "dataelementcontent.h" + +#include +#include + +namespace security +{ + +/*! + * \class DropdownList + * \brief Represents a dropdown list display element. + */ +class DropdownList : public DataElementContent +{ +public: + /*! + * \brief noSort + */ + bool noSort { false }; + + /*! + * \brief defaultItem The numerical value identifying the default choice of the list of items. + * The item list is numbered starting from 0. + */ + unsigned int defaultItem { 0 }; + + /*! + * \brief label Text associated with the drop-down list. + */ + std::string label{}; + + /*! + * \brief values Values of the drop-down list. + */ + std::vector values{}; + + /*! + * \brief refId A mapping to the element. + */ + std::string refId{}; +}; + +} // of namespace security + +#endif // SECURITY_DROPDOWNLIST_H diff --git a/src/plugins/security/model/presentation/groupbox.h b/src/plugins/security/model/presentation/groupbox.h new file mode 100644 index 000000000..9bc1c3d01 --- /dev/null +++ b/src/plugins/security/model/presentation/groupbox.h @@ -0,0 +1,73 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_GROUPBOX_H +#define SECURITY_GROUPBOX_H + +#include "dataelementcontent.h" +#include "presentationelements.h" + +#include + +namespace security +{ + +class PresentationElements; + +/*! + * \class GroupBox + * \brief The GroupBox class are used to provide an identifiable grouping for other graphical elements. + * + * \ingroup security + * \ingroup presentation + */ +class GroupBox: public DataElementContent +{ +public: + + /*! + * \brief hasCheckBox If group box has checkbox. + */ + bool hasCheckBox { false }; + + /*! + * \brief defaultChecked If group box's check box is checked. + */ + bool defaultChecked { false }; + + /*! + * \brief elements Content of the group box. + */ + std::unique_ptr elements{}; + + /*! + * \brief label Description of the group box. + */ + std::string label{}; + + /*! + * \brief hasBorder If group box is flat or it has border. + */ + bool hasBorder { false }; +}; + +} // of namespace security + +#endif // SECURITY_GROUPBOX_H diff --git a/src/plugins/security/model/presentation/ldapsearchdialog.h b/src/plugins/security/model/presentation/ldapsearchdialog.h new file mode 100644 index 000000000..df2da7fb7 --- /dev/null +++ b/src/plugins/security/model/presentation/ldapsearchdialog.h @@ -0,0 +1,69 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_LDAP_SEARCH_DIALOG_H +#define SECURITY_LDAP_SEARCH_DIALOG_H + +#include "dataelementcontent.h" + +#include + +namespace security +{ + +/*! + * \class LdapSearchDialog + * \brief Represents a LDAP search dialog display element.\nCan be associated with a TextElement. + * + * \ingroup security + * \ingroup presentation + */ +class LdapSearchDialog: public DataElementContent +{ +public: + /*! + * \brief dn Base DN for elements to search. + */ + std::string dn{}; + + /*! + * \brief filter LDAP search filter. + */ + std::string filter{}; + + /*! + * \brief addLabel Label for add button. + */ + std::string addLabel{}; + + /*! + * \brief removeLabel Label for remove button. + */ + std::string removeLabel{}; + + /*! + * \brief title Label for group box. + */ + std::string title{}; +}; + +} // of namespace security + +#endif // SECURITY_LDAP_SEARCH_DIALOG_H diff --git a/src/plugins/security/model/presentation/listbox.h b/src/plugins/security/model/presentation/listbox.h new file mode 100644 index 000000000..6c2dddf0b --- /dev/null +++ b/src/plugins/security/model/presentation/listbox.h @@ -0,0 +1,42 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_LISTBOX_H +#define SECURITY_LISTBOX_H + +#include "dataelementcontent.h" + +namespace security +{ + +/*! + * \class ListBox + * \brief Represents a listbox display element. + * + * \ingroup security + * \ingroup presentation + */ +class ListBox : public DataElementContent +{ +}; + +} // of namespace security + +#endif // SECURITY_LISTBOX_H diff --git a/src/plugins/security/model/presentation/longdecimaltextbox.h b/src/plugins/security/model/presentation/longdecimaltextbox.h new file mode 100644 index 000000000..289429352 --- /dev/null +++ b/src/plugins/security/model/presentation/longdecimaltextbox.h @@ -0,0 +1,58 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_LONG_DECIMAL_TEXTBOX_H +#define SECURITY_LONG_DECIMAL_TEXTBOX_H + +#include "dataelementcontent.h" + +namespace security { + +/** + * \class LongDecimalTextBox + * \brief Represents a text box with or without a spin control for entering long decimal numbers. + * + * \ingroup security + * \ingroup presentation + */ +class LongDecimalTextBox: public DataElementContent +{ +public: + + /*! + * \brief defaultValue + */ + uint64_t defaultValue{}; + + /*! + * \brief spinBox + */ + bool spinBox { false }; + + /*! + * \brief spinStep + */ + uint64_t spinStep {1}; + +}; + +} // of namespace security + +#endif // SECURITY_LONG_DECIMAL_TEXTBOX_H diff --git a/src/plugins/security/model/presentation/multitextbox.h b/src/plugins/security/model/presentation/multitextbox.h new file mode 100644 index 000000000..444634070 --- /dev/null +++ b/src/plugins/security/model/presentation/multitextbox.h @@ -0,0 +1,62 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_MULTITEXTBOX_H +#define SECURITY_MULTITEXTBOX_H + +#include "dataelementcontent.h" + +namespace security +{ + +/** + * \class MultiTextBox + * \brief Represents a textbox display element with default entry. + * + * \ingroup security + * \ingroup presentation + */ +class MultiTextBox : public DataElementContent +{ +public: + /*! + * \brief label + */ + std::string label{}; + + /*! + * \brief defaultValue + */ + std::string defaultValue{}; + + /*! + * \brief showAsDialog If we need to display multitext as a dialog. + */ + bool showAsDialog = false; + + /*! + * \brief defaultHeight Deafult height of the widget. + */ + unsigned int defaultHeight = 3; +}; + +} // of namespace security + +#endif // SECURITY_MULTITEXTBOX_H diff --git a/src/plugins/security/model/presentation/presentationelements.h b/src/plugins/security/model/presentation/presentationelements.h new file mode 100644 index 000000000..2240459a5 --- /dev/null +++ b/src/plugins/security/model/presentation/presentationelements.h @@ -0,0 +1,121 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_PRESENTATION_ELEMENTS_H +#define SECURITY_PRESENTATION_ELEMENTS_H + +#include "checkbox.h" +#include "combobox.h" +#include "comment.h" +#include "decimaltextbox.h" +#include "dropdownlist.h" +#include "groupbox.h" +#include "listbox.h" +#include "longdecimaltextbox.h" +#include "ldapsearchdialog.h" +#include "radiobutton.h" +#include "multitextbox.h" +#include "textbox.h" +#include "text.h" + +#include + +namespace security +{ + +class GroupBox; + +/*! + * \class PresentationElements + * \brief The PresentationElements class + */ +class PresentationElements +{ +public: + + /*! + * \brief decimalTextBox + */ + std::vector decimalTextBox {}; + + /*! + * \brief textBox + */ + std::vector textBox{}; + + /*! + * \brief checkBox + */ + std::vector checkBox{}; + + /*! + * \brief comboBox + */ + std::vector comboBox{}; + + /*! + * \brief dropdownList + */ + std::vector dropdownList{}; + + /*! + * \brief longDecimalTextBox + */ + std::vector longDecimalTextBox{}; + + /*! + * \brief multiTextBox + */ + std::vector multiTextBox{}; + + /*! + * \brief groupBox + */ + std::vector groupBox{}; + + /*! + * \brief listBox + */ + std::vector listBox{}; + + /*! + * \brief comment + */ + std::vector comment{}; + + /*! + * \brief text + */ + std::vector text{}; + + /*! + * \brief ldapSearchDialog + */ + std::vector ldapSearchDialog{}; + + /*! + * \brief radioButton + */ + std::vector radioButton{}; +}; + +} // of namespace security + +#endif // SECURITY_PRESENTATION_ELEMENTS_H diff --git a/src/plugins/security/model/presentation/radiobutton.h b/src/plugins/security/model/presentation/radiobutton.h new file mode 100644 index 000000000..fa20ac3f4 --- /dev/null +++ b/src/plugins/security/model/presentation/radiobutton.h @@ -0,0 +1,45 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_RADIO_BUTTON_H +#define SECURITY_RADIO_BUTTON_H + +#include "dataelement.h" + +namespace security +{ + +/*! + * \class RadioButton + * \brief Represents a radio button display element.\nCan be associated with a BooleanElement. + */ +class RadioButton: public DataElement +{ +public: + + /*! + * \brief defaultChecked Shows if radio button is enabled by default. + */ + bool defaultChecked { false }; +}; + +} // of namespace security + +#endif // SECURITY_RADIO_BUTTON_H diff --git a/src/plugins/security/model/presentation/securitydescriptoreditor.h b/src/plugins/security/model/presentation/securitydescriptoreditor.h new file mode 100644 index 000000000..de86cf75d --- /dev/null +++ b/src/plugins/security/model/presentation/securitydescriptoreditor.h @@ -0,0 +1,44 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_SECURITY_DESCRIPTOR_EDITOR_H +#define SECURITY_SECURITY_DESCRIPTOR_EDITOR_H + +#include "dataelement.h" + +namespace security +{ + +/*! + * \class SecurityDescriptorEditor + * \brief Represents a security descriptor editor display element. + */ +class SecurityDescriptorEditor: public DataElement +{ +public: + /*! + * \brief label Label of the security editor button. + */ + std::string label{}; +}; + +} // of namespace security + +#endif // SECURITY_SECURITY_DESCRIPTOR_EDITOR_H diff --git a/src/plugins/security/model/presentation/securitypresentation.h b/src/plugins/security/model/presentation/securitypresentation.h new file mode 100644 index 000000000..b9da122c3 --- /dev/null +++ b/src/plugins/security/model/presentation/securitypresentation.h @@ -0,0 +1,82 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_SECURITY_PRESENTATION_H +#define SECURITY_SECURITY_PRESENTATION_H + +#include "presentationelements.h" + +#include +#include +#include +#include +#include + +namespace security +{ +// the variant to visit +typedef ::std::variant, + std::shared_ptr, + std::shared_ptr, + std::shared_ptr, + std::shared_ptr, + std::shared_ptr, + std::shared_ptr, + std::shared_ptr, + std::shared_ptr, + std::shared_ptr, + std::shared_ptr, + std::shared_ptr, + std::shared_ptr > PresentationElement; + +/*! + * \class SecurityPresentation + * \brief Root presentation element. + * + * \ingroup security + * \ingroup presentation + */ +class SecurityPresentation: public PresentationElements +{ +public: + /*! + * \brief id Id of current presentation element. + */ + std::string id{}; + + /*! + * \brief text + */ + std::string text{}; + + /*! + * \brief icon Icon associated with current presentation element. + */ + std::string icon{}; + + /*! + * \brief widgets List of widgets, associated with their ids. + */ + std::vector> widgets{}; +}; + +} // of namespace security + +#endif // SECURITY_SECURITY_PRESENTATION_H diff --git a/src/plugins/security/model/presentation/securitypresentationresources.h b/src/plugins/security/model/presentation/securitypresentationresources.h new file mode 100644 index 000000000..3244c5e74 --- /dev/null +++ b/src/plugins/security/model/presentation/securitypresentationresources.h @@ -0,0 +1,70 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_SECURITY_PRESENTATION_RESOURCES_H +#define SECURITY_SECURITY_PRESENTATION_RESOURCES_H + +#include "securitypresentation.h" + +#include +#include + +namespace security +{ + +/*! + * \class SecurityPresentationResources + * \brief Root presentation element. + */ +class SecurityPresentationResources +{ +public: + /*! + * \brief displayName The localized friendly name of the policy settings file. + * Unsupported by current Group Policy tools. + */ + std::string displayName{}; + + /*! + * \brief description The localized description of policy settings contained in an .adml file. + * Unsupported by current Group Policy tools. + */ + std::string description{}; + + /*! + * \brief annotation A comment string for .adml files. + * Strings added to this tag will not be processed by Group Policy tools. + */ + std::vector annotation{}; + + /*! + * \brief stringTable A table of localized strings. + */ + std::map stringTable{}; + + /*! + * \brief presentationTable A table of presentation elements representing policy setting parameters. + */ + std::vector>> presentationTable{}; +}; + +} // of namespace security + +#endif // SECURITY_SECURITY_PRESENTATION_RESOURCES_H diff --git a/src/plugins/security/model/presentation/text.h b/src/plugins/security/model/presentation/text.h new file mode 100644 index 000000000..63c3c1398 --- /dev/null +++ b/src/plugins/security/model/presentation/text.h @@ -0,0 +1,47 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_TEXT_H +#define SECURITY_TEXT_H + +#include "dataelement.h" + +#include + +namespace security +{ + +/** + * \class Text + * \brief Represents a text display element with default entry. + */ +class Text: public DataElement +{ +public: + + /*! + * \brief content + */ + std::string content{}; +}; + +} // of namespace security + +#endif // SECURITY_TEXT_H diff --git a/src/plugins/security/model/presentation/textbox.h b/src/plugins/security/model/presentation/textbox.h new file mode 100644 index 000000000..8538d4d29 --- /dev/null +++ b/src/plugins/security/model/presentation/textbox.h @@ -0,0 +1,52 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_TEXTBOX_H +#define SECURITY_TEXTBOX_H + +#include "dataelementcontent.h" + +#include + +namespace security +{ + +/** + * \class TextBox + * \brief Represents a textbox display element with default entry. + */ +class TextBox: public DataElementContent +{ +public: + + /*! + * \brief label + */ + std::string label{}; + + /*! + * \brief defaultValue + */ + std::string defaultValue{}; +}; + +} // of namespace security + +#endif // SECURITY_TEXTBOX_H diff --git a/src/plugins/security/model/sdmx/booleanelement.h b/src/plugins/security/model/sdmx/booleanelement.h new file mode 100644 index 000000000..c32322dad --- /dev/null +++ b/src/plugins/security/model/sdmx/booleanelement.h @@ -0,0 +1,39 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_BOOLEAN_ELEMENT_H +#define SECURITY_BOOLEAN_ELEMENT_H + +#include "securityelement.h" + +namespace security +{ + +/*! + * \class BooleanElement + * \brief Describes a choice element in a policy with associated values for the true and false cases. + */ +class BooleanElement: public SecurityElement +{ +}; + +} // of namespace security + +#endif // SECURITY_BOOLEAN_ELEMENT_H diff --git a/src/plugins/security/model/sdmx/decimalelement.h b/src/plugins/security/model/sdmx/decimalelement.h new file mode 100644 index 000000000..ea67c8542 --- /dev/null +++ b/src/plugins/security/model/sdmx/decimalelement.h @@ -0,0 +1,66 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_DECIMAL_ELEMENT_H +#define SECURITY_DECIMAL_ELEMENT_H + +#include "security.h" + +#include "securityelement.h" + +namespace security +{ + +/*! + * \brief The DecimalElement class + */ +class DecimalElement: public SecurityElement +{ +public: + + /*! + * + */ + bool required { false }; + + /*! + * + */ + bool soft { false }; + + /*! + * + */ + bool storeAsText { false }; + + /*! + * + */ + uint32_t minValue { std::numeric_limits::min() }; + + /*! + * + */ + uint32_t maxValue { std::numeric_limits::max() }; +}; + +} // of namespace security + +#endif // SECURITY_DECIMAL_ELEMENT_H diff --git a/src/plugins/security/model/sdmx/decimaltype.h b/src/plugins/security/model/sdmx/decimaltype.h new file mode 100644 index 000000000..a62f50359 --- /dev/null +++ b/src/plugins/security/model/sdmx/decimaltype.h @@ -0,0 +1,45 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_DECIMALTYPE_H +#define SECURITY_DECIMALTYPE_H + +#include "security.h" + +#include + +namespace security +{ + +/*! + * \brief The DecimalType class + */ +class DecimalType { +public: + + /** + * + */ + uint32_t value {0}; +}; + +} // of namespace security + +#endif // SECURITY_DECIMALTYPE_H diff --git a/src/plugins/security/model/sdmx/enumerationelement.h b/src/plugins/security/model/sdmx/enumerationelement.h new file mode 100644 index 000000000..0e3871645 --- /dev/null +++ b/src/plugins/security/model/sdmx/enumerationelement.h @@ -0,0 +1,46 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_ENUMERATION_ELEMENT_H +#define SECURITY_ENUMERATION_ELEMENT_H + +#include "security.h" + +#include "securityelement.h" + +namespace security +{ + +/*! + * \class EnumerationElement + * \brief The EnumerationElement class + */ +class EnumerationElement: public SecurityElement +{ +public: + /*! + * \brief required + */ + bool required { false }; +}; + +} // of namespace security + +#endif // SECURITY_ENUMERATION_ELEMENT_H diff --git a/src/plugins/security/model/sdmx/listelement.h b/src/plugins/security/model/sdmx/listelement.h new file mode 100644 index 000000000..f16e1652c --- /dev/null +++ b/src/plugins/security/model/sdmx/listelement.h @@ -0,0 +1,62 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_LIST_ELEMENT_H +#define SECURITY_LIST_ELEMENT_H + +#include "security.h" + +#include "securityelement.h" + +namespace security +{ + +/*! + * \class ListElement + * \brief The ListElement class + */ +class ListElement: public SecurityElement +{ +public: + + /*! + * \brief valuePrefix + */ + std::string valuePrefix{}; + + /*! + * \brief additive + */ + bool additive { false }; + + /*! + * \brief expandable + */ + bool expandable { false }; + + /*! + * \brief explicitValue + */ + bool explicitValue { false }; +}; + +} // of namespace security + +#endif // SECURITY_LIST_ELEMENT_H diff --git a/src/plugins/security/model/sdmx/longdecimalelement.h b/src/plugins/security/model/sdmx/longdecimalelement.h new file mode 100644 index 000000000..cedd67ac9 --- /dev/null +++ b/src/plugins/security/model/sdmx/longdecimalelement.h @@ -0,0 +1,67 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_LONG_DECIMAL_ELEMENT_H +#define SECURITY_LONG_DECIMAL_ELEMENT_H + +#include "security.h" + +#include "securityelement.h" + +namespace security +{ + +/*! + * \class LongDecimalElement + * \brief The LongDecimalElement class + */ +class LongDecimalElement: public SecurityElement +{ +public: + + /*! + * \brief required + */ + bool required { false }; + + /*! + * \brief sorf + */ + bool soft { false }; + + /*! + * \brief storeAsText + */ + bool storeAsText { false }; + + /*! + * \brief minValue + */ + uint64_t minValue { std::numeric_limits::min() }; + + /** + * \brief maxValue + */ + uint64_t maxValue { std::numeric_limits::max() }; +}; + +} // of namespace security + +#endif // SECURITY_LONG_DECIMAL_ELEMENT_H diff --git a/src/plugins/security/model/sdmx/longdecimaltype.h b/src/plugins/security/model/sdmx/longdecimaltype.h new file mode 100644 index 000000000..f8669f77d --- /dev/null +++ b/src/plugins/security/model/sdmx/longdecimaltype.h @@ -0,0 +1,46 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_LONG_DECIMAL_TYPE_H +#define SECURITY_LONG_DECIMAL_TYPE_H + +#include "security.h" + +#include + +namespace security +{ + +/*! + * \class LongDecimalElement + * \brief The LongDecimalType class + */ +class LongDecimalType +{ +public: + /*! + * \brief value + */ + uint64_t value {}; +}; + +} // of namespace security + +#endif // SECURITY_LONG_DECIMAL_TYPE_H diff --git a/src/plugins/security/model/sdmx/multitextelement.h b/src/plugins/security/model/sdmx/multitextelement.h new file mode 100644 index 000000000..a1c179418 --- /dev/null +++ b/src/plugins/security/model/sdmx/multitextelement.h @@ -0,0 +1,41 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_MULTITEXT_ELEMENT_H +#define SECURITY_MULTITEXT_ELEMENT_H + +#include "security.h" + +#include "securityelement.h" + +namespace security +{ + +/*! + * \class MultiTextElement + * \brief Describes a multi line text element in a policy. + */ +class MultiTextElement: public SecurityElement +{ +}; + +} // of namespace security + +#endif // SECURITY_MULTITEXT_ELEMENT_H diff --git a/src/plugins/security/model/sdmx/security.h b/src/plugins/security/model/sdmx/security.h new file mode 100644 index 000000000..87fef60f0 --- /dev/null +++ b/src/plugins/security/model/sdmx/security.h @@ -0,0 +1,31 @@ +#ifndef SECURITY_H +#define SECURITY_H + +namespace security +{ + +/** + * \enum SecurityType + * \brief bAn enumeration of the 3 possible types a security definition can belong to. + */ +enum class SecurityType +{ + /*! + * + */ + User = 0, + + /*! + * + */ + Machine = 1, + + /*! + * + */ + Both = 2 +}; + +} // of namespace security + +#endif // SECURITY_H diff --git a/src/plugins/security/model/sdmx/securitydefinition.h b/src/plugins/security/model/sdmx/securitydefinition.h new file mode 100644 index 000000000..8a7b6d465 --- /dev/null +++ b/src/plugins/security/model/sdmx/securitydefinition.h @@ -0,0 +1,112 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_SECURITY_DEFINITION_H +#define SECURITY_SECURITY_DEFINITION_H + +#include "security.h" + +#include "securityelements.h" +#include "securityvalue.h" +#include "securityvaluelist.h" + +#include +#include +#include + +namespace security +{ + +/*! + \class SecurityDefinition + * \brief The SecurityDefinition class + */ +class SecurityDefinition +{ +public: + /*! + * \brief name + */ + std::string name {}; + + /*! + * \brief displayName + */ + std::string displayName {}; + + /*! + * \brief explainText + */ + std::string explainText {}; + + /*! + * \brief sectionName + */ + std::unique_ptr sectionName {}; + + /*! + * \brief propertyName + */ + std::unique_ptr propertyName {}; + + /*! + * \brief securityType + */ + SecurityType securityType { SecurityType::Machine }; + + /*! + * \brief presentation A reference to a policy presentation in the localized presentation section/table. + */ + std::unique_ptr presentation{}; + + /*! + * \brief parentCategory + */ + std::string parentCategory {}; + + /*! + * \brief elements + */ + std::vector> elements {}; + + /*! + * \brief enabledValue + */ + std::unique_ptr enabledValue {}; + + /*! + * \brief disabledValue + */ + std::unique_ptr disabledValue {}; + + /*! + * \brief enabledList + */ + std::unique_ptr enabledList{}; + + /*! + * \brief disabledList + */ + std::unique_ptr disabledList{}; +}; + +} // of namespace security + +#endif // SECURITY_SECURITY_DEFINITION_H diff --git a/src/plugins/security/model/sdmx/securitydefinitions.h b/src/plugins/security/model/sdmx/securitydefinitions.h new file mode 100644 index 000000000..ef600aa65 --- /dev/null +++ b/src/plugins/security/model/sdmx/securitydefinitions.h @@ -0,0 +1,68 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_SECURITY_DEFINITIONS_H +#define SECURITY_SECURITY_DEFINITIONS_H + +#include "security.h" + +#include "securitydefinition.h" + +#include "../presentation/category.h" + +#include +#include +#include + +namespace security +{ + +/*! + * \class SecurityDefinitions + * \brief The SecurityDefinitions class + */ +class SecurityDefinitions +{ +public: + /*! + * \brief revision + */ + std::string revision{}; + + /*! + * \brief schemaVersion + */ + std::string schemaVersion{}; + + /*! + * \brief categories Contains a list of categories under which Group Policy + * settings will be displayed in the Editor. + */ + std::vector> categories{}; + + /*! + * \brief security + */ + std::vector > security {}; +}; + +} // of namespace security + +#endif // SECURITY_SECURITY_DEFINITIONS_H diff --git a/src/plugins/security/model/sdmx/securityelement.h b/src/plugins/security/model/sdmx/securityelement.h new file mode 100644 index 000000000..cc801b2a7 --- /dev/null +++ b/src/plugins/security/model/sdmx/securityelement.h @@ -0,0 +1,58 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_SECURITY_ELEMENT_H +#define SECURITY_SECURITY_ELEMENT_H + +#include "security.h" + +#include +#include + +namespace security +{ + +/*! + * \class SecurityElement + * \brief The SecurityElement class + */ +class SecurityElement +{ +public: + + /*! + * \brief refId + */ + std::string refId{}; + + /*! + * \brief clientExtension + */ + QUuid clientExtension{}; + + /*! + * \brief propertyName + */ + std::string propertyName{}; +}; + +} // of namespace security + +#endif // SECURITY_SECURITY_ELEMENT_H diff --git a/src/plugins/security/model/sdmx/securityelements.h b/src/plugins/security/model/sdmx/securityelements.h new file mode 100644 index 000000000..7ea104c9a --- /dev/null +++ b/src/plugins/security/model/sdmx/securityelements.h @@ -0,0 +1,85 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_SECURITY_ELEMENTS_H +#define SECURITY_SECURITY_ELEMENTS_H + +#include "security.h" + +#include "booleanelement.h" +#include "decimalelement.h" +#include "enumerationelement.h" +#include "listelement.h" +#include "longdecimalelement.h" +#include "multitextelement.h" +#include "textelement.h" + +#include +#include + +namespace security +{ + +/*! + * \class SecurityElements + * \brief The SecurityElements class + */ +class SecurityElements +{ +public: + /*! + * \brief boolean + */ + std::vector boolean {}; + + /*! + * \brief decimal + */ + std::vector decimal {}; + + /*! + * \brief text + */ + std::vector text {}; + + /*! + * \brief enumElement + */ + std::vector enumElement {}; + + /*! + * \brief list + */ + std::vector list {}; + + /*! + * \brief longDecimal + */ + std::vector longDecimal {}; + + /*! + * \brief multiText + */ + std::vector multiText {}; +}; + +} // of namespace security + +#endif // SECURITY_SECURITY_ELEMENTS_H diff --git a/src/plugins/security/model/sdmx/securityitem.h b/src/plugins/security/model/sdmx/securityitem.h new file mode 100644 index 000000000..3021ef409 --- /dev/null +++ b/src/plugins/security/model/sdmx/securityitem.h @@ -0,0 +1,61 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_SECURITY_ITEM_H +#define SECURITY_SECURITY_ITEM_H + +#include "security.h" + +#include "securityvalue.h" + +#include + +namespace security { + +/*! + * \class SecurityItem + * \brief The SecurityItem class represents element of security policy. + * + * \ingroup security + * + * \see SecurityValue + */ +class SecurityItem +{ +public: + /*! + * \brief sectionName Name of the section to place item into. + */ + std::string sectionName {}; + + /*! + * \brief propertyName Name of the property associated with this security policy element. + */ + std::string propertyName {}; + + /*! + * \brief value Value of current element. + */ + SecurityValue value {}; +}; + +} // of namespace security + +#endif // SECURITY_SECURITY_ITEM_H diff --git a/src/plugins/security/model/sdmx/securityvalue.h b/src/plugins/security/model/sdmx/securityvalue.h new file mode 100644 index 000000000..9f09b4b5a --- /dev/null +++ b/src/plugins/security/model/sdmx/securityvalue.h @@ -0,0 +1,40 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_SECURITY_VALUE_H +#define SECURITY_SECURITY_VALUE_H + +#include "security.h" + +namespace security { + +/*! + * \class SecurityValue + * \brief The SecurityValue class + */ +class SecurityValue +{ +public: + // TODO: implement +}; + +} // of namespace security + +#endif // SECURITY_SECURITY_VALUE_H diff --git a/src/plugins/security/model/sdmx/securityvaluelist.h b/src/plugins/security/model/sdmx/securityvaluelist.h new file mode 100644 index 000000000..9b49f3401 --- /dev/null +++ b/src/plugins/security/model/sdmx/securityvaluelist.h @@ -0,0 +1,53 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_SECURITY_VALUE_LIST_H +#define SECURITY_SECURITY_VALUE_LIST_H + +#include "security.h" + +#include "securityvalue.h" + +#include +#include + +namespace security { + +/*! + \class SecurityValueList + * \brief The SecurityValueList class stores list of values. + */ +class SecurityValueList +{ +public: + /*! + * \brief item List of items. + */ + std::vector items{}; + + /*! + * \brief defaultString + */ + std::string defaultString{}; +}; + +} // of namespace security + +#endif // SECURITY_SECURITY_VALUE_LIST_H diff --git a/src/plugins/security/model/sdmx/textelement.h b/src/plugins/security/model/sdmx/textelement.h new file mode 100644 index 000000000..f844b9b7d --- /dev/null +++ b/src/plugins/security/model/sdmx/textelement.h @@ -0,0 +1,59 @@ +/*********************************************************************************************************************** + ** + ** Copyright (C) 2023 BaseALT Ltd. + ** + ** This program is free software; you can redistribute it and/or + ** modify it under the terms of the GNU General Public License + ** as published by the Free Software Foundation; either version 2 + ** of the License, or (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program; if not, write to the Free Software + ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ** + ***********************************************************************************************************************/ + +#ifndef SECURITY_TEXT_ELEMENT_H +#define SECURITY_TEXT_ELEMENT_H + +#include "security.h" + +#include "securityelement.h" + +namespace security +{ + +/** + * \class TextElement + * \brief Describes a single line text element in a policy. + * + * \ingroup model + */ +class TextElement: public SecurityElement +{ +public: + + /*! + * \brief required If this element is required. + */ + bool required { false }; + + /*! + * \brief maxLength Maximum length of text element. If text exceeds maximum length it will be truncated. + */ + uint32_t maxLength { 1024 }; + + /*! + * \brief soft If previous value should be replaced. + */ + bool soft { false }; +}; + +} // of namespace security + +#endif // SECURITY_TEXT_ELEMENT_H diff --git a/src/plugins/security/model/ui/browseldapdialog.cpp b/src/plugins/security/model/ui/browseldapdialog.cpp new file mode 100644 index 000000000..94874ae89 --- /dev/null +++ b/src/plugins/security/model/ui/browseldapdialog.cpp @@ -0,0 +1,47 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2023 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#include "browseldapdialog.h" +#include "ui_browseldapdialog.h" + +namespace security +{ + +class BrowseLdapDialogPrivate +{ +private: +}; + +BrowseLdapDialog::BrowseLdapDialog(QWidget *parent) + : QDialog(parent) + , d(new BrowseLdapDialogPrivate()) + , ui(new Ui::BrowseLdapDialog()) +{ + ui->setupUi(this); +} + +BrowseLdapDialog::~BrowseLdapDialog() +{ + delete d; + delete ui; +} + +} + diff --git a/src/plugins/security/model/ui/browseldapdialog.h b/src/plugins/security/model/ui/browseldapdialog.h new file mode 100644 index 000000000..dc189aa7e --- /dev/null +++ b/src/plugins/security/model/ui/browseldapdialog.h @@ -0,0 +1,59 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2023 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#ifndef SECURITY_BROWSE_LDAP_DIALOG_H +#define SECURITY_BROWSE_LDAP_DIALOG_H + +#include + +QT_BEGIN_NAMESPACE +namespace Ui { class BrowseLdapDialog; } +QT_END_NAMESPACE + +namespace security +{ + +class BrowseLdapDialogPrivate; + +class BrowseLdapDialog : public QDialog +{ +public: + Q_OBJECT + +public: + explicit BrowseLdapDialog(QWidget* parent = nullptr); + ~BrowseLdapDialog() override; + +private: + BrowseLdapDialog(const BrowseLdapDialog&) = delete; // copy ctor + BrowseLdapDialog(BrowseLdapDialog&&) = delete; // move ctor + BrowseLdapDialog& operator=(const BrowseLdapDialog&) = delete; // copy assignment + BrowseLdapDialog& operator=(BrowseLdapDialog&&) = delete; // move assignment + +private: + BrowseLdapDialogPrivate *d{}; + +private: + Ui::BrowseLdapDialog *ui{}; +}; + +} + +#endif//SECURITY_BROWSE_LDAP_DIALOG_H diff --git a/src/plugins/security/model/ui/browseldapdialog.ui b/src/plugins/security/model/ui/browseldapdialog.ui new file mode 100644 index 000000000..3f264baf7 --- /dev/null +++ b/src/plugins/security/model/ui/browseldapdialog.ui @@ -0,0 +1,81 @@ + + + BrowseLdapDialog + + + + 0 + 0 + 411 + 83 + + + + Dialog + + + + + + Browse + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + Resource to browse: + + + + + + + + + buttonBox + accepted() + BrowseLdapDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + BrowseLdapDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/plugins/security/model/ui/i18n/security_translation_en.ts b/src/plugins/security/model/ui/i18n/security_translation_en.ts new file mode 100644 index 000000000..be256c7dc --- /dev/null +++ b/src/plugins/security/model/ui/i18n/security_translation_en.ts @@ -0,0 +1,141 @@ + + + + + BrowseLdapDialog + + + Dialog + Dialog + + + + Browse + Browse + + + + Resource to browse: + Resource to browse: + + + + LdapSearchListWidget + + + Form + Form + + + + Add button + Add button + + + + Remove button + Remove button + + + + QObject + + + [Local Group Policy] + [Local Group Policy] + + + + Local group policies + Local group policies + + + + Machine + Machine + + + + Machine level policies + Machine level policies + + + + + System settings + System settings + + + + System settings for computer + System settings for computer + + + + + Security Settings + Security Settings + + + + Machine level security settings + Machine level security settings + + + + User + User + + + + User level policies + User level policies + + + + System settings for user + System settings for user + + + + User level security settings + User level security settings + + + + Edit + Edit + + + + SecurityWidget + + + Form + Form + + + + Help: + Help: + + + + &Cancel + &Cancel + + + + &OK + &OK + + + + security::SecurityWidget + + + Security policy: + Security policy: + + + diff --git a/src/plugins/security/model/ui/i18n/security_translation_ru.ts b/src/plugins/security/model/ui/i18n/security_translation_ru.ts new file mode 100644 index 000000000..d6562a5a3 --- /dev/null +++ b/src/plugins/security/model/ui/i18n/security_translation_ru.ts @@ -0,0 +1,141 @@ + + + + + BrowseLdapDialog + + + Dialog + Диалог + + + + Browse + Просмотр + + + + Resource to browse: + Ресурс для поиска: + + + + LdapSearchListWidget + + + Form + Форма + + + + Add button + Кнопка добавить + + + + Remove button + Кнопка удалить + + + + QObject + + + [Local Group Policy] + [Локальная групповая политика] + + + + Local group policies + Локальные групповые политики + + + + Machine + Компьютер + + + + Machine level policies + Политики уровня компьютера + + + + + System settings + Настройки системы + + + + System settings for computer + Настройки системы для компьютера + + + + + Security Settings + Настройки безопастности + + + + Machine level security settings + Настройки безопастности компьютера + + + + User + Пользователь + + + + User level policies + Групповые политики пользователя + + + + System settings for user + Настройки системы пользователя + + + + User level security settings + Настройки безовпстности пользователя + + + + Edit + Редактировать + + + + SecurityWidget + + + Form + Форма + + + + Help: + Помощь: + + + + &Cancel + &Отмена + + + + &OK + &ОК + + + + security::SecurityWidget + + + Security policy: + Политика безопастности: + + + diff --git a/src/plugins/security/model/ui/ldapsearchlistwidget.cpp b/src/plugins/security/model/ui/ldapsearchlistwidget.cpp new file mode 100644 index 000000000..3dd238819 --- /dev/null +++ b/src/plugins/security/model/ui/ldapsearchlistwidget.cpp @@ -0,0 +1,91 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2023 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#include "ldapsearchlistwidget.h" +#include "ui_ldapsearchlistwidget.h" + +#include "browseldapdialog.h" + +#include + +namespace security +{ + +class LdapSearchListWidgetPrivate +{ +public: + QString filter{}; + QString dn{}; + + LdapSearchListWidgetPrivate(const QString &newFilter, const QString &newDN) + : filter(newFilter) + , dn(newDN) + {} +}; + +LdapSearchListWidget::LdapSearchListWidget(const QString &filter, const QString &dn, const QString &title, QWidget *parent) + : QWidget(parent) + , d(new LdapSearchListWidgetPrivate(filter, dn)) + , ui(new Ui::LdapSearchListWidget()) +{ + ui->setupUi(this); + + ui->groupBox->setTitle(title); +} + +LdapSearchListWidget::LdapSearchListWidget(const std::string &filter, const std::string &dn, const std::string &title, QWidget *parent) + : LdapSearchListWidget(QString::fromStdString(filter), QString::fromStdString(dn), QString::fromStdString(title), parent) +{ +} + +LdapSearchListWidget::~LdapSearchListWidget() +{ + delete d; + delete ui; +} + +void LdapSearchListWidget::setAddButtonText(const QString &text) +{ + ui->addButton->setText(text); +} + +void LdapSearchListWidget::setRemoveButtonText(const QString &text) +{ + ui->removeButton->setText(text); +} + +void security::LdapSearchListWidget::on_addButton_clicked() +{ + auto browseLdapDialog = new BrowseLdapDialog(this); + browseLdapDialog->show(); +} + +void security::LdapSearchListWidget::on_removeButton_clicked() +{ + auto selectedItems = ui->listWidget->selectedItems(); + + for (const auto& selectedItem : selectedItems) + { + ui->listWidget->removeItemWidget(selectedItem); + delete selectedItem; + } +} + +} diff --git a/src/plugins/security/model/ui/ldapsearchlistwidget.h b/src/plugins/security/model/ui/ldapsearchlistwidget.h new file mode 100644 index 000000000..0e3b7190b --- /dev/null +++ b/src/plugins/security/model/ui/ldapsearchlistwidget.h @@ -0,0 +1,67 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2023 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#ifndef SECURITY_LDAP_SEARCH_LIST_WIDGET_H +#define SECURITY_LDAP_SEARCH_LIST_WIDGET_H + +#include + +QT_BEGIN_NAMESPACE +namespace Ui { class LdapSearchListWidget; } +QT_END_NAMESPACE + +namespace security +{ + +class LdapSearchListWidgetPrivate; + +class LdapSearchListWidget : public QWidget +{ +public: + Q_OBJECT + +public: + explicit LdapSearchListWidget(const QString& filter, const QString& dn, const QString &title, QWidget* parent = nullptr); + explicit LdapSearchListWidget(const std::string& filter, const std::string& dn, const std::string &title, QWidget* parent = nullptr); + ~LdapSearchListWidget() override; + + void setAddButtonText(const QString& text); + void setRemoveButtonText(const QString& text); + +private slots: + void on_addButton_clicked(); + void on_removeButton_clicked(); + +private: + LdapSearchListWidget(const LdapSearchListWidget&) = delete; // copy ctor + LdapSearchListWidget(LdapSearchListWidget&&) = delete; // move ctor + LdapSearchListWidget& operator=(const LdapSearchListWidget&) = delete; // copy assignment + LdapSearchListWidget& operator=(LdapSearchListWidget&&) = delete; // move assignment + +private: + LdapSearchListWidgetPrivate *d{}; + +private: + Ui::LdapSearchListWidget *ui{}; +}; + +} + +#endif//SECURITY_LDAP_SEARCH_LIST_WIDGET_H diff --git a/src/plugins/security/model/ui/ldapsearchlistwidget.ui b/src/plugins/security/model/ui/ldapsearchlistwidget.ui new file mode 100644 index 000000000..4868c302e --- /dev/null +++ b/src/plugins/security/model/ui/ldapsearchlistwidget.ui @@ -0,0 +1,84 @@ + + + LdapSearchListWidget + + + + 0 + 0 + 411 + 300 + + + + Form + + + + + + Ldap search header: + + + false + + + true + + + false + + + + 7 + + + 7 + + + 7 + + + 7 + + + 5 + + + + + + + + Add button + + + + + + + Remove button + + + + + + + Qt::Horizontal + + + + 190 + 20 + + + + + + + + + + + + diff --git a/src/plugins/security/model/ui/presentationbuilder.cpp b/src/plugins/security/model/ui/presentationbuilder.cpp new file mode 100644 index 000000000..f425e7455 --- /dev/null +++ b/src/plugins/security/model/ui/presentationbuilder.cpp @@ -0,0 +1,356 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2023 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#include "presentationbuilder.h" + +#include + +#include "../presentation/checkbox.h" +#include "../presentation/combobox.h" +#include "../presentation/decimaltextbox.h" +#include "../presentation/dropdownlist.h" +#include "../presentation/groupbox.h" +#include "../presentation/ldapsearchdialog.h" +#include "../presentation/listbox.h" +#include "../presentation/longdecimaltextbox.h" +#include "../presentation/multitextbox.h" +#include "../presentation/text.h" +#include "../presentation/textbox.h" + +#include "../presentation/securitypresentationresources.h" +#include "ldapsearchlistwidget.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +template +inline constexpr bool always_false_v = false; + +namespace security +{ + +template +QLayoutItem *createAndAttachLabel(QWidget *buddy, const QString &text) +{ + Q_UNUSED(text); + + TLayoutItem *container = new TLayoutItem(); + container->addWidget(buddy); + return container; +} + +class PresentationBuilderPrivate +{ +public: + + void visit(DecimalTextBox &widget) const + { + QWidget *textBox = createAnyDecimalTextBox(widget.spinBox, widget.defaultValue, widget.spinStep); + + QLayoutItem *container = createAndAttachLabel(textBox, QString::fromStdString(widget.postfix)); + + addToLayout(container); + } + + void visit(TextBox &widget) const + { + QLineEdit *lineEdit = new QLineEdit(); + lineEdit->setText(QString::fromStdString(widget.defaultValue)); + + QLayoutItem *container = createAndAttachLabel(lineEdit, QString::fromStdString(widget.label)); + + addToLayout(container); + } + + void visit(CheckBox &widget) const + { + QCheckBox *checkBox = new QCheckBox(); + + checkBox->setChecked(widget.defaultChecked); + QLayoutItem *container = createAndAttachLabel(checkBox, QString::fromStdString(widget.postfix)); + + addToLayout(container); + } + + void visit(ComboBox &widget) const + { + QComboBox *comboBox = new QComboBox(); + comboBox->setCurrentText(QString::fromStdString(widget.defaultValue)); + for (const auto &item : widget.suggestion) + { + comboBox->addItem(QString::fromStdString(item)); + } + + QLayoutItem *container = createAndAttachLabel(comboBox, QString::fromStdString(widget.label)); + + addToLayout(container); + } + + void visit(DropdownList &widget) const + { + QComboBox *comboBox = new QComboBox(); + comboBox->setCurrentIndex(widget.defaultItem); + + QLayoutItem *container = createAndAttachLabel(comboBox, QString::fromStdString(widget.label)); + + if (widget.values.size() > 0) + { + for (auto &value : widget.values) + { + comboBox->addItem(QString::fromStdString(value)); + } + if (widget.defaultItem < widget.values.size()) + { + comboBox->setCurrentIndex(widget.defaultItem); + } + } + + addToLayout(container); + } + + void visit(LongDecimalTextBox &widget) const + { + QWidget *textBox = createAnyDecimalTextBox(widget.spinBox, widget.defaultValue, widget.spinStep); + + QLayoutItem *container = createAndAttachLabel(textBox, QString::fromStdString(widget.postfix)); + + addToLayout(container); + } + + void visit(MultiTextBox &widget) const + { + Q_UNUSED(widget); + QTextEdit *textEdit = new QTextEdit(); + textEdit->setMaximumHeight(widget.defaultHeight * textEdit->fontMetrics().height()); + + addToLayout(textEdit); + } + + void visit(GroupBox &widget) const + { + QGroupBox *groupBox = new QGroupBox(); + groupBox->setCheckable(widget.hasCheckBox); + groupBox->setChecked(widget.defaultChecked); + + // TODO: Implement. + + addToLayout(groupBox); + } + + void visit(ListBox &widget) const + { + QPushButton *button = new QPushButton(QObject::tr("Edit")); + + QLayoutItem *container = createAndAttachLabel(button, QString::fromStdString(widget.postfix)); + + auto onClicked = [&]() { + gpui::ListBoxDialog *listBox = new gpui::ListBoxDialog(QString::fromStdString(widget.postfix)); + listBox->setAttribute(Qt::WA_DeleteOnClose); + + listBox->show(); + }; + + QObject::connect(button, &QPushButton::clicked, onClicked); + + addToLayout(container); + } + + void visit(LdapSearchDialog &widget) const + { + LdapSearchListWidget* ldapSearchListWidget = new LdapSearchListWidget(widget.filter, widget.dn, widget.title); + ldapSearchListWidget->setAddButtonText(QString::fromStdString(widget.addLabel)); + ldapSearchListWidget->setRemoveButtonText(QString::fromStdString(widget.removeLabel)); + + QLayoutItem *container = createAndAttachLabel(ldapSearchListWidget, + QString::fromStdString(widget.postfix)); + + addToLayout(container); + } + + void visit(RadioButton &widget) const + { + QRadioButton *radioButton = new QRadioButton(); + + radioButton->setChecked(widget.defaultChecked); + QLayoutItem *container = createAndAttachLabel(radioButton, ""); + + addToLayout(container); + } + + void visit(Comment &widget) const + { + QLabel *label = new QLabel(); + label->setText(QString::fromStdString(widget.text)); + label->setWordWrap(true); + label->setAlignment(Qt::AlignHCenter); + addToLayout(label); + } + + void visit(Text &widget) const + { + QLabel *label = new QLabel(); + label->setText(QString::fromStdString(widget.content)); + label->setWordWrap(true); + label->setAlignment(Qt::AlignHCenter); + addToLayout(label); + } + + void setLayout(QLayout *layout) { m_layout = layout; } + + void setSecurity(const SecurityDefinition &security) { m_security = &security; } + + void setCurrentElementName(std::string elementName) { m_elementName = elementName; } + +private: + QLayout *m_layout = nullptr; + const SecurityDefinition *m_security = nullptr; + std::string m_elementName = ""; + +private: + void addToLayout(QWidget *widget) const + { + if (m_layout) + { + m_layout->addWidget(widget); + } + } + + void addToLayout(QLayoutItem *container) const + { + if (container) + { + m_layout->addItem(container); + } + } + +private: + template + QWidget *createAnyDecimalTextBox(bool spin, Number value, Number step) const + { + if (spin) + { + ::gui::AltSpinBox *spinBox = new ::gui::AltSpinBox(); + spinBox->setMinimum(0); + spinBox->setMaximum(std::numeric_limits::max()); + spinBox->setSingleStep(step); + spinBox->setValue(value); + + return spinBox; + } + + QLineEdit *edit = new QLineEdit(); + edit->setText(QString::number(value)); + edit->setValidator(new QIntValidator(0, std::numeric_limits::max())); + + return edit; + } +}; + +PresentationBuilderPrivate* PresentationBuilder::d = new PresentationBuilderPrivate(); + +QVBoxLayout *PresentationBuilder::build(const PresentationBuilderParams ¶ms) +{ + QVBoxLayout *layout = new QVBoxLayout(); + d->setLayout(layout); + d->setSecurity(params.security); + + for (const auto &widget : params.presentation.widgets) + { + d->setCurrentElementName(widget.first); + + std::visit([](auto&& arg) noexcept + { + using T = std::decay_t; + if constexpr (std::is_same_v >) + { + d->visit(*arg); + } + else if constexpr (std::is_same_v >) + { + d->visit(*arg); + } + else if constexpr (std::is_same_v >) + { + d->visit(*arg); + } + else if constexpr (std::is_same_v >) + { + d->visit(*arg); + } + else if constexpr (std::is_same_v >) + { + d->visit(*arg); + } + else if constexpr (std::is_same_v >) + { + d->visit(*arg); + } + else if constexpr (std::is_same_v >) + { + d->visit(*arg); + } + else if constexpr (std::is_same_v >) + { + d->visit(*arg); + } + else if constexpr (std::is_same_v >) + { + d->visit(*arg); + } + else if constexpr (std::is_same_v >) + { + d->visit(*arg); + } + else if constexpr (std::is_same_v >) + { + d->visit(*arg); + } + else if constexpr (std::is_same_v >) + { + d->visit(*arg); + } + else if constexpr (std::is_same_v >) + { + d->visit(*arg); + } + else + { + static_assert(always_false_v, "non-exhaustive visitor!"); + } + }, widget.second); + } + layout->addStretch(); + + return layout; +} + +} diff --git a/src/plugins/security/model/ui/presentationbuilder.h b/src/plugins/security/model/ui/presentationbuilder.h new file mode 100644 index 000000000..86f3f2053 --- /dev/null +++ b/src/plugins/security/model/ui/presentationbuilder.h @@ -0,0 +1,65 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2023 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#ifndef GPUI_SECURITY_PRESENTATION_BUILDER_H +#define GPUI_SECURITY_PRESENTATION_BUILDER_H + +#include +#include +#include + +namespace security +{ + class SecurityPresentation; + class SecurityDefinition; +} + +namespace security +{ + struct PresentationBuilderParams final + { + const security::SecurityPresentation& presentation; + const security::SecurityDefinition& security; + }; + + class PresentationBuilderPrivate; + + /*! + * \class PresentationBuilder + * \brief The PresentationBuilder class + * + * \ingroup gui + */ + class PresentationBuilder + { + public: + /*! + * @brief build + * @param presentation Defines a reference to policy representation. + * @return nullptr if build failed, and widget associated with policy otherwise. + */ + static QVBoxLayout *build(const PresentationBuilderParams& params); + + private: + static PresentationBuilderPrivate* d; + }; +} + +#endif // GPUI_SECURITY_PRESENTATION_BUILDER_H diff --git a/src/plugins/security/model/ui/securityproxymodel.cpp b/src/plugins/security/model/ui/securityproxymodel.cpp new file mode 100644 index 000000000..661bce9f7 --- /dev/null +++ b/src/plugins/security/model/ui/securityproxymodel.cpp @@ -0,0 +1,73 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2023 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#include "securityproxymodel.h" + +#include "../administrative_templates/bundle/itemtype.h" +#include "../administrative_templates/bundle/policyroles.h" + +#include "securitywidget.h" + +namespace security +{ + +class SecurityProxyModelPrivate +{ +public: +}; + +SecurityProxyModel::SecurityProxyModel() + : d(new SecurityProxyModelPrivate()) +{ +} + +SecurityProxyModel::~SecurityProxyModel() +{ + delete d; +} + +QVariant SecurityProxyModel::data(const QModelIndex &proxyIndex, int role) const +{ + if (role == model::bundle::POLICY_WIDGET) + { + std::function widgetCreator = [=]() { + auto contentWidget = new SecurityWidget(); + + contentWidget->setMachineSecuritySource(); + contentWidget->setUserSecuritySource(); + + contentWidget->setModelIndex(proxyIndex); + + connect(contentWidget, + &SecurityWidget::savePolicyChanges, + this, + &SecurityProxyModel::savePolicyChanges); + return contentWidget; + }; + + return QVariant::fromValue(widgetCreator); + } + + return QIdentityProxyModel::data(proxyIndex, role); +} + +} // namespace security + +Q_DECLARE_METATYPE(std::function) diff --git a/src/plugins/security/model/ui/securityproxymodel.h b/src/plugins/security/model/ui/securityproxymodel.h new file mode 100644 index 000000000..e4acbcfa5 --- /dev/null +++ b/src/plugins/security/model/ui/securityproxymodel.h @@ -0,0 +1,58 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2023 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#ifndef GPUI_SECURITY_PROXY_MODEL_H +#define GPUI_SECURITY_PROXY_MODEL_H + +#include + +namespace security +{ +class SecurityProxyModelPrivate; + +class SecurityProxyModel : public QIdentityProxyModel +{ + Q_OBJECT + +public: + SecurityProxyModel(); + ~SecurityProxyModel(); + + QVariant data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const override; + + void setUserSecuritySource(); + void setMachineSecuritySource(); + +signals: + void savePolicyChanges(); + +private: + SecurityProxyModelPrivate *d = nullptr; + +private: + SecurityProxyModel(const SecurityProxyModel &) = delete; // copy ctor + SecurityProxyModel(SecurityProxyModel &&) = delete; // move ctor + SecurityProxyModel &operator=(const SecurityProxyModel &) = delete; // copy assignment + SecurityProxyModel &operator=(SecurityProxyModel &&) = delete; // move assignment +}; + +} // namespace security + +#endif // GPUI_SECURITY_PROXY_MODEL_H diff --git a/src/plugins/security/model/ui/securitywidget.cpp b/src/plugins/security/model/ui/securitywidget.cpp new file mode 100644 index 000000000..142316166 --- /dev/null +++ b/src/plugins/security/model/ui/securitywidget.cpp @@ -0,0 +1,99 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2023 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#include "securitywidget.h" +#include "ui_securitywidget.h" + +#include "../administrative_templates/bundle/itemtype.h" +#include "../administrative_templates/bundle/policyroles.h" + +#include "../sdmx/securitydefinition.h" +#include "../presentation/securitypresentation.h" + +#include "presentationbuilder.h" + +using namespace model::bundle; + +namespace security +{ +typedef std::shared_ptr<::security::SecurityDefinition> SecurityPtr; +typedef std::shared_ptr<::security::SecurityPresentation> PresentationPtr; + + +SecurityWidget::SecurityWidget(QWidget *parent) + : PluginWidgetInterface(parent) + , ui(new Ui::SecurityWidget()) +{ + ui->setupUi(this); +} + +SecurityWidget::~SecurityWidget() +{ + delete ui; +} + +void SecurityWidget::setModelIndex(const QModelIndex &index) +{ + const QAbstractItemModel *model = index.model(); + + if (model) + { + ui->securityNameLabel->setText((tr("Security policy: ") + model->data(index, Qt::DisplayRole).value()).trimmed()); + ui->descriptionTextEdit->setText(model->data(index, PolicyRoles::EXPLAIN_TEXT).value()); + + if (model->data(index, PolicyRoles::ITEM_TYPE).value() == ItemType::ITEM_TYPE_POLICY) + { + auto presentation = model->data(index, PolicyRoles::PRESENTATION).value(); + auto security = model->data(index, PolicyRoles::POLICY).value(); + + if (presentation && security) + { + auto layout = ::security::PresentationBuilder::build( + { + *presentation, + *security, + }); + + if (layout) + { + ui->contentScrollArea->widget()->setLayout(layout); + } + } + } + } +} + +void SecurityWidget::setUserSecuritySource() +{ +} + +void SecurityWidget::setMachineSecuritySource() +{ +} + +bool SecurityWidget::hasDataChanged() +{ + return false; +} + +} + +Q_DECLARE_METATYPE(std::shared_ptr<::security::SecurityDefinition>) +Q_DECLARE_METATYPE(std::shared_ptr<::security::SecurityPresentation>) diff --git a/src/plugins/security/model/ui/securitywidget.h b/src/plugins/security/model/ui/securitywidget.h new file mode 100644 index 000000000..de42523c1 --- /dev/null +++ b/src/plugins/security/model/ui/securitywidget.h @@ -0,0 +1,66 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2023 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#ifndef SECURITY_SECURITY_WIDGET_H +#define SECURITY_SECURITY_WIDGET_H + +#include + +#include "../../gui/pluginwidgetinterface.h" + +QT_BEGIN_NAMESPACE +namespace Ui { class SecurityWidget; } +QT_END_NAMESPACE + +namespace security +{ + +class SecurityWidget : public gui::PluginWidgetInterface +{ +public: + Q_OBJECT + +public: + explicit SecurityWidget(QWidget* parent = nullptr); + ~SecurityWidget(); + + void setModelIndex(const QModelIndex &index); + + void setUserSecuritySource(); + void setMachineSecuritySource(); + + virtual bool hasDataChanged() override final; + +signals: + void savePolicyChanges(); + +private: + SecurityWidget(const SecurityWidget&) = delete; // copy ctor + SecurityWidget(SecurityWidget&&) = delete; // move ctor + SecurityWidget& operator=(const SecurityWidget&) = delete; // copy assignment + SecurityWidget& operator=(SecurityWidget&&) = delete; // move assignment + +private: + Ui::SecurityWidget *ui {nullptr}; +}; + +} + +#endif // SECURITY_SECURITY_WIDGET_H diff --git a/src/plugins/security/model/ui/securitywidget.ui b/src/plugins/security/model/ui/securitywidget.ui new file mode 100644 index 000000000..76dd2dc51 --- /dev/null +++ b/src/plugins/security/model/ui/securitywidget.ui @@ -0,0 +1,161 @@ + + + SecurityWidget + + + + 0 + 0 + 649 + 544 + + + + Form + + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 0 + 52 + + + + + 16777215 + 52 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 0 + 0 + + + + + + + true + + + + + + + + + + Qt::Horizontal + + + + true + + + + + 0 + 0 + 400 + 445 + + + + + + + + + + Help: + + + descriptionTextEdit + + + + + + + + 0 + 4 + + + + + 215 + 0 + + + + Qt::NoFocus + + + true + + + + + + + + + + + Qt::Horizontal + + + + 508 + 20 + + + + + + + + &Cancel + + + + + + + &OK + + + + + + + + diff --git a/src/plugins/security/schema/CMakeLists.txt b/src/plugins/security/schema/CMakeLists.txt new file mode 100644 index 000000000..93d5b7815 --- /dev/null +++ b/src/plugins/security/schema/CMakeLists.txt @@ -0,0 +1,10 @@ +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") + +set(XSD_FILES + "${CMAKE_CURRENT_SOURCE_DIR}/basetypes.xsd" + "${CMAKE_CURRENT_SOURCE_DIR}/securitydefinitions.xsd" + "${CMAKE_CURRENT_SOURCE_DIR}/securitydefinitionfiles.xsd" + "${CMAKE_CURRENT_SOURCE_DIR}/security.xsd" +) + +add_xsd_library(security_static_xsd_library ${XSD_FILES}) diff --git a/src/plugins/security/schema/basetypes.xsd b/src/plugins/security/schema/basetypes.xsd new file mode 100644 index 000000000..b25b908ed --- /dev/null +++ b/src/plugins/security/schema/basetypes.xsd @@ -0,0 +1,104 @@ + + + + + A standard {12345678-1234-1234-1234-123456789abcd} style guid string. + + + + + + + + + + + + + + + A reference to a localized string in the localized string section/table. + + + + + + + + + A reference to a policy presentation in the localized presentation section/table. + + + + + + + + + A localized string id (used in the localized string section/table). + + + + + + + + + + + + + + + + The base type for all defined type names, e.g. categories. + + + + + + + + + The base type for all references to defined types, e.g. categories. + + + + + + + + + A localized string + + + + + + + + + + + A valid registry key path (without reference to local system or user hive). + + + + + + + A valid registry value +name. + + + + + + + A valid file name (without a file path). + + + + + + diff --git a/src/plugins/security/schema/security.xsd b/src/plugins/security/schema/security.xsd new file mode 100644 index 000000000..fb69d7846 --- /dev/null +++ b/src/plugins/security/schema/security.xsd @@ -0,0 +1,427 @@ + + + + + Describes a choice element in a policy with associated values for the true and false cases. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Describes a list element in a security policy. + + + + + + + + + + + + + Describes a multi line text element in a policy. + + + + + + + + Describes a single line text element in a policy. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + An enumeration of the 3 possible types a security definition can belong to. + + + + + + + + + + A grouping of security definitions. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Root presentation element. + + + + + + + + + + + + + + Represents a checkbox display element.\nCan be associated with a BooleanElement. + + + + + + + + + + + + + + + Represents a text box with or without a spin control for entering decimal numbers. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Represents a combobox display element with default/suggested entries. + + + + + + + + + + + + + + + + Represents a textbox display element with default entry. + + + + + + + + + + + + + Represents a dropdown list display element. + + + + + + + Represents a textbox display element with default entry. + + + + + + + + + + + + + Represents a listbox display element. + + + + + + + + Represents a comment display element. + + + + + + + + + + + Represents a security descriptor editor display element. + + + + + + + + + + Represents a LDAP search dialog display element.\nCan be associated with a TextElement. + + + + + + + + + + + + + + Represents a radio button display element.\nCan be associated with a BooleanElement. + + + + + + + + + + A standard {12345678-1234-1234-1234-123456789abcd} style guid string. + + + + + + + + + + + Represents a text box with or without a spin control for entering long decimal numbers. + + + + + + + + + + + + A localized string + + + + + + + + + + + + + + + + + + + + A table of referenced localized strings and policy presentations. + + + + + + + + + + + + + + + + + + + diff --git a/src/plugins/security/schema/securitydefinitionfiles.xsd b/src/plugins/security/schema/securitydefinitionfiles.xsd new file mode 100644 index 000000000..acff348b6 --- /dev/null +++ b/src/plugins/security/schema/securitydefinitionfiles.xsd @@ -0,0 +1,3 @@ + + + diff --git a/src/plugins/security/schema/securitydefinitions.xsd b/src/plugins/security/schema/securitydefinitions.xsd new file mode 100644 index 000000000..d8b6b4ef6 --- /dev/null +++ b/src/plugins/security/schema/securitydefinitions.xsd @@ -0,0 +1,4 @@ + + + + diff --git a/src/plugins/security/securityplugin.cpp b/src/plugins/security/securityplugin.cpp new file mode 100644 index 000000000..f7f9f3059 --- /dev/null +++ b/src/plugins/security/securityplugin.cpp @@ -0,0 +1,40 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2023 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#include "core/plugin.h" + +#include "securitysnapin.h" + +#include "core/isnapin.h" + +namespace gpui +{ +class SecurityPlugin : public Plugin +{ +public: + SecurityPlugin() + : gpui::Plugin("SecuritySnapIn") + { + GPUI_REGISTER_PLUGIN_CLASS(typeid(::gpui::ISnapIn).name(), SecuritySnapIn); + } +}; +} // namespace gpui + +GPUI_EXPORT_PLUGIN(security, ::gpui::SecurityPlugin) diff --git a/src/plugins/security/securitysnapin.cpp b/src/plugins/security/securitysnapin.cpp new file mode 100644 index 000000000..6d1afdd27 --- /dev/null +++ b/src/plugins/security/securitysnapin.cpp @@ -0,0 +1,167 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2023 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#include "securitysnapin.h" + +#include + +#include "model/ui/securityproxymodel.h" +#include "model/bundle/securitybundle.h" + +#include "../storage/smb/smbdirectory.h" + + +using namespace security; + +namespace gpui +{ +class SecuritySnapInPrivate +{ +public: + std::string sdmxPath = "/usr/share/PolicyDefinitions/"; + std::string localeName = "en-US"; + std::string policyPath = ""; + + std::unique_ptr model = nullptr; + std::unique_ptr proxyModel = nullptr; + + void onDataSave() + { + createDirectory(policyPath + "/User/"); + createDirectory(policyPath + "/Machine/"); + } + + void policyBundleLoad() + { + auto bundle = std::make_unique(); + model = bundle->loadFolder(sdmxPath, localeName); + proxyModel->setSourceModel(model.get()); + } + + void createDirectory(const std::string &directoryName) + { + const QString path = QString::fromStdString(directoryName); + + if (path.startsWith("smb://")) + { + gpui::smb::SmbDirectory dir(path); + + if (!dir.exists()) + { + dir.mkdir(path); + } + } + else + { + QDir dir(path); + + if (!dir.exists()) + { + dir.mkdir(path); + } + } + } + + SecuritySnapInPrivate() {} + +private: + SecuritySnapInPrivate(const SecuritySnapInPrivate&) = delete; // copy ctor + SecuritySnapInPrivate(SecuritySnapInPrivate&&) = delete; // move ctor + SecuritySnapInPrivate& operator=(const SecuritySnapInPrivate&) = delete; // copy assignment + SecuritySnapInPrivate& operator=(SecuritySnapInPrivate&&) = delete; // move assignment + +}; + +SecuritySnapIn::SecuritySnapIn() + : AbstractSnapIn("ISnapIn", + "SecuritySnapIn", + "Snap-in for security management.", + {1, 0, 0}, + "GPL-2.0", + "Copyright (C) 2023 BaseALT Ltd. ") + , d(new SecuritySnapInPrivate()) +{ +} + +void SecuritySnapIn::onInitialize(QMainWindow *window) +{ + auto mainWindow = dynamic_cast<::gpui::MainWindow *>(window); + + if (mainWindow) + { + d->sdmxPath = mainWindow->getAdmxPath().toStdString(); + d->localeName = mainWindow->getLanguage().toStdString(); + qWarning() << "Setting default settings for security templates snap-in: " + << d->sdmxPath.c_str() + << d->localeName.c_str(); + } + + d->proxyModel = std::make_unique(); + + d->policyBundleLoad(); + + QObject::connect(d->proxyModel.get(), &SecurityProxyModel::savePolicyChanges, [&]() { + d->onDataSave(); + }); + + setRootNode(static_cast(d->proxyModel.get())); + + if (mainWindow) + { + QObject::connect(mainWindow, &MainWindow::admxPathChanged, [&](const QString &admxPath) { + qWarning() << "Loading bundle from snap-in: " << admxPath; + d->sdmxPath = admxPath.toStdString(); + d->policyBundleLoad(); + }); + + QObject::connect(d->proxyModel.get(), + &SecurityProxyModel::savePolicyChanges, + mainWindow, + &MainWindow::updateStatusBar); + } +} + +void SecuritySnapIn::onShutdown() +{ +} + +void SecuritySnapIn::onDataLoad(const std::string &policyPath, const std::string &locale) +{ + Q_UNUSED(locale); + + if (!policyPath.empty()) + { + d->policyPath = policyPath; + } +} + +void SecuritySnapIn::onDataSave() +{ + d->onDataSave(); +} + +void SecuritySnapIn::onRetranslateUI(const std::string &locale) +{ + d->localeName = locale; + d->policyBundleLoad(); + setRootNode(static_cast(d->proxyModel.get())); +} + +} diff --git a/src/plugins/security/securitysnapin.h b/src/plugins/security/securitysnapin.h new file mode 100644 index 000000000..26f1c303c --- /dev/null +++ b/src/plugins/security/securitysnapin.h @@ -0,0 +1,52 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2023 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#ifndef GPUI_SECURITY_SNAPIN_H +#define GPUI_SECURITY_SNAPIN_H + +#include "core/abstractsnapin.h" + +namespace gpui +{ + +class SecuritySnapInPrivate; + +class SecuritySnapIn final : public AbstractSnapIn +{ +public: + SecuritySnapIn(); + + void onInitialize(QMainWindow *mainWindow) override; + + void onShutdown() override; + + void onDataLoad(const std::string &policyPath, const std::string &locale) override; + + void onDataSave() override; + + void onRetranslateUI(const std::string &locale) override; + +private: + std::unique_ptr d; +}; + +} // namespace gpui + +#endif//GPUI_SECURITY_SNAPIN_H diff --git a/tests/data/security/user_rights_assignment/security.sdml b/tests/data/security/user_rights_assignment/security.sdml new file mode 100644 index 000000000..2c12ec4ab --- /dev/null +++ b/tests/data/security/user_rights_assignment/security.sdml @@ -0,0 +1,22 @@ + + + + + Deny log on as a batch job + +Deny log on as a service + +This security setting determines which service accounts are prevented from registering a process as a service. This policy setting supersedes the Log on as a service policy setting if an account is subject to both policies. + +Note: This security setting does not apply to the System, Local Service, or Network Service accounts. + +Default: None. + + + + + + + + + \ No newline at end of file diff --git a/tests/data/security/user_rights_assignment/security.sdmx b/tests/data/security/user_rights_assignment/security.sdmx new file mode 100644 index 000000000..895a6baee --- /dev/null +++ b/tests/data/security/user_rights_assignment/security.sdmx @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + +