2010-10-12 08:53:47 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2009-12-09 11:54:57 -06:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
2010-02-12 08:01:35 -06:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2009-12-09 11:54:57 -06:00
|
|
|
*
|
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
|
|
|
*
|
|
|
|
* This file is part of OpenOffice.org.
|
|
|
|
*
|
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#include "com/sun/star/task/DocumentPasswordRequest.hpp"
|
2010-06-18 06:31:23 -05:00
|
|
|
#include "com/sun/star/task/DocumentPasswordRequest2.hpp"
|
2009-12-09 11:54:57 -06:00
|
|
|
#include "com/sun/star/task/DocumentMSPasswordRequest.hpp"
|
2010-06-18 06:31:23 -05:00
|
|
|
#include "com/sun/star/task/DocumentMSPasswordRequest2.hpp"
|
2009-12-09 11:54:57 -06:00
|
|
|
#include "com/sun/star/task/MasterPasswordRequest.hpp"
|
|
|
|
#include "com/sun/star/task/XInteractionAbort.hpp"
|
|
|
|
#include "com/sun/star/task/XInteractionPassword.hpp"
|
2010-06-18 06:31:23 -05:00
|
|
|
#include "com/sun/star/task/XInteractionPassword2.hpp"
|
2009-12-09 11:54:57 -06:00
|
|
|
#include "com/sun/star/task/XInteractionRetry.hpp"
|
|
|
|
#include "com/sun/star/ucb/XInteractionSupplyAuthentication2.hpp"
|
|
|
|
#include "com/sun/star/ucb/URLAuthenticationRequest.hpp"
|
|
|
|
|
2010-06-18 06:31:23 -05:00
|
|
|
#include "osl/diagnose.h"
|
2009-12-09 11:54:57 -06:00
|
|
|
#include "rtl/digest.h"
|
2010-10-16 03:18:35 -05:00
|
|
|
#include "osl/mutex.hxx"
|
2009-12-09 11:54:57 -06:00
|
|
|
#include "tools/errcode.hxx"
|
|
|
|
#include "vcl/msgbox.hxx"
|
2010-06-18 06:31:23 -05:00
|
|
|
#include "vcl/abstdlg.hxx"
|
2009-12-09 11:54:57 -06:00
|
|
|
#include "vcl/svapp.hxx"
|
|
|
|
|
|
|
|
#include "ids.hrc"
|
|
|
|
#include "getcontinuations.hxx"
|
|
|
|
#include "passwordcontainer.hxx"
|
|
|
|
#include "loginerr.hxx"
|
|
|
|
#include "logindlg.hxx"
|
|
|
|
#include "masterpasscrtdlg.hxx"
|
|
|
|
#include "masterpassworddlg.hxx"
|
|
|
|
#include "passworddlg.hxx"
|
|
|
|
|
|
|
|
#include "iahndl.hxx"
|
|
|
|
|
2011-09-22 09:00:08 -05:00
|
|
|
#include <boost/scoped_ptr.hpp>
|
|
|
|
|
2009-12-09 11:54:57 -06:00
|
|
|
using namespace com::sun::star;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
void
|
|
|
|
executeLoginDialog(
|
|
|
|
Window * pParent,
|
|
|
|
LoginErrorInfo & rInfo,
|
|
|
|
rtl::OUString const & rRealm)
|
|
|
|
SAL_THROW((uno::RuntimeException))
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2010-10-13 02:47:36 -05:00
|
|
|
SolarMutexGuard aGuard;
|
2009-12-09 11:54:57 -06:00
|
|
|
|
2010-06-18 06:31:23 -05:00
|
|
|
bool bAccount = (rInfo.GetFlags() & LOGINERROR_FLAG_MODIFY_ACCOUNT) != 0;
|
2010-05-06 07:23:16 -05:00
|
|
|
bool bSavePassword = rInfo.GetCanRememberPassword();
|
2009-12-09 11:54:57 -06:00
|
|
|
bool bCanUseSysCreds = rInfo.GetCanUseSystemCredentials();
|
|
|
|
|
|
|
|
sal_uInt16 nFlags = 0;
|
|
|
|
if (rInfo.GetPath().Len() == 0)
|
|
|
|
nFlags |= LF_NO_PATH;
|
|
|
|
if (rInfo.GetErrorText().Len() == 0)
|
|
|
|
nFlags |= LF_NO_ERRORTEXT;
|
|
|
|
if (!bAccount)
|
|
|
|
nFlags |= LF_NO_ACCOUNT;
|
|
|
|
if (!(rInfo.GetFlags() & LOGINERROR_FLAG_MODIFY_USER_NAME))
|
|
|
|
nFlags |= LF_USERNAME_READONLY;
|
|
|
|
|
|
|
|
if (!bSavePassword)
|
|
|
|
nFlags |= LF_NO_SAVEPASSWORD;
|
|
|
|
|
|
|
|
if (!bCanUseSysCreds)
|
|
|
|
nFlags |= LF_NO_USESYSCREDS;
|
|
|
|
|
2011-09-22 09:00:08 -05:00
|
|
|
boost::scoped_ptr< ResMgr > xManager( ResMgr::CreateResMgr(CREATEVERSIONRESMGR_NAME(uui)));
|
2009-12-09 11:54:57 -06:00
|
|
|
UniString aRealm(rRealm);
|
2011-09-22 09:00:08 -05:00
|
|
|
boost::scoped_ptr< LoginDialog > xDialog(
|
2010-06-18 06:31:23 -05:00
|
|
|
new LoginDialog( pParent, nFlags, rInfo.GetServer(), &aRealm, xManager.get()));
|
2009-12-09 11:54:57 -06:00
|
|
|
if (rInfo.GetErrorText().Len() != 0)
|
|
|
|
xDialog->SetErrorText(rInfo.GetErrorText());
|
|
|
|
xDialog->SetName(rInfo.GetUserName());
|
|
|
|
if (bAccount)
|
|
|
|
xDialog->ClearAccount();
|
|
|
|
else
|
|
|
|
xDialog->ClearPassword();
|
|
|
|
xDialog->SetPassword(rInfo.GetPassword());
|
|
|
|
|
|
|
|
if (bSavePassword)
|
|
|
|
{
|
2010-05-06 07:23:16 -05:00
|
|
|
xDialog->SetSavePasswordText(
|
|
|
|
ResId(rInfo.GetIsRememberPersistent()
|
|
|
|
? RID_SAVE_PASSWORD
|
|
|
|
: RID_KEEP_PASSWORD,
|
|
|
|
*xManager.get()));
|
|
|
|
|
|
|
|
xDialog->SetSavePassword(rInfo.GetIsRememberPassword());
|
2009-12-09 11:54:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( bCanUseSysCreds )
|
2010-06-18 06:31:23 -05:00
|
|
|
xDialog->SetUseSystemCredentials( rInfo.GetIsUseSystemCredentials() );
|
2009-12-09 11:54:57 -06:00
|
|
|
|
|
|
|
rInfo.SetResult(xDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK :
|
|
|
|
ERRCODE_BUTTON_CANCEL);
|
|
|
|
rInfo.SetUserName(xDialog->GetName());
|
|
|
|
rInfo.SetPassword(xDialog->GetPassword());
|
|
|
|
rInfo.SetAccount(xDialog->GetAccount());
|
2010-05-06 07:23:16 -05:00
|
|
|
rInfo.SetIsRememberPassword(xDialog->IsSavePassword());
|
2009-12-09 11:54:57 -06:00
|
|
|
|
|
|
|
if ( bCanUseSysCreds )
|
|
|
|
rInfo.SetIsUseSystemCredentials( xDialog->IsUseSystemCredentials() );
|
|
|
|
}
|
|
|
|
catch (std::bad_alloc const &)
|
|
|
|
{
|
|
|
|
throw uno::RuntimeException(
|
|
|
|
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("out of memory")),
|
|
|
|
uno::Reference< uno::XInterface >());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-06 07:23:16 -05:00
|
|
|
void getRememberModes(
|
|
|
|
uno::Sequence< ucb::RememberAuthentication > const & rRememberModes,
|
|
|
|
ucb::RememberAuthentication & rPreferredMode,
|
|
|
|
ucb::RememberAuthentication & rAlternateMode )
|
|
|
|
{
|
|
|
|
sal_Int32 nCount = rRememberModes.getLength();
|
|
|
|
OSL_ENSURE( (nCount > 0) && (nCount < 4),
|
|
|
|
"ucb::RememberAuthentication sequence size mismatch!" );
|
|
|
|
if ( nCount == 1 )
|
|
|
|
{
|
|
|
|
rPreferredMode = rAlternateMode = rRememberModes[ 0 ];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool bHasRememberModeSession = false;
|
|
|
|
bool bHasRememberModePersistent = false;
|
|
|
|
|
|
|
|
for (sal_Int32 i = 0; i < nCount; ++i)
|
|
|
|
{
|
|
|
|
switch ( rRememberModes[i] )
|
|
|
|
{
|
|
|
|
case ucb::RememberAuthentication_NO:
|
|
|
|
break;
|
|
|
|
case ucb::RememberAuthentication_SESSION:
|
|
|
|
bHasRememberModeSession = true;
|
|
|
|
break;
|
|
|
|
case ucb::RememberAuthentication_PERSISTENT:
|
|
|
|
bHasRememberModePersistent = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
OSL_TRACE( "Unsupported RememberAuthentication value" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bHasRememberModePersistent)
|
|
|
|
{
|
|
|
|
rPreferredMode = ucb::RememberAuthentication_PERSISTENT;
|
|
|
|
if (bHasRememberModeSession)
|
|
|
|
rAlternateMode = ucb::RememberAuthentication_SESSION;
|
|
|
|
else
|
|
|
|
rAlternateMode = ucb::RememberAuthentication_NO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rPreferredMode = ucb::RememberAuthentication_SESSION;
|
|
|
|
rAlternateMode = ucb::RememberAuthentication_NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-09 11:54:57 -06:00
|
|
|
void
|
|
|
|
handleAuthenticationRequest_(
|
|
|
|
Window * pParent,
|
|
|
|
uno::Reference< task::XInteractionHandler > const & xIH,
|
|
|
|
uno::Reference< lang::XMultiServiceFactory > const & xServiceFactory,
|
|
|
|
ucb::AuthenticationRequest const & rRequest,
|
|
|
|
uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
|
|
|
|
rContinuations,
|
|
|
|
const rtl::OUString & rURL)
|
|
|
|
SAL_THROW((uno::RuntimeException))
|
|
|
|
{
|
|
|
|
uno::Reference< task::XInteractionRetry > xRetry;
|
|
|
|
uno::Reference< task::XInteractionAbort > xAbort;
|
|
|
|
uno::Reference< ucb::XInteractionSupplyAuthentication >
|
|
|
|
xSupplyAuthentication;
|
|
|
|
uno::Reference< ucb::XInteractionSupplyAuthentication2 >
|
|
|
|
xSupplyAuthentication2;
|
|
|
|
getContinuations(rContinuations, &xRetry, &xAbort, &xSupplyAuthentication);
|
|
|
|
if (xSupplyAuthentication.is())
|
|
|
|
xSupplyAuthentication2.set(xSupplyAuthentication, uno::UNO_QUERY);
|
|
|
|
|
|
|
|
//////////////////////////
|
2010-05-06 07:23:16 -05:00
|
|
|
// First, try to obtain credentials from password container service.
|
2009-12-09 11:54:57 -06:00
|
|
|
uui::PasswordContainerHelper aPwContainerHelper(xServiceFactory);
|
|
|
|
if (aPwContainerHelper.handleAuthenticationRequest(rRequest,
|
|
|
|
xSupplyAuthentication,
|
|
|
|
rURL,
|
|
|
|
xIH))
|
|
|
|
{
|
|
|
|
xSupplyAuthentication->select();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////
|
|
|
|
// Second, try to obtain credentials from user via password dialog.
|
2010-05-06 07:23:16 -05:00
|
|
|
ucb::RememberAuthentication eDefaultRememberMode
|
|
|
|
= ucb::RememberAuthentication_SESSION;
|
|
|
|
ucb::RememberAuthentication ePreferredRememberMode
|
|
|
|
= eDefaultRememberMode;
|
|
|
|
ucb::RememberAuthentication eAlternateRememberMode
|
|
|
|
= ucb::RememberAuthentication_NO;
|
|
|
|
|
2009-12-09 11:54:57 -06:00
|
|
|
if (xSupplyAuthentication.is())
|
|
|
|
{
|
2010-05-06 07:23:16 -05:00
|
|
|
getRememberModes(
|
|
|
|
xSupplyAuthentication->getRememberPasswordModes(
|
|
|
|
eDefaultRememberMode),
|
|
|
|
ePreferredRememberMode,
|
|
|
|
eAlternateRememberMode);
|
2009-12-09 11:54:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool bCanUseSystemCredentials;
|
|
|
|
sal_Bool bDefaultUseSystemCredentials;
|
|
|
|
if (xSupplyAuthentication2.is())
|
|
|
|
{
|
|
|
|
bCanUseSystemCredentials
|
|
|
|
= xSupplyAuthentication2->canUseSystemCredentials(
|
|
|
|
bDefaultUseSystemCredentials);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bCanUseSystemCredentials = sal_False;
|
|
|
|
bDefaultUseSystemCredentials = sal_False;
|
|
|
|
}
|
|
|
|
|
|
|
|
LoginErrorInfo aInfo;
|
|
|
|
aInfo.SetTitle(rRequest.ServerName);
|
|
|
|
aInfo.SetServer(rRequest.ServerName);
|
|
|
|
if (rRequest.HasAccount)
|
|
|
|
aInfo.SetAccount(rRequest.Account);
|
|
|
|
if (rRequest.HasUserName)
|
|
|
|
aInfo.SetUserName(rRequest.UserName);
|
|
|
|
if (rRequest.HasPassword)
|
|
|
|
aInfo.SetPassword(rRequest.Password);
|
|
|
|
aInfo.SetErrorText(rRequest.Diagnostic);
|
2010-05-06 07:23:16 -05:00
|
|
|
|
|
|
|
aInfo.SetCanRememberPassword(
|
|
|
|
ePreferredRememberMode != eAlternateRememberMode);
|
|
|
|
aInfo.SetIsRememberPassword(
|
2010-08-23 06:43:42 -05:00
|
|
|
ePreferredRememberMode == eDefaultRememberMode);
|
2010-05-06 07:23:16 -05:00
|
|
|
aInfo.SetIsRememberPersistent(
|
|
|
|
ePreferredRememberMode == ucb::RememberAuthentication_PERSISTENT);
|
|
|
|
|
2009-12-09 11:54:57 -06:00
|
|
|
aInfo.SetCanUseSystemCredentials(bCanUseSystemCredentials);
|
|
|
|
aInfo.SetIsUseSystemCredentials( bDefaultUseSystemCredentials );
|
|
|
|
aInfo.SetModifyAccount(rRequest.HasAccount
|
|
|
|
&& xSupplyAuthentication.is()
|
|
|
|
&& xSupplyAuthentication->canSetAccount());
|
|
|
|
aInfo.SetModifyUserName(rRequest.HasUserName
|
|
|
|
&& xSupplyAuthentication.is()
|
|
|
|
&& xSupplyAuthentication->canSetUserName());
|
|
|
|
executeLoginDialog(pParent,
|
|
|
|
aInfo,
|
|
|
|
rRequest.HasRealm ? rRequest.Realm : rtl::OUString());
|
|
|
|
switch (aInfo.GetResult())
|
|
|
|
{
|
|
|
|
case ERRCODE_BUTTON_OK:
|
|
|
|
if (xSupplyAuthentication.is())
|
|
|
|
{
|
|
|
|
if (xSupplyAuthentication->canSetUserName())
|
|
|
|
xSupplyAuthentication->setUserName(aInfo.GetUserName());
|
|
|
|
if (xSupplyAuthentication->canSetPassword())
|
|
|
|
xSupplyAuthentication->setPassword(aInfo.GetPassword());
|
2010-05-06 07:23:16 -05:00
|
|
|
|
|
|
|
if (ePreferredRememberMode != eAlternateRememberMode)
|
|
|
|
{
|
2011-02-21 14:37:13 -06:00
|
|
|
// user had the choice.
|
2010-05-06 07:23:16 -05:00
|
|
|
if (aInfo.GetIsRememberPassword())
|
|
|
|
xSupplyAuthentication->setRememberPassword(
|
|
|
|
ePreferredRememberMode);
|
|
|
|
else
|
|
|
|
xSupplyAuthentication->setRememberPassword(
|
|
|
|
eAlternateRememberMode);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// user had no choice.
|
|
|
|
xSupplyAuthentication->setRememberPassword(
|
|
|
|
ePreferredRememberMode);
|
|
|
|
}
|
|
|
|
|
2009-12-09 11:54:57 -06:00
|
|
|
if (rRequest.HasRealm)
|
|
|
|
{
|
|
|
|
if (xSupplyAuthentication->canSetRealm())
|
|
|
|
xSupplyAuthentication->setRealm(aInfo.GetAccount());
|
|
|
|
}
|
|
|
|
else if (xSupplyAuthentication->canSetAccount())
|
|
|
|
xSupplyAuthentication->setAccount(aInfo.GetAccount());
|
|
|
|
|
|
|
|
if ( xSupplyAuthentication2.is() && bCanUseSystemCredentials )
|
|
|
|
xSupplyAuthentication2->setUseSystemCredentials(
|
|
|
|
aInfo.GetIsUseSystemCredentials() );
|
|
|
|
|
|
|
|
xSupplyAuthentication->select();
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////
|
|
|
|
// Third, store credentials in password container.
|
|
|
|
|
2010-05-06 07:23:16 -05:00
|
|
|
if ( aInfo.GetIsUseSystemCredentials() )
|
|
|
|
{
|
|
|
|
if (aInfo.GetIsRememberPassword())
|
|
|
|
{
|
|
|
|
if (!aPwContainerHelper.addRecord(
|
|
|
|
rURL.getLength() ? rURL : rRequest.ServerName,
|
|
|
|
rtl::OUString(), // empty u/p -> sys creds
|
|
|
|
uno::Sequence< rtl::OUString >(),
|
|
|
|
xIH,
|
|
|
|
ePreferredRememberMode
|
|
|
|
== ucb::RememberAuthentication_PERSISTENT))
|
|
|
|
{
|
|
|
|
xSupplyAuthentication->setRememberPassword(
|
|
|
|
ucb::RememberAuthentication_NO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (eAlternateRememberMode
|
|
|
|
== ucb::RememberAuthentication_SESSION)
|
|
|
|
{
|
|
|
|
if (!aPwContainerHelper.addRecord(
|
|
|
|
rURL.getLength() ? rURL : rRequest.ServerName,
|
|
|
|
rtl::OUString(), // empty u/p -> sys creds
|
|
|
|
uno::Sequence< rtl::OUString >(),
|
|
|
|
xIH,
|
|
|
|
false /* SESSION */))
|
|
|
|
{
|
|
|
|
xSupplyAuthentication->setRememberPassword(
|
|
|
|
ucb::RememberAuthentication_NO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Empty user name can not be valid:
|
|
|
|
else if (aInfo.GetUserName().Len() != 0)
|
|
|
|
{
|
|
|
|
uno::Sequence< rtl::OUString >
|
|
|
|
aPassList(aInfo.GetAccount().Len() == 0 ? 1 : 2);
|
|
|
|
aPassList[0] = aInfo.GetPassword();
|
|
|
|
if (aInfo.GetAccount().Len() != 0)
|
|
|
|
aPassList[1] = aInfo.GetAccount();
|
|
|
|
|
|
|
|
if (aInfo.GetIsRememberPassword())
|
|
|
|
{
|
|
|
|
if (!aPwContainerHelper.addRecord(
|
|
|
|
rURL.getLength() ? rURL : rRequest.ServerName,
|
|
|
|
aInfo.GetUserName(),
|
|
|
|
aPassList,
|
|
|
|
xIH,
|
|
|
|
ePreferredRememberMode
|
|
|
|
== ucb::RememberAuthentication_PERSISTENT))
|
|
|
|
{
|
|
|
|
xSupplyAuthentication->setRememberPassword(
|
|
|
|
ucb::RememberAuthentication_NO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (eAlternateRememberMode
|
|
|
|
== ucb::RememberAuthentication_SESSION)
|
|
|
|
{
|
|
|
|
if (!aPwContainerHelper.addRecord(
|
|
|
|
rURL.getLength() ? rURL : rRequest.ServerName,
|
|
|
|
aInfo.GetUserName(),
|
|
|
|
aPassList,
|
|
|
|
xIH,
|
|
|
|
false /* SESSION */))
|
|
|
|
{
|
|
|
|
xSupplyAuthentication->setRememberPassword(
|
|
|
|
ucb::RememberAuthentication_NO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-12-09 11:54:57 -06:00
|
|
|
|
|
|
|
case ERRCODE_BUTTON_RETRY:
|
|
|
|
if (xRetry.is())
|
|
|
|
xRetry->select();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (xAbort.is())
|
|
|
|
xAbort->select();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
executeMasterPasswordDialog(
|
|
|
|
Window * pParent,
|
|
|
|
LoginErrorInfo & rInfo,
|
|
|
|
task::PasswordRequestMode nMode)
|
|
|
|
SAL_THROW((uno::RuntimeException))
|
|
|
|
{
|
|
|
|
rtl::OString aMaster;
|
|
|
|
try
|
|
|
|
{
|
2010-10-13 02:47:36 -05:00
|
|
|
SolarMutexGuard aGuard;
|
2009-12-09 11:54:57 -06:00
|
|
|
|
2011-09-22 09:00:08 -05:00
|
|
|
boost::scoped_ptr< ResMgr > xManager(
|
2009-12-09 11:54:57 -06:00
|
|
|
ResMgr::CreateResMgr(CREATEVERSIONRESMGR_NAME(uui)));
|
|
|
|
if( nMode == task::PasswordRequestMode_PASSWORD_CREATE )
|
|
|
|
{
|
2011-09-22 09:00:08 -05:00
|
|
|
boost::scoped_ptr< MasterPasswordCreateDialog > xDialog(
|
2009-12-09 11:54:57 -06:00
|
|
|
new MasterPasswordCreateDialog(pParent, xManager.get()));
|
|
|
|
rInfo.SetResult(xDialog->Execute()
|
|
|
|
== RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL);
|
|
|
|
aMaster = rtl::OUStringToOString(
|
|
|
|
xDialog->GetMasterPassword(), RTL_TEXTENCODING_UTF8);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-22 09:00:08 -05:00
|
|
|
boost::scoped_ptr< MasterPasswordDialog > xDialog(
|
2009-12-09 11:54:57 -06:00
|
|
|
new MasterPasswordDialog(pParent, nMode, xManager.get()));
|
|
|
|
rInfo.SetResult(xDialog->Execute()
|
|
|
|
== RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL);
|
|
|
|
aMaster = rtl::OUStringToOString(
|
|
|
|
xDialog->GetMasterPassword(), RTL_TEXTENCODING_UTF8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (std::bad_alloc const &)
|
|
|
|
{
|
|
|
|
throw uno::RuntimeException(
|
|
|
|
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("out of memory")),
|
|
|
|
uno::Reference< uno::XInterface >());
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_uInt8 aKey[RTL_DIGEST_LENGTH_MD5];
|
|
|
|
rtl_digest_PBKDF2(aKey,
|
|
|
|
RTL_DIGEST_LENGTH_MD5,
|
|
|
|
reinterpret_cast< sal_uInt8 const * >(aMaster.getStr()),
|
|
|
|
aMaster.getLength(),
|
|
|
|
reinterpret_cast< sal_uInt8 const * >(
|
|
|
|
"3B5509ABA6BC42D9A3A1F3DAD49E56A51"),
|
|
|
|
32,
|
|
|
|
1000);
|
|
|
|
|
|
|
|
rtl::OUStringBuffer aBuffer;
|
|
|
|
for (int i = 0; i < RTL_DIGEST_LENGTH_MD5; ++i)
|
|
|
|
{
|
|
|
|
aBuffer.append(static_cast< sal_Unicode >('a' + (aKey[i] >> 4)));
|
|
|
|
aBuffer.append(static_cast< sal_Unicode >('a' + (aKey[i] & 15)));
|
|
|
|
}
|
|
|
|
rInfo.SetPassword(aBuffer.makeStringAndClear());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
handleMasterPasswordRequest_(
|
|
|
|
Window * pParent,
|
|
|
|
task::PasswordRequestMode nMode,
|
|
|
|
uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
|
|
|
|
rContinuations)
|
|
|
|
SAL_THROW((uno::RuntimeException))
|
|
|
|
{
|
|
|
|
uno::Reference< task::XInteractionRetry > xRetry;
|
|
|
|
uno::Reference< task::XInteractionAbort > xAbort;
|
|
|
|
uno::Reference< ucb::XInteractionSupplyAuthentication >
|
|
|
|
xSupplyAuthentication;
|
|
|
|
getContinuations(rContinuations, &xRetry, &xAbort, &xSupplyAuthentication);
|
|
|
|
LoginErrorInfo aInfo;
|
|
|
|
|
|
|
|
// in case of master password a hash code is returned
|
|
|
|
executeMasterPasswordDialog(pParent, aInfo, nMode);
|
|
|
|
|
|
|
|
switch (aInfo.GetResult())
|
|
|
|
{
|
|
|
|
case ERRCODE_BUTTON_OK:
|
|
|
|
if (xSupplyAuthentication.is())
|
|
|
|
{
|
|
|
|
if (xSupplyAuthentication->canSetPassword())
|
|
|
|
xSupplyAuthentication->setPassword(aInfo.GetPassword());
|
|
|
|
xSupplyAuthentication->select();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ERRCODE_BUTTON_RETRY:
|
|
|
|
if (xRetry.is())
|
|
|
|
xRetry->select();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (xAbort.is())
|
|
|
|
xAbort->select();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
executePasswordDialog(
|
|
|
|
Window * pParent,
|
|
|
|
LoginErrorInfo & rInfo,
|
|
|
|
task::PasswordRequestMode nMode,
|
|
|
|
::rtl::OUString aDocName,
|
2010-06-18 06:31:23 -05:00
|
|
|
bool bMSCryptoMode,
|
2010-09-06 03:02:33 -05:00
|
|
|
bool bIsPasswordToModify,
|
|
|
|
bool bIsSimplePasswordRequest )
|
2009-12-09 11:54:57 -06:00
|
|
|
SAL_THROW((uno::RuntimeException))
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2010-10-13 02:47:36 -05:00
|
|
|
SolarMutexGuard aGuard;
|
2009-12-09 11:54:57 -06:00
|
|
|
|
2011-09-22 09:00:08 -05:00
|
|
|
boost::scoped_ptr< ResMgr > xManager(
|
2009-12-09 11:54:57 -06:00
|
|
|
ResMgr::CreateResMgr(CREATEVERSIONRESMGR_NAME(uui)));
|
|
|
|
if( nMode == task::PasswordRequestMode_PASSWORD_CREATE )
|
|
|
|
{
|
2010-09-06 03:02:33 -05:00
|
|
|
if (bIsSimplePasswordRequest)
|
|
|
|
{
|
2011-09-22 09:00:08 -05:00
|
|
|
boost::scoped_ptr< PasswordDialog > pDialog(
|
2010-09-06 03:02:33 -05:00
|
|
|
new PasswordDialog( pParent, nMode, xManager.get(), aDocName,
|
|
|
|
bIsPasswordToModify, bIsSimplePasswordRequest ) );
|
|
|
|
pDialog->SetMinLen(0);
|
|
|
|
|
|
|
|
rInfo.SetResult( pDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL );
|
|
|
|
rInfo.SetPassword( pDialog->GetPassword() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const sal_uInt16 nMaxPasswdLen = bMSCryptoMode ? 15 : 0; // 0 -> allow any length
|
2009-12-09 11:54:57 -06:00
|
|
|
|
2010-09-06 03:02:33 -05:00
|
|
|
VclAbstractDialogFactory * pFact = VclAbstractDialogFactory::Create();
|
|
|
|
AbstractPasswordToOpenModifyDialog *pTmp = pFact->CreatePasswordToOpenModifyDialog( pParent, 0, nMaxPasswdLen, bIsPasswordToModify );
|
2011-09-22 09:00:08 -05:00
|
|
|
boost::scoped_ptr< AbstractPasswordToOpenModifyDialog > pDialog( pTmp );
|
2010-06-18 06:31:23 -05:00
|
|
|
|
2010-09-06 03:02:33 -05:00
|
|
|
rInfo.SetResult( pDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL );
|
|
|
|
rInfo.SetPassword( pDialog->GetPasswordToOpen() );
|
|
|
|
rInfo.SetPasswordToModify( pDialog->GetPasswordToModify() );
|
|
|
|
rInfo.SetRecommendToOpenReadonly( pDialog->IsRecommendToOpenReadonly() );
|
|
|
|
}
|
2009-12-09 11:54:57 -06:00
|
|
|
}
|
2010-09-06 03:02:33 -05:00
|
|
|
else // enter password or reenter password
|
2009-12-09 11:54:57 -06:00
|
|
|
{
|
2011-09-22 09:00:08 -05:00
|
|
|
boost::scoped_ptr< PasswordDialog > pDialog(
|
2010-09-06 03:02:33 -05:00
|
|
|
new PasswordDialog( pParent, nMode, xManager.get(), aDocName,
|
|
|
|
bIsPasswordToModify, bIsSimplePasswordRequest ) );
|
|
|
|
pDialog->SetMinLen(0);
|
2009-12-09 11:54:57 -06:00
|
|
|
|
2010-06-18 06:31:23 -05:00
|
|
|
rInfo.SetResult( pDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL );
|
|
|
|
rInfo.SetPassword( bIsPasswordToModify ? String() : pDialog->GetPassword() );
|
|
|
|
rInfo.SetPasswordToModify( bIsPasswordToModify ? pDialog->GetPassword() : String() );
|
2009-12-09 11:54:57 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (std::bad_alloc const &)
|
|
|
|
{
|
|
|
|
throw uno::RuntimeException(
|
|
|
|
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("out of memory")),
|
|
|
|
uno::Reference< uno::XInterface>());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
handlePasswordRequest_(
|
|
|
|
Window * pParent,
|
|
|
|
task::PasswordRequestMode nMode,
|
|
|
|
uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
|
|
|
|
rContinuations,
|
|
|
|
::rtl::OUString aDocumentName,
|
2010-06-18 06:31:23 -05:00
|
|
|
bool bMSCryptoMode,
|
2010-09-06 03:02:33 -05:00
|
|
|
bool bIsPasswordToModify,
|
|
|
|
bool bIsSimplePasswordRequest = false )
|
2009-12-09 11:54:57 -06:00
|
|
|
SAL_THROW((uno::RuntimeException))
|
|
|
|
{
|
|
|
|
uno::Reference< task::XInteractionRetry > xRetry;
|
|
|
|
uno::Reference< task::XInteractionAbort > xAbort;
|
|
|
|
uno::Reference< task::XInteractionPassword > xPassword;
|
2010-06-18 06:31:23 -05:00
|
|
|
uno::Reference< task::XInteractionPassword2 > xPassword2;
|
|
|
|
getContinuations(rContinuations, &xRetry, &xAbort, &xPassword2, &xPassword);
|
|
|
|
|
|
|
|
if ( xPassword2.is() && !xPassword.is() )
|
|
|
|
xPassword.set( xPassword2, uno::UNO_QUERY_THROW );
|
|
|
|
|
2009-12-09 11:54:57 -06:00
|
|
|
LoginErrorInfo aInfo;
|
|
|
|
|
2010-06-18 06:31:23 -05:00
|
|
|
executePasswordDialog( pParent, aInfo, nMode,
|
2010-09-06 03:02:33 -05:00
|
|
|
aDocumentName, bMSCryptoMode, bIsPasswordToModify, bIsSimplePasswordRequest );
|
2009-12-09 11:54:57 -06:00
|
|
|
|
|
|
|
switch (aInfo.GetResult())
|
|
|
|
{
|
|
|
|
case ERRCODE_BUTTON_OK:
|
2010-06-18 06:31:23 -05:00
|
|
|
OSL_ENSURE( !bIsPasswordToModify || xPassword2.is(), "PasswordToModify is requested, but there is no Interaction!" );
|
2009-12-09 11:54:57 -06:00
|
|
|
if (xPassword.is())
|
|
|
|
{
|
2010-06-18 06:31:23 -05:00
|
|
|
if (xPassword2.is())
|
|
|
|
{
|
|
|
|
xPassword2->setPasswordToModify( aInfo.GetPasswordToModify() );
|
|
|
|
xPassword2->setRecommendReadOnly( aInfo.IsRecommendToOpenReadonly() );
|
|
|
|
}
|
|
|
|
|
2009-12-09 11:54:57 -06:00
|
|
|
xPassword->setPassword(aInfo.GetPassword());
|
|
|
|
xPassword->select();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ERRCODE_BUTTON_RETRY:
|
|
|
|
if (xRetry.is())
|
|
|
|
xRetry->select();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (xAbort.is())
|
|
|
|
xAbort->select();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
bool
|
|
|
|
UUIInteractionHelper::handleAuthenticationRequest(
|
|
|
|
uno::Reference< task::XInteractionRequest > const & rRequest)
|
|
|
|
SAL_THROW((uno::RuntimeException))
|
|
|
|
{
|
|
|
|
uno::Any aAnyRequest(rRequest->getRequest());
|
|
|
|
|
|
|
|
ucb::URLAuthenticationRequest aURLAuthenticationRequest;
|
|
|
|
if (aAnyRequest >>= aURLAuthenticationRequest)
|
|
|
|
{
|
|
|
|
handleAuthenticationRequest_(getParentProperty(),
|
|
|
|
getInteractionHandler(),
|
|
|
|
m_xServiceFactory,
|
|
|
|
aURLAuthenticationRequest,
|
|
|
|
rRequest->getContinuations(),
|
|
|
|
aURLAuthenticationRequest.URL);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ucb::AuthenticationRequest aAuthenticationRequest;
|
|
|
|
if (aAnyRequest >>= aAuthenticationRequest)
|
|
|
|
{
|
|
|
|
handleAuthenticationRequest_(getParentProperty(),
|
|
|
|
getInteractionHandler(),
|
|
|
|
m_xServiceFactory,
|
|
|
|
aAuthenticationRequest,
|
|
|
|
rRequest->getContinuations(),
|
|
|
|
rtl::OUString());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
UUIInteractionHelper::handleMasterPasswordRequest(
|
|
|
|
uno::Reference< task::XInteractionRequest > const & rRequest)
|
|
|
|
SAL_THROW((uno::RuntimeException))
|
|
|
|
{
|
|
|
|
uno::Any aAnyRequest(rRequest->getRequest());
|
|
|
|
|
|
|
|
task::MasterPasswordRequest aMasterPasswordRequest;
|
|
|
|
if (aAnyRequest >>= aMasterPasswordRequest)
|
|
|
|
{
|
|
|
|
handleMasterPasswordRequest_(getParentProperty(),
|
|
|
|
aMasterPasswordRequest.Mode,
|
|
|
|
rRequest->getContinuations());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
UUIInteractionHelper::handlePasswordRequest(
|
|
|
|
uno::Reference< task::XInteractionRequest > const & rRequest)
|
|
|
|
SAL_THROW((uno::RuntimeException))
|
|
|
|
{
|
2010-06-18 06:31:23 -05:00
|
|
|
// parameters to be filled for the call to handlePasswordRequest_
|
|
|
|
Window * pParent = getParentProperty();
|
|
|
|
task::PasswordRequestMode nMode = task::PasswordRequestMode_PASSWORD_ENTER;
|
|
|
|
uno::Sequence< uno::Reference< task::XInteractionContinuation > > const & rContinuations = rRequest->getContinuations();
|
|
|
|
::rtl::OUString aDocumentName;
|
|
|
|
bool bMSCryptoMode = false;
|
|
|
|
bool bIsPasswordToModify = false;
|
|
|
|
|
|
|
|
bool bDoHandleRequest = false;
|
|
|
|
|
2009-12-09 11:54:57 -06:00
|
|
|
uno::Any aAnyRequest(rRequest->getRequest());
|
|
|
|
|
2010-06-18 06:31:23 -05:00
|
|
|
task::DocumentPasswordRequest2 aDocumentPasswordRequest2;
|
|
|
|
if (!bDoHandleRequest && (aAnyRequest >>= aDocumentPasswordRequest2))
|
|
|
|
{
|
|
|
|
nMode = aDocumentPasswordRequest2.Mode;
|
|
|
|
aDocumentName = aDocumentPasswordRequest2.Name;
|
|
|
|
OSL_ENSURE( bMSCryptoMode == false, "bMSCryptoMode should be false" );
|
|
|
|
bIsPasswordToModify = aDocumentPasswordRequest2.IsRequestPasswordToModify;
|
|
|
|
|
|
|
|
bDoHandleRequest = true;
|
|
|
|
}
|
|
|
|
|
2009-12-09 11:54:57 -06:00
|
|
|
task::DocumentPasswordRequest aDocumentPasswordRequest;
|
2010-06-18 06:31:23 -05:00
|
|
|
if (!bDoHandleRequest && (aAnyRequest >>= aDocumentPasswordRequest))
|
2009-12-09 11:54:57 -06:00
|
|
|
{
|
2010-06-18 06:31:23 -05:00
|
|
|
nMode = aDocumentPasswordRequest.Mode;
|
|
|
|
aDocumentName = aDocumentPasswordRequest.Name;
|
|
|
|
OSL_ENSURE( bMSCryptoMode == false, "bMSCryptoMode should be false" );
|
|
|
|
OSL_ENSURE( bIsPasswordToModify == false, "bIsPasswordToModify should be false" );
|
|
|
|
|
|
|
|
bDoHandleRequest = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
task::DocumentMSPasswordRequest2 aDocumentMSPasswordRequest2;
|
|
|
|
if (!bDoHandleRequest && (aAnyRequest >>= aDocumentMSPasswordRequest2))
|
|
|
|
{
|
|
|
|
nMode = aDocumentMSPasswordRequest2.Mode;
|
|
|
|
aDocumentName = aDocumentMSPasswordRequest2.Name;
|
|
|
|
bMSCryptoMode = true;
|
|
|
|
bIsPasswordToModify = aDocumentMSPasswordRequest2.IsRequestPasswordToModify;
|
|
|
|
|
|
|
|
bDoHandleRequest = true;
|
2009-12-09 11:54:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
task::DocumentMSPasswordRequest aDocumentMSPasswordRequest;
|
2010-06-18 06:31:23 -05:00
|
|
|
if (!bDoHandleRequest && (aAnyRequest >>= aDocumentMSPasswordRequest))
|
2009-12-09 11:54:57 -06:00
|
|
|
{
|
2010-06-18 06:31:23 -05:00
|
|
|
nMode = aDocumentMSPasswordRequest.Mode;
|
|
|
|
aDocumentName = aDocumentMSPasswordRequest.Name;
|
|
|
|
bMSCryptoMode = true;
|
|
|
|
OSL_ENSURE( bIsPasswordToModify == false, "bIsPasswordToModify should be false" );
|
|
|
|
|
|
|
|
bDoHandleRequest = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bDoHandleRequest)
|
|
|
|
{
|
|
|
|
handlePasswordRequest_( pParent, nMode, rContinuations,
|
|
|
|
aDocumentName, bMSCryptoMode, bIsPasswordToModify );
|
2009-12-09 11:54:57 -06:00
|
|
|
return true;
|
|
|
|
}
|
2010-04-28 07:22:16 -05:00
|
|
|
|
|
|
|
task::PasswordRequest aPasswordRequest;
|
|
|
|
if( aAnyRequest >>= aPasswordRequest )
|
|
|
|
{
|
|
|
|
handlePasswordRequest_(getParentProperty(),
|
|
|
|
aPasswordRequest.Mode,
|
|
|
|
rRequest->getContinuations(),
|
|
|
|
rtl::OUString(),
|
2010-06-24 03:44:42 -05:00
|
|
|
false /* bool bMSCryptoMode */,
|
2010-09-06 03:02:33 -05:00
|
|
|
false /* bool bIsPasswordToModify */,
|
|
|
|
true /* bool bIsSimplePasswordRequest */ );
|
2010-04-28 07:22:16 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-12-09 11:54:57 -06:00
|
|
|
return false;
|
|
|
|
}
|
2010-06-18 06:31:23 -05:00
|
|
|
|
2010-10-12 08:53:47 -05:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|