1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * Effective License of whole file:
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License version 2.1, as published by the Free Software Foundation.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
22 * The Contents of this file are made available subject to the terms of
23 * the GNU Lesser General Public License Version 2.1
25 * Copyright: 2000 by Sun Microsystems, Inc.
27 * Contributor(s): Joerg Budischewski
29 * All parts contributed on or after August 2011:
31 * Version: MPL 1.1 / GPLv3+ / LGPLv2.1+
33 * The contents of this file are subject to the Mozilla Public License Version
34 * 1.1 (the "License"); you may not use this file except in compliance with
35 * the License or as specified alternatively below. You may obtain a copy of
36 * the License at http://www.mozilla.org/MPL/
38 * Software distributed under the License is distributed on an "AS IS" basis,
39 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
40 * for the specific language governing rights and limitations under the
43 * Major Contributor(s):
44 * [ Copyright (C) 2011 Lionel Elie Mamane <lionel@mamane.lu> ]
46 * All Rights Reserved.
48 * For minor contributions see the git repository.
50 * Alternatively, the contents of this file may be used under the terms of
51 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
52 * the GNU Lesser General Public License Version 2.1 or later (the "LGPLv2.1+"),
53 * in which case the provisions of the GPLv3+ or the LGPLv2.1+ are applicable
54 * instead of those above.
56 ************************************************************************/
58 #include <rtl/ustrbuf.hxx>
60 #include <cppuhelper/typeprovider.hxx>
61 #include <cppuhelper/queryinterface.hxx>
63 #include <com/sun/star/beans/PropertyAttribute.hpp>
65 #include <com/sun/star/sdbc/XRow.hpp>
66 #include <com/sun/star/sdbc/XParameters.hpp>
68 #include "pq_xuser.hxx"
69 #include "pq_tools.hxx"
70 #include "pq_statics.hxx"
72 using osl::MutexGuard
;
76 using rtl::OUStringBuffer
;
78 using com::sun::star::container::XNameAccess
;
79 using com::sun::star::container::XIndexAccess
;
80 using com::sun::star::container::ElementExistException
;
81 using com::sun::star::container::NoSuchElementException
;
83 using com::sun::star::uno::Reference
;
84 using com::sun::star::uno::Exception
;
85 using com::sun::star::uno::UNO_QUERY
;
86 using com::sun::star::uno::XInterface
;
87 using com::sun::star::uno::Sequence
;
88 using com::sun::star::uno::Any
;
89 using com::sun::star::uno::makeAny
;
90 using com::sun::star::uno::Type
;
91 using com::sun::star::uno::RuntimeException
;
93 using com::sun::star::lang::IllegalArgumentException
;
94 using com::sun::star::lang::IndexOutOfBoundsException
;
96 using com::sun::star::beans::XPropertySetInfo
;
97 using com::sun::star::beans::XFastPropertySet
;
98 using com::sun::star::beans::XMultiPropertySet
;
99 using com::sun::star::beans::XPropertySet
;
100 using com::sun::star::beans::Property
;
102 using com::sun::star::sdbc::XResultSet
;
103 using com::sun::star::sdbc::XPreparedStatement
;
104 using com::sun::star::sdbc::XStatement
;
105 using com::sun::star::sdbc::XParameters
;
106 using com::sun::star::sdbc::XRow
;
107 using com::sun::star::sdbc::SQLException
;
109 namespace pq_sdbc_driver
112 #define ASCII_STR(x) OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )
114 User::User( const ::rtl::Reference
< RefCountedMutex
> & refMutex
,
115 const Reference
< com::sun::star::sdbc::XConnection
> & connection
,
116 ConnectionSettings
*pSettings
)
118 getStatics().refl
.user
.implName
,
119 getStatics().refl
.user
.serviceNames
,
123 * getStatics().refl
.user
.pProps
)
126 Reference
< XPropertySet
> User::createDataDescriptor( ) throw (RuntimeException
)
128 UserDescriptor
* pUser
= new UserDescriptor( m_refMutex
, m_conn
, m_pSettings
);
129 pUser
->copyValuesFrom( this );
131 return Reference
< XPropertySet
> ( pUser
);
135 Sequence
<Type
> User::getTypes() throw( RuntimeException
)
137 static cppu::OTypeCollection
*pCollection
;
140 MutexGuard
guard( osl::Mutex::getGlobalMutex() );
143 static cppu::OTypeCollection
collection(
144 getCppuType( (Reference
< com::sun::star::sdbcx::XUser
> *) 0 ),
145 ReflectionBase::getTypes());
146 pCollection
= &collection
;
149 return pCollection
->getTypes();
152 Sequence
< sal_Int8
> User::getImplementationId() throw( RuntimeException
)
154 return getStatics().refl
.user
.implementationId
;
157 Any
User::queryInterface( const Type
& reqType
) throw (RuntimeException
)
161 ret
= ReflectionBase::queryInterface( reqType
);
162 if( ! ret
.hasValue() )
163 ret
= ::cppu::queryInterface(
165 static_cast< com::sun::star::sdbcx::XUser
* > ( this ) );
170 void User::changePassword(
171 const ::rtl::OUString
& oldPassword
, const ::rtl::OUString
& newPassword
)
172 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
175 rtl::OUStringBuffer
buf(128);
176 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER USER " ) );
177 bufferQuoteIdentifier( buf
, extractStringProperty( this, getStatics().NAME
), m_pSettings
);
178 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM( " PASSWORD " ) );
179 bufferQuoteConstant( buf
, newPassword
, m_pSettings
);
180 Reference
< XStatement
> stmt
= m_conn
->createStatement();
181 DisposeGuard
guard( stmt
);
182 stmt
->executeUpdate( buf
.makeStringAndClear() );
185 sal_Int32
User::getPrivileges( const ::rtl::OUString
& objName
, sal_Int32 objType
)
186 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
188 sal_Int32 ret
= 0xffffffff;
189 if( isLog( m_pSettings
, LogLevel::INFO
) )
191 Statics
& st
= getStatics();
192 rtl::OUString user
= extractStringProperty( this, st
.NAME
);
194 rtl::OUStringBuffer
buf( 128 );
195 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("User::getPrivileges[") );
196 buf
.append( extractStringProperty( this, st
.NAME
) );
197 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM( "] got called for " ) );
198 buf
.append( objName
);
199 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM( "(type=" ) );
200 buf
.append( objType
);
201 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM( ")" ) );
202 log( m_pSettings
, LogLevel::INFO
, buf
.makeStringAndClear() );
208 sal_Int32
User::getGrantablePrivileges( const ::rtl::OUString
& objName
, sal_Int32 objType
)
209 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
211 (void) objName
; (void) objType
;
216 void User::grantPrivileges( const ::rtl::OUString
& objName
, sal_Int32 objType
, sal_Int32 objPrivileges
)
217 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
219 (void) objName
; (void) objType
; (void) objPrivileges
;
220 throw com::sun::star::sdbc::SQLException(
221 ASCII_STR( "pq_driver: privilege change not implemented yet" ),
222 *this, OUString(), 1, Any() );
225 void User::revokePrivileges( const ::rtl::OUString
& objName
, sal_Int32 objType
, sal_Int32 objPrivileges
)
226 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
228 (void) objName
; (void) objType
; (void) objPrivileges
;
229 throw com::sun::star::sdbc::SQLException(
230 ASCII_STR( "pq_driver: privilege change not implemented yet" ),
231 *this, OUString(), 1, Any() );
234 //______________________________________________________________________________________
235 UserDescriptor::UserDescriptor(
236 const ::rtl::Reference
< RefCountedMutex
> & refMutex
,
237 const Reference
< com::sun::star::sdbc::XConnection
> & connection
,
238 ConnectionSettings
*pSettings
)
240 getStatics().refl
.userDescriptor
.implName
,
241 getStatics().refl
.userDescriptor
.serviceNames
,
245 * getStatics().refl
.userDescriptor
.pProps
)
248 Reference
< XPropertySet
> UserDescriptor::createDataDescriptor( ) throw (RuntimeException
)
250 UserDescriptor
* pUser
= new UserDescriptor( m_refMutex
, m_conn
, m_pSettings
);
251 pUser
->copyValuesFrom( this );
253 return Reference
< XPropertySet
> ( pUser
);