21#include <com/sun/star/sdbc/XRow.hpp>
22#include <com/sun/star/sdbc/XResultSet.hpp>
25#include <com/sun/star/sdbcx/Privilege.hpp>
26#include <com/sun/star/sdbcx/PrivilegeObject.hpp>
41OMySQLUser::OMySQLUser(css::uno::Reference<css::sdbc::XConnection> _xConnection)
72 Sequence<Property> aProps;
88 sal_Int32 nRights, nRightsWithGrant;
94 sal_Int32& nRights, sal_Int32& nRightsWithGrant)
96 nRightsWithGrant = nRights = 0;
98 Reference<XDatabaseMetaData> xMeta =
m_xConnection->getMetaData();
101 ::dbtools::EComposeRule::InDataManipulation);
102 Reference<XResultSet> xRes;
105 case PrivilegeObject::TABLE:
106 case PrivilegeObject::VIEW:
111 xRes = xMeta->getTablePrivileges(aCatalog,
sSchema, sTable);
115 case PrivilegeObject::COLUMN:
120 xRes = xMeta->getColumnPrivileges(aCatalog,
sSchema, sTable,
"%");
128 static const char sYes[] =
"YES";
130 nRightsWithGrant = nRights = 0;
132 Reference<XRow> xCurrentRow(xRes, UNO_QUERY);
133 while (xCurrentRow.is() && xRes->next())
135 OUString sGrantee = xCurrentRow->getString(5);
136 OUString sPrivilege = xCurrentRow->getString(6);
137 OUString sGrantable = xCurrentRow->getString(7);
139 if (!
m_Name.equalsIgnoreAsciiCase(sGrantee))
142 if (sPrivilege.equalsIgnoreAsciiCase(
"SELECT"))
144 nRights |= Privilege::SELECT;
145 if (sGrantable.equalsIgnoreAsciiCase(sYes))
146 nRightsWithGrant |= Privilege::SELECT;
148 else if (sPrivilege.equalsIgnoreAsciiCase(
"INSERT"))
150 nRights |= Privilege::INSERT;
151 if (sGrantable.equalsIgnoreAsciiCase(sYes))
152 nRightsWithGrant |= Privilege::INSERT;
154 else if (sPrivilege.equalsIgnoreAsciiCase(
"UPDATE"))
156 nRights |= Privilege::UPDATE;
157 if (sGrantable.equalsIgnoreAsciiCase(sYes))
158 nRightsWithGrant |= Privilege::UPDATE;
160 else if (sPrivilege.equalsIgnoreAsciiCase(
"DELETE"))
162 nRights |= Privilege::DELETE;
163 if (sGrantable.equalsIgnoreAsciiCase(sYes))
164 nRightsWithGrant |= Privilege::DELETE;
166 else if (sPrivilege.equalsIgnoreAsciiCase(
"READ"))
168 nRights |= Privilege::READ;
169 if (sGrantable.equalsIgnoreAsciiCase(sYes))
170 nRightsWithGrant |= Privilege::READ;
172 else if (sPrivilege.equalsIgnoreAsciiCase(
"CREATE"))
174 nRights |= Privilege::CREATE;
175 if (sGrantable.equalsIgnoreAsciiCase(sYes))
176 nRightsWithGrant |= Privilege::CREATE;
178 else if (sPrivilege.equalsIgnoreAsciiCase(
"ALTER"))
180 nRights |= Privilege::ALTER;
181 if (sGrantable.equalsIgnoreAsciiCase(sYes))
182 nRightsWithGrant |= Privilege::ALTER;
184 else if (sPrivilege.equalsIgnoreAsciiCase(
"REFERENCES"))
186 nRights |= Privilege::REFERENCE;
187 if (sGrantable.equalsIgnoreAsciiCase(sYes))
188 nRightsWithGrant |= Privilege::REFERENCE;
190 else if (sPrivilege.equalsIgnoreAsciiCase(
"DROP"))
192 nRights |= Privilege::DROP;
193 if (sGrantable.equalsIgnoreAsciiCase(sYes))
194 nRightsWithGrant |= Privilege::DROP;
197 ::comphelper::disposeComponent(xRes);
205 sal_Int32 nRights, nRightsWithGrant;
207 return nRightsWithGrant;
211 sal_Int32 objPrivileges)
213 if (objType != PrivilegeObject::TABLE)
223 if (sPrivs.isEmpty())
226 Reference<XDatabaseMetaData> xMeta =
m_xConnection->getMetaData();
228 =
"GRANT " + sPrivs +
" ON "
232 Reference<XStatement> xStmt =
m_xConnection->createStatement();
234 xStmt->execute(sGrant);
235 ::comphelper::disposeComponent(xStmt);
239 sal_Int32 objPrivileges)
241 if (objType != PrivilegeObject::TABLE)
251 if (sPrivs.isEmpty())
254 Reference<XDatabaseMetaData> xMeta =
m_xConnection->getMetaData();
256 =
"REVOKE " + sPrivs +
" ON "
260 Reference<XStatement> xStmt =
m_xConnection->createStatement();
262 xStmt->execute(sGrant);
263 ::comphelper::disposeComponent(xStmt);
268 const OUString& newPassword)
272 OUString sAlterPwd =
"SET PASSWORD FOR " +
m_Name +
"@\"%\" = PASSWORD('" + newPassword +
"')";
274 Reference<XStatement> xStmt =
m_xConnection->createStatement();
277 xStmt->execute(sAlterPwd);
278 ::comphelper::disposeComponent(xStmt);
285 if ((nRights & Privilege::INSERT) == Privilege::INSERT)
288 if ((nRights & Privilege::DELETE) == Privilege::DELETE)
290 if (!sPrivs.isEmpty())
295 if ((nRights & Privilege::UPDATE) == Privilege::UPDATE)
297 if (!sPrivs.isEmpty())
302 if ((nRights & Privilege::ALTER) == Privilege::ALTER)
304 if (!sPrivs.isEmpty())
309 if ((nRights & Privilege::SELECT) == Privilege::SELECT)
311 if (!sPrivs.isEmpty())
316 if ((nRights & Privilege::REFERENCE) == Privilege::REFERENCE)
318 if (!sPrivs.isEmpty())
320 sPrivs +=
"REFERENCES";
connectivity::sdbcx::OUser_BASE OUser_BASE_RBHELPER
::cppu::IPropertyArrayHelper * getArrayHelper()
void describeProperties(css::uno::Sequence< css::beans::Property > &_rProps) const
void registerProperty(const OUString &_rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, void *_pPointerToMember, const css::uno::Type &_rMemberType)
helper class for accessing resources shared by different libraries in the connectivity module
OUString getResourceString(TranslateId pResId) const
loads a string from the shared resource file
virtual void refreshGroups() override
virtual void SAL_CALL revokePrivileges(const OUString &objName, sal_Int32 objType, sal_Int32 objPrivileges) override
virtual void SAL_CALL grantPrivileges(const OUString &objName, sal_Int32 objType, sal_Int32 objPrivileges) override
virtual sal_Int32 SAL_CALL getGrantablePrivileges(const OUString &objName, sal_Int32 objType) override
virtual sal_Int32 SAL_CALL getPrivileges(const OUString &objName, sal_Int32 objType) override
static OUString getPrivilegeString(sal_Int32 nRights)
OMySQLUser(css::uno::Reference< css::sdbc::XConnection > _xConnection)
void findPrivilegesAndGrantPrivileges(const OUString &objName, sal_Int32 objType, sal_Int32 &nRights, sal_Int32 &nRightsWithGrant)
virtual void SAL_CALL changePassword(const OUString &objPassword, const OUString &newPassword) override
css::uno::Reference< css::sdbc::XConnection > m_xConnection
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
virtual void construct() override
OUserExtend(const css::uno::Reference< css::sdbc::XConnection > &_xConnection)
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const override
mutable::osl::Mutex m_aMutex
::cppu::WeakComponentImplHelper< css::sdbcx::XUser, css::sdbcx::XGroupsSupplier, css::container::XNamed, css::lang::XServiceInfo > OUser_BASE
void checkDisposed(bool _bThrow)
Reference< XConnection > m_xConnection
#define PROPERTY_ID_PASSWORD