1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
3  *
4  *  Effective License of whole file:
5  *
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.
9  *
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.
14  *
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,
18  *    MA  02111-1307  USA
19  *
20  *  Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
21  *
22  *    The Contents of this file are made available subject to the terms of
23  *    the GNU Lesser General Public License Version 2.1
24  *
25  *    Copyright: 2000 by Sun Microsystems, Inc.
26  *
27  *    Contributor(s): Joerg Budischewski
28  *
29  *  All parts contributed on or after August 2011:
30  *
31  *    This Source Code Form is subject to the terms of the Mozilla Public
32  *    License, v. 2.0. If a copy of the MPL was not distributed with this
33  *    file, You can obtain one at http://mozilla.org/MPL/2.0/.
34  *
35  ************************************************************************/
36 
37 #include <rtl/ustrbuf.hxx>
38 
39 #include <cppuhelper/typeprovider.hxx>
40 #include <cppuhelper/queryinterface.hxx>
41 
42 #include <com/sun/star/beans/PropertyAttribute.hpp>
43 #include <com/sun/star/sdbc/SQLException.hpp>
44 
45 #include "pq_xuser.hxx"
46 #include "pq_tools.hxx"
47 #include "pq_statics.hxx"
48 
49 using com::sun::star::uno::Reference;
50 using com::sun::star::uno::Sequence;
51 using com::sun::star::uno::Any;
52 using com::sun::star::uno::Type;
53 
54 using com::sun::star::beans::XPropertySet;
55 
56 using com::sun::star::sdbc::XStatement;
57 using com::sun::star::sdbc::SQLException;
58 
59 namespace pq_sdbc_driver
60 {
61 
User(const::rtl::Reference<comphelper::RefCountedMutex> & refMutex,const Reference<css::sdbc::XConnection> & connection,ConnectionSettings * pSettings)62 User::User( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex,
63             const Reference< css::sdbc::XConnection > & connection,
64             ConnectionSettings *pSettings )
65     : ReflectionBase(
66         getStatics().refl.user.implName,
67         getStatics().refl.user.serviceNames,
68         refMutex,
69         connection,
70         pSettings,
71         * getStatics().refl.user.pProps )
72 {}
73 
createDataDescriptor()74 Reference< XPropertySet > User::createDataDescriptor(  )
75 {
76     UserDescriptor * pUser = new UserDescriptor( m_xMutex, m_conn, m_pSettings );
77     pUser->copyValuesFrom( this );
78 
79     return Reference< XPropertySet > ( pUser );
80 }
81 
82 
getTypes()83 Sequence<Type > User::getTypes()
84 {
85     static cppu::OTypeCollection collection(
86         cppu::UnoType<css::sdbcx::XUser>::get(),
87         ReflectionBase::getTypes());
88 
89     return collection.getTypes();
90 }
91 
getImplementationId()92 Sequence< sal_Int8> User::getImplementationId()
93 {
94     return css::uno::Sequence<sal_Int8>();
95 }
96 
queryInterface(const Type & reqType)97 Any User::queryInterface( const Type & reqType )
98 {
99     Any ret = ReflectionBase::queryInterface( reqType );
100     if( ! ret.hasValue() )
101         ret = ::cppu::queryInterface(
102             reqType,
103             static_cast< css::sdbcx::XUser * > ( this ) );
104     return ret;
105 }
106 
107 
changePassword(const OUString &,const OUString & newPassword)108 void User::changePassword(
109     const OUString&, const OUString& newPassword )
110 {
111     OUStringBuffer buf(128);
112     buf.append( "ALTER USER " );
113     bufferQuoteIdentifier( buf, extractStringProperty( this, getStatics().NAME ), m_pSettings );
114     buf.append( " PASSWORD " );
115     bufferQuoteConstant( buf, newPassword, m_pSettings );
116     Reference< XStatement > stmt = m_conn->createStatement();
117     DisposeGuard guard( stmt );
118     stmt->executeUpdate( buf.makeStringAndClear() );
119 }
120 
getPrivileges(const OUString & objName,sal_Int32 objType)121 sal_Int32 User::getPrivileges( const OUString& objName, sal_Int32 objType )
122 {
123     if (isLog(m_pSettings, LogLevel::Info))
124     {
125         Statics & st = getStatics();
126 
127         OUStringBuffer buf( 128 );
128         buf.append( "User::getPrivileges[" ).append( extractStringProperty( this, st.NAME ) )
129                     .append( "] got called for " ).append( objName ).append( "(type=" )
130                     .append( OUString::number(objType) ).append(")");
131         log(m_pSettings, LogLevel::Info, buf.makeStringAndClear());
132     }
133     // all privileges
134     return 0xffffffff;
135 }
136 
getGrantablePrivileges(const OUString &,sal_Int32)137 sal_Int32 User::getGrantablePrivileges( const OUString&, sal_Int32 )
138 {
139     // all privileges
140     return 0xffffffff;
141 }
142 
grantPrivileges(const OUString &,sal_Int32,sal_Int32)143 void User::grantPrivileges( const OUString&, sal_Int32, sal_Int32 )
144 {
145     throw css::sdbc::SQLException("pq_driver: privilege change not implemented yet",
146                                              *this, OUString(), 1, Any() );
147 }
148 
revokePrivileges(const OUString &,sal_Int32,sal_Int32)149 void User::revokePrivileges( const OUString&, sal_Int32, sal_Int32 )
150 {
151     throw css::sdbc::SQLException("pq_driver: privilege change not implemented yet",
152                                              *this, OUString(), 1, Any() );
153 }
154 
155 
UserDescriptor(const::rtl::Reference<comphelper::RefCountedMutex> & refMutex,const Reference<css::sdbc::XConnection> & connection,ConnectionSettings * pSettings)156 UserDescriptor::UserDescriptor(
157     const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex,
158     const Reference< css::sdbc::XConnection > & connection,
159     ConnectionSettings *pSettings )
160     : ReflectionBase(
161         getStatics().refl.userDescriptor.implName,
162         getStatics().refl.userDescriptor.serviceNames,
163         refMutex,
164         connection,
165         pSettings,
166         * getStatics().refl.userDescriptor.pProps )
167 {}
168 
createDataDescriptor()169 Reference< XPropertySet > UserDescriptor::createDataDescriptor(  )
170 {
171     UserDescriptor * pUser = new UserDescriptor( m_xMutex, m_conn, m_pSettings );
172     pUser->copyValuesFrom( this );
173 
174     return Reference< XPropertySet > ( pUser );
175 }
176 
177 
178 }
179 
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
181