summaryrefslogtreecommitdiff
path: root/connectivity/source/drivers
diff options
context:
space:
mode:
authorJulien Nabet <serval2412@yahoo.fr>2023-12-03 16:04:11 +0100
committerJulien Nabet <serval2412@yahoo.fr>2023-12-03 17:38:11 +0100
commit033f973e22f4d76a8e55a5591ac46249c149901d (patch)
tree169e7c6f41a817bab7be10b45e6c5df6db1f071e /connectivity/source/drivers
parentf8610622068edc0d69854fb44546fae7245a9568 (diff)
Mysql/Mariadb: implement Users::appendObject to allow users creation
Change-Id: I49d4b08470a741bfb15d5d473ba6ccf19c55c964 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160266 Reviewed-by: Julien Nabet <serval2412@yahoo.fr> Tested-by: Julien Nabet <serval2412@yahoo.fr>
Diffstat (limited to 'connectivity/source/drivers')
-rw-r--r--connectivity/source/drivers/mysqlc/mysqlc_user.cxx29
-rw-r--r--connectivity/source/drivers/mysqlc/mysqlc_user.hxx22
-rw-r--r--connectivity/source/drivers/mysqlc/mysqlc_users.cxx26
3 files changed, 72 insertions, 5 deletions
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_user.cxx b/connectivity/source/drivers/mysqlc/mysqlc_user.cxx
index b04415f1808e..6e8c3d734a67 100644
--- a/connectivity/source/drivers/mysqlc/mysqlc_user.cxx
+++ b/connectivity/source/drivers/mysqlc/mysqlc_user.cxx
@@ -15,6 +15,7 @@
#include <com/sun/star/sdbc/XRow.hpp>
#include <com/sun/star/sdbcx/Privilege.hpp>
#include <com/sun/star/sdbcx/PrivilegeObject.hpp>
+#include <TConnection.hxx>
using namespace ::connectivity;
using namespace ::connectivity::mysqlc;
@@ -37,6 +38,22 @@ User::User(css::uno::Reference<css::sdbc::XConnection> xConnection, const OUStri
{
}
+OUserExtend::OUserExtend(const css::uno::Reference<css::sdbc::XConnection>& xConnection,
+ const OUString& rName)
+ : User(xConnection, rName)
+{
+ construct();
+}
+
+void OUserExtend::construct()
+{
+ registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),
+ PROPERTY_ID_NAME, 0, &m_Name, ::cppu::UnoType<OUString>::get());
+
+ registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD),
+ PROPERTY_ID_PASSWORD, 0, &m_Password, ::cppu::UnoType<OUString>::get());
+}
+
void User::changePassword(const OUString& /* oldPassword */, const OUString& newPassword)
{
css::uno::Reference<XStatement> statement = m_xConnection->createStatement();
@@ -44,6 +61,18 @@ void User::changePassword(const OUString& /* oldPassword */, const OUString& new
::comphelper::disposeComponent(statement);
}
+cppu::IPropertyArrayHelper* OUserExtend::createArrayHelper() const
+{
+ css::uno::Sequence<css::beans::Property> aProps;
+ describeProperties(aProps);
+ return new cppu::OPropertyArrayHelper(aProps);
+}
+
+cppu::IPropertyArrayHelper& OUserExtend::getInfoHelper()
+{
+ return *OUserExtend_PROP::getArrayHelper();
+}
+
typedef connectivity::sdbcx::OUser_BASE OUser_BASE_RBHELPER;
sal_Int32 SAL_CALL User::getPrivileges(const OUString& objName, sal_Int32 objType)
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_user.hxx b/connectivity/source/drivers/mysqlc/mysqlc_user.hxx
index d9b0435fdf78..f0449836ce6c 100644
--- a/connectivity/source/drivers/mysqlc/mysqlc_user.hxx
+++ b/connectivity/source/drivers/mysqlc/mysqlc_user.hxx
@@ -21,6 +21,8 @@ class User : public ::connectivity::sdbcx::OUser
{
css::uno::Reference<css::sdbc::XConnection> m_xConnection;
+ OUString m_Password;
+
public:
/**
* Create a "new" descriptor, which isn't yet in the database.
@@ -46,6 +48,26 @@ public:
virtual void refreshGroups() override;
};
+class OUserExtend;
+typedef ::comphelper::OPropertyArrayUsageHelper<OUserExtend> OUserExtend_PROP;
+
+class OUserExtend : public User, public OUserExtend_PROP
+{
+ OUString m_Password;
+
+protected:
+ // OPropertyArrayUsageHelper
+ virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const override;
+ // OPropertySetHelper
+ virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override;
+
+public:
+ OUserExtend(const css::uno::Reference<css::sdbc::XConnection>& _xConnection,
+ const OUString& rName);
+
+ virtual void construct() override;
+};
+
} // namespace connectivity::mysqlc
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_users.cxx b/connectivity/source/drivers/mysqlc/mysqlc_users.cxx
index eb7de4cd4639..5e494226a95c 100644
--- a/connectivity/source/drivers/mysqlc/mysqlc_users.cxx
+++ b/connectivity/source/drivers/mysqlc/mysqlc_users.cxx
@@ -12,6 +12,8 @@
#include "mysqlc_user.hxx"
#include "mysqlc_users.hxx"
#include <comphelper/types.hxx>
+#include <connectivity/dbtools.hxx>
+#include <TConnection.hxx>
using namespace ::connectivity;
using namespace ::connectivity::mysqlc;
@@ -40,7 +42,7 @@ void Users::impl_refresh()
ObjectType Users::createObject(const OUString& rName)
{
- return new User(m_xMetaData->getConnection(), rName);
+ return new OUserExtend(m_xMetaData->getConnection(), rName);
}
uno::Reference<XPropertySet> Users::createDescriptor()
@@ -48,14 +50,28 @@ uno::Reference<XPropertySet> Users::createDescriptor()
// There is some internal magic so that the same class can be used as either
// a descriptor or as a normal user. See VUser.cxx for the details. In our
// case we just need to ensure we use the correct constructor.
- return new User(m_xMetaData->getConnection());
+ return new OUserExtend(m_xMetaData->getConnection(), "");
}
//----- XAppend ---------------------------------------------------------------
-ObjectType Users::appendObject(const OUString& rName, const uno::Reference<XPropertySet>&)
+ObjectType Users::appendObject(const OUString& rName,
+ const uno::Reference<XPropertySet>& descriptor)
{
- // TODO: set sSql as appropriate
- m_xMetaData->getConnection()->createStatement()->execute(OUString());
+ OUString aSql("GRANT USAGE ON * TO ");
+ OUString aQuote = m_xMetaData->getIdentifierQuoteString();
+ aSql += ::dbtools::quoteName(aQuote, rName) + " @\"%\" ";
+ OUString sPassword;
+ descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD))
+ >>= sPassword;
+ if (!sPassword.isEmpty())
+ {
+ aSql += " IDENTIFIED BY '" + sPassword + "'";
+ }
+
+ Reference<XStatement> statement = m_xMetaData->getConnection()->createStatement();
+ if (statement.is())
+ statement->execute(aSql);
+ ::comphelper::disposeComponent(statement);
return createObject(rName);
}