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