21#include <com/sun/star/sdbc/XRow.hpp>
22#include <com/sun/star/sdbc/XResultSet.hpp>
26#include <com/sun/star/sdbcx/Privilege.hpp>
27#include <com/sun/star/sdbcx/PrivilegeObject.hpp>
41OHSQLUser::OHSQLUser( css::uno::Reference< css::sdbc::XConnection > _xConnection) :
connectivity::sdbcx::
OUser(true)
71 Sequence< Property > aProps;
87 sal_Int32 nRights,nRightsWithGrant;
94 nRightsWithGrant = nRights = 0;
96 Reference<XDatabaseMetaData> xMeta =
m_xConnection->getMetaData();
99 Reference<XResultSet> xRes;
102 case PrivilegeObject::TABLE:
103 case PrivilegeObject::VIEW:
108 xRes = xMeta->getTablePrivileges(aCatalog,
sSchema,sTable);
112 case PrivilegeObject::COLUMN:
117 xRes = xMeta->getColumnPrivileges(aCatalog,
sSchema,sTable,
"%");
125 static const char sYes [] =
"YES";
127 nRightsWithGrant = nRights = 0;
129 Reference<XRow> xCurrentRow(xRes,UNO_QUERY);
130 while( xCurrentRow.is() && xRes->next() )
132 OUString sGrantee = xCurrentRow->getString(5);
133 OUString sPrivilege = xCurrentRow->getString(6);
134 OUString sGrantable = xCurrentRow->getString(7);
136 if (!
m_Name.equalsIgnoreAsciiCase(sGrantee))
139 if (sPrivilege.equalsIgnoreAsciiCase(
"SELECT"))
141 nRights |= Privilege::SELECT;
142 if ( sGrantable.equalsIgnoreAsciiCase(sYes) )
143 nRightsWithGrant |= Privilege::SELECT;
145 else if (sPrivilege.equalsIgnoreAsciiCase(
"INSERT"))
147 nRights |= Privilege::INSERT;
148 if ( sGrantable.equalsIgnoreAsciiCase(sYes) )
149 nRightsWithGrant |= Privilege::INSERT;
151 else if (sPrivilege.equalsIgnoreAsciiCase(
"UPDATE"))
153 nRights |= Privilege::UPDATE;
154 if ( sGrantable.equalsIgnoreAsciiCase(sYes) )
155 nRightsWithGrant |= Privilege::UPDATE;
157 else if (sPrivilege.equalsIgnoreAsciiCase(
"DELETE"))
159 nRights |= Privilege::DELETE;
160 if ( sGrantable.equalsIgnoreAsciiCase(sYes) )
161 nRightsWithGrant |= Privilege::DELETE;
163 else if (sPrivilege.equalsIgnoreAsciiCase(
"READ"))
165 nRights |= Privilege::READ;
166 if ( sGrantable.equalsIgnoreAsciiCase(sYes) )
167 nRightsWithGrant |= Privilege::READ;
169 else if (sPrivilege.equalsIgnoreAsciiCase(
"CREATE"))
171 nRights |= Privilege::CREATE;
172 if ( sGrantable.equalsIgnoreAsciiCase(sYes) )
173 nRightsWithGrant |= Privilege::CREATE;
175 else if (sPrivilege.equalsIgnoreAsciiCase(
"ALTER"))
177 nRights |= Privilege::ALTER;
178 if ( sGrantable.equalsIgnoreAsciiCase(sYes) )
179 nRightsWithGrant |= Privilege::ALTER;
181 else if (sPrivilege.equalsIgnoreAsciiCase(
"REFERENCE"))
183 nRights |= Privilege::REFERENCE;
184 if ( sGrantable.equalsIgnoreAsciiCase(sYes) )
185 nRightsWithGrant |= Privilege::REFERENCE;
187 else if (sPrivilege.equalsIgnoreAsciiCase(
"DROP"))
189 nRights |= Privilege::DROP;
190 if ( sGrantable.equalsIgnoreAsciiCase(sYes) )
191 nRightsWithGrant |= Privilege::DROP;
194 ::comphelper::disposeComponent(xRes);
202 sal_Int32 nRights,nRightsWithGrant;
204 return nRightsWithGrant;
209 if ( objType != PrivilegeObject::TABLE )
220 if(!sPrivs.isEmpty())
222 Reference<XDatabaseMetaData> xMeta =
m_xConnection->getMetaData();
223 OUString sGrant =
"GRANT " + sPrivs +
227 Reference<XStatement> xStmt =
m_xConnection->createStatement();
229 xStmt->execute(sGrant);
230 ::comphelper::disposeComponent(xStmt);
236 if ( objType != PrivilegeObject::TABLE )
246 if(!sPrivs.isEmpty())
248 Reference<XDatabaseMetaData> xMeta =
m_xConnection->getMetaData();
249 OUString sGrant =
"REVOKE " + sPrivs +
253 Reference<XStatement> xStmt =
m_xConnection->createStatement();
255 xStmt->execute(sGrant);
256 ::comphelper::disposeComponent(xStmt);
266 Reference<XDatabaseMetaData> xMeta =
m_xConnection->getMetaData();
268 if(
m_Name != xMeta->getUserName() )
273 OUString sAlterPwd =
"SET PASSWORD " +
276 Reference<XStatement> xStmt =
m_xConnection->createStatement();
279 xStmt->execute(sAlterPwd);
280 ::comphelper::disposeComponent(xStmt);
287 if((nRights & Privilege::INSERT) == Privilege::INSERT)
290 if((nRights & Privilege::DELETE) == Privilege::DELETE)
292 if(!sPrivs.isEmpty())
297 if((nRights & Privilege::UPDATE) == Privilege::UPDATE)
299 if(!sPrivs.isEmpty())
304 if((nRights & Privilege::ALTER) == Privilege::ALTER)
306 if(!sPrivs.isEmpty())
311 if((nRights & Privilege::SELECT) == Privilege::SELECT)
313 if(!sPrivs.isEmpty())
318 if((nRights & Privilege::REFERENCE) == Privilege::REFERENCE)
320 if(!sPrivs.isEmpty())
322 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 changePassword(const OUString &objPassword, const OUString &newPassword) override
virtual sal_Int32 SAL_CALL getPrivileges(const OUString &objName, sal_Int32 objType) override
static OUString getPrivilegeString(sal_Int32 nRights)
OHSQLUser(css::uno::Reference< css::sdbc::XConnection > _xConnection)
virtual void SAL_CALL revokePrivileges(const OUString &objName, sal_Int32 objType, sal_Int32 objPrivileges) override
css::uno::Reference< css::sdbc::XConnection > m_xConnection
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
void findPrivilegesAndGrantPrivileges(const OUString &objName, sal_Int32 objType, sal_Int32 &nRights, sal_Int32 &nRightsWithGrant)
OUserExtend(const css::uno::Reference< css::sdbc::XConnection > &_xConnection)
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const override
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
virtual void construct() 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