21#include <osl/diagnose.h>
23#include <com/sun/star/lang/XMultiServiceFactory.hpp>
24#include <com/sun/star/task/NoMasterException.hpp>
25#include <com/sun/star/task/PasswordContainer.hpp>
26#include <com/sun/star/task/XInteractionHandler2.hpp>
27#include <com/sun/star/ucb/AuthenticationRequest.hpp>
28#include <com/sun/star/ucb/URLAuthenticationRequest.hpp>
29#include <com/sun/star/ucb/XInteractionSupplyAuthentication.hpp>
30#include <com/sun/star/ucb/XInteractionSupplyAuthentication2.hpp>
31#include <officecfg/Office/Common.hxx>
41 bool bUseSystemCredentials,
42 const ucb::AuthenticationRequest & rRequest,
43 const task::UrlRecord & aRec,
44 const uno::Reference< ucb::XInteractionSupplyAuthentication > &
45 xSupplyAuthentication,
46 const uno::Reference< ucb::XInteractionSupplyAuthentication2 > &
47 xSupplyAuthentication2,
48 bool bCanUseSystemCredentials,
49 bool bCheckForEqualPasswords )
51 if ( bUseSystemCredentials )
55 if ( xSupplyAuthentication2.is() && bCanUseSystemCredentials )
57 xSupplyAuthentication2->setUseSystemCredentials(
true );
62 else if (aRec.UserList.hasElements())
64 if (!aRec.UserList[0].Passwords.hasElements())
74 if (!bCheckForEqualPasswords || !rRequest.HasPassword
75 || rRequest.Password != aRec.UserList[0].Passwords[0])
77 if (xSupplyAuthentication->canSetUserName())
78 xSupplyAuthentication->
79 setUserName(aRec.UserList[0].UserName);
81 if (xSupplyAuthentication->canSetPassword())
82 xSupplyAuthentication->
83 setPassword(aRec.UserList[0].Passwords[0]);
84 if (aRec.UserList[0].Passwords.getLength() > 1)
86 if (rRequest.HasRealm)
88 if (xSupplyAuthentication->canSetRealm())
89 xSupplyAuthentication->
90 setRealm(aRec.UserList[0].Passwords[1]);
92 else if (xSupplyAuthentication->canSetAccount())
93 xSupplyAuthentication->
94 setAccount(aRec.UserList[0].Passwords[1]);
97 if ( xSupplyAuthentication2.is() && bCanUseSystemCredentials )
98 xSupplyAuthentication2->setUseSystemCredentials(
false );
112 uno::Reference< uno::XComponentContext >
const & xContext ):
118 ucb::AuthenticationRequest
const & rRequest,
119 uno::Reference< ucb::XInteractionSupplyAuthentication >
const &
120 xSupplyAuthentication,
121 OUString
const & rURL,
122 uno::Reference< task::XInteractionHandler2 >
const & xIH )
126 uno::Reference< ucb::XInteractionSupplyAuthentication2 >
127 xSupplyAuthentication2(xSupplyAuthentication, uno::UNO_QUERY);
129 bool bCanUseSystemCredentials =
false;
130 if (xSupplyAuthentication2.is())
132 sal_Bool bDefaultUseSystemCredentials;
133 bCanUseSystemCredentials
134 = xSupplyAuthentication2->canUseSystemCredentials(
135 bDefaultUseSystemCredentials );
138 if ( bCanUseSystemCredentials )
141 bool bUseSystemCredentials = ::officecfg::Office::Common::Passwords::TrySystemCredentialsFirst::get();
142 if (!bUseSystemCredentials)
146 rURL.isEmpty() ? rRequest.ServerName : rURL);
147 bUseSystemCredentials = !aResult.isEmpty();
149 if ( bUseSystemCredentials )
151 if ( fillContinuation(
true,
154 xSupplyAuthentication,
155 xSupplyAuthentication2,
156 bCanUseSystemCredentials,
165 if (rRequest.HasUserName && rRequest.HasPassword)
169 if (rRequest.UserName.isEmpty())
171 task::UrlRecord aRec;
172 if ( !rURL.isEmpty() )
175 if ( !aRec.UserList.hasElements() )
181 if ( fillContinuation(
false,
184 xSupplyAuthentication,
185 xSupplyAuthentication2,
186 bCanUseSystemCredentials,
194 task::UrlRecord aRec;
195 if ( !rURL.isEmpty() )
197 rURL, rRequest.UserName, xIH);
199 if ( !aRec.UserList.hasElements() )
203 rRequest.ServerName, rRequest.UserName, xIH);
206 if ( fillContinuation(
false,
209 xSupplyAuthentication,
210 xSupplyAuthentication2,
211 bCanUseSystemCredentials,
218 catch (task::NoMasterException
const &)
226 OUString
const & rURL,
227 OUString
const & rUsername,
228 uno::Sequence< OUString >
const & rPasswords,
229 uno::Reference< task::XInteractionHandler2 >
const & xIH,
234 if ( !rUsername.isEmpty() )
237 "Got no XPasswordContainer!" );
264 catch ( task::NoMasterException
const & )
274 const uno::Reference< uno::XComponentContext >& xContext )
275: m_aPwContainerHelper( xContext )
293 return "com.sun.star.comp.uui.PasswordContainerInteractionHandler";
300 const OUString& ServiceName )
307uno::Sequence< OUString > SAL_CALL
310 return {
"com.sun.star.task.PasswordContainerInteractionHandler" };
320 const uno::Reference< task::XInteractionRequest >& rRequest )
328 const uno::Reference< task::XInteractionRequest >& rRequest )
330 if ( !rRequest.is() )
333 uno::Any aAnyRequest( rRequest->getRequest() );
335 ucb::AuthenticationRequest aAuthenticationRequest;
336 if ( !( aAnyRequest >>= aAuthenticationRequest ) )
340 ucb::URLAuthenticationRequest aURLAuthenticationRequest;
341 if ( aAnyRequest >>= aURLAuthenticationRequest )
342 aURL = aURLAuthenticationRequest.URL;
344 const uno::Sequence< uno::Reference< task::XInteractionContinuation > >
345 rContinuations = rRequest->getContinuations();
347 uno::Reference< ucb::XInteractionSupplyAuthentication >
348 xSupplyAuthentication;
350 for (
const auto& rContinuation : rContinuations )
352 xSupplyAuthentication.set( rContinuation, uno::UNO_QUERY );
353 if( xSupplyAuthentication.is() )
357 if ( !xSupplyAuthentication.is() )
362 handleAuthenticationRequest( aAuthenticationRequest,
363 xSupplyAuthentication,
372 xSupplyAuthentication->select();
381extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
383 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const&)
PasswordContainerHelper(css::uno::Reference< css::uno::XComponentContext > const &xContext)
bool handleAuthenticationRequest(css::ucb::AuthenticationRequest const &rRequest, css::uno::Reference< css::ucb::XInteractionSupplyAuthentication > const &xSupplyAuthentication, OUString const &rURL, css::uno::Reference< css::task::XInteractionHandler2 > const &xIH)
This member function tries to handle an authentication interaction request by looking up credentials ...
css::uno::Reference< css::task::XPasswordContainer2 > m_xPasswordContainer
bool addRecord(OUString const &rURL, OUString const &rUsername, css::uno::Sequence< OUString > const &rPasswords, css::uno::Reference< css::task::XInteractionHandler2 > const &xIH, bool bPersist)
This member function adds credentials for the given URL to the password container.
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
PasswordContainerHelper m_aPwContainerHelper
PasswordContainerInteractionHandler(const css::uno::Reference< css::uno::XComponentContext > &xContext)
virtual void SAL_CALL handle(const css::uno::Reference< css::task::XInteractionRequest > &Request) override
virtual ~PasswordContainerInteractionHandler() override
virtual sal_Bool SAL_CALL handleInteractionRequest(const css::uno::Reference< css::task::XInteractionRequest > &Request) override
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
css::uno::Reference< css::deployment::XPackageRegistry > create(css::uno::Reference< css::deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, css::uno::Reference< css::uno::XComponentContext > const &xComponentContext)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_uui_PasswordContainerInteractionHandler_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)