1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*9b5730f6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*9b5730f6SAndrew Rist * distributed with this work for additional information
6*9b5730f6SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*9b5730f6SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist * with the License. You may obtain a copy of the License at
10*9b5730f6SAndrew Rist *
11*9b5730f6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*9b5730f6SAndrew Rist *
13*9b5730f6SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist * KIND, either express or implied. See the License for the
17*9b5730f6SAndrew Rist * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist * under the License.
19*9b5730f6SAndrew Rist *
20*9b5730f6SAndrew Rist *************************************************************/
21*9b5730f6SAndrew Rist
22*9b5730f6SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir #include "ado/AUser.hxx"
27cdf0e10cSrcweir #include "ado/ACatalog.hxx"
28cdf0e10cSrcweir #include "ado/AGroups.hxx"
29cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
30cdf0e10cSrcweir #include <comphelper/sequence.hxx>
31cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
32cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp>
33cdf0e10cSrcweir #ifndef _CONNECTIVITY_ADO_BCONNECTION_HXX_
34cdf0e10cSrcweir #include "ado/AConnection.hxx"
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #include "ado/Awrapado.hxx"
37cdf0e10cSrcweir
38cdf0e10cSrcweir using namespace connectivity::ado;
39cdf0e10cSrcweir using namespace com::sun::star::uno;
40cdf0e10cSrcweir using namespace com::sun::star::lang;
41cdf0e10cSrcweir using namespace com::sun::star::beans;
42cdf0e10cSrcweir using namespace com::sun::star::sdbc;
43cdf0e10cSrcweir
44cdf0e10cSrcweir // -------------------------------------------------------------------------
OAdoUser(OCatalog * _pParent,sal_Bool _bCase,ADOUser * _pUser)45cdf0e10cSrcweir OAdoUser::OAdoUser(OCatalog* _pParent,sal_Bool _bCase, ADOUser* _pUser)
46cdf0e10cSrcweir : OUser_TYPEDEF(_bCase)
47cdf0e10cSrcweir ,m_pCatalog(_pParent)
48cdf0e10cSrcweir {
49cdf0e10cSrcweir construct();
50cdf0e10cSrcweir
51cdf0e10cSrcweir if(_pUser)
52cdf0e10cSrcweir m_aUser = WpADOUser(_pUser);
53cdf0e10cSrcweir else
54cdf0e10cSrcweir m_aUser.Create();
55cdf0e10cSrcweir }
56cdf0e10cSrcweir // -------------------------------------------------------------------------
OAdoUser(OCatalog * _pParent,sal_Bool _bCase,const::rtl::OUString & _Name)57cdf0e10cSrcweir OAdoUser::OAdoUser(OCatalog* _pParent,sal_Bool _bCase, const ::rtl::OUString& _Name)
58cdf0e10cSrcweir : OUser_TYPEDEF(_Name,_bCase)
59cdf0e10cSrcweir , m_pCatalog(_pParent)
60cdf0e10cSrcweir {
61cdf0e10cSrcweir construct();
62cdf0e10cSrcweir m_aUser.Create();
63cdf0e10cSrcweir m_aUser.put_Name(_Name);
64cdf0e10cSrcweir }
65cdf0e10cSrcweir // -------------------------------------------------------------------------
refreshGroups()66cdf0e10cSrcweir void OAdoUser::refreshGroups()
67cdf0e10cSrcweir {
68cdf0e10cSrcweir TStringVector aVector;
69cdf0e10cSrcweir WpADOGroups aGroups(m_aUser.get_Groups());
70cdf0e10cSrcweir aGroups.fillElementNames(aVector);
71cdf0e10cSrcweir if(m_pGroups)
72cdf0e10cSrcweir m_pGroups->reFill(aVector);
73cdf0e10cSrcweir else
74cdf0e10cSrcweir m_pGroups = new OGroups(m_pCatalog,m_aMutex,aVector,aGroups,isCaseSensitive());
75cdf0e10cSrcweir }
76cdf0e10cSrcweir //--------------------------------------------------------------------------
getUnoTunnelImplementationId()77cdf0e10cSrcweir Sequence< sal_Int8 > OAdoUser::getUnoTunnelImplementationId()
78cdf0e10cSrcweir {
79cdf0e10cSrcweir static ::cppu::OImplementationId * pId = 0;
80cdf0e10cSrcweir if (! pId)
81cdf0e10cSrcweir {
82cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
83cdf0e10cSrcweir if (! pId)
84cdf0e10cSrcweir {
85cdf0e10cSrcweir static ::cppu::OImplementationId aId;
86cdf0e10cSrcweir pId = &aId;
87cdf0e10cSrcweir }
88cdf0e10cSrcweir }
89cdf0e10cSrcweir return pId->getImplementationId();
90cdf0e10cSrcweir }
91cdf0e10cSrcweir
92cdf0e10cSrcweir // com::sun::star::lang::XUnoTunnel
93cdf0e10cSrcweir //------------------------------------------------------------------
getSomething(const Sequence<sal_Int8> & rId)94cdf0e10cSrcweir sal_Int64 OAdoUser::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException)
95cdf0e10cSrcweir {
96cdf0e10cSrcweir return (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
97cdf0e10cSrcweir ? reinterpret_cast< sal_Int64 >( this )
98cdf0e10cSrcweir : OUser_TYPEDEF::getSomething(rId);
99cdf0e10cSrcweir }
100cdf0e10cSrcweir
101cdf0e10cSrcweir // -------------------------------------------------------------------------
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any & rValue)102cdf0e10cSrcweir void OAdoUser::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)throw (Exception)
103cdf0e10cSrcweir {
104cdf0e10cSrcweir if(m_aUser.IsValid())
105cdf0e10cSrcweir {
106cdf0e10cSrcweir
107cdf0e10cSrcweir switch(nHandle)
108cdf0e10cSrcweir {
109cdf0e10cSrcweir case PROPERTY_ID_NAME:
110cdf0e10cSrcweir {
111cdf0e10cSrcweir ::rtl::OUString aVal;
112cdf0e10cSrcweir rValue >>= aVal;
113cdf0e10cSrcweir m_aUser.put_Name(aVal);
114cdf0e10cSrcweir }
115cdf0e10cSrcweir break;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir }
118cdf0e10cSrcweir }
119cdf0e10cSrcweir // -------------------------------------------------------------------------
getFastPropertyValue(Any & rValue,sal_Int32 nHandle) const120cdf0e10cSrcweir void OAdoUser::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const
121cdf0e10cSrcweir {
122cdf0e10cSrcweir if(m_aUser.IsValid())
123cdf0e10cSrcweir {
124cdf0e10cSrcweir switch(nHandle)
125cdf0e10cSrcweir {
126cdf0e10cSrcweir case PROPERTY_ID_NAME:
127cdf0e10cSrcweir rValue <<= m_aUser.get_Name();
128cdf0e10cSrcweir break;
129cdf0e10cSrcweir }
130cdf0e10cSrcweir }
131cdf0e10cSrcweir }
132cdf0e10cSrcweir // -------------------------------------------------------------------------
OUserExtend(OCatalog * _pParent,sal_Bool _bCase,ADOUser * _pUser)133cdf0e10cSrcweir OUserExtend::OUserExtend(OCatalog* _pParent,sal_Bool _bCase, ADOUser* _pUser)
134cdf0e10cSrcweir : OAdoUser(_pParent,_bCase,_pUser)
135cdf0e10cSrcweir {
136cdf0e10cSrcweir }
137cdf0e10cSrcweir // -------------------------------------------------------------------------
OUserExtend(OCatalog * _pParent,sal_Bool _bCase,const::rtl::OUString & _Name)138cdf0e10cSrcweir OUserExtend::OUserExtend(OCatalog* _pParent,sal_Bool _bCase, const ::rtl::OUString& _Name)
139cdf0e10cSrcweir : OAdoUser(_pParent,_bCase,_Name)
140cdf0e10cSrcweir {
141cdf0e10cSrcweir }
142cdf0e10cSrcweir
143cdf0e10cSrcweir // -------------------------------------------------------------------------
construct()144cdf0e10cSrcweir void OUserExtend::construct()
145cdf0e10cSrcweir {
146cdf0e10cSrcweir OUser_TYPEDEF::construct();
147cdf0e10cSrcweir registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD), PROPERTY_ID_PASSWORD,0,&m_Password,::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
148cdf0e10cSrcweir }
149cdf0e10cSrcweir // -----------------------------------------------------------------------------
createArrayHelper() const150cdf0e10cSrcweir cppu::IPropertyArrayHelper* OUserExtend::createArrayHelper() const
151cdf0e10cSrcweir {
152cdf0e10cSrcweir Sequence< com::sun::star::beans::Property > aProps;
153cdf0e10cSrcweir describeProperties(aProps);
154cdf0e10cSrcweir return new cppu::OPropertyArrayHelper(aProps);
155cdf0e10cSrcweir }
156cdf0e10cSrcweir // -------------------------------------------------------------------------
getInfoHelper()157cdf0e10cSrcweir cppu::IPropertyArrayHelper & OUserExtend::getInfoHelper()
158cdf0e10cSrcweir {
159cdf0e10cSrcweir return *OUserExtend_PROP::getArrayHelper();
160cdf0e10cSrcweir }
161cdf0e10cSrcweir // -----------------------------------------------------------------------------
162cdf0e10cSrcweir // -----------------------------------------------------------------------------
acquire()163cdf0e10cSrcweir void SAL_CALL OAdoUser::acquire() throw()
164cdf0e10cSrcweir {
165cdf0e10cSrcweir OUser_TYPEDEF::acquire();
166cdf0e10cSrcweir }
167cdf0e10cSrcweir // -----------------------------------------------------------------------------
release()168cdf0e10cSrcweir void SAL_CALL OAdoUser::release() throw()
169cdf0e10cSrcweir {
170cdf0e10cSrcweir OUser_TYPEDEF::release();
171cdf0e10cSrcweir }
172cdf0e10cSrcweir // -----------------------------------------------------------------------------
getPrivileges(const::rtl::OUString & objName,sal_Int32 objType)173cdf0e10cSrcweir sal_Int32 SAL_CALL OAdoUser::getPrivileges( const ::rtl::OUString& objName, sal_Int32 objType ) throw(SQLException, RuntimeException)
174cdf0e10cSrcweir {
175cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex);
176cdf0e10cSrcweir checkDisposed(OUser_BASE_TYPEDEF::rBHelper.bDisposed);
177cdf0e10cSrcweir
178cdf0e10cSrcweir return ADOS::mapAdoRights2Sdbc(m_aUser.GetPermissions(objName, ADOS::mapObjectType2Ado(objType)));
179cdf0e10cSrcweir }
180cdf0e10cSrcweir // -------------------------------------------------------------------------
getGrantablePrivileges(const::rtl::OUString & objName,sal_Int32 objType)181cdf0e10cSrcweir sal_Int32 SAL_CALL OAdoUser::getGrantablePrivileges( const ::rtl::OUString& objName, sal_Int32 objType ) throw(SQLException, RuntimeException)
182cdf0e10cSrcweir {
183cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex);
184cdf0e10cSrcweir checkDisposed(OUser_BASE_TYPEDEF::rBHelper.bDisposed);
185cdf0e10cSrcweir
186cdf0e10cSrcweir sal_Int32 nRights = 0;
187cdf0e10cSrcweir RightsEnum eRights = m_aUser.GetPermissions(objName, ADOS::mapObjectType2Ado(objType));
188cdf0e10cSrcweir if((eRights & adRightWithGrant) == adRightWithGrant)
189cdf0e10cSrcweir nRights = ADOS::mapAdoRights2Sdbc(eRights);
190cdf0e10cSrcweir ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),*this);
191cdf0e10cSrcweir return nRights;
192cdf0e10cSrcweir }
193cdf0e10cSrcweir // -------------------------------------------------------------------------
grantPrivileges(const::rtl::OUString & objName,sal_Int32 objType,sal_Int32 objPrivileges)194cdf0e10cSrcweir void SAL_CALL OAdoUser::grantPrivileges( const ::rtl::OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) throw(SQLException, RuntimeException)
195cdf0e10cSrcweir {
196cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex);
197cdf0e10cSrcweir checkDisposed(OUser_BASE_TYPEDEF::rBHelper.bDisposed);
198cdf0e10cSrcweir m_aUser.SetPermissions(objName,ADOS::mapObjectType2Ado(objType),adAccessGrant,RightsEnum(ADOS::mapRights2Ado(objPrivileges)));
199cdf0e10cSrcweir ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),*this);
200cdf0e10cSrcweir }
201cdf0e10cSrcweir // -------------------------------------------------------------------------
revokePrivileges(const::rtl::OUString & objName,sal_Int32 objType,sal_Int32 objPrivileges)202cdf0e10cSrcweir void SAL_CALL OAdoUser::revokePrivileges( const ::rtl::OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) throw(SQLException, RuntimeException)
203cdf0e10cSrcweir {
204cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex);
205cdf0e10cSrcweir checkDisposed(OUser_BASE_TYPEDEF::rBHelper.bDisposed);
206cdf0e10cSrcweir m_aUser.SetPermissions(objName,ADOS::mapObjectType2Ado(objType),adAccessRevoke,RightsEnum(ADOS::mapRights2Ado(objPrivileges)));
207cdf0e10cSrcweir ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),*this);
208cdf0e10cSrcweir }
209cdf0e10cSrcweir // -----------------------------------------------------------------------------
210cdf0e10cSrcweir // XUser
changePassword(const::rtl::OUString & objPassword,const::rtl::OUString & newPassword)211cdf0e10cSrcweir void SAL_CALL OAdoUser::changePassword( const ::rtl::OUString& objPassword, const ::rtl::OUString& newPassword ) throw(SQLException, RuntimeException)
212cdf0e10cSrcweir {
213cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex);
214cdf0e10cSrcweir checkDisposed(OUser_BASE_TYPEDEF::rBHelper.bDisposed);
215cdf0e10cSrcweir m_aUser.ChangePassword(objPassword,newPassword);
216cdf0e10cSrcweir ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),*this);
217cdf0e10cSrcweir }
218cdf0e10cSrcweir // -----------------------------------------------------------------------------
219cdf0e10cSrcweir
220cdf0e10cSrcweir
221cdf0e10cSrcweir
222cdf0e10cSrcweir
223cdf0e10cSrcweir
224