Update ooo320-m1
[ooovba.git] / connectivity / source / drivers / ado / AUser.cxx
blob1bf8da983f5d55e0d3a4f0f41318de5aa186740b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AUser.cxx,v $
10 * $Revision: 1.20 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "ado/AUser.hxx"
34 #include "ado/ACatalog.hxx"
35 #include "ado/AGroups.hxx"
36 #include <cppuhelper/typeprovider.hxx>
37 #include <comphelper/sequence.hxx>
38 #include <com/sun/star/sdbc/XRow.hpp>
39 #include <com/sun/star/sdbc/XResultSet.hpp>
40 #ifndef _CONNECTIVITY_ADO_BCONNECTION_HXX_
41 #include "ado/AConnection.hxx"
42 #endif
43 #include "ado/Awrapado.hxx"
45 using namespace connectivity::ado;
46 using namespace com::sun::star::uno;
47 using namespace com::sun::star::lang;
48 using namespace com::sun::star::beans;
49 using namespace com::sun::star::sdbc;
51 // -------------------------------------------------------------------------
52 OAdoUser::OAdoUser(OCatalog* _pParent,sal_Bool _bCase, ADOUser* _pUser)
53 : OUser_TYPEDEF(_bCase)
54 ,m_pCatalog(_pParent)
56 construct();
58 if(_pUser)
59 m_aUser = WpADOUser(_pUser);
60 else
61 m_aUser.Create();
63 // -------------------------------------------------------------------------
64 OAdoUser::OAdoUser(OCatalog* _pParent,sal_Bool _bCase, const ::rtl::OUString& _Name)
65 : OUser_TYPEDEF(_Name,_bCase)
66 , m_pCatalog(_pParent)
68 construct();
69 m_aUser.Create();
70 m_aUser.put_Name(_Name);
72 // -------------------------------------------------------------------------
73 void OAdoUser::refreshGroups()
75 TStringVector aVector;
76 WpADOGroups aGroups(m_aUser.get_Groups());
77 aGroups.fillElementNames(aVector);
78 if(m_pGroups)
79 m_pGroups->reFill(aVector);
80 else
81 m_pGroups = new OGroups(m_pCatalog,m_aMutex,aVector,aGroups,isCaseSensitive());
83 //--------------------------------------------------------------------------
84 Sequence< sal_Int8 > OAdoUser::getUnoTunnelImplementationId()
86 static ::cppu::OImplementationId * pId = 0;
87 if (! pId)
89 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
90 if (! pId)
92 static ::cppu::OImplementationId aId;
93 pId = &aId;
96 return pId->getImplementationId();
99 // com::sun::star::lang::XUnoTunnel
100 //------------------------------------------------------------------
101 sal_Int64 OAdoUser::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException)
103 return (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
104 ? reinterpret_cast< sal_Int64 >( this )
105 : OUser_TYPEDEF::getSomething(rId);
108 // -------------------------------------------------------------------------
109 void OAdoUser::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)throw (Exception)
111 if(m_aUser.IsValid())
114 switch(nHandle)
116 case PROPERTY_ID_NAME:
118 ::rtl::OUString aVal;
119 rValue >>= aVal;
120 m_aUser.put_Name(aVal);
122 break;
126 // -------------------------------------------------------------------------
127 void OAdoUser::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const
129 if(m_aUser.IsValid())
131 switch(nHandle)
133 case PROPERTY_ID_NAME:
134 rValue <<= m_aUser.get_Name();
135 break;
139 // -------------------------------------------------------------------------
140 OUserExtend::OUserExtend(OCatalog* _pParent,sal_Bool _bCase, ADOUser* _pUser)
141 : OAdoUser(_pParent,_bCase,_pUser)
144 // -------------------------------------------------------------------------
145 OUserExtend::OUserExtend(OCatalog* _pParent,sal_Bool _bCase, const ::rtl::OUString& _Name)
146 : OAdoUser(_pParent,_bCase,_Name)
150 // -------------------------------------------------------------------------
151 void OUserExtend::construct()
153 OUser_TYPEDEF::construct();
154 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD), PROPERTY_ID_PASSWORD,0,&m_Password,::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
156 // -----------------------------------------------------------------------------
157 cppu::IPropertyArrayHelper* OUserExtend::createArrayHelper() const
159 Sequence< com::sun::star::beans::Property > aProps;
160 describeProperties(aProps);
161 return new cppu::OPropertyArrayHelper(aProps);
163 // -------------------------------------------------------------------------
164 cppu::IPropertyArrayHelper & OUserExtend::getInfoHelper()
166 return *OUserExtend_PROP::getArrayHelper();
168 // -----------------------------------------------------------------------------
169 // -----------------------------------------------------------------------------
170 void SAL_CALL OAdoUser::acquire() throw()
172 OUser_TYPEDEF::acquire();
174 // -----------------------------------------------------------------------------
175 void SAL_CALL OAdoUser::release() throw()
177 OUser_TYPEDEF::release();
179 // -----------------------------------------------------------------------------
180 sal_Int32 SAL_CALL OAdoUser::getPrivileges( const ::rtl::OUString& objName, sal_Int32 objType ) throw(SQLException, RuntimeException)
182 ::osl::MutexGuard aGuard(m_aMutex);
183 checkDisposed(OUser_BASE_TYPEDEF::rBHelper.bDisposed);
185 return ADOS::mapAdoRights2Sdbc(m_aUser.GetPermissions(objName, ADOS::mapObjectType2Ado(objType)));
187 // -------------------------------------------------------------------------
188 sal_Int32 SAL_CALL OAdoUser::getGrantablePrivileges( const ::rtl::OUString& objName, sal_Int32 objType ) throw(SQLException, RuntimeException)
190 ::osl::MutexGuard aGuard(m_aMutex);
191 checkDisposed(OUser_BASE_TYPEDEF::rBHelper.bDisposed);
193 sal_Int32 nRights = 0;
194 RightsEnum eRights = m_aUser.GetPermissions(objName, ADOS::mapObjectType2Ado(objType));
195 if((eRights & adRightWithGrant) == adRightWithGrant)
196 nRights = ADOS::mapAdoRights2Sdbc(eRights);
197 ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),*this);
198 return nRights;
200 // -------------------------------------------------------------------------
201 void SAL_CALL OAdoUser::grantPrivileges( const ::rtl::OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) throw(SQLException, RuntimeException)
203 ::osl::MutexGuard aGuard(m_aMutex);
204 checkDisposed(OUser_BASE_TYPEDEF::rBHelper.bDisposed);
205 m_aUser.SetPermissions(objName,ADOS::mapObjectType2Ado(objType),adAccessGrant,RightsEnum(ADOS::mapRights2Ado(objPrivileges)));
206 ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),*this);
208 // -------------------------------------------------------------------------
209 void SAL_CALL OAdoUser::revokePrivileges( const ::rtl::OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) throw(SQLException, RuntimeException)
211 ::osl::MutexGuard aGuard(m_aMutex);
212 checkDisposed(OUser_BASE_TYPEDEF::rBHelper.bDisposed);
213 m_aUser.SetPermissions(objName,ADOS::mapObjectType2Ado(objType),adAccessRevoke,RightsEnum(ADOS::mapRights2Ado(objPrivileges)));
214 ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),*this);
216 // -----------------------------------------------------------------------------
217 // XUser
218 void SAL_CALL OAdoUser::changePassword( const ::rtl::OUString& objPassword, const ::rtl::OUString& newPassword ) throw(SQLException, RuntimeException)
220 ::osl::MutexGuard aGuard(m_aMutex);
221 checkDisposed(OUser_BASE_TYPEDEF::rBHelper.bDisposed);
222 m_aUser.ChangePassword(objPassword,newPassword);
223 ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),*this);
225 // -----------------------------------------------------------------------------