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