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