bump product version to 4.1.6.2
[LibreOffice.git] / uui / source / iahndl-authentication.cxx
blob50e4d078b1114ce17a03dbe6b6354fb8f8f259c3
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/XInteractionSupplyAuthentication2.hpp"
32 #include "com/sun/star/ucb/URLAuthenticationRequest.hpp"
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"
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"
51 #include "iahndl.hxx"
53 #include <boost/scoped_ptr.hpp>
55 using namespace com::sun::star;
57 namespace {
59 void
60 executeLoginDialog(
61 Window * pParent,
62 LoginErrorInfo & rInfo,
63 OUString const & rRealm)
64 SAL_THROW((uno::RuntimeException))
66 try
68 SolarMutexGuard aGuard;
70 bool bAccount = (rInfo.GetFlags() & LOGINERROR_FLAG_MODIFY_ACCOUNT) != 0;
71 bool bSavePassword = rInfo.GetCanRememberPassword();
72 bool bCanUseSysCreds = rInfo.GetCanUseSystemCredentials();
74 sal_uInt16 nFlags = 0;
75 if (rInfo.GetPath().Len() == 0)
76 nFlags |= LF_NO_PATH;
77 if (rInfo.GetErrorText().Len() == 0)
78 nFlags |= LF_NO_ERRORTEXT;
79 if (!bAccount)
80 nFlags |= LF_NO_ACCOUNT;
81 if (!(rInfo.GetFlags() & LOGINERROR_FLAG_MODIFY_USER_NAME))
82 nFlags |= LF_USERNAME_READONLY;
84 if (!bSavePassword)
85 nFlags |= LF_NO_SAVEPASSWORD;
87 if (!bCanUseSysCreds)
88 nFlags |= LF_NO_USESYSCREDS;
90 boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
91 boost::scoped_ptr< LoginDialog > xDialog(
92 new LoginDialog( pParent, nFlags, rInfo.GetServer(), rRealm, xManager.get()));
93 if (rInfo.GetErrorText().Len() != 0)
94 xDialog->SetErrorText(rInfo.GetErrorText());
95 xDialog->SetName(rInfo.GetUserName());
96 if (bAccount)
97 xDialog->ClearAccount();
98 else
99 xDialog->ClearPassword();
100 xDialog->SetPassword(rInfo.GetPassword());
102 if (bSavePassword)
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(OUString("out of memory"),
129 uno::Reference< uno::XInterface >());
133 void getRememberModes(
134 uno::Sequence< ucb::RememberAuthentication > const & rRememberModes,
135 ucb::RememberAuthentication & rPreferredMode,
136 ucb::RememberAuthentication & rAlternateMode )
138 sal_Int32 nCount = rRememberModes.getLength();
139 OSL_ENSURE( (nCount > 0) && (nCount < 4),
140 "ucb::RememberAuthentication sequence size mismatch!" );
141 if ( nCount == 1 )
143 rPreferredMode = rAlternateMode = rRememberModes[ 0 ];
144 return;
146 else
148 bool bHasRememberModeSession = false;
149 bool bHasRememberModePersistent = false;
151 for (sal_Int32 i = 0; i < nCount; ++i)
153 switch ( rRememberModes[i] )
155 case ucb::RememberAuthentication_NO:
156 break;
157 case ucb::RememberAuthentication_SESSION:
158 bHasRememberModeSession = true;
159 break;
160 case ucb::RememberAuthentication_PERSISTENT:
161 bHasRememberModePersistent = true;
162 break;
163 default:
164 OSL_TRACE( "Unsupported RememberAuthentication value" );
165 break;
169 if (bHasRememberModePersistent)
171 rPreferredMode = ucb::RememberAuthentication_PERSISTENT;
172 if (bHasRememberModeSession)
173 rAlternateMode = ucb::RememberAuthentication_SESSION;
174 else
175 rAlternateMode = ucb::RememberAuthentication_NO;
177 else
179 rPreferredMode = ucb::RememberAuthentication_SESSION;
180 rAlternateMode = ucb::RememberAuthentication_NO;
185 void
186 handleAuthenticationRequest_(
187 Window * pParent,
188 uno::Reference< task::XInteractionHandler2 > const & xIH,
189 uno::Reference< uno::XComponentContext > const & xContext,
190 ucb::AuthenticationRequest const & rRequest,
191 uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
192 rContinuations,
193 const OUString & rURL)
194 SAL_THROW((uno::RuntimeException))
196 uno::Reference< task::XInteractionRetry > xRetry;
197 uno::Reference< task::XInteractionAbort > xAbort;
198 uno::Reference< ucb::XInteractionSupplyAuthentication >
199 xSupplyAuthentication;
200 uno::Reference< ucb::XInteractionSupplyAuthentication2 >
201 xSupplyAuthentication2;
202 getContinuations(rContinuations, &xRetry, &xAbort, &xSupplyAuthentication);
203 if (xSupplyAuthentication.is())
204 xSupplyAuthentication2.set(xSupplyAuthentication, uno::UNO_QUERY);
206 //////////////////////////
207 // First, try to obtain credentials from password container service.
208 uui::PasswordContainerHelper aPwContainerHelper(xContext);
209 if (aPwContainerHelper.handleAuthenticationRequest(rRequest,
210 xSupplyAuthentication,
211 rURL,
212 xIH))
214 xSupplyAuthentication->select();
215 return;
218 //////////////////////////
219 // Second, try to obtain credentials from user via password dialog.
220 ucb::RememberAuthentication eDefaultRememberMode
221 = ucb::RememberAuthentication_SESSION;
222 ucb::RememberAuthentication ePreferredRememberMode
223 = eDefaultRememberMode;
224 ucb::RememberAuthentication eAlternateRememberMode
225 = ucb::RememberAuthentication_NO;
227 if (xSupplyAuthentication.is())
229 getRememberModes(
230 xSupplyAuthentication->getRememberPasswordModes(
231 eDefaultRememberMode),
232 ePreferredRememberMode,
233 eAlternateRememberMode);
236 sal_Bool bCanUseSystemCredentials;
237 sal_Bool bDefaultUseSystemCredentials;
238 if (xSupplyAuthentication2.is())
240 bCanUseSystemCredentials
241 = xSupplyAuthentication2->canUseSystemCredentials(
242 bDefaultUseSystemCredentials);
244 else
246 bCanUseSystemCredentials = sal_False;
247 bDefaultUseSystemCredentials = sal_False;
250 LoginErrorInfo aInfo;
251 aInfo.SetTitle(rRequest.ServerName);
252 aInfo.SetServer(rRequest.ServerName);
253 if (rRequest.HasAccount)
254 aInfo.SetAccount(rRequest.Account);
255 if (rRequest.HasUserName)
256 aInfo.SetUserName(rRequest.UserName);
257 if (rRequest.HasPassword)
258 aInfo.SetPassword(rRequest.Password);
259 aInfo.SetErrorText(rRequest.Diagnostic);
261 aInfo.SetCanRememberPassword(
262 ePreferredRememberMode != eAlternateRememberMode);
263 aInfo.SetIsRememberPassword(
264 ePreferredRememberMode == eDefaultRememberMode);
265 aInfo.SetIsRememberPersistent(
266 ePreferredRememberMode == ucb::RememberAuthentication_PERSISTENT);
268 aInfo.SetCanUseSystemCredentials(bCanUseSystemCredentials);
269 aInfo.SetIsUseSystemCredentials( bDefaultUseSystemCredentials );
270 aInfo.SetModifyAccount(rRequest.HasAccount
271 && xSupplyAuthentication.is()
272 && xSupplyAuthentication->canSetAccount());
273 aInfo.SetModifyUserName(rRequest.HasUserName
274 && xSupplyAuthentication.is()
275 && xSupplyAuthentication->canSetUserName());
276 executeLoginDialog(pParent,
277 aInfo,
278 rRequest.HasRealm ? rRequest.Realm : OUString());
279 switch (aInfo.GetResult())
281 case ERRCODE_BUTTON_OK:
282 if (xSupplyAuthentication.is())
284 if (xSupplyAuthentication->canSetUserName())
285 xSupplyAuthentication->setUserName(aInfo.GetUserName());
286 if (xSupplyAuthentication->canSetPassword())
287 xSupplyAuthentication->setPassword(aInfo.GetPassword());
289 if (ePreferredRememberMode != eAlternateRememberMode)
291 // user had the choice.
292 if (aInfo.GetIsRememberPassword())
293 xSupplyAuthentication->setRememberPassword(
294 ePreferredRememberMode);
295 else
296 xSupplyAuthentication->setRememberPassword(
297 eAlternateRememberMode);
299 else
301 // user had no choice.
302 xSupplyAuthentication->setRememberPassword(
303 ePreferredRememberMode);
306 if (rRequest.HasRealm)
308 if (xSupplyAuthentication->canSetRealm())
309 xSupplyAuthentication->setRealm(aInfo.GetAccount());
311 else if (xSupplyAuthentication->canSetAccount())
312 xSupplyAuthentication->setAccount(aInfo.GetAccount());
314 if ( xSupplyAuthentication2.is() && bCanUseSystemCredentials )
315 xSupplyAuthentication2->setUseSystemCredentials(
316 aInfo.GetIsUseSystemCredentials() );
318 xSupplyAuthentication->select();
321 //////////////////////////
322 // Third, store credentials in password container.
324 if ( aInfo.GetIsUseSystemCredentials() )
326 if (aInfo.GetIsRememberPassword())
328 if (!aPwContainerHelper.addRecord(
329 !rURL.isEmpty() ? rURL : rRequest.ServerName,
330 OUString(), // empty u/p -> sys creds
331 uno::Sequence< OUString >(),
332 xIH,
333 ePreferredRememberMode
334 == ucb::RememberAuthentication_PERSISTENT))
336 xSupplyAuthentication->setRememberPassword(
337 ucb::RememberAuthentication_NO);
340 else if (eAlternateRememberMode
341 == ucb::RememberAuthentication_SESSION)
343 if (!aPwContainerHelper.addRecord(
344 !rURL.isEmpty() ? rURL : rRequest.ServerName,
345 OUString(), // empty u/p -> sys creds
346 uno::Sequence< OUString >(),
347 xIH,
348 false /* SESSION */))
350 xSupplyAuthentication->setRememberPassword(
351 ucb::RememberAuthentication_NO);
355 // Empty user name can not be valid:
356 else if (aInfo.GetUserName().Len() != 0)
358 uno::Sequence< OUString >
359 aPassList(aInfo.GetAccount().Len() == 0 ? 1 : 2);
360 aPassList[0] = aInfo.GetPassword();
361 if (aInfo.GetAccount().Len() != 0)
362 aPassList[1] = aInfo.GetAccount();
364 if (aInfo.GetIsRememberPassword())
366 if (!aPwContainerHelper.addRecord(
367 !rURL.isEmpty() ? rURL : rRequest.ServerName,
368 aInfo.GetUserName(),
369 aPassList,
370 xIH,
371 ePreferredRememberMode
372 == ucb::RememberAuthentication_PERSISTENT))
374 xSupplyAuthentication->setRememberPassword(
375 ucb::RememberAuthentication_NO);
378 else if (eAlternateRememberMode
379 == ucb::RememberAuthentication_SESSION)
381 if (!aPwContainerHelper.addRecord(
382 !rURL.isEmpty() ? rURL : rRequest.ServerName,
383 aInfo.GetUserName(),
384 aPassList,
385 xIH,
386 false /* SESSION */))
388 xSupplyAuthentication->setRememberPassword(
389 ucb::RememberAuthentication_NO);
393 break;
395 case ERRCODE_BUTTON_RETRY:
396 if (xRetry.is())
397 xRetry->select();
398 break;
400 default:
401 if (xAbort.is())
402 xAbort->select();
403 break;
407 void
408 executeMasterPasswordDialog(
409 Window * pParent,
410 LoginErrorInfo & rInfo,
411 task::PasswordRequestMode nMode)
412 SAL_THROW((uno::RuntimeException))
414 OString aMaster;
417 SolarMutexGuard aGuard;
419 boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
420 if( nMode == task::PasswordRequestMode_PASSWORD_CREATE )
422 boost::scoped_ptr< MasterPasswordCreateDialog > xDialog(
423 new MasterPasswordCreateDialog(pParent, xManager.get()));
424 rInfo.SetResult(xDialog->Execute()
425 == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL);
426 aMaster = OUStringToOString(
427 xDialog->GetMasterPassword(), RTL_TEXTENCODING_UTF8);
429 else
431 boost::scoped_ptr< MasterPasswordDialog > xDialog(
432 new MasterPasswordDialog(pParent, nMode, xManager.get()));
433 rInfo.SetResult(xDialog->Execute()
434 == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL);
435 aMaster = OUStringToOString(
436 xDialog->GetMasterPassword(), RTL_TEXTENCODING_UTF8);
439 catch (std::bad_alloc const &)
441 throw uno::RuntimeException(OUString("out of memory"),
442 uno::Reference< uno::XInterface >());
445 sal_uInt8 aKey[RTL_DIGEST_LENGTH_MD5];
446 rtl_digest_PBKDF2(aKey,
447 RTL_DIGEST_LENGTH_MD5,
448 reinterpret_cast< sal_uInt8 const * >(aMaster.getStr()),
449 aMaster.getLength(),
450 reinterpret_cast< sal_uInt8 const * >(
451 "3B5509ABA6BC42D9A3A1F3DAD49E56A51"),
453 1000);
455 OUStringBuffer aBuffer;
456 for (int i = 0; i < RTL_DIGEST_LENGTH_MD5; ++i)
458 aBuffer.append(static_cast< sal_Unicode >('a' + (aKey[i] >> 4)));
459 aBuffer.append(static_cast< sal_Unicode >('a' + (aKey[i] & 15)));
461 rInfo.SetPassword(aBuffer.makeStringAndClear());
464 void
465 handleMasterPasswordRequest_(
466 Window * pParent,
467 task::PasswordRequestMode nMode,
468 uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
469 rContinuations)
470 SAL_THROW((uno::RuntimeException))
472 uno::Reference< task::XInteractionRetry > xRetry;
473 uno::Reference< task::XInteractionAbort > xAbort;
474 uno::Reference< ucb::XInteractionSupplyAuthentication >
475 xSupplyAuthentication;
476 getContinuations(rContinuations, &xRetry, &xAbort, &xSupplyAuthentication);
477 LoginErrorInfo aInfo;
479 // in case of master password a hash code is returned
480 executeMasterPasswordDialog(pParent, aInfo, nMode);
482 switch (aInfo.GetResult())
484 case ERRCODE_BUTTON_OK:
485 if (xSupplyAuthentication.is())
487 if (xSupplyAuthentication->canSetPassword())
488 xSupplyAuthentication->setPassword(aInfo.GetPassword());
489 xSupplyAuthentication->select();
491 break;
493 case ERRCODE_BUTTON_RETRY:
494 if (xRetry.is())
495 xRetry->select();
496 break;
498 default:
499 if (xAbort.is())
500 xAbort->select();
501 break;
505 void
506 executePasswordDialog(
507 Window * pParent,
508 LoginErrorInfo & rInfo,
509 task::PasswordRequestMode nMode,
510 OUString aDocName,
511 bool bMSCryptoMode,
512 bool bIsPasswordToModify,
513 bool bIsSimplePasswordRequest )
514 SAL_THROW((uno::RuntimeException))
518 SolarMutexGuard aGuard;
520 boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
521 if( nMode == task::PasswordRequestMode_PASSWORD_CREATE )
523 if (bIsSimplePasswordRequest)
525 boost::scoped_ptr< PasswordDialog > pDialog(
526 new PasswordDialog( pParent, nMode, xManager.get(), aDocName,
527 bIsPasswordToModify, bIsSimplePasswordRequest ) );
528 pDialog->SetMinLen(0);
530 rInfo.SetResult( pDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL );
531 rInfo.SetPassword( pDialog->GetPassword() );
533 else
535 const sal_uInt16 nMaxPasswdLen = bMSCryptoMode ? 15 : 0; // 0 -> allow any length
537 VclAbstractDialogFactory * pFact = VclAbstractDialogFactory::Create();
538 AbstractPasswordToOpenModifyDialog *pTmp = pFact->CreatePasswordToOpenModifyDialog( pParent, 0, nMaxPasswdLen, bIsPasswordToModify );
539 boost::scoped_ptr< AbstractPasswordToOpenModifyDialog > pDialog( pTmp );
541 rInfo.SetResult( pDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL );
542 rInfo.SetPassword( pDialog->GetPasswordToOpen() );
543 rInfo.SetPasswordToModify( pDialog->GetPasswordToModify() );
544 rInfo.SetRecommendToOpenReadonly( pDialog->IsRecommendToOpenReadonly() );
547 else // enter password or reenter password
549 boost::scoped_ptr< PasswordDialog > pDialog(
550 new PasswordDialog( pParent, nMode, xManager.get(), aDocName,
551 bIsPasswordToModify, bIsSimplePasswordRequest ) );
552 pDialog->SetMinLen(0);
554 rInfo.SetResult( pDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL );
555 rInfo.SetPassword( bIsPasswordToModify ? String() : pDialog->GetPassword() );
556 rInfo.SetPasswordToModify( bIsPasswordToModify ? pDialog->GetPassword() : String() );
559 catch (std::bad_alloc const &)
561 throw uno::RuntimeException(OUString("out of memory"),
562 uno::Reference< uno::XInterface>());
566 void
567 handlePasswordRequest_(
568 Window * pParent,
569 task::PasswordRequestMode nMode,
570 uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
571 rContinuations,
572 OUString aDocumentName,
573 bool bMSCryptoMode,
574 bool bIsPasswordToModify,
575 bool bIsSimplePasswordRequest = false )
576 SAL_THROW((uno::RuntimeException))
578 uno::Reference< task::XInteractionRetry > xRetry;
579 uno::Reference< task::XInteractionAbort > xAbort;
580 uno::Reference< task::XInteractionPassword > xPassword;
581 uno::Reference< task::XInteractionPassword2 > xPassword2;
582 getContinuations(rContinuations, &xRetry, &xAbort, &xPassword2, &xPassword);
584 if ( xPassword2.is() && !xPassword.is() )
585 xPassword.set( xPassword2, uno::UNO_QUERY_THROW );
587 LoginErrorInfo aInfo;
589 executePasswordDialog( pParent, aInfo, nMode,
590 aDocumentName, bMSCryptoMode, bIsPasswordToModify, bIsSimplePasswordRequest );
592 switch (aInfo.GetResult())
594 case ERRCODE_BUTTON_OK:
595 OSL_ENSURE( !bIsPasswordToModify || xPassword2.is(), "PasswordToModify is requested, but there is no Interaction!" );
596 if (xPassword.is())
598 if (xPassword2.is())
600 xPassword2->setPasswordToModify( aInfo.GetPasswordToModify() );
601 xPassword2->setRecommendReadOnly( aInfo.IsRecommendToOpenReadonly() );
604 xPassword->setPassword(aInfo.GetPassword());
605 xPassword->select();
607 break;
609 case ERRCODE_BUTTON_RETRY:
610 if (xRetry.is())
611 xRetry->select();
612 break;
614 default:
615 if (xAbort.is())
616 xAbort->select();
617 break;
621 } // namespace
623 bool
624 UUIInteractionHelper::handleAuthenticationRequest(
625 uno::Reference< task::XInteractionRequest > const & rRequest)
626 SAL_THROW((uno::RuntimeException))
628 uno::Any aAnyRequest(rRequest->getRequest());
630 ucb::URLAuthenticationRequest aURLAuthenticationRequest;
631 if (aAnyRequest >>= aURLAuthenticationRequest)
633 handleAuthenticationRequest_(getParentProperty(),
634 getInteractionHandler(),
635 m_xContext,
636 aURLAuthenticationRequest,
637 rRequest->getContinuations(),
638 aURLAuthenticationRequest.URL);
639 return true;
642 ucb::AuthenticationRequest aAuthenticationRequest;
643 if (aAnyRequest >>= aAuthenticationRequest)
645 handleAuthenticationRequest_(getParentProperty(),
646 getInteractionHandler(),
647 m_xContext,
648 aAuthenticationRequest,
649 rRequest->getContinuations(),
650 OUString());
651 return true;
653 return false;
656 bool
657 UUIInteractionHelper::handleMasterPasswordRequest(
658 uno::Reference< task::XInteractionRequest > const & rRequest)
659 SAL_THROW((uno::RuntimeException))
661 uno::Any aAnyRequest(rRequest->getRequest());
663 task::MasterPasswordRequest aMasterPasswordRequest;
664 if (aAnyRequest >>= aMasterPasswordRequest)
666 handleMasterPasswordRequest_(getParentProperty(),
667 aMasterPasswordRequest.Mode,
668 rRequest->getContinuations());
669 return true;
671 return false;
674 bool
675 UUIInteractionHelper::handlePasswordRequest(
676 uno::Reference< task::XInteractionRequest > const & rRequest)
677 SAL_THROW((uno::RuntimeException))
679 // parameters to be filled for the call to handlePasswordRequest_
680 Window * pParent = getParentProperty();
681 task::PasswordRequestMode nMode = task::PasswordRequestMode_PASSWORD_ENTER;
682 uno::Sequence< uno::Reference< task::XInteractionContinuation > > const & rContinuations = rRequest->getContinuations();
683 OUString aDocumentName;
684 bool bMSCryptoMode = false;
685 bool bIsPasswordToModify = false;
687 bool bDoHandleRequest = false;
689 uno::Any aAnyRequest(rRequest->getRequest());
691 task::DocumentPasswordRequest2 aDocumentPasswordRequest2;
692 if (!bDoHandleRequest && (aAnyRequest >>= aDocumentPasswordRequest2))
694 nMode = aDocumentPasswordRequest2.Mode;
695 aDocumentName = aDocumentPasswordRequest2.Name;
696 OSL_ENSURE( bMSCryptoMode == false, "bMSCryptoMode should be false" );
697 bIsPasswordToModify = aDocumentPasswordRequest2.IsRequestPasswordToModify;
699 bDoHandleRequest = true;
702 task::DocumentPasswordRequest aDocumentPasswordRequest;
703 if (!bDoHandleRequest && (aAnyRequest >>= aDocumentPasswordRequest))
705 nMode = aDocumentPasswordRequest.Mode;
706 aDocumentName = aDocumentPasswordRequest.Name;
707 OSL_ENSURE( bMSCryptoMode == false, "bMSCryptoMode should be false" );
708 OSL_ENSURE( bIsPasswordToModify == false, "bIsPasswordToModify should be false" );
710 bDoHandleRequest = true;
713 task::DocumentMSPasswordRequest2 aDocumentMSPasswordRequest2;
714 if (!bDoHandleRequest && (aAnyRequest >>= aDocumentMSPasswordRequest2))
716 nMode = aDocumentMSPasswordRequest2.Mode;
717 aDocumentName = aDocumentMSPasswordRequest2.Name;
718 bMSCryptoMode = true;
719 bIsPasswordToModify = aDocumentMSPasswordRequest2.IsRequestPasswordToModify;
721 bDoHandleRequest = true;
724 task::DocumentMSPasswordRequest aDocumentMSPasswordRequest;
725 if (!bDoHandleRequest && (aAnyRequest >>= aDocumentMSPasswordRequest))
727 nMode = aDocumentMSPasswordRequest.Mode;
728 aDocumentName = aDocumentMSPasswordRequest.Name;
729 bMSCryptoMode = true;
730 OSL_ENSURE( bIsPasswordToModify == false, "bIsPasswordToModify should be false" );
732 bDoHandleRequest = true;
735 if (bDoHandleRequest)
737 handlePasswordRequest_( pParent, nMode, rContinuations,
738 aDocumentName, bMSCryptoMode, bIsPasswordToModify );
739 return true;
742 task::PasswordRequest aPasswordRequest;
743 if( aAnyRequest >>= aPasswordRequest )
745 handlePasswordRequest_(getParentProperty(),
746 aPasswordRequest.Mode,
747 rRequest->getContinuations(),
748 OUString(),
749 false /* bool bMSCryptoMode */,
750 false /* bool bIsPasswordToModify */,
751 true /* bool bIsSimplePasswordRequest */ );
752 return true;
755 return false;
758 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */