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