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 : #include "comphelper/processfactory.hxx"
21 :
22 : #include "com/sun/star/task/DocumentPasswordRequest.hpp"
23 : #include "com/sun/star/task/DocumentPasswordRequest2.hpp"
24 : #include "com/sun/star/task/DocumentMSPasswordRequest.hpp"
25 : #include "com/sun/star/task/DocumentMSPasswordRequest2.hpp"
26 : #include "com/sun/star/task/MasterPasswordRequest.hpp"
27 : #include "com/sun/star/task/XInteractionAbort.hpp"
28 : #include "com/sun/star/task/XInteractionPassword.hpp"
29 : #include "com/sun/star/task/XInteractionPassword2.hpp"
30 : #include "com/sun/star/task/XInteractionRetry.hpp"
31 : #include "com/sun/star/ucb/XInteractionSupplyAuthentication2.hpp"
32 : #include "com/sun/star/ucb/URLAuthenticationRequest.hpp"
33 :
34 : #include "osl/diagnose.h"
35 : #include "rtl/digest.h"
36 : #include "osl/mutex.hxx"
37 : #include "tools/errcode.hxx"
38 : #include "vcl/msgbox.hxx"
39 : #include "vcl/abstdlg.hxx"
40 : #include "vcl/svapp.hxx"
41 :
42 : #include "ids.hrc"
43 : #include "getcontinuations.hxx"
44 : #include "passwordcontainer.hxx"
45 : #include "loginerr.hxx"
46 : #include "logindlg.hxx"
47 : #include "masterpasscrtdlg.hxx"
48 : #include "masterpassworddlg.hxx"
49 : #include "passworddlg.hxx"
50 :
51 : #include "iahndl.hxx"
52 :
53 : #include <boost/scoped_ptr.hpp>
54 :
55 : using namespace com::sun::star;
56 :
57 : namespace {
58 :
59 : void
60 0 : executeLoginDialog(
61 : Window * pParent,
62 : LoginErrorInfo & rInfo,
63 : rtl::OUString const & rRealm)
64 : SAL_THROW((uno::RuntimeException))
65 : {
66 : try
67 : {
68 0 : SolarMutexGuard aGuard;
69 :
70 0 : bool bAccount = (rInfo.GetFlags() & LOGINERROR_FLAG_MODIFY_ACCOUNT) != 0;
71 0 : bool bSavePassword = rInfo.GetCanRememberPassword();
72 0 : bool bCanUseSysCreds = rInfo.GetCanUseSystemCredentials();
73 :
74 0 : sal_uInt16 nFlags = 0;
75 0 : if (rInfo.GetPath().Len() == 0)
76 0 : nFlags |= LF_NO_PATH;
77 0 : if (rInfo.GetErrorText().Len() == 0)
78 0 : nFlags |= LF_NO_ERRORTEXT;
79 0 : if (!bAccount)
80 0 : nFlags |= LF_NO_ACCOUNT;
81 0 : if (!(rInfo.GetFlags() & LOGINERROR_FLAG_MODIFY_USER_NAME))
82 0 : nFlags |= LF_USERNAME_READONLY;
83 :
84 0 : if (!bSavePassword)
85 0 : nFlags |= LF_NO_SAVEPASSWORD;
86 :
87 0 : if (!bCanUseSysCreds)
88 0 : nFlags |= LF_NO_USESYSCREDS;
89 :
90 0 : boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
91 : boost::scoped_ptr< LoginDialog > xDialog(
92 0 : new LoginDialog( pParent, nFlags, rInfo.GetServer(), rRealm, xManager.get()));
93 0 : if (rInfo.GetErrorText().Len() != 0)
94 0 : xDialog->SetErrorText(rInfo.GetErrorText());
95 0 : xDialog->SetName(rInfo.GetUserName());
96 0 : if (bAccount)
97 0 : xDialog->ClearAccount();
98 : else
99 0 : xDialog->ClearPassword();
100 0 : xDialog->SetPassword(rInfo.GetPassword());
101 :
102 0 : if (bSavePassword)
103 : {
104 : xDialog->SetSavePasswordText(
105 0 : ResId(rInfo.GetIsRememberPersistent()
106 : ? RID_SAVE_PASSWORD
107 : : RID_KEEP_PASSWORD,
108 0 : *xManager.get()));
109 :
110 0 : xDialog->SetSavePassword(rInfo.GetIsRememberPassword());
111 : }
112 :
113 0 : if ( bCanUseSysCreds )
114 0 : xDialog->SetUseSystemCredentials( rInfo.GetIsUseSystemCredentials() );
115 :
116 0 : rInfo.SetResult(xDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK :
117 0 : ERRCODE_BUTTON_CANCEL);
118 0 : rInfo.SetUserName(xDialog->GetName());
119 0 : rInfo.SetPassword(xDialog->GetPassword());
120 0 : rInfo.SetAccount(xDialog->GetAccount());
121 0 : rInfo.SetIsRememberPassword(xDialog->IsSavePassword());
122 :
123 0 : if ( bCanUseSysCreds )
124 0 : rInfo.SetIsUseSystemCredentials( xDialog->IsUseSystemCredentials() );
125 : }
126 0 : catch (std::bad_alloc const &)
127 : {
128 : throw uno::RuntimeException(OUString("out of memory"),
129 0 : uno::Reference< uno::XInterface >());
130 : }
131 0 : }
132 :
133 0 : void getRememberModes(
134 : uno::Sequence< ucb::RememberAuthentication > const & rRememberModes,
135 : ucb::RememberAuthentication & rPreferredMode,
136 : ucb::RememberAuthentication & rAlternateMode )
137 : {
138 0 : sal_Int32 nCount = rRememberModes.getLength();
139 : OSL_ENSURE( (nCount > 0) && (nCount < 4),
140 : "ucb::RememberAuthentication sequence size mismatch!" );
141 0 : if ( nCount == 1 )
142 : {
143 0 : rPreferredMode = rAlternateMode = rRememberModes[ 0 ];
144 0 : return;
145 : }
146 : else
147 : {
148 0 : bool bHasRememberModeSession = false;
149 0 : bool bHasRememberModePersistent = false;
150 :
151 0 : for (sal_Int32 i = 0; i < nCount; ++i)
152 : {
153 0 : switch ( rRememberModes[i] )
154 : {
155 : case ucb::RememberAuthentication_NO:
156 0 : break;
157 : case ucb::RememberAuthentication_SESSION:
158 0 : bHasRememberModeSession = true;
159 0 : break;
160 : case ucb::RememberAuthentication_PERSISTENT:
161 0 : bHasRememberModePersistent = true;
162 0 : break;
163 : default:
164 : OSL_TRACE( "Unsupported RememberAuthentication value" );
165 0 : break;
166 : }
167 : }
168 :
169 0 : if (bHasRememberModePersistent)
170 : {
171 0 : rPreferredMode = ucb::RememberAuthentication_PERSISTENT;
172 0 : if (bHasRememberModeSession)
173 0 : rAlternateMode = ucb::RememberAuthentication_SESSION;
174 : else
175 0 : rAlternateMode = ucb::RememberAuthentication_NO;
176 : }
177 : else
178 : {
179 0 : rPreferredMode = ucb::RememberAuthentication_SESSION;
180 0 : rAlternateMode = ucb::RememberAuthentication_NO;
181 : }
182 : }
183 : }
184 :
185 : void
186 0 : handleAuthenticationRequest_(
187 : Window * pParent,
188 : uno::Reference< task::XInteractionHandler2 > const & xIH,
189 : uno::Reference< lang::XMultiServiceFactory > const & xServiceFactory,
190 : ucb::AuthenticationRequest const & rRequest,
191 : uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
192 : rContinuations,
193 : const rtl::OUString & rURL)
194 : SAL_THROW((uno::RuntimeException))
195 : {
196 0 : uno::Reference< task::XInteractionRetry > xRetry;
197 0 : uno::Reference< task::XInteractionAbort > xAbort;
198 : uno::Reference< ucb::XInteractionSupplyAuthentication >
199 0 : xSupplyAuthentication;
200 : uno::Reference< ucb::XInteractionSupplyAuthentication2 >
201 0 : xSupplyAuthentication2;
202 0 : getContinuations(rContinuations, &xRetry, &xAbort, &xSupplyAuthentication);
203 0 : if (xSupplyAuthentication.is())
204 0 : xSupplyAuthentication2.set(xSupplyAuthentication, uno::UNO_QUERY);
205 :
206 : //////////////////////////
207 : // First, try to obtain credentials from password container service.
208 0 : uui::PasswordContainerHelper aPwContainerHelper(comphelper::getComponentContext(xServiceFactory));
209 0 : if (aPwContainerHelper.handleAuthenticationRequest(rRequest,
210 : xSupplyAuthentication,
211 : rURL,
212 : xIH))
213 : {
214 0 : xSupplyAuthentication->select();
215 0 : return;
216 : }
217 :
218 : //////////////////////////
219 : // Second, try to obtain credentials from user via password dialog.
220 : ucb::RememberAuthentication eDefaultRememberMode
221 0 : = ucb::RememberAuthentication_SESSION;
222 : ucb::RememberAuthentication ePreferredRememberMode
223 0 : = eDefaultRememberMode;
224 : ucb::RememberAuthentication eAlternateRememberMode
225 0 : = ucb::RememberAuthentication_NO;
226 :
227 0 : if (xSupplyAuthentication.is())
228 : {
229 : getRememberModes(
230 0 : xSupplyAuthentication->getRememberPasswordModes(
231 0 : eDefaultRememberMode),
232 : ePreferredRememberMode,
233 0 : eAlternateRememberMode);
234 : }
235 :
236 : sal_Bool bCanUseSystemCredentials;
237 : sal_Bool bDefaultUseSystemCredentials;
238 0 : if (xSupplyAuthentication2.is())
239 : {
240 : bCanUseSystemCredentials
241 0 : = xSupplyAuthentication2->canUseSystemCredentials(
242 0 : bDefaultUseSystemCredentials);
243 : }
244 : else
245 : {
246 0 : bCanUseSystemCredentials = sal_False;
247 0 : bDefaultUseSystemCredentials = sal_False;
248 : }
249 :
250 0 : LoginErrorInfo aInfo;
251 0 : aInfo.SetTitle(rRequest.ServerName);
252 0 : aInfo.SetServer(rRequest.ServerName);
253 0 : if (rRequest.HasAccount)
254 0 : aInfo.SetAccount(rRequest.Account);
255 0 : if (rRequest.HasUserName)
256 0 : aInfo.SetUserName(rRequest.UserName);
257 0 : if (rRequest.HasPassword)
258 0 : aInfo.SetPassword(rRequest.Password);
259 0 : aInfo.SetErrorText(rRequest.Diagnostic);
260 :
261 : aInfo.SetCanRememberPassword(
262 0 : ePreferredRememberMode != eAlternateRememberMode);
263 : aInfo.SetIsRememberPassword(
264 0 : ePreferredRememberMode == eDefaultRememberMode);
265 : aInfo.SetIsRememberPersistent(
266 0 : ePreferredRememberMode == ucb::RememberAuthentication_PERSISTENT);
267 :
268 0 : aInfo.SetCanUseSystemCredentials(bCanUseSystemCredentials);
269 0 : aInfo.SetIsUseSystemCredentials( bDefaultUseSystemCredentials );
270 : aInfo.SetModifyAccount(rRequest.HasAccount
271 0 : && xSupplyAuthentication.is()
272 0 : && xSupplyAuthentication->canSetAccount());
273 : aInfo.SetModifyUserName(rRequest.HasUserName
274 0 : && xSupplyAuthentication.is()
275 0 : && xSupplyAuthentication->canSetUserName());
276 : executeLoginDialog(pParent,
277 : aInfo,
278 0 : rRequest.HasRealm ? rRequest.Realm : rtl::OUString());
279 0 : switch (aInfo.GetResult())
280 : {
281 : case ERRCODE_BUTTON_OK:
282 0 : if (xSupplyAuthentication.is())
283 : {
284 0 : if (xSupplyAuthentication->canSetUserName())
285 0 : xSupplyAuthentication->setUserName(aInfo.GetUserName());
286 0 : if (xSupplyAuthentication->canSetPassword())
287 0 : xSupplyAuthentication->setPassword(aInfo.GetPassword());
288 :
289 0 : if (ePreferredRememberMode != eAlternateRememberMode)
290 : {
291 : // user had the choice.
292 0 : if (aInfo.GetIsRememberPassword())
293 0 : xSupplyAuthentication->setRememberPassword(
294 0 : ePreferredRememberMode);
295 : else
296 0 : xSupplyAuthentication->setRememberPassword(
297 0 : eAlternateRememberMode);
298 : }
299 : else
300 : {
301 : // user had no choice.
302 0 : xSupplyAuthentication->setRememberPassword(
303 0 : ePreferredRememberMode);
304 : }
305 :
306 0 : if (rRequest.HasRealm)
307 : {
308 0 : if (xSupplyAuthentication->canSetRealm())
309 0 : xSupplyAuthentication->setRealm(aInfo.GetAccount());
310 : }
311 0 : else if (xSupplyAuthentication->canSetAccount())
312 0 : xSupplyAuthentication->setAccount(aInfo.GetAccount());
313 :
314 0 : if ( xSupplyAuthentication2.is() && bCanUseSystemCredentials )
315 0 : xSupplyAuthentication2->setUseSystemCredentials(
316 0 : aInfo.GetIsUseSystemCredentials() );
317 :
318 0 : xSupplyAuthentication->select();
319 : }
320 :
321 : //////////////////////////
322 : // Third, store credentials in password container.
323 :
324 0 : if ( aInfo.GetIsUseSystemCredentials() )
325 : {
326 0 : if (aInfo.GetIsRememberPassword())
327 : {
328 0 : if (!aPwContainerHelper.addRecord(
329 0 : !rURL.isEmpty() ? rURL : rRequest.ServerName,
330 : rtl::OUString(), // empty u/p -> sys creds
331 : uno::Sequence< rtl::OUString >(),
332 : xIH,
333 : ePreferredRememberMode
334 0 : == ucb::RememberAuthentication_PERSISTENT))
335 : {
336 0 : xSupplyAuthentication->setRememberPassword(
337 0 : ucb::RememberAuthentication_NO);
338 : }
339 : }
340 0 : else if (eAlternateRememberMode
341 : == ucb::RememberAuthentication_SESSION)
342 : {
343 0 : if (!aPwContainerHelper.addRecord(
344 0 : !rURL.isEmpty() ? rURL : rRequest.ServerName,
345 : rtl::OUString(), // empty u/p -> sys creds
346 : uno::Sequence< rtl::OUString >(),
347 : xIH,
348 0 : false /* SESSION */))
349 : {
350 0 : xSupplyAuthentication->setRememberPassword(
351 0 : ucb::RememberAuthentication_NO);
352 : }
353 : }
354 : }
355 : // Empty user name can not be valid:
356 0 : else if (aInfo.GetUserName().Len() != 0)
357 : {
358 : uno::Sequence< rtl::OUString >
359 0 : aPassList(aInfo.GetAccount().Len() == 0 ? 1 : 2);
360 0 : aPassList[0] = aInfo.GetPassword();
361 0 : if (aInfo.GetAccount().Len() != 0)
362 0 : aPassList[1] = aInfo.GetAccount();
363 :
364 0 : if (aInfo.GetIsRememberPassword())
365 : {
366 0 : if (!aPwContainerHelper.addRecord(
367 0 : !rURL.isEmpty() ? rURL : rRequest.ServerName,
368 0 : aInfo.GetUserName(),
369 : aPassList,
370 : xIH,
371 : ePreferredRememberMode
372 0 : == ucb::RememberAuthentication_PERSISTENT))
373 : {
374 0 : xSupplyAuthentication->setRememberPassword(
375 0 : ucb::RememberAuthentication_NO);
376 : }
377 : }
378 0 : else if (eAlternateRememberMode
379 : == ucb::RememberAuthentication_SESSION)
380 : {
381 0 : if (!aPwContainerHelper.addRecord(
382 0 : !rURL.isEmpty() ? rURL : rRequest.ServerName,
383 0 : aInfo.GetUserName(),
384 : aPassList,
385 : xIH,
386 0 : false /* SESSION */))
387 : {
388 0 : xSupplyAuthentication->setRememberPassword(
389 0 : ucb::RememberAuthentication_NO);
390 : }
391 0 : }
392 : }
393 0 : break;
394 :
395 : case ERRCODE_BUTTON_RETRY:
396 0 : if (xRetry.is())
397 0 : xRetry->select();
398 0 : break;
399 :
400 : default:
401 0 : if (xAbort.is())
402 0 : xAbort->select();
403 0 : break;
404 0 : }
405 : }
406 :
407 : void
408 0 : executeMasterPasswordDialog(
409 : Window * pParent,
410 : LoginErrorInfo & rInfo,
411 : task::PasswordRequestMode nMode)
412 : SAL_THROW((uno::RuntimeException))
413 : {
414 0 : rtl::OString aMaster;
415 : try
416 : {
417 0 : SolarMutexGuard aGuard;
418 :
419 0 : boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
420 0 : if( nMode == task::PasswordRequestMode_PASSWORD_CREATE )
421 : {
422 : boost::scoped_ptr< MasterPasswordCreateDialog > xDialog(
423 0 : new MasterPasswordCreateDialog(pParent, xManager.get()));
424 0 : rInfo.SetResult(xDialog->Execute()
425 0 : == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL);
426 : aMaster = rtl::OUStringToOString(
427 0 : xDialog->GetMasterPassword(), RTL_TEXTENCODING_UTF8);
428 : }
429 : else
430 : {
431 : boost::scoped_ptr< MasterPasswordDialog > xDialog(
432 0 : new MasterPasswordDialog(pParent, nMode, xManager.get()));
433 0 : rInfo.SetResult(xDialog->Execute()
434 0 : == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL);
435 : aMaster = rtl::OUStringToOString(
436 0 : xDialog->GetMasterPassword(), RTL_TEXTENCODING_UTF8);
437 0 : }
438 : }
439 0 : catch (std::bad_alloc const &)
440 : {
441 : throw uno::RuntimeException(OUString("out of memory"),
442 0 : uno::Reference< uno::XInterface >());
443 : }
444 :
445 : sal_uInt8 aKey[RTL_DIGEST_LENGTH_MD5];
446 : rtl_digest_PBKDF2(aKey,
447 : RTL_DIGEST_LENGTH_MD5,
448 0 : reinterpret_cast< sal_uInt8 const * >(aMaster.getStr()),
449 0 : aMaster.getLength(),
450 : reinterpret_cast< sal_uInt8 const * >(
451 : "3B5509ABA6BC42D9A3A1F3DAD49E56A51"),
452 : 32,
453 0 : 1000);
454 :
455 0 : rtl::OUStringBuffer aBuffer;
456 0 : for (int i = 0; i < RTL_DIGEST_LENGTH_MD5; ++i)
457 : {
458 0 : aBuffer.append(static_cast< sal_Unicode >('a' + (aKey[i] >> 4)));
459 0 : aBuffer.append(static_cast< sal_Unicode >('a' + (aKey[i] & 15)));
460 : }
461 0 : rInfo.SetPassword(aBuffer.makeStringAndClear());
462 0 : }
463 :
464 : void
465 0 : handleMasterPasswordRequest_(
466 : Window * pParent,
467 : task::PasswordRequestMode nMode,
468 : uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
469 : rContinuations)
470 : SAL_THROW((uno::RuntimeException))
471 : {
472 0 : uno::Reference< task::XInteractionRetry > xRetry;
473 0 : uno::Reference< task::XInteractionAbort > xAbort;
474 : uno::Reference< ucb::XInteractionSupplyAuthentication >
475 0 : xSupplyAuthentication;
476 0 : getContinuations(rContinuations, &xRetry, &xAbort, &xSupplyAuthentication);
477 0 : LoginErrorInfo aInfo;
478 :
479 : // in case of master password a hash code is returned
480 0 : executeMasterPasswordDialog(pParent, aInfo, nMode);
481 :
482 0 : switch (aInfo.GetResult())
483 : {
484 : case ERRCODE_BUTTON_OK:
485 0 : if (xSupplyAuthentication.is())
486 : {
487 0 : if (xSupplyAuthentication->canSetPassword())
488 0 : xSupplyAuthentication->setPassword(aInfo.GetPassword());
489 0 : xSupplyAuthentication->select();
490 : }
491 0 : break;
492 :
493 : case ERRCODE_BUTTON_RETRY:
494 0 : if (xRetry.is())
495 0 : xRetry->select();
496 0 : break;
497 :
498 : default:
499 0 : if (xAbort.is())
500 0 : xAbort->select();
501 0 : break;
502 0 : }
503 0 : }
504 :
505 : void
506 0 : executePasswordDialog(
507 : Window * pParent,
508 : LoginErrorInfo & rInfo,
509 : task::PasswordRequestMode nMode,
510 : ::rtl::OUString aDocName,
511 : bool bMSCryptoMode,
512 : bool bIsPasswordToModify,
513 : bool bIsSimplePasswordRequest )
514 : SAL_THROW((uno::RuntimeException))
515 : {
516 : try
517 : {
518 0 : SolarMutexGuard aGuard;
519 :
520 0 : boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
521 0 : if( nMode == task::PasswordRequestMode_PASSWORD_CREATE )
522 : {
523 0 : if (bIsSimplePasswordRequest)
524 : {
525 : boost::scoped_ptr< PasswordDialog > pDialog(
526 : new PasswordDialog( pParent, nMode, xManager.get(), aDocName,
527 0 : bIsPasswordToModify, bIsSimplePasswordRequest ) );
528 0 : pDialog->SetMinLen(0);
529 :
530 0 : rInfo.SetResult( pDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL );
531 0 : rInfo.SetPassword( pDialog->GetPassword() );
532 : }
533 : else
534 : {
535 0 : const sal_uInt16 nMaxPasswdLen = bMSCryptoMode ? 15 : 0; // 0 -> allow any length
536 :
537 0 : VclAbstractDialogFactory * pFact = VclAbstractDialogFactory::Create();
538 0 : AbstractPasswordToOpenModifyDialog *pTmp = pFact->CreatePasswordToOpenModifyDialog( pParent, 0, nMaxPasswdLen, bIsPasswordToModify );
539 0 : boost::scoped_ptr< AbstractPasswordToOpenModifyDialog > pDialog( pTmp );
540 :
541 0 : rInfo.SetResult( pDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL );
542 0 : rInfo.SetPassword( pDialog->GetPasswordToOpen() );
543 0 : rInfo.SetPasswordToModify( pDialog->GetPasswordToModify() );
544 0 : rInfo.SetRecommendToOpenReadonly( pDialog->IsRecommendToOpenReadonly() );
545 : }
546 : }
547 : else // enter password or reenter password
548 : {
549 : boost::scoped_ptr< PasswordDialog > pDialog(
550 : new PasswordDialog( pParent, nMode, xManager.get(), aDocName,
551 0 : bIsPasswordToModify, bIsSimplePasswordRequest ) );
552 0 : pDialog->SetMinLen(0);
553 :
554 0 : rInfo.SetResult( pDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL );
555 0 : rInfo.SetPassword( bIsPasswordToModify ? String() : pDialog->GetPassword() );
556 0 : rInfo.SetPasswordToModify( bIsPasswordToModify ? pDialog->GetPassword() : String() );
557 0 : }
558 : }
559 0 : catch (std::bad_alloc const &)
560 : {
561 : throw uno::RuntimeException(OUString("out of memory"),
562 0 : uno::Reference< uno::XInterface>());
563 : }
564 0 : }
565 :
566 : void
567 0 : handlePasswordRequest_(
568 : Window * pParent,
569 : task::PasswordRequestMode nMode,
570 : uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
571 : rContinuations,
572 : ::rtl::OUString aDocumentName,
573 : bool bMSCryptoMode,
574 : bool bIsPasswordToModify,
575 : bool bIsSimplePasswordRequest = false )
576 : SAL_THROW((uno::RuntimeException))
577 : {
578 0 : uno::Reference< task::XInteractionRetry > xRetry;
579 0 : uno::Reference< task::XInteractionAbort > xAbort;
580 0 : uno::Reference< task::XInteractionPassword > xPassword;
581 0 : uno::Reference< task::XInteractionPassword2 > xPassword2;
582 0 : getContinuations(rContinuations, &xRetry, &xAbort, &xPassword2, &xPassword);
583 :
584 0 : if ( xPassword2.is() && !xPassword.is() )
585 0 : xPassword.set( xPassword2, uno::UNO_QUERY_THROW );
586 :
587 0 : LoginErrorInfo aInfo;
588 :
589 : executePasswordDialog( pParent, aInfo, nMode,
590 0 : aDocumentName, bMSCryptoMode, bIsPasswordToModify, bIsSimplePasswordRequest );
591 :
592 0 : switch (aInfo.GetResult())
593 : {
594 : case ERRCODE_BUTTON_OK:
595 : OSL_ENSURE( !bIsPasswordToModify || xPassword2.is(), "PasswordToModify is requested, but there is no Interaction!" );
596 0 : if (xPassword.is())
597 : {
598 0 : if (xPassword2.is())
599 : {
600 0 : xPassword2->setPasswordToModify( aInfo.GetPasswordToModify() );
601 0 : xPassword2->setRecommendReadOnly( aInfo.IsRecommendToOpenReadonly() );
602 : }
603 :
604 0 : xPassword->setPassword(aInfo.GetPassword());
605 0 : xPassword->select();
606 : }
607 0 : break;
608 :
609 : case ERRCODE_BUTTON_RETRY:
610 0 : if (xRetry.is())
611 0 : xRetry->select();
612 0 : break;
613 :
614 : default:
615 0 : if (xAbort.is())
616 0 : xAbort->select();
617 0 : break;
618 0 : }
619 0 : }
620 :
621 : } // namespace
622 :
623 : bool
624 0 : UUIInteractionHelper::handleAuthenticationRequest(
625 : uno::Reference< task::XInteractionRequest > const & rRequest)
626 : SAL_THROW((uno::RuntimeException))
627 : {
628 0 : uno::Any aAnyRequest(rRequest->getRequest());
629 :
630 0 : ucb::URLAuthenticationRequest aURLAuthenticationRequest;
631 0 : if (aAnyRequest >>= aURLAuthenticationRequest)
632 : {
633 : handleAuthenticationRequest_(getParentProperty(),
634 : getInteractionHandler(),
635 : m_xServiceFactory,
636 : aURLAuthenticationRequest,
637 0 : rRequest->getContinuations(),
638 0 : aURLAuthenticationRequest.URL);
639 0 : return true;
640 : }
641 :
642 0 : ucb::AuthenticationRequest aAuthenticationRequest;
643 0 : if (aAnyRequest >>= aAuthenticationRequest)
644 : {
645 : handleAuthenticationRequest_(getParentProperty(),
646 : getInteractionHandler(),
647 : m_xServiceFactory,
648 : aAuthenticationRequest,
649 0 : rRequest->getContinuations(),
650 0 : rtl::OUString());
651 0 : return true;
652 : }
653 0 : return false;
654 : }
655 :
656 : bool
657 0 : UUIInteractionHelper::handleMasterPasswordRequest(
658 : uno::Reference< task::XInteractionRequest > const & rRequest)
659 : SAL_THROW((uno::RuntimeException))
660 : {
661 0 : uno::Any aAnyRequest(rRequest->getRequest());
662 :
663 0 : task::MasterPasswordRequest aMasterPasswordRequest;
664 0 : if (aAnyRequest >>= aMasterPasswordRequest)
665 : {
666 : handleMasterPasswordRequest_(getParentProperty(),
667 : aMasterPasswordRequest.Mode,
668 0 : rRequest->getContinuations());
669 0 : return true;
670 : }
671 0 : return false;
672 : }
673 :
674 : bool
675 0 : UUIInteractionHelper::handlePasswordRequest(
676 : uno::Reference< task::XInteractionRequest > const & rRequest)
677 : SAL_THROW((uno::RuntimeException))
678 : {
679 : // parameters to be filled for the call to handlePasswordRequest_
680 0 : Window * pParent = getParentProperty();
681 0 : task::PasswordRequestMode nMode = task::PasswordRequestMode_PASSWORD_ENTER;
682 0 : uno::Sequence< uno::Reference< task::XInteractionContinuation > > const & rContinuations = rRequest->getContinuations();
683 0 : ::rtl::OUString aDocumentName;
684 0 : bool bMSCryptoMode = false;
685 0 : bool bIsPasswordToModify = false;
686 :
687 0 : bool bDoHandleRequest = false;
688 :
689 0 : uno::Any aAnyRequest(rRequest->getRequest());
690 :
691 0 : task::DocumentPasswordRequest2 aDocumentPasswordRequest2;
692 0 : if (!bDoHandleRequest && (aAnyRequest >>= aDocumentPasswordRequest2))
693 : {
694 0 : nMode = aDocumentPasswordRequest2.Mode;
695 0 : aDocumentName = aDocumentPasswordRequest2.Name;
696 : OSL_ENSURE( bMSCryptoMode == false, "bMSCryptoMode should be false" );
697 0 : bIsPasswordToModify = aDocumentPasswordRequest2.IsRequestPasswordToModify;
698 :
699 0 : bDoHandleRequest = true;
700 : }
701 :
702 0 : task::DocumentPasswordRequest aDocumentPasswordRequest;
703 0 : if (!bDoHandleRequest && (aAnyRequest >>= aDocumentPasswordRequest))
704 : {
705 0 : nMode = aDocumentPasswordRequest.Mode;
706 0 : aDocumentName = aDocumentPasswordRequest.Name;
707 : OSL_ENSURE( bMSCryptoMode == false, "bMSCryptoMode should be false" );
708 : OSL_ENSURE( bIsPasswordToModify == false, "bIsPasswordToModify should be false" );
709 :
710 0 : bDoHandleRequest = true;
711 : }
712 :
713 0 : task::DocumentMSPasswordRequest2 aDocumentMSPasswordRequest2;
714 0 : if (!bDoHandleRequest && (aAnyRequest >>= aDocumentMSPasswordRequest2))
715 : {
716 0 : nMode = aDocumentMSPasswordRequest2.Mode;
717 0 : aDocumentName = aDocumentMSPasswordRequest2.Name;
718 0 : bMSCryptoMode = true;
719 0 : bIsPasswordToModify = aDocumentMSPasswordRequest2.IsRequestPasswordToModify;
720 :
721 0 : bDoHandleRequest = true;
722 : }
723 :
724 0 : task::DocumentMSPasswordRequest aDocumentMSPasswordRequest;
725 0 : if (!bDoHandleRequest && (aAnyRequest >>= aDocumentMSPasswordRequest))
726 : {
727 0 : nMode = aDocumentMSPasswordRequest.Mode;
728 0 : aDocumentName = aDocumentMSPasswordRequest.Name;
729 0 : bMSCryptoMode = true;
730 : OSL_ENSURE( bIsPasswordToModify == false, "bIsPasswordToModify should be false" );
731 :
732 0 : bDoHandleRequest = true;
733 : }
734 :
735 0 : if (bDoHandleRequest)
736 : {
737 : handlePasswordRequest_( pParent, nMode, rContinuations,
738 0 : aDocumentName, bMSCryptoMode, bIsPasswordToModify );
739 0 : return true;
740 : }
741 :
742 0 : task::PasswordRequest aPasswordRequest;
743 0 : if( aAnyRequest >>= aPasswordRequest )
744 : {
745 : handlePasswordRequest_(getParentProperty(),
746 : aPasswordRequest.Mode,
747 0 : rRequest->getContinuations(),
748 : rtl::OUString(),
749 : false /* bool bMSCryptoMode */,
750 : false /* bool bIsPasswordToModify */,
751 0 : true /* bool bIsSimplePasswordRequest */ );
752 0 : return true;
753 : }
754 :
755 0 : return false;
756 : }
757 :
758 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|