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