Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / uui / source / iahndl-authentication.cxx
blob76eaada570f19932501cb5980526323abf52dee0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "com/sun/star/task/DocumentPasswordRequest.hpp"
30 #include "com/sun/star/task/DocumentPasswordRequest2.hpp"
31 #include "com/sun/star/task/DocumentMSPasswordRequest.hpp"
32 #include "com/sun/star/task/DocumentMSPasswordRequest2.hpp"
33 #include "com/sun/star/task/MasterPasswordRequest.hpp"
34 #include "com/sun/star/task/XInteractionAbort.hpp"
35 #include "com/sun/star/task/XInteractionPassword.hpp"
36 #include "com/sun/star/task/XInteractionPassword2.hpp"
37 #include "com/sun/star/task/XInteractionRetry.hpp"
38 #include "com/sun/star/ucb/XInteractionSupplyAuthentication2.hpp"
39 #include "com/sun/star/ucb/URLAuthenticationRequest.hpp"
41 #include "osl/diagnose.h"
42 #include "rtl/digest.h"
43 #include "osl/mutex.hxx"
44 #include "tools/errcode.hxx"
45 #include "vcl/msgbox.hxx"
46 #include "vcl/abstdlg.hxx"
47 #include "vcl/svapp.hxx"
49 #include "ids.hrc"
50 #include "getcontinuations.hxx"
51 #include "passwordcontainer.hxx"
52 #include "loginerr.hxx"
53 #include "logindlg.hxx"
54 #include "masterpasscrtdlg.hxx"
55 #include "masterpassworddlg.hxx"
56 #include "passworddlg.hxx"
58 #include "iahndl.hxx"
60 #include <boost/scoped_ptr.hpp>
62 using namespace com::sun::star;
64 namespace {
66 void
67 executeLoginDialog(
68 Window * pParent,
69 LoginErrorInfo & rInfo,
70 rtl::OUString const & rRealm)
71 SAL_THROW((uno::RuntimeException))
73 try
75 SolarMutexGuard aGuard;
77 bool bAccount = (rInfo.GetFlags() & LOGINERROR_FLAG_MODIFY_ACCOUNT) != 0;
78 bool bSavePassword = rInfo.GetCanRememberPassword();
79 bool bCanUseSysCreds = rInfo.GetCanUseSystemCredentials();
81 sal_uInt16 nFlags = 0;
82 if (rInfo.GetPath().Len() == 0)
83 nFlags |= LF_NO_PATH;
84 if (rInfo.GetErrorText().Len() == 0)
85 nFlags |= LF_NO_ERRORTEXT;
86 if (!bAccount)
87 nFlags |= LF_NO_ACCOUNT;
88 if (!(rInfo.GetFlags() & LOGINERROR_FLAG_MODIFY_USER_NAME))
89 nFlags |= LF_USERNAME_READONLY;
91 if (!bSavePassword)
92 nFlags |= LF_NO_SAVEPASSWORD;
94 if (!bCanUseSysCreds)
95 nFlags |= LF_NO_USESYSCREDS;
97 boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
98 boost::scoped_ptr< LoginDialog > xDialog(
99 new LoginDialog( pParent, nFlags, rInfo.GetServer(), rRealm, xManager.get()));
100 if (rInfo.GetErrorText().Len() != 0)
101 xDialog->SetErrorText(rInfo.GetErrorText());
102 xDialog->SetName(rInfo.GetUserName());
103 if (bAccount)
104 xDialog->ClearAccount();
105 else
106 xDialog->ClearPassword();
107 xDialog->SetPassword(rInfo.GetPassword());
109 if (bSavePassword)
111 xDialog->SetSavePasswordText(
112 ResId(rInfo.GetIsRememberPersistent()
113 ? RID_SAVE_PASSWORD
114 : RID_KEEP_PASSWORD,
115 *xManager.get()));
117 xDialog->SetSavePassword(rInfo.GetIsRememberPassword());
120 if ( bCanUseSysCreds )
121 xDialog->SetUseSystemCredentials( rInfo.GetIsUseSystemCredentials() );
123 rInfo.SetResult(xDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK :
124 ERRCODE_BUTTON_CANCEL);
125 rInfo.SetUserName(xDialog->GetName());
126 rInfo.SetPassword(xDialog->GetPassword());
127 rInfo.SetAccount(xDialog->GetAccount());
128 rInfo.SetIsRememberPassword(xDialog->IsSavePassword());
130 if ( bCanUseSysCreds )
131 rInfo.SetIsUseSystemCredentials( xDialog->IsUseSystemCredentials() );
133 catch (std::bad_alloc const &)
135 throw uno::RuntimeException(
136 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("out of memory")),
137 uno::Reference< uno::XInterface >());
141 void getRememberModes(
142 uno::Sequence< ucb::RememberAuthentication > const & rRememberModes,
143 ucb::RememberAuthentication & rPreferredMode,
144 ucb::RememberAuthentication & rAlternateMode )
146 sal_Int32 nCount = rRememberModes.getLength();
147 OSL_ENSURE( (nCount > 0) && (nCount < 4),
148 "ucb::RememberAuthentication sequence size mismatch!" );
149 if ( nCount == 1 )
151 rPreferredMode = rAlternateMode = rRememberModes[ 0 ];
152 return;
154 else
156 bool bHasRememberModeSession = false;
157 bool bHasRememberModePersistent = false;
159 for (sal_Int32 i = 0; i < nCount; ++i)
161 switch ( rRememberModes[i] )
163 case ucb::RememberAuthentication_NO:
164 break;
165 case ucb::RememberAuthentication_SESSION:
166 bHasRememberModeSession = true;
167 break;
168 case ucb::RememberAuthentication_PERSISTENT:
169 bHasRememberModePersistent = true;
170 break;
171 default:
172 OSL_TRACE( "Unsupported RememberAuthentication value" );
173 break;
177 if (bHasRememberModePersistent)
179 rPreferredMode = ucb::RememberAuthentication_PERSISTENT;
180 if (bHasRememberModeSession)
181 rAlternateMode = ucb::RememberAuthentication_SESSION;
182 else
183 rAlternateMode = ucb::RememberAuthentication_NO;
185 else
187 rPreferredMode = ucb::RememberAuthentication_SESSION;
188 rAlternateMode = ucb::RememberAuthentication_NO;
193 void
194 handleAuthenticationRequest_(
195 Window * pParent,
196 uno::Reference< task::XInteractionHandler > const & xIH,
197 uno::Reference< lang::XMultiServiceFactory > const & xServiceFactory,
198 ucb::AuthenticationRequest const & rRequest,
199 uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
200 rContinuations,
201 const rtl::OUString & rURL)
202 SAL_THROW((uno::RuntimeException))
204 uno::Reference< task::XInteractionRetry > xRetry;
205 uno::Reference< task::XInteractionAbort > xAbort;
206 uno::Reference< ucb::XInteractionSupplyAuthentication >
207 xSupplyAuthentication;
208 uno::Reference< ucb::XInteractionSupplyAuthentication2 >
209 xSupplyAuthentication2;
210 getContinuations(rContinuations, &xRetry, &xAbort, &xSupplyAuthentication);
211 if (xSupplyAuthentication.is())
212 xSupplyAuthentication2.set(xSupplyAuthentication, uno::UNO_QUERY);
214 //////////////////////////
215 // First, try to obtain credentials from password container service.
216 uui::PasswordContainerHelper aPwContainerHelper(xServiceFactory);
217 if (aPwContainerHelper.handleAuthenticationRequest(rRequest,
218 xSupplyAuthentication,
219 rURL,
220 xIH))
222 xSupplyAuthentication->select();
223 return;
226 //////////////////////////
227 // Second, try to obtain credentials from user via password dialog.
228 ucb::RememberAuthentication eDefaultRememberMode
229 = ucb::RememberAuthentication_SESSION;
230 ucb::RememberAuthentication ePreferredRememberMode
231 = eDefaultRememberMode;
232 ucb::RememberAuthentication eAlternateRememberMode
233 = ucb::RememberAuthentication_NO;
235 if (xSupplyAuthentication.is())
237 getRememberModes(
238 xSupplyAuthentication->getRememberPasswordModes(
239 eDefaultRememberMode),
240 ePreferredRememberMode,
241 eAlternateRememberMode);
244 sal_Bool bCanUseSystemCredentials;
245 sal_Bool bDefaultUseSystemCredentials;
246 if (xSupplyAuthentication2.is())
248 bCanUseSystemCredentials
249 = xSupplyAuthentication2->canUseSystemCredentials(
250 bDefaultUseSystemCredentials);
252 else
254 bCanUseSystemCredentials = sal_False;
255 bDefaultUseSystemCredentials = sal_False;
258 LoginErrorInfo aInfo;
259 aInfo.SetTitle(rRequest.ServerName);
260 aInfo.SetServer(rRequest.ServerName);
261 if (rRequest.HasAccount)
262 aInfo.SetAccount(rRequest.Account);
263 if (rRequest.HasUserName)
264 aInfo.SetUserName(rRequest.UserName);
265 if (rRequest.HasPassword)
266 aInfo.SetPassword(rRequest.Password);
267 aInfo.SetErrorText(rRequest.Diagnostic);
269 aInfo.SetCanRememberPassword(
270 ePreferredRememberMode != eAlternateRememberMode);
271 aInfo.SetIsRememberPassword(
272 ePreferredRememberMode == eDefaultRememberMode);
273 aInfo.SetIsRememberPersistent(
274 ePreferredRememberMode == ucb::RememberAuthentication_PERSISTENT);
276 aInfo.SetCanUseSystemCredentials(bCanUseSystemCredentials);
277 aInfo.SetIsUseSystemCredentials( bDefaultUseSystemCredentials );
278 aInfo.SetModifyAccount(rRequest.HasAccount
279 && xSupplyAuthentication.is()
280 && xSupplyAuthentication->canSetAccount());
281 aInfo.SetModifyUserName(rRequest.HasUserName
282 && xSupplyAuthentication.is()
283 && xSupplyAuthentication->canSetUserName());
284 executeLoginDialog(pParent,
285 aInfo,
286 rRequest.HasRealm ? rRequest.Realm : rtl::OUString());
287 switch (aInfo.GetResult())
289 case ERRCODE_BUTTON_OK:
290 if (xSupplyAuthentication.is())
292 if (xSupplyAuthentication->canSetUserName())
293 xSupplyAuthentication->setUserName(aInfo.GetUserName());
294 if (xSupplyAuthentication->canSetPassword())
295 xSupplyAuthentication->setPassword(aInfo.GetPassword());
297 if (ePreferredRememberMode != eAlternateRememberMode)
299 // user had the choice.
300 if (aInfo.GetIsRememberPassword())
301 xSupplyAuthentication->setRememberPassword(
302 ePreferredRememberMode);
303 else
304 xSupplyAuthentication->setRememberPassword(
305 eAlternateRememberMode);
307 else
309 // user had no choice.
310 xSupplyAuthentication->setRememberPassword(
311 ePreferredRememberMode);
314 if (rRequest.HasRealm)
316 if (xSupplyAuthentication->canSetRealm())
317 xSupplyAuthentication->setRealm(aInfo.GetAccount());
319 else if (xSupplyAuthentication->canSetAccount())
320 xSupplyAuthentication->setAccount(aInfo.GetAccount());
322 if ( xSupplyAuthentication2.is() && bCanUseSystemCredentials )
323 xSupplyAuthentication2->setUseSystemCredentials(
324 aInfo.GetIsUseSystemCredentials() );
326 xSupplyAuthentication->select();
329 //////////////////////////
330 // Third, store credentials in password container.
332 if ( aInfo.GetIsUseSystemCredentials() )
334 if (aInfo.GetIsRememberPassword())
336 if (!aPwContainerHelper.addRecord(
337 !rURL.isEmpty() ? rURL : rRequest.ServerName,
338 rtl::OUString(), // empty u/p -> sys creds
339 uno::Sequence< rtl::OUString >(),
340 xIH,
341 ePreferredRememberMode
342 == ucb::RememberAuthentication_PERSISTENT))
344 xSupplyAuthentication->setRememberPassword(
345 ucb::RememberAuthentication_NO);
348 else if (eAlternateRememberMode
349 == ucb::RememberAuthentication_SESSION)
351 if (!aPwContainerHelper.addRecord(
352 !rURL.isEmpty() ? rURL : rRequest.ServerName,
353 rtl::OUString(), // empty u/p -> sys creds
354 uno::Sequence< rtl::OUString >(),
355 xIH,
356 false /* SESSION */))
358 xSupplyAuthentication->setRememberPassword(
359 ucb::RememberAuthentication_NO);
363 // Empty user name can not be valid:
364 else if (aInfo.GetUserName().Len() != 0)
366 uno::Sequence< rtl::OUString >
367 aPassList(aInfo.GetAccount().Len() == 0 ? 1 : 2);
368 aPassList[0] = aInfo.GetPassword();
369 if (aInfo.GetAccount().Len() != 0)
370 aPassList[1] = aInfo.GetAccount();
372 if (aInfo.GetIsRememberPassword())
374 if (!aPwContainerHelper.addRecord(
375 !rURL.isEmpty() ? rURL : rRequest.ServerName,
376 aInfo.GetUserName(),
377 aPassList,
378 xIH,
379 ePreferredRememberMode
380 == ucb::RememberAuthentication_PERSISTENT))
382 xSupplyAuthentication->setRememberPassword(
383 ucb::RememberAuthentication_NO);
386 else if (eAlternateRememberMode
387 == ucb::RememberAuthentication_SESSION)
389 if (!aPwContainerHelper.addRecord(
390 !rURL.isEmpty() ? rURL : rRequest.ServerName,
391 aInfo.GetUserName(),
392 aPassList,
393 xIH,
394 false /* SESSION */))
396 xSupplyAuthentication->setRememberPassword(
397 ucb::RememberAuthentication_NO);
401 break;
403 case ERRCODE_BUTTON_RETRY:
404 if (xRetry.is())
405 xRetry->select();
406 break;
408 default:
409 if (xAbort.is())
410 xAbort->select();
411 break;
415 void
416 executeMasterPasswordDialog(
417 Window * pParent,
418 LoginErrorInfo & rInfo,
419 task::PasswordRequestMode nMode)
420 SAL_THROW((uno::RuntimeException))
422 rtl::OString aMaster;
425 SolarMutexGuard aGuard;
427 boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
428 if( nMode == task::PasswordRequestMode_PASSWORD_CREATE )
430 boost::scoped_ptr< MasterPasswordCreateDialog > xDialog(
431 new MasterPasswordCreateDialog(pParent, xManager.get()));
432 rInfo.SetResult(xDialog->Execute()
433 == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL);
434 aMaster = rtl::OUStringToOString(
435 xDialog->GetMasterPassword(), RTL_TEXTENCODING_UTF8);
437 else
439 boost::scoped_ptr< MasterPasswordDialog > xDialog(
440 new MasterPasswordDialog(pParent, nMode, xManager.get()));
441 rInfo.SetResult(xDialog->Execute()
442 == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL);
443 aMaster = rtl::OUStringToOString(
444 xDialog->GetMasterPassword(), RTL_TEXTENCODING_UTF8);
447 catch (std::bad_alloc const &)
449 throw uno::RuntimeException(
450 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("out of memory")),
451 uno::Reference< uno::XInterface >());
454 sal_uInt8 aKey[RTL_DIGEST_LENGTH_MD5];
455 rtl_digest_PBKDF2(aKey,
456 RTL_DIGEST_LENGTH_MD5,
457 reinterpret_cast< sal_uInt8 const * >(aMaster.getStr()),
458 aMaster.getLength(),
459 reinterpret_cast< sal_uInt8 const * >(
460 "3B5509ABA6BC42D9A3A1F3DAD49E56A51"),
462 1000);
464 rtl::OUStringBuffer aBuffer;
465 for (int i = 0; i < RTL_DIGEST_LENGTH_MD5; ++i)
467 aBuffer.append(static_cast< sal_Unicode >('a' + (aKey[i] >> 4)));
468 aBuffer.append(static_cast< sal_Unicode >('a' + (aKey[i] & 15)));
470 rInfo.SetPassword(aBuffer.makeStringAndClear());
473 void
474 handleMasterPasswordRequest_(
475 Window * pParent,
476 task::PasswordRequestMode nMode,
477 uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
478 rContinuations)
479 SAL_THROW((uno::RuntimeException))
481 uno::Reference< task::XInteractionRetry > xRetry;
482 uno::Reference< task::XInteractionAbort > xAbort;
483 uno::Reference< ucb::XInteractionSupplyAuthentication >
484 xSupplyAuthentication;
485 getContinuations(rContinuations, &xRetry, &xAbort, &xSupplyAuthentication);
486 LoginErrorInfo aInfo;
488 // in case of master password a hash code is returned
489 executeMasterPasswordDialog(pParent, aInfo, nMode);
491 switch (aInfo.GetResult())
493 case ERRCODE_BUTTON_OK:
494 if (xSupplyAuthentication.is())
496 if (xSupplyAuthentication->canSetPassword())
497 xSupplyAuthentication->setPassword(aInfo.GetPassword());
498 xSupplyAuthentication->select();
500 break;
502 case ERRCODE_BUTTON_RETRY:
503 if (xRetry.is())
504 xRetry->select();
505 break;
507 default:
508 if (xAbort.is())
509 xAbort->select();
510 break;
514 void
515 executePasswordDialog(
516 Window * pParent,
517 LoginErrorInfo & rInfo,
518 task::PasswordRequestMode nMode,
519 ::rtl::OUString aDocName,
520 bool bMSCryptoMode,
521 bool bIsPasswordToModify,
522 bool bIsSimplePasswordRequest )
523 SAL_THROW((uno::RuntimeException))
527 SolarMutexGuard aGuard;
529 boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
530 if( nMode == task::PasswordRequestMode_PASSWORD_CREATE )
532 if (bIsSimplePasswordRequest)
534 boost::scoped_ptr< PasswordDialog > pDialog(
535 new PasswordDialog( pParent, nMode, xManager.get(), aDocName,
536 bIsPasswordToModify, bIsSimplePasswordRequest ) );
537 pDialog->SetMinLen(0);
539 rInfo.SetResult( pDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL );
540 rInfo.SetPassword( pDialog->GetPassword() );
542 else
544 const sal_uInt16 nMaxPasswdLen = bMSCryptoMode ? 15 : 0; // 0 -> allow any length
546 VclAbstractDialogFactory * pFact = VclAbstractDialogFactory::Create();
547 AbstractPasswordToOpenModifyDialog *pTmp = pFact->CreatePasswordToOpenModifyDialog( pParent, 0, nMaxPasswdLen, bIsPasswordToModify );
548 boost::scoped_ptr< AbstractPasswordToOpenModifyDialog > pDialog( pTmp );
550 rInfo.SetResult( pDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL );
551 rInfo.SetPassword( pDialog->GetPasswordToOpen() );
552 rInfo.SetPasswordToModify( pDialog->GetPasswordToModify() );
553 rInfo.SetRecommendToOpenReadonly( pDialog->IsRecommendToOpenReadonly() );
556 else // enter password or reenter password
558 boost::scoped_ptr< PasswordDialog > pDialog(
559 new PasswordDialog( pParent, nMode, xManager.get(), aDocName,
560 bIsPasswordToModify, bIsSimplePasswordRequest ) );
561 pDialog->SetMinLen(0);
563 rInfo.SetResult( pDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL );
564 rInfo.SetPassword( bIsPasswordToModify ? String() : pDialog->GetPassword() );
565 rInfo.SetPasswordToModify( bIsPasswordToModify ? pDialog->GetPassword() : String() );
568 catch (std::bad_alloc const &)
570 throw uno::RuntimeException(
571 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("out of memory")),
572 uno::Reference< uno::XInterface>());
576 void
577 handlePasswordRequest_(
578 Window * pParent,
579 task::PasswordRequestMode nMode,
580 uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
581 rContinuations,
582 ::rtl::OUString aDocumentName,
583 bool bMSCryptoMode,
584 bool bIsPasswordToModify,
585 bool bIsSimplePasswordRequest = false )
586 SAL_THROW((uno::RuntimeException))
588 uno::Reference< task::XInteractionRetry > xRetry;
589 uno::Reference< task::XInteractionAbort > xAbort;
590 uno::Reference< task::XInteractionPassword > xPassword;
591 uno::Reference< task::XInteractionPassword2 > xPassword2;
592 getContinuations(rContinuations, &xRetry, &xAbort, &xPassword2, &xPassword);
594 if ( xPassword2.is() && !xPassword.is() )
595 xPassword.set( xPassword2, uno::UNO_QUERY_THROW );
597 LoginErrorInfo aInfo;
599 executePasswordDialog( pParent, aInfo, nMode,
600 aDocumentName, bMSCryptoMode, bIsPasswordToModify, bIsSimplePasswordRequest );
602 switch (aInfo.GetResult())
604 case ERRCODE_BUTTON_OK:
605 OSL_ENSURE( !bIsPasswordToModify || xPassword2.is(), "PasswordToModify is requested, but there is no Interaction!" );
606 if (xPassword.is())
608 if (xPassword2.is())
610 xPassword2->setPasswordToModify( aInfo.GetPasswordToModify() );
611 xPassword2->setRecommendReadOnly( aInfo.IsRecommendToOpenReadonly() );
614 xPassword->setPassword(aInfo.GetPassword());
615 xPassword->select();
617 break;
619 case ERRCODE_BUTTON_RETRY:
620 if (xRetry.is())
621 xRetry->select();
622 break;
624 default:
625 if (xAbort.is())
626 xAbort->select();
627 break;
631 } // namespace
633 bool
634 UUIInteractionHelper::handleAuthenticationRequest(
635 uno::Reference< task::XInteractionRequest > const & rRequest)
636 SAL_THROW((uno::RuntimeException))
638 uno::Any aAnyRequest(rRequest->getRequest());
640 ucb::URLAuthenticationRequest aURLAuthenticationRequest;
641 if (aAnyRequest >>= aURLAuthenticationRequest)
643 handleAuthenticationRequest_(getParentProperty(),
644 getInteractionHandler(),
645 m_xServiceFactory,
646 aURLAuthenticationRequest,
647 rRequest->getContinuations(),
648 aURLAuthenticationRequest.URL);
649 return true;
652 ucb::AuthenticationRequest aAuthenticationRequest;
653 if (aAnyRequest >>= aAuthenticationRequest)
655 handleAuthenticationRequest_(getParentProperty(),
656 getInteractionHandler(),
657 m_xServiceFactory,
658 aAuthenticationRequest,
659 rRequest->getContinuations(),
660 rtl::OUString());
661 return true;
663 return false;
666 bool
667 UUIInteractionHelper::handleMasterPasswordRequest(
668 uno::Reference< task::XInteractionRequest > const & rRequest)
669 SAL_THROW((uno::RuntimeException))
671 uno::Any aAnyRequest(rRequest->getRequest());
673 task::MasterPasswordRequest aMasterPasswordRequest;
674 if (aAnyRequest >>= aMasterPasswordRequest)
676 handleMasterPasswordRequest_(getParentProperty(),
677 aMasterPasswordRequest.Mode,
678 rRequest->getContinuations());
679 return true;
681 return false;
684 bool
685 UUIInteractionHelper::handlePasswordRequest(
686 uno::Reference< task::XInteractionRequest > const & rRequest)
687 SAL_THROW((uno::RuntimeException))
689 // parameters to be filled for the call to handlePasswordRequest_
690 Window * pParent = getParentProperty();
691 task::PasswordRequestMode nMode = task::PasswordRequestMode_PASSWORD_ENTER;
692 uno::Sequence< uno::Reference< task::XInteractionContinuation > > const & rContinuations = rRequest->getContinuations();
693 ::rtl::OUString aDocumentName;
694 bool bMSCryptoMode = false;
695 bool bIsPasswordToModify = false;
697 bool bDoHandleRequest = false;
699 uno::Any aAnyRequest(rRequest->getRequest());
701 task::DocumentPasswordRequest2 aDocumentPasswordRequest2;
702 if (!bDoHandleRequest && (aAnyRequest >>= aDocumentPasswordRequest2))
704 nMode = aDocumentPasswordRequest2.Mode;
705 aDocumentName = aDocumentPasswordRequest2.Name;
706 OSL_ENSURE( bMSCryptoMode == false, "bMSCryptoMode should be false" );
707 bIsPasswordToModify = aDocumentPasswordRequest2.IsRequestPasswordToModify;
709 bDoHandleRequest = true;
712 task::DocumentPasswordRequest aDocumentPasswordRequest;
713 if (!bDoHandleRequest && (aAnyRequest >>= aDocumentPasswordRequest))
715 nMode = aDocumentPasswordRequest.Mode;
716 aDocumentName = aDocumentPasswordRequest.Name;
717 OSL_ENSURE( bMSCryptoMode == false, "bMSCryptoMode should be false" );
718 OSL_ENSURE( bIsPasswordToModify == false, "bIsPasswordToModify should be false" );
720 bDoHandleRequest = true;
723 task::DocumentMSPasswordRequest2 aDocumentMSPasswordRequest2;
724 if (!bDoHandleRequest && (aAnyRequest >>= aDocumentMSPasswordRequest2))
726 nMode = aDocumentMSPasswordRequest2.Mode;
727 aDocumentName = aDocumentMSPasswordRequest2.Name;
728 bMSCryptoMode = true;
729 bIsPasswordToModify = aDocumentMSPasswordRequest2.IsRequestPasswordToModify;
731 bDoHandleRequest = true;
734 task::DocumentMSPasswordRequest aDocumentMSPasswordRequest;
735 if (!bDoHandleRequest && (aAnyRequest >>= aDocumentMSPasswordRequest))
737 nMode = aDocumentMSPasswordRequest.Mode;
738 aDocumentName = aDocumentMSPasswordRequest.Name;
739 bMSCryptoMode = true;
740 OSL_ENSURE( bIsPasswordToModify == false, "bIsPasswordToModify should be false" );
742 bDoHandleRequest = true;
745 if (bDoHandleRequest)
747 handlePasswordRequest_( pParent, nMode, rContinuations,
748 aDocumentName, bMSCryptoMode, bIsPasswordToModify );
749 return true;
752 task::PasswordRequest aPasswordRequest;
753 if( aAnyRequest >>= aPasswordRequest )
755 handlePasswordRequest_(getParentProperty(),
756 aPasswordRequest.Mode,
757 rRequest->getContinuations(),
758 rtl::OUString(),
759 false /* bool bMSCryptoMode */,
760 false /* bool bIsPasswordToModify */,
761 true /* bool bIsSimplePasswordRequest */ );
762 return true;
765 return false;
768 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */