bump product version to 5.0.4.1
[LibreOffice.git] / uui / source / iahndl-authentication.cxx
blob3249e9db67bfa12a93ae3f5fa31d64aaaaa8fb66
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <comphelper/processfactory.hxx>
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/XInteractionAuthFallback.hpp>
32 #include <com/sun/star/ucb/XInteractionSupplyAuthentication2.hpp>
33 #include <com/sun/star/ucb/URLAuthenticationRequest.hpp>
35 #include <osl/diagnose.h>
36 #include <rtl/digest.h>
37 #include <osl/mutex.hxx>
38 #include <tools/errcode.hxx>
39 #include <vcl/msgbox.hxx>
40 #include <vcl/abstdlg.hxx>
41 #include <vcl/svapp.hxx>
43 #include "authfallbackdlg.hxx"
44 #include "ids.hrc"
45 #include "getcontinuations.hxx"
46 #include "passwordcontainer.hxx"
47 #include "loginerr.hxx"
48 #include "logindlg.hxx"
49 #include "masterpasscrtdlg.hxx"
50 #include "masterpassworddlg.hxx"
51 #include "passworddlg.hxx"
53 #include "iahndl.hxx"
55 #include <boost/scoped_ptr.hpp>
57 using namespace com::sun::star;
59 namespace {
61 void
62 executeLoginDialog(
63 vcl::Window * pParent,
64 LoginErrorInfo & rInfo,
65 OUString const & rRealm)
67 try
69 SolarMutexGuard aGuard;
71 bool bAccount = (rInfo.GetFlags() & LOGINERROR_FLAG_MODIFY_ACCOUNT) != 0;
72 bool bSavePassword = rInfo.GetCanRememberPassword();
73 bool bCanUseSysCreds = rInfo.GetCanUseSystemCredentials();
75 sal_uInt16 nFlags = 0;
76 if (rInfo.GetPath().isEmpty())
77 nFlags |= LF_NO_PATH;
78 if (rInfo.GetErrorText().isEmpty())
79 nFlags |= LF_NO_ERRORTEXT;
80 if (!bAccount)
81 nFlags |= LF_NO_ACCOUNT;
82 if (!(rInfo.GetFlags() & LOGINERROR_FLAG_MODIFY_USER_NAME))
83 nFlags |= LF_USERNAME_READONLY;
85 if (!bSavePassword)
86 nFlags |= LF_NO_SAVEPASSWORD;
88 if (!bCanUseSysCreds)
89 nFlags |= LF_NO_USESYSCREDS;
91 ScopedVclPtrInstance< LoginDialog > xDialog(pParent, nFlags, rInfo.GetServer(), rRealm);
92 if (!rInfo.GetErrorText().isEmpty())
93 xDialog->SetErrorText(rInfo.GetErrorText());
94 xDialog->SetName(rInfo.GetUserName());
95 if (bAccount)
96 xDialog->ClearAccount();
97 else
98 xDialog->ClearPassword();
99 xDialog->SetPassword(rInfo.GetPassword());
101 if (bSavePassword)
103 boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
104 xDialog->SetSavePasswordText(
105 ResId(rInfo.GetIsRememberPersistent()
106 ? RID_SAVE_PASSWORD
107 : RID_KEEP_PASSWORD,
108 *xManager.get()));
110 xDialog->SetSavePassword(rInfo.GetIsRememberPassword());
113 if ( bCanUseSysCreds )
114 xDialog->SetUseSystemCredentials( rInfo.GetIsUseSystemCredentials() );
116 rInfo.SetResult(xDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK :
117 ERRCODE_BUTTON_CANCEL);
118 rInfo.SetUserName(xDialog->GetName());
119 rInfo.SetPassword(xDialog->GetPassword());
120 rInfo.SetAccount(xDialog->GetAccount());
121 rInfo.SetIsRememberPassword(xDialog->IsSavePassword());
123 if ( bCanUseSysCreds )
124 rInfo.SetIsUseSystemCredentials( xDialog->IsUseSystemCredentials() );
126 catch (std::bad_alloc const &)
128 throw uno::RuntimeException("out of memory");
132 void getRememberModes(
133 uno::Sequence< ucb::RememberAuthentication > const & rRememberModes,
134 ucb::RememberAuthentication & rPreferredMode,
135 ucb::RememberAuthentication & rAlternateMode )
137 sal_Int32 nCount = rRememberModes.getLength();
138 OSL_ENSURE( (nCount > 0) && (nCount < 4),
139 "ucb::RememberAuthentication sequence size mismatch!" );
140 if ( nCount == 1 )
142 rPreferredMode = rAlternateMode = rRememberModes[ 0 ];
143 return;
145 else
147 bool bHasRememberModeSession = false;
148 bool bHasRememberModePersistent = false;
150 for (sal_Int32 i = 0; i < nCount; ++i)
152 switch ( rRememberModes[i] )
154 case ucb::RememberAuthentication_NO:
155 break;
156 case ucb::RememberAuthentication_SESSION:
157 bHasRememberModeSession = true;
158 break;
159 case ucb::RememberAuthentication_PERSISTENT:
160 bHasRememberModePersistent = true;
161 break;
162 default:
163 OSL_TRACE( "Unsupported RememberAuthentication value" );
164 break;
168 if (bHasRememberModePersistent)
170 rPreferredMode = ucb::RememberAuthentication_PERSISTENT;
171 if (bHasRememberModeSession)
172 rAlternateMode = ucb::RememberAuthentication_SESSION;
173 else
174 rAlternateMode = ucb::RememberAuthentication_NO;
176 else
178 rPreferredMode = ucb::RememberAuthentication_SESSION;
179 rAlternateMode = ucb::RememberAuthentication_NO;
184 void
185 handleAuthenticationRequest_(
186 vcl::Window * pParent,
187 uno::Reference< task::XInteractionHandler2 > const & xIH,
188 uno::Reference< uno::XComponentContext > const & xContext,
189 ucb::AuthenticationRequest const & rRequest,
190 uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
191 rContinuations,
192 const OUString & rURL)
194 uno::Reference< task::XInteractionRetry > xRetry;
195 uno::Reference< task::XInteractionAbort > xAbort;
196 uno::Reference< ucb::XInteractionSupplyAuthentication >
197 xSupplyAuthentication;
198 uno::Reference< ucb::XInteractionSupplyAuthentication2 >
199 xSupplyAuthentication2;
200 getContinuations(rContinuations, &xRetry, &xAbort, &xSupplyAuthentication);
201 if (xSupplyAuthentication.is())
202 xSupplyAuthentication2.set(xSupplyAuthentication, uno::UNO_QUERY);
205 // First, try to obtain credentials from password container service.
206 uui::PasswordContainerHelper aPwContainerHelper(xContext);
207 if (aPwContainerHelper.handleAuthenticationRequest(rRequest,
208 xSupplyAuthentication,
209 rURL,
210 xIH))
212 xSupplyAuthentication->select();
213 return;
217 // Second, try to obtain credentials from user via password dialog.
218 ucb::RememberAuthentication eDefaultRememberMode
219 = ucb::RememberAuthentication_SESSION;
220 ucb::RememberAuthentication ePreferredRememberMode
221 = eDefaultRememberMode;
222 ucb::RememberAuthentication eAlternateRememberMode
223 = ucb::RememberAuthentication_NO;
225 if (xSupplyAuthentication.is())
227 getRememberModes(
228 xSupplyAuthentication->getRememberPasswordModes(
229 eDefaultRememberMode),
230 ePreferredRememberMode,
231 eAlternateRememberMode);
234 bool bCanUseSystemCredentials;
235 sal_Bool bDefaultUseSystemCredentials;
236 if (xSupplyAuthentication2.is())
238 bCanUseSystemCredentials
239 = xSupplyAuthentication2->canUseSystemCredentials(
240 bDefaultUseSystemCredentials);
242 else
244 bCanUseSystemCredentials = false;
245 bDefaultUseSystemCredentials = sal_False;
248 LoginErrorInfo aInfo;
249 aInfo.SetTitle(rRequest.ServerName);
250 aInfo.SetServer(rRequest.ServerName);
251 if (rRequest.HasAccount)
252 aInfo.SetAccount(rRequest.Account);
253 if (rRequest.HasUserName)
254 aInfo.SetUserName(rRequest.UserName);
255 if (rRequest.HasPassword)
256 aInfo.SetPassword(rRequest.Password);
257 aInfo.SetErrorText(rRequest.Diagnostic);
259 aInfo.SetCanRememberPassword(
260 ePreferredRememberMode != eAlternateRememberMode);
261 aInfo.SetIsRememberPassword(
262 ePreferredRememberMode == eDefaultRememberMode);
263 aInfo.SetIsRememberPersistent(
264 ePreferredRememberMode == ucb::RememberAuthentication_PERSISTENT);
266 aInfo.SetCanUseSystemCredentials(bCanUseSystemCredentials);
267 aInfo.SetIsUseSystemCredentials( bDefaultUseSystemCredentials );
268 aInfo.SetModifyAccount(rRequest.HasAccount
269 && xSupplyAuthentication.is()
270 && xSupplyAuthentication->canSetAccount());
271 aInfo.SetModifyUserName(rRequest.HasUserName
272 && xSupplyAuthentication.is()
273 && xSupplyAuthentication->canSetUserName());
274 executeLoginDialog(pParent,
275 aInfo,
276 rRequest.HasRealm ? rRequest.Realm : OUString());
277 switch (aInfo.GetResult())
279 case ERRCODE_BUTTON_OK:
280 if (xSupplyAuthentication.is())
282 if (xSupplyAuthentication->canSetUserName())
283 xSupplyAuthentication->setUserName(aInfo.GetUserName());
284 if (xSupplyAuthentication->canSetPassword())
285 xSupplyAuthentication->setPassword(aInfo.GetPassword());
287 if (ePreferredRememberMode != eAlternateRememberMode)
289 // user had the choice.
290 if (aInfo.GetIsRememberPassword())
291 xSupplyAuthentication->setRememberPassword(
292 ePreferredRememberMode);
293 else
294 xSupplyAuthentication->setRememberPassword(
295 eAlternateRememberMode);
297 else
299 // user had no choice.
300 xSupplyAuthentication->setRememberPassword(
301 ePreferredRememberMode);
304 if (rRequest.HasRealm)
306 if (xSupplyAuthentication->canSetRealm())
307 xSupplyAuthentication->setRealm(aInfo.GetAccount());
309 else if (xSupplyAuthentication->canSetAccount())
310 xSupplyAuthentication->setAccount(aInfo.GetAccount());
312 if ( xSupplyAuthentication2.is() && bCanUseSystemCredentials )
313 xSupplyAuthentication2->setUseSystemCredentials(
314 aInfo.GetIsUseSystemCredentials() );
316 xSupplyAuthentication->select();
320 // Third, store credentials in password container.
322 if ( aInfo.GetIsUseSystemCredentials() )
324 if (aInfo.GetIsRememberPassword())
326 if (!aPwContainerHelper.addRecord(
327 !rURL.isEmpty() ? rURL : rRequest.ServerName,
328 OUString(), // empty u/p -> sys creds
329 uno::Sequence< OUString >(),
330 xIH,
331 ePreferredRememberMode
332 == ucb::RememberAuthentication_PERSISTENT))
334 xSupplyAuthentication->setRememberPassword(
335 ucb::RememberAuthentication_NO);
338 else if (eAlternateRememberMode
339 == ucb::RememberAuthentication_SESSION)
341 if (!aPwContainerHelper.addRecord(
342 !rURL.isEmpty() ? rURL : rRequest.ServerName,
343 OUString(), // empty u/p -> sys creds
344 uno::Sequence< OUString >(),
345 xIH,
346 false /* SESSION */))
348 xSupplyAuthentication->setRememberPassword(
349 ucb::RememberAuthentication_NO);
353 // Empty user name can not be valid:
354 else if (!aInfo.GetUserName().isEmpty())
356 uno::Sequence< OUString >
357 aPassList(aInfo.GetAccount().isEmpty() ? 1 : 2);
358 aPassList[0] = aInfo.GetPassword();
359 if (!aInfo.GetAccount().isEmpty())
360 aPassList[1] = aInfo.GetAccount();
362 if (aInfo.GetIsRememberPassword())
364 if (!aPwContainerHelper.addRecord(
365 !rURL.isEmpty() ? rURL : rRequest.ServerName,
366 aInfo.GetUserName(),
367 aPassList,
368 xIH,
369 ePreferredRememberMode
370 == ucb::RememberAuthentication_PERSISTENT))
372 xSupplyAuthentication->setRememberPassword(
373 ucb::RememberAuthentication_NO);
376 else if (eAlternateRememberMode
377 == ucb::RememberAuthentication_SESSION)
379 if (!aPwContainerHelper.addRecord(
380 !rURL.isEmpty() ? rURL : rRequest.ServerName,
381 aInfo.GetUserName(),
382 aPassList,
383 xIH,
384 false /* SESSION */))
386 xSupplyAuthentication->setRememberPassword(
387 ucb::RememberAuthentication_NO);
391 break;
393 case ERRCODE_BUTTON_RETRY:
394 if (xRetry.is())
395 xRetry->select();
396 break;
398 default:
399 if (xAbort.is())
400 xAbort->select();
401 break;
405 void
406 executeMasterPasswordDialog(
407 vcl::Window * pParent,
408 LoginErrorInfo & rInfo,
409 task::PasswordRequestMode nMode)
411 OString aMaster;
414 SolarMutexGuard aGuard;
416 boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
417 if( nMode == task::PasswordRequestMode_PASSWORD_CREATE )
419 ScopedVclPtrInstance< MasterPasswordCreateDialog > xDialog(
420 pParent, xManager.get());
421 rInfo.SetResult(xDialog->Execute()
422 == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL);
423 aMaster = OUStringToOString(
424 xDialog->GetMasterPassword(), RTL_TEXTENCODING_UTF8);
426 else
428 ScopedVclPtrInstance< MasterPasswordDialog > xDialog(
429 pParent, nMode, xManager.get());
430 rInfo.SetResult(xDialog->Execute()
431 == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL);
432 aMaster = OUStringToOString(
433 xDialog->GetMasterPassword(), RTL_TEXTENCODING_UTF8);
436 catch (std::bad_alloc const &)
438 throw uno::RuntimeException("out of memory");
441 sal_uInt8 aKey[RTL_DIGEST_LENGTH_MD5];
442 rtl_digest_PBKDF2(aKey,
443 RTL_DIGEST_LENGTH_MD5,
444 reinterpret_cast< sal_uInt8 const * >(aMaster.getStr()),
445 aMaster.getLength(),
446 reinterpret_cast< sal_uInt8 const * >(
447 "3B5509ABA6BC42D9A3A1F3DAD49E56A51"),
449 1000);
451 OUStringBuffer aBuffer;
452 for (int i = 0; i < RTL_DIGEST_LENGTH_MD5; ++i)
454 aBuffer.append(static_cast< sal_Unicode >('a' + (aKey[i] >> 4)));
455 aBuffer.append(static_cast< sal_Unicode >('a' + (aKey[i] & 15)));
457 rInfo.SetPassword(aBuffer.makeStringAndClear());
460 void
461 handleMasterPasswordRequest_(
462 vcl::Window * pParent,
463 task::PasswordRequestMode nMode,
464 uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
465 rContinuations)
467 uno::Reference< task::XInteractionRetry > xRetry;
468 uno::Reference< task::XInteractionAbort > xAbort;
469 uno::Reference< ucb::XInteractionSupplyAuthentication >
470 xSupplyAuthentication;
471 getContinuations(rContinuations, &xRetry, &xAbort, &xSupplyAuthentication);
472 LoginErrorInfo aInfo;
474 // in case of master password a hash code is returned
475 executeMasterPasswordDialog(pParent, aInfo, nMode);
477 switch (aInfo.GetResult())
479 case ERRCODE_BUTTON_OK:
480 if (xSupplyAuthentication.is())
482 if (xSupplyAuthentication->canSetPassword())
483 xSupplyAuthentication->setPassword(aInfo.GetPassword());
484 xSupplyAuthentication->select();
486 break;
488 case ERRCODE_BUTTON_RETRY:
489 if (xRetry.is())
490 xRetry->select();
491 break;
493 default:
494 if (xAbort.is())
495 xAbort->select();
496 break;
500 void
501 executePasswordDialog(
502 vcl::Window * pParent,
503 LoginErrorInfo & rInfo,
504 task::PasswordRequestMode nMode,
505 const OUString& aDocName,
506 bool bMSCryptoMode,
507 bool bIsPasswordToModify,
508 bool bIsSimplePasswordRequest )
512 SolarMutexGuard aGuard;
514 boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
515 if( nMode == task::PasswordRequestMode_PASSWORD_CREATE )
517 if (bIsSimplePasswordRequest)
519 VclPtr< PasswordDialog > pDialog(
520 VclPtr<PasswordDialog>::Create( pParent, nMode, xManager.get(), aDocName,
521 bIsPasswordToModify, bIsSimplePasswordRequest ) );
522 pDialog->SetMinLen(0);
524 rInfo.SetResult( pDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL );
525 rInfo.SetPassword( pDialog->GetPassword() );
527 else
529 const sal_uInt16 nMaxPasswdLen = bMSCryptoMode ? 15 : 0; // 0 -> allow any length
531 VclAbstractDialogFactory * pFact = VclAbstractDialogFactory::Create();
532 AbstractPasswordToOpenModifyDialog *pTmp = pFact->CreatePasswordToOpenModifyDialog( pParent, 0, nMaxPasswdLen, bIsPasswordToModify );
533 boost::scoped_ptr< AbstractPasswordToOpenModifyDialog > pDialog( pTmp );
535 rInfo.SetResult( pDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL );
536 rInfo.SetPassword( pDialog->GetPasswordToOpen() );
537 rInfo.SetPasswordToModify( pDialog->GetPasswordToModify() );
538 rInfo.SetRecommendToOpenReadonly( pDialog->IsRecommendToOpenReadonly() );
541 else // enter password or reenter password
543 VclPtr< PasswordDialog > pDialog(
544 VclPtr<PasswordDialog>::Create( pParent, nMode, xManager.get(), aDocName,
545 bIsPasswordToModify, bIsSimplePasswordRequest ) );
546 pDialog->SetMinLen(0);
548 rInfo.SetResult( pDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL );
549 rInfo.SetPassword( bIsPasswordToModify ? OUString() : pDialog->GetPassword() );
550 rInfo.SetPasswordToModify( bIsPasswordToModify ? pDialog->GetPassword() : OUString() );
553 catch (std::bad_alloc const &)
555 throw uno::RuntimeException("out of memory",
556 uno::Reference< uno::XInterface>());
560 void
561 handlePasswordRequest_(
562 vcl::Window * pParent,
563 task::PasswordRequestMode nMode,
564 uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
565 rContinuations,
566 const OUString& aDocumentName,
567 bool bMSCryptoMode,
568 bool bIsPasswordToModify,
569 bool bIsSimplePasswordRequest = false )
571 uno::Reference< task::XInteractionRetry > xRetry;
572 uno::Reference< task::XInteractionAbort > xAbort;
573 uno::Reference< task::XInteractionPassword > xPassword;
574 uno::Reference< task::XInteractionPassword2 > xPassword2;
575 getContinuations(rContinuations, &xRetry, &xAbort, &xPassword2, &xPassword);
577 if ( xPassword2.is() && !xPassword.is() )
578 xPassword.set( xPassword2, uno::UNO_QUERY_THROW );
580 LoginErrorInfo aInfo;
582 executePasswordDialog( pParent, aInfo, nMode,
583 aDocumentName, bMSCryptoMode, bIsPasswordToModify, bIsSimplePasswordRequest );
585 switch (aInfo.GetResult())
587 case ERRCODE_BUTTON_OK:
588 OSL_ENSURE( !bIsPasswordToModify || xPassword2.is(), "PasswordToModify is requested, but there is no Interaction!" );
589 if (xPassword.is())
591 if (xPassword2.is())
593 xPassword2->setPasswordToModify( aInfo.GetPasswordToModify() );
594 xPassword2->setRecommendReadOnly( aInfo.IsRecommendToOpenReadonly() );
597 xPassword->setPassword(aInfo.GetPassword());
598 xPassword->select();
600 break;
602 case ERRCODE_BUTTON_RETRY:
603 if (xRetry.is())
604 xRetry->select();
605 break;
607 default:
608 if (xAbort.is())
609 xAbort->select();
610 break;
614 } // namespace
616 bool
617 UUIInteractionHelper::handleAuthenticationRequest(
618 uno::Reference< task::XInteractionRequest > const & rRequest)
620 uno::Any aAnyRequest(rRequest->getRequest());
622 ucb::URLAuthenticationRequest aURLAuthenticationRequest;
623 if (aAnyRequest >>= aURLAuthenticationRequest)
625 handleAuthenticationRequest_(getParentProperty(),
626 getInteractionHandler(),
627 m_xContext,
628 aURLAuthenticationRequest,
629 rRequest->getContinuations(),
630 aURLAuthenticationRequest.URL);
631 return true;
634 ucb::AuthenticationRequest aAuthenticationRequest;
635 if (aAnyRequest >>= aAuthenticationRequest)
637 handleAuthenticationRequest_(getParentProperty(),
638 getInteractionHandler(),
639 m_xContext,
640 aAuthenticationRequest,
641 rRequest->getContinuations(),
642 OUString());
643 return true;
645 return false;
648 bool
649 UUIInteractionHelper::handleMasterPasswordRequest(
650 uno::Reference< task::XInteractionRequest > const & rRequest)
652 uno::Any aAnyRequest(rRequest->getRequest());
654 task::MasterPasswordRequest aMasterPasswordRequest;
655 if (aAnyRequest >>= aMasterPasswordRequest)
657 handleMasterPasswordRequest_(getParentProperty(),
658 aMasterPasswordRequest.Mode,
659 rRequest->getContinuations());
660 return true;
662 return false;
665 bool
666 UUIInteractionHelper::handlePasswordRequest(
667 uno::Reference< task::XInteractionRequest > const & rRequest)
669 // parameters to be filled for the call to handlePasswordRequest_
670 vcl::Window * pParent = getParentProperty();
671 task::PasswordRequestMode nMode = task::PasswordRequestMode_PASSWORD_ENTER;
672 uno::Sequence< uno::Reference< task::XInteractionContinuation > > const & rContinuations = rRequest->getContinuations();
673 OUString aDocumentName;
674 bool bMSCryptoMode = false;
675 bool bIsPasswordToModify = false;
677 bool bDoHandleRequest = false;
679 uno::Any aAnyRequest(rRequest->getRequest());
681 task::DocumentPasswordRequest2 aDocumentPasswordRequest2;
682 if (!bDoHandleRequest && (aAnyRequest >>= aDocumentPasswordRequest2))
684 nMode = aDocumentPasswordRequest2.Mode;
685 aDocumentName = aDocumentPasswordRequest2.Name;
686 OSL_ENSURE( !bMSCryptoMode, "bMSCryptoMode should be false" );
687 bIsPasswordToModify = aDocumentPasswordRequest2.IsRequestPasswordToModify;
689 bDoHandleRequest = true;
692 task::DocumentPasswordRequest aDocumentPasswordRequest;
693 if (!bDoHandleRequest && (aAnyRequest >>= aDocumentPasswordRequest))
695 nMode = aDocumentPasswordRequest.Mode;
696 aDocumentName = aDocumentPasswordRequest.Name;
697 OSL_ENSURE( !bMSCryptoMode, "bMSCryptoMode should be false" );
698 OSL_ENSURE( !bIsPasswordToModify, "bIsPasswordToModify should be false" );
700 bDoHandleRequest = true;
703 task::DocumentMSPasswordRequest2 aDocumentMSPasswordRequest2;
704 if (!bDoHandleRequest && (aAnyRequest >>= aDocumentMSPasswordRequest2))
706 nMode = aDocumentMSPasswordRequest2.Mode;
707 aDocumentName = aDocumentMSPasswordRequest2.Name;
708 bMSCryptoMode = true;
709 bIsPasswordToModify = aDocumentMSPasswordRequest2.IsRequestPasswordToModify;
711 bDoHandleRequest = true;
714 task::DocumentMSPasswordRequest aDocumentMSPasswordRequest;
715 if (!bDoHandleRequest && (aAnyRequest >>= aDocumentMSPasswordRequest))
717 nMode = aDocumentMSPasswordRequest.Mode;
718 aDocumentName = aDocumentMSPasswordRequest.Name;
719 bMSCryptoMode = true;
720 OSL_ENSURE( !bIsPasswordToModify, "bIsPasswordToModify should be false" );
722 bDoHandleRequest = true;
725 if (bDoHandleRequest)
727 handlePasswordRequest_( pParent, nMode, rContinuations,
728 aDocumentName, bMSCryptoMode, bIsPasswordToModify );
729 return true;
732 task::PasswordRequest aPasswordRequest;
733 if( aAnyRequest >>= aPasswordRequest )
735 handlePasswordRequest_(getParentProperty(),
736 aPasswordRequest.Mode,
737 rRequest->getContinuations(),
738 OUString(),
739 false /* bool bMSCryptoMode */,
740 false /* bool bIsPasswordToModify */,
741 true /* bool bIsSimplePasswordRequest */ );
742 return true;
745 return false;
748 bool
749 UUIInteractionHelper::handleAuthFallbackRequest( OUString & instructions,
750 OUString & url,
751 uno::Sequence< uno::Reference< task::XInteractionContinuation > > const & rContinuations )
753 vcl::Window * pParent = getParentProperty( );
754 VclPtrInstance<AuthFallbackDlg> dlg( pParent, instructions, url );
755 int retCode = dlg->Execute( );
756 uno::Reference< task::XInteractionAbort > xAbort;
757 uno::Reference< ucb::XInteractionAuthFallback > xAuthFallback;
758 getContinuations(rContinuations, &xAbort, &xAuthFallback);
760 if( retCode == RET_OK && xAuthFallback.is( ) )
762 xAuthFallback->setCode( dlg->GetCode( ) );
763 xAuthFallback->select( );
766 return true;
769 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */