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