xref: /AOO41X/main/uui/source/passwordcontainer.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include "cppuhelper/factory.hxx"
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include "com/sun/star/lang/XMultiServiceFactory.hpp"
31*cdf0e10cSrcweir #include "com/sun/star/task/NoMasterException.hpp"
32*cdf0e10cSrcweir #include "com/sun/star/task/XInteractionHandler.hpp"
33*cdf0e10cSrcweir #include "com/sun/star/task/XMasterPasswordHandling.hpp"
34*cdf0e10cSrcweir #include "com/sun/star/task/XPasswordContainer.hpp"
35*cdf0e10cSrcweir #include "com/sun/star/task/XUrlContainer.hpp"
36*cdf0e10cSrcweir #include "com/sun/star/ucb/AuthenticationRequest.hpp"
37*cdf0e10cSrcweir #include "com/sun/star/ucb/URLAuthenticationRequest.hpp"
38*cdf0e10cSrcweir #include "com/sun/star/ucb/XInteractionSupplyAuthentication.hpp"
39*cdf0e10cSrcweir #include "com/sun/star/ucb/XInteractionSupplyAuthentication2.hpp"
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #include "passwordcontainer.hxx"
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir using namespace com::sun::star;
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir namespace {
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir //=========================================================================
48*cdf0e10cSrcweir bool fillContinuation(
49*cdf0e10cSrcweir     bool bUseSystemCredentials,
50*cdf0e10cSrcweir     const ucb::AuthenticationRequest & rRequest,
51*cdf0e10cSrcweir     const task::UrlRecord & aRec,
52*cdf0e10cSrcweir     const uno::Reference< ucb::XInteractionSupplyAuthentication > &
53*cdf0e10cSrcweir         xSupplyAuthentication,
54*cdf0e10cSrcweir     const uno::Reference< ucb::XInteractionSupplyAuthentication2 > &
55*cdf0e10cSrcweir         xSupplyAuthentication2,
56*cdf0e10cSrcweir     bool bCanUseSystemCredentials,
57*cdf0e10cSrcweir     bool bCheckForEqualPasswords )
58*cdf0e10cSrcweir {
59*cdf0e10cSrcweir     if ( bUseSystemCredentials )
60*cdf0e10cSrcweir     {
61*cdf0e10cSrcweir         // "use system creds" record found.
62*cdf0e10cSrcweir         // Wants client that we use it?
63*cdf0e10cSrcweir         if ( xSupplyAuthentication2.is() && bCanUseSystemCredentials )
64*cdf0e10cSrcweir         {
65*cdf0e10cSrcweir             xSupplyAuthentication2->setUseSystemCredentials( sal_True );
66*cdf0e10cSrcweir             return true;
67*cdf0e10cSrcweir         }
68*cdf0e10cSrcweir         return false;
69*cdf0e10cSrcweir     }
70*cdf0e10cSrcweir     else if (aRec.UserList.getLength() != 0)
71*cdf0e10cSrcweir     {
72*cdf0e10cSrcweir         if (aRec.UserList[0].Passwords.getLength() == 0)
73*cdf0e10cSrcweir         {
74*cdf0e10cSrcweir             // Password sequence can be empty, for instance if master
75*cdf0e10cSrcweir             // password was not given (e.g. master pw dialog canceled)
76*cdf0e10cSrcweir             // pw container does not throw NoMasterException in this case.
77*cdf0e10cSrcweir             // bug???
78*cdf0e10cSrcweir             return false;
79*cdf0e10cSrcweir         }
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir         // "user/pass" record found.
82*cdf0e10cSrcweir         if (!bCheckForEqualPasswords || !rRequest.HasPassword
83*cdf0e10cSrcweir             || rRequest.Password != aRec.UserList[0].Passwords[0]) // failed login attempt?
84*cdf0e10cSrcweir         {
85*cdf0e10cSrcweir             if (xSupplyAuthentication->canSetUserName())
86*cdf0e10cSrcweir                 xSupplyAuthentication->
87*cdf0e10cSrcweir                     setUserName(aRec.UserList[0].UserName.getStr());
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir             if (xSupplyAuthentication->canSetPassword())
90*cdf0e10cSrcweir                 xSupplyAuthentication->
91*cdf0e10cSrcweir                     setPassword(aRec.UserList[0].Passwords[0].getStr());
92*cdf0e10cSrcweir             if (aRec.UserList[0].Passwords.getLength() > 1)
93*cdf0e10cSrcweir             {
94*cdf0e10cSrcweir                 if (rRequest.HasRealm)
95*cdf0e10cSrcweir                 {
96*cdf0e10cSrcweir                     if (xSupplyAuthentication->canSetRealm())
97*cdf0e10cSrcweir                         xSupplyAuthentication->
98*cdf0e10cSrcweir                             setRealm(aRec.UserList[0].Passwords[1].
99*cdf0e10cSrcweir                                 getStr());
100*cdf0e10cSrcweir                 }
101*cdf0e10cSrcweir                 else if (xSupplyAuthentication->canSetAccount())
102*cdf0e10cSrcweir                     xSupplyAuthentication->
103*cdf0e10cSrcweir                         setAccount(aRec.UserList[0].Passwords[1].
104*cdf0e10cSrcweir                             getStr());
105*cdf0e10cSrcweir             }
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir             if ( xSupplyAuthentication2.is() && bCanUseSystemCredentials )
108*cdf0e10cSrcweir                 xSupplyAuthentication2->setUseSystemCredentials( sal_False );
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir             return true;
111*cdf0e10cSrcweir         }
112*cdf0e10cSrcweir     }
113*cdf0e10cSrcweir     return false;
114*cdf0e10cSrcweir }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir } // namespace
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir namespace uui {
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir //=========================================================================
121*cdf0e10cSrcweir PasswordContainerHelper::PasswordContainerHelper(
122*cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory > const & xServiceFactory )
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir     OSL_ENSURE(xServiceFactory.is(), "no service factory given!");
125*cdf0e10cSrcweir     if (xServiceFactory.is())
126*cdf0e10cSrcweir         try
127*cdf0e10cSrcweir         {
128*cdf0e10cSrcweir             m_xPasswordContainer
129*cdf0e10cSrcweir                 = uno::Reference< task::XPasswordContainer >(
130*cdf0e10cSrcweir                       xServiceFactory->
131*cdf0e10cSrcweir                           createInstance(
132*cdf0e10cSrcweir                               rtl::OUString(
133*cdf0e10cSrcweir                                   RTL_CONSTASCII_USTRINGPARAM(
134*cdf0e10cSrcweir                                      "com.sun.star.task.PasswordContainer"))),
135*cdf0e10cSrcweir                       uno::UNO_QUERY);
136*cdf0e10cSrcweir         }
137*cdf0e10cSrcweir         catch (uno::Exception const &)
138*cdf0e10cSrcweir         {}
139*cdf0e10cSrcweir     OSL_ENSURE(m_xPasswordContainer.is(),
140*cdf0e10cSrcweir                "unable to instanciate password container service");
141*cdf0e10cSrcweir }
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir //=========================================================================
144*cdf0e10cSrcweir bool PasswordContainerHelper::handleAuthenticationRequest(
145*cdf0e10cSrcweir     ucb::AuthenticationRequest const & rRequest,
146*cdf0e10cSrcweir     uno::Reference< ucb::XInteractionSupplyAuthentication > const &
147*cdf0e10cSrcweir         xSupplyAuthentication,
148*cdf0e10cSrcweir     rtl::OUString const & rURL,
149*cdf0e10cSrcweir     uno::Reference< task::XInteractionHandler > const & xIH )
150*cdf0e10cSrcweir         SAL_THROW((uno::RuntimeException))
151*cdf0e10cSrcweir {
152*cdf0e10cSrcweir     // Is continuation even a XInteractionSupplyAuthentication2, which
153*cdf0e10cSrcweir     // is derived from XInteractionSupplyAuthentication?
154*cdf0e10cSrcweir     uno::Reference< ucb::XInteractionSupplyAuthentication2 >
155*cdf0e10cSrcweir         xSupplyAuthentication2(xSupplyAuthentication, uno::UNO_QUERY);
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir     sal_Bool bCanUseSystemCredentials = sal_False;
158*cdf0e10cSrcweir     if (xSupplyAuthentication2.is())
159*cdf0e10cSrcweir     {
160*cdf0e10cSrcweir         sal_Bool bDefaultUseSystemCredentials;
161*cdf0e10cSrcweir         bCanUseSystemCredentials
162*cdf0e10cSrcweir             =  xSupplyAuthentication2->canUseSystemCredentials(
163*cdf0e10cSrcweir                 bDefaultUseSystemCredentials );
164*cdf0e10cSrcweir     }
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir     uno::Reference< task::XPasswordContainer > xContainer(
167*cdf0e10cSrcweir         m_xPasswordContainer );
168*cdf0e10cSrcweir     uno::Reference< task::XUrlContainer > xUrlContainer(
169*cdf0e10cSrcweir         m_xPasswordContainer, uno::UNO_QUERY );
170*cdf0e10cSrcweir     OSL_ENSURE( xUrlContainer.is(), "Got no XUrlContainer!" );
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir     if ( !xContainer.is() || !xUrlContainer.is() )
173*cdf0e10cSrcweir         return false;
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir     if ( bCanUseSystemCredentials )
176*cdf0e10cSrcweir     {
177*cdf0e10cSrcweir         // Runtime / Persistent info avail for current auth request?
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir         rtl::OUString aResult = xUrlContainer->findUrl(
180*cdf0e10cSrcweir             rURL.getLength() ? rURL : rRequest.ServerName );
181*cdf0e10cSrcweir         if ( aResult.getLength() > 0 )
182*cdf0e10cSrcweir         {
183*cdf0e10cSrcweir             if ( fillContinuation( true,
184*cdf0e10cSrcweir                                    rRequest,
185*cdf0e10cSrcweir                                    task::UrlRecord(),
186*cdf0e10cSrcweir                                    xSupplyAuthentication,
187*cdf0e10cSrcweir                                    xSupplyAuthentication2,
188*cdf0e10cSrcweir                                    bCanUseSystemCredentials,
189*cdf0e10cSrcweir                                    false ) )
190*cdf0e10cSrcweir             {
191*cdf0e10cSrcweir                 return true;
192*cdf0e10cSrcweir             }
193*cdf0e10cSrcweir         }
194*cdf0e10cSrcweir     }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir     // xContainer works with userName passwdSequences pairs:
197*cdf0e10cSrcweir     if (rRequest.HasUserName && rRequest.HasPassword)
198*cdf0e10cSrcweir     {
199*cdf0e10cSrcweir         try
200*cdf0e10cSrcweir         {
201*cdf0e10cSrcweir             if (rRequest.UserName.getLength() == 0)
202*cdf0e10cSrcweir             {
203*cdf0e10cSrcweir                 task::UrlRecord aRec;
204*cdf0e10cSrcweir                 if ( rURL.getLength() )
205*cdf0e10cSrcweir                     aRec = xContainer->find(rURL, xIH);
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir                 if ( aRec.UserList.getLength() == 0 )
208*cdf0e10cSrcweir                 {
209*cdf0e10cSrcweir                     // compat: try server name.
210*cdf0e10cSrcweir                     aRec = xContainer->find(rRequest.ServerName, xIH);
211*cdf0e10cSrcweir                 }
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir                 if ( fillContinuation( false,
214*cdf0e10cSrcweir                                        rRequest,
215*cdf0e10cSrcweir                                        aRec,
216*cdf0e10cSrcweir                                        xSupplyAuthentication,
217*cdf0e10cSrcweir                                        xSupplyAuthentication2,
218*cdf0e10cSrcweir                                        bCanUseSystemCredentials,
219*cdf0e10cSrcweir                                        false ) )
220*cdf0e10cSrcweir                 {
221*cdf0e10cSrcweir                     return true;
222*cdf0e10cSrcweir                 }
223*cdf0e10cSrcweir             }
224*cdf0e10cSrcweir             else
225*cdf0e10cSrcweir             {
226*cdf0e10cSrcweir                 task::UrlRecord aRec;
227*cdf0e10cSrcweir                 if ( rURL.getLength() )
228*cdf0e10cSrcweir                     aRec = xContainer->findForName(
229*cdf0e10cSrcweir                         rURL, rRequest.UserName, xIH);
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir                 if ( aRec.UserList.getLength() == 0 )
232*cdf0e10cSrcweir                 {
233*cdf0e10cSrcweir                     // compat: try server name.
234*cdf0e10cSrcweir                     aRec = xContainer->findForName(
235*cdf0e10cSrcweir                         rRequest.ServerName, rRequest.UserName, xIH);
236*cdf0e10cSrcweir                 }
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir                 if ( fillContinuation( false,
239*cdf0e10cSrcweir                                        rRequest,
240*cdf0e10cSrcweir                                        aRec,
241*cdf0e10cSrcweir                                        xSupplyAuthentication,
242*cdf0e10cSrcweir                                        xSupplyAuthentication2,
243*cdf0e10cSrcweir                                        bCanUseSystemCredentials,
244*cdf0e10cSrcweir                                        true ) )
245*cdf0e10cSrcweir                 {
246*cdf0e10cSrcweir                     return true;
247*cdf0e10cSrcweir                 }
248*cdf0e10cSrcweir             }
249*cdf0e10cSrcweir         }
250*cdf0e10cSrcweir         catch (task::NoMasterException const &)
251*cdf0e10cSrcweir         {} // user did not enter master password
252*cdf0e10cSrcweir     }
253*cdf0e10cSrcweir     return false;
254*cdf0e10cSrcweir }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir //=========================================================================
257*cdf0e10cSrcweir bool PasswordContainerHelper::addRecord(
258*cdf0e10cSrcweir     rtl::OUString const & rURL,
259*cdf0e10cSrcweir     rtl::OUString const & rUsername,
260*cdf0e10cSrcweir     uno::Sequence< rtl::OUString > const & rPasswords,
261*cdf0e10cSrcweir     uno::Reference< task::XInteractionHandler > const & xIH,
262*cdf0e10cSrcweir     bool bPersist )
263*cdf0e10cSrcweir         SAL_THROW((uno::RuntimeException))
264*cdf0e10cSrcweir {
265*cdf0e10cSrcweir     try
266*cdf0e10cSrcweir     {
267*cdf0e10cSrcweir         if ( rUsername.getLength() )
268*cdf0e10cSrcweir         {
269*cdf0e10cSrcweir             OSL_ENSURE( m_xPasswordContainer.is(),
270*cdf0e10cSrcweir                         "Got no XPasswordContainer!" );
271*cdf0e10cSrcweir             if ( !m_xPasswordContainer.is() )
272*cdf0e10cSrcweir                 return false;
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir             if ( bPersist )
275*cdf0e10cSrcweir             {
276*cdf0e10cSrcweir                 uno::Reference< task::XMasterPasswordHandling > xMPH(
277*cdf0e10cSrcweir                     m_xPasswordContainer, uno::UNO_QUERY_THROW );
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir                 // If persistent storing of passwords is not yet
280*cdf0e10cSrcweir                 // allowed, enable it.
281*cdf0e10cSrcweir                 if ( !xMPH->isPersistentStoringAllowed() )
282*cdf0e10cSrcweir                     xMPH->allowPersistentStoring( sal_True );
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir                 m_xPasswordContainer->addPersistent( rURL,
285*cdf0e10cSrcweir                                                      rUsername,
286*cdf0e10cSrcweir                                                      rPasswords,
287*cdf0e10cSrcweir                                                      xIH );
288*cdf0e10cSrcweir             }
289*cdf0e10cSrcweir             else
290*cdf0e10cSrcweir                 m_xPasswordContainer->add( rURL,
291*cdf0e10cSrcweir                                            rUsername,
292*cdf0e10cSrcweir                                            rPasswords,
293*cdf0e10cSrcweir                                            xIH );
294*cdf0e10cSrcweir         }
295*cdf0e10cSrcweir         else
296*cdf0e10cSrcweir         {
297*cdf0e10cSrcweir             uno::Reference< task::XUrlContainer >
298*cdf0e10cSrcweir                 xContainer( m_xPasswordContainer, uno::UNO_QUERY );
299*cdf0e10cSrcweir             OSL_ENSURE( xContainer.is(), "Got no XUrlContainer!" );
300*cdf0e10cSrcweir             if ( !xContainer.is() )
301*cdf0e10cSrcweir                 return false;
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir             xContainer->addUrl( rURL, bPersist );
304*cdf0e10cSrcweir         }
305*cdf0e10cSrcweir     }
306*cdf0e10cSrcweir     catch ( task::NoMasterException const & )
307*cdf0e10cSrcweir     {
308*cdf0e10cSrcweir         // user did not enter master password
309*cdf0e10cSrcweir         return false;
310*cdf0e10cSrcweir     }
311*cdf0e10cSrcweir     return true;
312*cdf0e10cSrcweir }
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir //=========================================================================
315*cdf0e10cSrcweir //=========================================================================
316*cdf0e10cSrcweir //=========================================================================
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir PasswordContainerInteractionHandler::PasswordContainerInteractionHandler(
319*cdf0e10cSrcweir     const uno::Reference< lang::XMultiServiceFactory >& xSMgr )
320*cdf0e10cSrcweir : m_aPwContainerHelper( xSMgr )
321*cdf0e10cSrcweir {
322*cdf0e10cSrcweir }
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir //=========================================================================
325*cdf0e10cSrcweir // virtual
326*cdf0e10cSrcweir PasswordContainerInteractionHandler::~PasswordContainerInteractionHandler()
327*cdf0e10cSrcweir {
328*cdf0e10cSrcweir }
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir //=========================================================================
331*cdf0e10cSrcweir //
332*cdf0e10cSrcweir // XServiceInfo methods.
333*cdf0e10cSrcweir //
334*cdf0e10cSrcweir //=========================================================================
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir // virtual
337*cdf0e10cSrcweir ::rtl::OUString SAL_CALL
338*cdf0e10cSrcweir PasswordContainerInteractionHandler::getImplementationName()
339*cdf0e10cSrcweir     throw ( uno::RuntimeException )
340*cdf0e10cSrcweir {
341*cdf0e10cSrcweir     return getImplementationName_Static();
342*cdf0e10cSrcweir }
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir //=========================================================================
345*cdf0e10cSrcweir // virtual
346*cdf0e10cSrcweir sal_Bool SAL_CALL
347*cdf0e10cSrcweir PasswordContainerInteractionHandler::supportsService(
348*cdf0e10cSrcweir         const ::rtl::OUString& ServiceName )
349*cdf0e10cSrcweir     throw ( uno::RuntimeException )
350*cdf0e10cSrcweir {
351*cdf0e10cSrcweir     uno::Sequence< rtl::OUString > aSNL = getSupportedServiceNames();
352*cdf0e10cSrcweir     const rtl::OUString * pArray = aSNL.getConstArray();
353*cdf0e10cSrcweir     for ( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
354*cdf0e10cSrcweir     {
355*cdf0e10cSrcweir         if ( pArray[ i ] == ServiceName )
356*cdf0e10cSrcweir             return sal_True;
357*cdf0e10cSrcweir     }
358*cdf0e10cSrcweir     return sal_False;
359*cdf0e10cSrcweir }
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir //=========================================================================
362*cdf0e10cSrcweir // virtual
363*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL
364*cdf0e10cSrcweir PasswordContainerInteractionHandler::getSupportedServiceNames()
365*cdf0e10cSrcweir     throw ( uno::RuntimeException )
366*cdf0e10cSrcweir {
367*cdf0e10cSrcweir     return getSupportedServiceNames_Static();
368*cdf0e10cSrcweir }
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir //=========================================================================
371*cdf0e10cSrcweir // static
372*cdf0e10cSrcweir rtl::OUString
373*cdf0e10cSrcweir PasswordContainerInteractionHandler::getImplementationName_Static()
374*cdf0e10cSrcweir {
375*cdf0e10cSrcweir     return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
376*cdf0e10cSrcweir         "com.sun.star.comp.uui.PasswordContainerInteractionHandler" ) );
377*cdf0e10cSrcweir }
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir //=========================================================================
380*cdf0e10cSrcweir // static
381*cdf0e10cSrcweir uno::Sequence< rtl::OUString >
382*cdf0e10cSrcweir PasswordContainerInteractionHandler::getSupportedServiceNames_Static()
383*cdf0e10cSrcweir {
384*cdf0e10cSrcweir     uno::Sequence< rtl::OUString > aSNS( 1 );
385*cdf0e10cSrcweir     aSNS.getArray()[ 0 ]
386*cdf0e10cSrcweir         = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
387*cdf0e10cSrcweir             "com.sun.star.task.PasswordContainerInteractionHandler" ) );
388*cdf0e10cSrcweir     return aSNS;
389*cdf0e10cSrcweir }
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir //=========================================================================
392*cdf0e10cSrcweir //
393*cdf0e10cSrcweir // XInteractionHandler methods.
394*cdf0e10cSrcweir //
395*cdf0e10cSrcweir //=========================================================================
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir // virtual
398*cdf0e10cSrcweir void SAL_CALL
399*cdf0e10cSrcweir PasswordContainerInteractionHandler::handle(
400*cdf0e10cSrcweir         const uno::Reference< task::XInteractionRequest >& rRequest )
401*cdf0e10cSrcweir     throw ( uno::RuntimeException )
402*cdf0e10cSrcweir {
403*cdf0e10cSrcweir     if ( !rRequest.is() )
404*cdf0e10cSrcweir         return;
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir     uno::Any aAnyRequest( rRequest->getRequest() );
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir     ucb::AuthenticationRequest aAuthenticationRequest;
409*cdf0e10cSrcweir     if ( !( aAnyRequest >>= aAuthenticationRequest ) )
410*cdf0e10cSrcweir         return;
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir     rtl::OUString aURL;
413*cdf0e10cSrcweir     ucb::URLAuthenticationRequest aURLAuthenticationRequest;
414*cdf0e10cSrcweir     if ( aAnyRequest >>= aURLAuthenticationRequest )
415*cdf0e10cSrcweir         aURL = aURLAuthenticationRequest.URL;
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir     uno::Sequence< uno::Reference< task::XInteractionContinuation > >
418*cdf0e10cSrcweir         rContinuations = rRequest->getContinuations();
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir     uno::Reference< ucb::XInteractionSupplyAuthentication >
421*cdf0e10cSrcweir         xSupplyAuthentication;
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir     for ( sal_Int32 i = 0; i < rContinuations.getLength(); ++i )
424*cdf0e10cSrcweir     {
425*cdf0e10cSrcweir         xSupplyAuthentication
426*cdf0e10cSrcweir             = uno::Reference< ucb::XInteractionSupplyAuthentication >(
427*cdf0e10cSrcweir                 rContinuations[i], uno::UNO_QUERY );
428*cdf0e10cSrcweir         if( xSupplyAuthentication.is() )
429*cdf0e10cSrcweir             break;
430*cdf0e10cSrcweir     }
431*cdf0e10cSrcweir 
432*cdf0e10cSrcweir     if ( !xSupplyAuthentication.is() )
433*cdf0e10cSrcweir         return;
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir     // Try to obatin credentials from password container.
436*cdf0e10cSrcweir     if ( m_aPwContainerHelper.
437*cdf0e10cSrcweir              handleAuthenticationRequest( aAuthenticationRequest,
438*cdf0e10cSrcweir                                           xSupplyAuthentication,
439*cdf0e10cSrcweir                                           aURL,
440*cdf0e10cSrcweir                                           // @@@ FIXME: this not able to
441*cdf0e10cSrcweir                                           // handle master pw request!
442*cdf0e10cSrcweir                                           // master pw request is never
443*cdf0e10cSrcweir                                           // solvable without UI!
444*cdf0e10cSrcweir                                           this ) )
445*cdf0e10cSrcweir     {
446*cdf0e10cSrcweir         // successfully handled
447*cdf0e10cSrcweir         xSupplyAuthentication->select();
448*cdf0e10cSrcweir     }
449*cdf0e10cSrcweir }
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir //=========================================================================
452*cdf0e10cSrcweir //
453*cdf0e10cSrcweir // Service factory implementation.
454*cdf0e10cSrcweir //
455*cdf0e10cSrcweir //=========================================================================
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir static uno::Reference< uno::XInterface > SAL_CALL
458*cdf0e10cSrcweir PasswordContainerInteractionHandler_CreateInstance(
459*cdf0e10cSrcweir         const uno::Reference< lang::XMultiServiceFactory> & rSMgr )
460*cdf0e10cSrcweir     throw( uno::Exception )
461*cdf0e10cSrcweir {
462*cdf0e10cSrcweir     lang::XServiceInfo * pX = static_cast< lang::XServiceInfo * >(
463*cdf0e10cSrcweir         new PasswordContainerInteractionHandler( rSMgr ) );
464*cdf0e10cSrcweir     return uno::Reference< uno::XInterface >::query( pX );
465*cdf0e10cSrcweir }
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir //=========================================================================
468*cdf0e10cSrcweir // static
469*cdf0e10cSrcweir uno::Reference< lang::XSingleServiceFactory >
470*cdf0e10cSrcweir PasswordContainerInteractionHandler::createServiceFactory(
471*cdf0e10cSrcweir     const uno::Reference< lang::XMultiServiceFactory >& rxServiceMgr )
472*cdf0e10cSrcweir {
473*cdf0e10cSrcweir     return uno::Reference< lang::XSingleServiceFactory >(
474*cdf0e10cSrcweir         cppu::createOneInstanceFactory(
475*cdf0e10cSrcweir             rxServiceMgr,
476*cdf0e10cSrcweir             PasswordContainerInteractionHandler::getImplementationName_Static(),
477*cdf0e10cSrcweir             PasswordContainerInteractionHandler_CreateInstance,
478*cdf0e10cSrcweir             PasswordContainerInteractionHandler::getSupportedServiceNames_Static() ) );
479*cdf0e10cSrcweir }
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir } // namespace uui
482