Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : :
21 : : #include "UserAdmin.hxx"
22 : : #include "UserAdmin.hrc"
23 : : #include "UITools.hxx"
24 : : #include "dbu_dlg.hrc"
25 : : #include <comphelper/types.hxx>
26 : : #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
27 : : #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp>
28 : : #include <com/sun/star/sdbcx/XUsersSupplier.hpp>
29 : : #include <com/sun/star/sdbcx/XDrop.hpp>
30 : : #include <ucbhelper/interactionrequest.hxx>
31 : : #include <ucbhelper/simpleauthenticationrequest.hxx>
32 : : #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
33 : : #include <com/sun/star/beans/XPropertySet.hpp>
34 : : #include <com/sun/star/sdbcx/XUser.hpp>
35 : : #include <com/sun/star/sdbcx/XAppend.hpp>
36 : : #include "dbustrings.hrc"
37 : : #include <tools/debug.hxx>
38 : : #include "dbadmin.hxx"
39 : : #include "moduledbu.hxx"
40 : : #include <vcl/msgbox.hxx>
41 : : #include <sfx2/passwd.hxx>
42 : :
43 : : using namespace ::com::sun::star::container;
44 : : using namespace ::com::sun::star::beans;
45 : : using namespace ::com::sun::star::sdbcx;
46 : : using namespace ::com::sun::star::sdbc;
47 : : using namespace ::com::sun::star::uno;
48 : : using namespace ::com::sun::star::task;
49 : : using namespace dbaui;
50 : : using namespace ucbhelper;
51 : : using namespace comphelper;
52 : :
53 : :
54 [ # # ][ # # ]: 0 : class OPasswordDialog : public ModalDialog
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
55 : : {
56 : : FixedLine aFLUser;
57 : : FixedText aFTOldPassword;
58 : : Edit aEDOldPassword;
59 : : FixedText aFTPassword;
60 : : Edit aEDPassword;
61 : : FixedText aFTPasswordRepeat;
62 : : Edit aEDPasswordRepeat;
63 : : OKButton aOKBtn;
64 : : CancelButton aCancelBtn;
65 : : HelpButton aHelpBtn;
66 : :
67 : :
68 : : DECL_LINK( OKHdl_Impl, void * );
69 : : DECL_LINK( ModifiedHdl, Edit * );
70 : :
71 : : public:
72 : : OPasswordDialog( Window* pParent,const String& _sUserName);
73 : :
74 : 0 : String GetOldPassword() const { return aEDOldPassword.GetText(); }
75 : 0 : String GetNewPassword() const { return aEDPassword.GetText(); }
76 : : };
77 : :
78 : 0 : OPasswordDialog::OPasswordDialog(Window* _pParent,const String& _sUserName) :
79 : :
80 : : ModalDialog( _pParent, ModuleRes( DLG_PASSWORD) ),
81 : :
82 : : aFLUser ( this, ModuleRes( FL_USER ) ),
83 : : aFTOldPassword ( this, ModuleRes( FT_OLDPASSWORD ) ),
84 : : aEDOldPassword ( this, ModuleRes( ED_OLDPASSWORD ) ),
85 : : aFTPassword ( this, ModuleRes( FT_PASSWORD ) ),
86 : : aEDPassword ( this, ModuleRes( ED_PASSWORD ) ),
87 : : aFTPasswordRepeat ( this, ModuleRes( FT_PASSWORD_REPEAT ) ),
88 : : aEDPasswordRepeat ( this, ModuleRes( ED_PASSWORD_REPEAT ) ),
89 : : aOKBtn ( this, ModuleRes( BTN_PASSWORD_OK ) ),
90 : : aCancelBtn ( this, ModuleRes( BTN_PASSWORD_CANCEL ) ),
91 [ # # ][ # # ]: 0 : aHelpBtn ( this, ModuleRes( BTN_PASSWORD_HELP ) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
92 : : {
93 : : // hide until a help is avalable
94 [ # # ]: 0 : aHelpBtn.Hide();
95 : :
96 [ # # ]: 0 : FreeResource();
97 [ # # ]: 0 : String sUser = aFLUser.GetText();
98 [ # # ]: 0 : sUser.SearchAndReplaceAscii("$name$: $",_sUserName);
99 [ # # ]: 0 : aFLUser.SetText(sUser);
100 [ # # ]: 0 : aOKBtn.Disable();
101 : :
102 [ # # ]: 0 : aOKBtn.SetClickHdl( LINK( this, OPasswordDialog, OKHdl_Impl ) );
103 [ # # ][ # # ]: 0 : aEDOldPassword.SetModifyHdl( LINK( this, OPasswordDialog, ModifiedHdl ) );
104 : 0 : }
105 : : // -----------------------------------------------------------------------------
106 : 0 : IMPL_LINK_NOARG(OPasswordDialog, OKHdl_Impl)
107 : : {
108 [ # # ][ # # ]: 0 : if( aEDPassword.GetText() == aEDPasswordRepeat.GetText() )
[ # # ][ # # ]
109 : 0 : EndDialog( RET_OK );
110 : : else
111 : : {
112 [ # # ][ # # ]: 0 : String aErrorMsg( ModuleRes( STR_ERROR_PASSWORDS_NOT_IDENTICAL));
113 [ # # ]: 0 : ErrorBox aErrorBox( this, WB_OK, aErrorMsg );
114 [ # # ]: 0 : aErrorBox.Execute();
115 [ # # ][ # # ]: 0 : aEDPassword.SetText( String() );
[ # # ]
116 [ # # ][ # # ]: 0 : aEDPasswordRepeat.SetText( String() );
[ # # ]
117 [ # # ][ # # ]: 0 : aEDPassword.GrabFocus();
[ # # ]
118 : : }
119 : 0 : return 0;
120 : : }
121 : : // -----------------------------------------------------------------------------
122 : 0 : IMPL_LINK( OPasswordDialog, ModifiedHdl, Edit *, pEdit )
123 : : {
124 [ # # ]: 0 : aOKBtn.Enable(pEdit->GetText().Len() != 0);
125 : 0 : return 0;
126 : : }
127 : :
128 : : DBG_NAME(OUserAdmin);
129 : : //================================================================================
130 : : // OUserAdmin
131 : : //================================================================================
132 : 0 : OUserAdmin::OUserAdmin(Window* pParent,const SfxItemSet& _rAttrSet)
133 : : : OGenericAdministrationPage( pParent, ModuleRes(TAB_PAGE_USERADMIN), _rAttrSet)
134 : : ,m_FL_USER( this , ModuleRes(FL_USER))
135 : : ,m_FT_USER( this , ModuleRes(FT_USER))
136 : : ,m_LB_USER( this , ModuleRes(LB_USER))
137 : : ,m_PB_NEWUSER( this , ModuleRes(PB_NEWUSER))
138 : : ,m_PB_CHANGEPWD( this , ModuleRes(PB_CHANGEPWD))
139 : : ,m_PB_DELETEUSER( this , ModuleRes(PB_DELETEUSER))
140 : : ,m_FL_TABLE_GRANTS( this , ModuleRes(FL_TABLE_GRANTS))
141 [ # # ][ # # ]: 0 : ,m_TableCtrl( this , ModuleRes(CTRL_TABLE_GRANTS))
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
142 : : {
143 : : DBG_CTOR(OUserAdmin,NULL);
144 [ # # ]: 0 : m_LB_USER.SetSelectHdl(LINK(this, OUserAdmin, ListDblClickHdl));
145 : :
146 [ # # ]: 0 : m_PB_NEWUSER.SetClickHdl(LINK(this, OUserAdmin, UserHdl));
147 [ # # ]: 0 : m_PB_CHANGEPWD.SetClickHdl(LINK(this, OUserAdmin, UserHdl));
148 [ # # ]: 0 : m_PB_DELETEUSER.SetClickHdl(LINK(this, OUserAdmin, UserHdl));
149 : :
150 [ # # ]: 0 : FreeResource();
151 : 0 : }
152 : : // -----------------------------------------------------------------------
153 [ # # ][ # # ]: 0 : OUserAdmin::~OUserAdmin()
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
154 : : {
155 : : DBG_DTOR(OUserAdmin,NULL);
156 [ # # ]: 0 : m_xConnection = NULL;
157 [ # # ]: 0 : }
158 : : // -----------------------------------------------------------------------
159 : 0 : void OUserAdmin::FillUserNames()
160 : : {
161 [ # # ]: 0 : if(m_xConnection.is())
162 : : {
163 [ # # ]: 0 : m_LB_USER.Clear();
164 : :
165 [ # # ][ # # ]: 0 : Reference<XDatabaseMetaData> xMetaData = m_xConnection->getMetaData();
166 : :
167 [ # # ]: 0 : if ( xMetaData.is() )
168 : : {
169 [ # # ][ # # ]: 0 : m_UserName = xMetaData->getUserName();
[ # # ]
170 : :
171 : : // first we need the users
172 [ # # ]: 0 : if ( m_xUsers.is() )
173 : : {
174 [ # # ]: 0 : m_LB_USER.Clear();
175 : :
176 [ # # ][ # # ]: 0 : m_aUserNames = m_xUsers->getElementNames();
[ # # ][ # # ]
177 : 0 : const ::rtl::OUString* pBegin = m_aUserNames.getConstArray();
178 : 0 : const ::rtl::OUString* pEnd = pBegin + m_aUserNames.getLength();
179 [ # # ]: 0 : for(;pBegin != pEnd;++pBegin)
180 [ # # ][ # # ]: 0 : m_LB_USER.InsertEntry(*pBegin);
[ # # ]
181 : :
182 [ # # ]: 0 : m_LB_USER.SelectEntryPos(0);
183 [ # # ][ # # ]: 0 : if(m_xUsers->hasByName(m_UserName))
[ # # ][ # # ]
184 : : {
185 : 0 : Reference<XAuthorizable> xAuth;
186 [ # # ][ # # ]: 0 : m_xUsers->getByName(m_UserName) >>= xAuth;
[ # # ][ # # ]
187 [ # # ]: 0 : m_TableCtrl.setGrantUser(xAuth);
188 : : }
189 : :
190 [ # # ][ # # ]: 0 : m_TableCtrl.setUserName(GetUser());
[ # # ][ # # ]
191 [ # # ]: 0 : m_TableCtrl.Init();
192 : : }
193 : 0 : }
194 : : }
195 : :
196 [ # # ]: 0 : Reference<XAppend> xAppend(m_xUsers,UNO_QUERY);
197 [ # # ]: 0 : m_PB_NEWUSER.Enable(xAppend.is());
198 [ # # ]: 0 : Reference<XDrop> xDrop(m_xUsers,UNO_QUERY);
199 [ # # ]: 0 : m_PB_DELETEUSER.Enable(xDrop.is());
200 : :
201 [ # # ]: 0 : m_PB_CHANGEPWD.Enable(m_xUsers.is());
202 [ # # ]: 0 : m_TableCtrl.Enable(m_xUsers.is());
203 : :
204 : 0 : }
205 : : // -----------------------------------------------------------------------
206 : 0 : SfxTabPage* OUserAdmin::Create( Window* pParent, const SfxItemSet& _rAttrSet )
207 : : {
208 [ # # ]: 0 : return ( new OUserAdmin( pParent, _rAttrSet ) );
209 : : }
210 : : // -----------------------------------------------------------------------
211 : 0 : IMPL_LINK( OUserAdmin, UserHdl, PushButton *, pButton )
212 : : {
213 : : try
214 : : {
215 [ # # ]: 0 : if(pButton == &m_PB_NEWUSER)
216 : : {
217 [ # # ]: 0 : SfxPasswordDialog aPwdDlg(this);
218 : 0 : aPwdDlg.ShowExtras(SHOWEXTRAS_ALL);
219 [ # # ][ # # ]: 0 : if(aPwdDlg.Execute())
220 : : {
221 [ # # ]: 0 : Reference<XDataDescriptorFactory> xUserFactory(m_xUsers,UNO_QUERY);
222 [ # # ][ # # ]: 0 : Reference<XPropertySet> xNewUser = xUserFactory->createDataDescriptor();
223 [ # # ]: 0 : if(xNewUser.is())
224 : : {
225 [ # # ][ # # ]: 0 : xNewUser->setPropertyValue(PROPERTY_NAME,makeAny(rtl::OUString(aPwdDlg.GetUser())));
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
226 [ # # ][ # # ]: 0 : xNewUser->setPropertyValue(PROPERTY_PASSWORD,makeAny(rtl::OUString(aPwdDlg.GetPassword())));
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
227 [ # # ]: 0 : Reference<XAppend> xAppend(m_xUsers,UNO_QUERY);
228 [ # # ]: 0 : if(xAppend.is())
229 [ # # ][ # # ]: 0 : xAppend->appendByDescriptor(xNewUser);
230 : 0 : }
231 [ # # ]: 0 : }
232 : : }
233 [ # # ]: 0 : else if(pButton == &m_PB_CHANGEPWD)
234 : : {
235 [ # # ]: 0 : String sName = GetUser();
236 : :
237 [ # # ][ # # ]: 0 : if(m_xUsers->hasByName(sName))
[ # # ][ # # ]
238 : : {
239 : 0 : Reference<XUser> xUser;
240 [ # # ][ # # ]: 0 : m_xUsers->getByName(sName) >>= xUser;
[ # # ][ # # ]
241 [ # # ]: 0 : if(xUser.is())
242 : : {
243 : 0 : ::rtl::OUString sNewPassword,sOldPassword;
244 [ # # ]: 0 : OPasswordDialog aDlg(this,sName);
245 [ # # ][ # # ]: 0 : if(aDlg.Execute() == RET_OK)
246 : : {
247 [ # # ][ # # ]: 0 : sNewPassword = aDlg.GetNewPassword();
[ # # ]
248 [ # # ][ # # ]: 0 : sOldPassword = aDlg.GetOldPassword();
[ # # ]
249 : :
250 [ # # ]: 0 : if(!sNewPassword.isEmpty())
251 [ # # ][ # # ]: 0 : xUser->changePassword(sOldPassword,sNewPassword);
252 [ # # ]: 0 : }
253 : 0 : }
254 [ # # ]: 0 : }
255 : : }
256 : : else
257 : : {// delete user
258 [ # # ][ # # ]: 0 : if(m_xUsers.is() && m_xUsers->hasByName(GetUser()))
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # #
# # # # ]
259 : : {
260 [ # # ]: 0 : Reference<XDrop> xDrop(m_xUsers,UNO_QUERY);
261 [ # # ]: 0 : if(xDrop.is())
262 : : {
263 [ # # ][ # # ]: 0 : QueryBox aQry(this, ModuleRes(QUERY_USERADMIN_DELETE_USER));
264 [ # # ][ # # ]: 0 : if(aQry.Execute() == RET_YES)
265 [ # # ][ # # ]: 0 : xDrop->dropByName(GetUser());
[ # # ][ # # ]
[ # # ][ # # ]
266 : 0 : }
267 : : }
268 : : }
269 [ # # ]: 0 : FillUserNames();
270 : : }
271 [ # # # ]: 0 : catch(const SQLException& e)
272 : : {
273 [ # # # # : 0 : ::dbaui::showError(::dbtools::SQLExceptionInfo(e),this,m_xORB);
# # ]
274 : 0 : return 0;
275 : : }
276 : 0 : catch(Exception& )
277 : : {
278 : 0 : return 0;
279 : : }
280 : :
281 : 0 : return 0;
282 : : }
283 : : // -----------------------------------------------------------------------
284 : 0 : IMPL_LINK( OUserAdmin, ListDblClickHdl, ListBox *, /*pListBox*/ )
285 : : {
286 [ # # ][ # # ]: 0 : m_TableCtrl.setUserName(GetUser());
287 : 0 : m_TableCtrl.UpdateTables();
288 : 0 : m_TableCtrl.DeactivateCell();
289 : 0 : m_TableCtrl.ActivateCell(m_TableCtrl.GetCurRow(),m_TableCtrl.GetCurColumnId());
290 : 0 : return 0;
291 : : }
292 : :
293 : : // -----------------------------------------------------------------------
294 : 0 : String OUserAdmin::GetUser()
295 : : {
296 : 0 : return m_LB_USER.GetSelectEntry();
297 : : }
298 : : // -----------------------------------------------------------------------------
299 : 0 : void OUserAdmin::fillControls(::std::vector< ISaveValueWrapper* >& /*_rControlList*/)
300 : : {
301 : 0 : }
302 : : // -----------------------------------------------------------------------
303 : 0 : void OUserAdmin::fillWindows(::std::vector< ISaveValueWrapper* >& /*_rControlList*/)
304 : : {
305 : 0 : }
306 : : // -----------------------------------------------------------------------------
307 : 0 : void OUserAdmin::implInitControls(const SfxItemSet& _rSet, sal_Bool _bSaveValue)
308 : : {
309 : 0 : m_TableCtrl.setORB(m_xORB);
310 : : try
311 : : {
312 [ # # ][ # # ]: 0 : if ( !m_xConnection.is() && m_pAdminDialog )
[ # # ]
313 : : {
314 [ # # ][ # # ]: 0 : m_xConnection = m_pAdminDialog->createConnection().first;
[ # # ]
315 [ # # ]: 0 : Reference< XTablesSupplier > xTablesSup(m_xConnection,UNO_QUERY);
316 [ # # ]: 0 : Reference<XUsersSupplier> xUsersSup(xTablesSup,UNO_QUERY);
317 [ # # ]: 0 : if ( !xUsersSup.is() )
318 : : {
319 [ # # ][ # # ]: 0 : Reference< XDataDefinitionSupplier > xDriver(m_pAdminDialog->getDriver(),UNO_QUERY);
320 [ # # ]: 0 : if ( xDriver.is() )
321 : : {
322 [ # # ][ # # ]: 0 : xUsersSup.set(xDriver->getDataDefinitionByConnection(m_xConnection),UNO_QUERY);
[ # # ]
323 [ # # ]: 0 : xTablesSup.set(xUsersSup,UNO_QUERY);
324 : 0 : }
325 : : }
326 [ # # ]: 0 : if ( xUsersSup.is() )
327 : : {
328 [ # # ]: 0 : m_TableCtrl.setTablesSupplier(xTablesSup);
329 [ # # ][ # # ]: 0 : m_xUsers = xUsersSup->getUsers();
[ # # ]
330 : 0 : }
331 : : }
332 [ # # ]: 0 : FillUserNames();
333 : : }
334 [ # # ]: 0 : catch(const SQLException& e)
335 : : {
336 [ # # # # : 0 : ::dbaui::showError(::dbtools::SQLExceptionInfo(e),this,m_xORB);
# # ]
337 : : }
338 : :
339 : 0 : OGenericAdministrationPage::implInitControls(_rSet, _bSaveValue);
340 : 0 : }
341 : :
342 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|