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 
31 #include <stdio.h>
32 #include "connectivity/sdbcx/VUser.hxx"
33 #include <com/sun/star/lang/DisposedException.hpp>
34 #include <com/sun/star/sdbcx/Privilege.hpp>
35 #include <com/sun/star/sdbcx/PrivilegeObject.hpp>
36 #include "TConnection.hxx"
37 #include "connectivity/sdbcx/VCollection.hxx"
38 #include <connectivity/dbexception.hxx>
39 #include <comphelper/sequence.hxx>
40 
41 // -------------------------------------------------------------------------
42 using namespace connectivity;
43 using namespace connectivity::sdbcx;
44 using namespace ::com::sun::star::sdbc;
45 using namespace ::com::sun::star::beans;
46 using namespace ::com::sun::star::uno;
47 using namespace ::com::sun::star::container;
48 using namespace ::com::sun::star::lang;
49 
50 IMPLEMENT_SERVICE_INFO(OUser,"com.sun.star.sdbcx.VUser","com.sun.star.sdbcx.User");
51 // -------------------------------------------------------------------------
52 OUser::OUser(sal_Bool _bCase)  : OUser_BASE(m_aMutex)
53 				, ODescriptor(OUser_BASE::rBHelper,_bCase,sal_True)
54 				, m_pGroups(NULL)
55 {
56 }
57 // -------------------------------------------------------------------------
58 OUser::OUser(const ::rtl::OUString& _Name,sal_Bool _bCase) :	OUser_BASE(m_aMutex)
59 						,ODescriptor(OUser_BASE::rBHelper,_bCase)
60 						,m_pGroups(NULL)
61 {
62 	m_Name = _Name;
63 }
64 // -------------------------------------------------------------------------
65 OUser::~OUser( )
66 {
67 	delete m_pGroups;
68 }
69 // -------------------------------------------------------------------------
70 void OUser::disposing(void)
71 {
72 	OPropertySetHelper::disposing();
73 	::osl::MutexGuard aGuard(m_aMutex);
74 	if(m_pGroups)
75 		m_pGroups->disposing();
76 }
77 // -------------------------------------------------------------------------
78 Any SAL_CALL OUser::queryInterface( const Type & rType ) throw(RuntimeException)
79 {
80     Any aRet = ODescriptor::queryInterface( rType);
81 	return aRet.hasValue() ? aRet : OUser_BASE::queryInterface( rType);
82 }
83 // -------------------------------------------------------------------------
84 Sequence< Type > SAL_CALL OUser::getTypes(  ) throw(RuntimeException)
85 {
86 	return ::comphelper::concatSequences(ODescriptor::getTypes(),OUser_BASE::getTypes());
87 }
88 // -------------------------------------------------------------------------
89 ::cppu::IPropertyArrayHelper* OUser::createArrayHelper( ) const
90 {
91         Sequence< Property > aProps;
92 	describeProperties(aProps);
93 	return new ::cppu::OPropertyArrayHelper(aProps);
94 
95 }
96 // -------------------------------------------------------------------------
97 ::cppu::IPropertyArrayHelper & OUser::getInfoHelper()
98 {
99 	return *const_cast<OUser*>(this)->getArrayHelper();
100 }
101 // -------------------------------------------------------------------------
102 // XUser
103 void SAL_CALL OUser::changePassword( const ::rtl::OUString& /*objPassword*/, const ::rtl::OUString& /*newPassword*/ ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
104 {
105 	::osl::MutexGuard aGuard(m_aMutex);
106 	checkDisposed(OUser_BASE::rBHelper.bDisposed);
107     ::dbtools::throwFeatureNotImplementedException( "XUser::changePassword", *this );
108 }
109 // -------------------------------------------------------------------------
110 // XGroupsSupplier
111 Reference< XNameAccess > SAL_CALL OUser::getGroups(  ) throw(RuntimeException)
112 {
113 	::osl::MutexGuard aGuard(m_aMutex);
114 	checkDisposed(OUser_BASE::rBHelper.bDisposed);
115 
116 	try
117 	{
118 		if ( !m_pGroups )
119 			refreshGroups();
120 	}
121 	catch( const RuntimeException& )
122 	{
123 		// allowed to leave this method
124 		throw;
125 	}
126 	catch( const Exception& )
127 	{
128 		// allowed
129 	}
130 
131 	return const_cast<OUser*>(this)->m_pGroups;
132 }
133 // -------------------------------------------------------------------------
134 // -------------------------------------------------------------------------
135 
136 sal_Int32 SAL_CALL OUser::getPrivileges( const ::rtl::OUString& /*objName*/, sal_Int32 /*objType*/ ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
137 {
138 	::osl::MutexGuard aGuard(m_aMutex);
139 	checkDisposed(OUser_BASE::rBHelper.bDisposed);
140     ::dbtools::throwFeatureNotImplementedException( "XAuthorizable::changePassword", *this );
141     return 0;
142 }
143 // -------------------------------------------------------------------------
144 sal_Int32 SAL_CALL OUser::getGrantablePrivileges( const ::rtl::OUString& /*objName*/, sal_Int32 /*objType*/ ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
145 {
146 	::osl::MutexGuard aGuard(m_aMutex);
147 	checkDisposed(OUser_BASE::rBHelper.bDisposed);
148     ::dbtools::throwFeatureNotImplementedException( "XAuthorizable::getGrantablePrivileges", *this );
149     return 0;
150 }
151 // -------------------------------------------------------------------------
152 void SAL_CALL OUser::grantPrivileges( const ::rtl::OUString& /*objName*/, sal_Int32 /*objType*/, sal_Int32 /*objPrivileges*/ ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
153 {
154 	::osl::MutexGuard aGuard(m_aMutex);
155 	checkDisposed(OUser_BASE::rBHelper.bDisposed);
156     ::dbtools::throwFeatureNotImplementedException( "XAuthorizable::grantPrivileges", *this );
157 }
158 // -------------------------------------------------------------------------
159 void SAL_CALL OUser::revokePrivileges( const ::rtl::OUString& /*objName*/, sal_Int32 /*objType*/, sal_Int32 /*objPrivileges*/ ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
160 {
161 	::osl::MutexGuard aGuard(m_aMutex);
162 	checkDisposed(OUser_BASE::rBHelper.bDisposed);
163     ::dbtools::throwFeatureNotImplementedException( "XAuthorizable::revokePrivileges", *this );
164 }
165 // -----------------------------------------------------------------------------
166 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OUser::getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException)
167 {
168 	return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
169 }
170 // -----------------------------------------------------------------------------
171 ::rtl::OUString SAL_CALL OUser::getName(  ) throw(::com::sun::star::uno::RuntimeException)
172 {
173 	return m_Name;
174 }
175 // -----------------------------------------------------------------------------
176 void SAL_CALL OUser::setName( const ::rtl::OUString& /*aName*/ ) throw(::com::sun::star::uno::RuntimeException)
177 {
178     OSL_ENSURE( false, "OUser::setName: not implemented!" );
179         // not allowed to throw an SQLException here ...
180 }
181 // -----------------------------------------------------------------------------
182 // XInterface
183 void SAL_CALL OUser::acquire() throw()
184 {
185 	OUser_BASE::acquire();
186 }
187 // -----------------------------------------------------------------------------
188 void SAL_CALL OUser::release() throw()
189 {
190 	OUser_BASE::release();
191 }
192 // -----------------------------------------------------------------------------
193 
194 
195