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 #ifndef INCLUDED_UUI_PASSWORDCONTAINER_HXX
29*cdf0e10cSrcweir #define INCLUDED_UUI_PASSWORDCONTAINER_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "cppuhelper/implbase2.hxx"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "com/sun/star/lang/XServiceInfo.hpp"
34*cdf0e10cSrcweir #include "com/sun/star/lang/XSingleServiceFactory.hpp"
35*cdf0e10cSrcweir #include "com/sun/star/task/XInteractionHandler.hpp"
36*cdf0e10cSrcweir #include "com/sun/star/task/XPasswordContainer.hpp"
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir namespace com {
39*cdf0e10cSrcweir     namespace sun {
40*cdf0e10cSrcweir         namespace star {
41*cdf0e10cSrcweir             namespace lang {
42*cdf0e10cSrcweir                 class XMultiServiceFactory;
43*cdf0e10cSrcweir             }
44*cdf0e10cSrcweir             namespace ucb {
45*cdf0e10cSrcweir                 class AuthenticationRequest;
46*cdf0e10cSrcweir                 class XInteractionSupplyAuthentication;
47*cdf0e10cSrcweir } } } }
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir namespace uui {
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir // ============================================================================
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir /** Passwordcontainer UNO service (com.sun.star.task.PasswordContainer) helper.
54*cdf0e10cSrcweir  */
55*cdf0e10cSrcweir class PasswordContainerHelper
56*cdf0e10cSrcweir {
57*cdf0e10cSrcweir public:
58*cdf0e10cSrcweir     PasswordContainerHelper(
59*cdf0e10cSrcweir         com::sun::star::uno::Reference<
60*cdf0e10cSrcweir             com::sun::star::lang::XMultiServiceFactory > const &
61*cdf0e10cSrcweir                 xServiceFactory );
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir     // ------------------------------------------------------------------------
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir     /** This member function tries to handle an authentication interaction
66*cdf0e10cSrcweir         request by looking up credentials for the given URL in the password
67*cdf0e10cSrcweir         container service.
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir         In case of success the given interaction continuation
70*cdf0e10cSrcweir         (XInteractionSupplyAuthentication) is filled with the credentials found
71*cdf0e10cSrcweir         in the password container.
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir         Please note the the continuation gets not "selected" by this
74*cdf0e10cSrcweir         implementation. "Selecting" the continuation is up to the caller (e.g.
75*cdf0e10cSrcweir         an implementation of XInteractionHandler::handle) of this function.
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir         @param rRequest
78*cdf0e10cSrcweir             The authentication request.
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir         @param xSupplyAuthentication
81*cdf0e10cSrcweir             The "supply authentication" interaction continuation.
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir         @param rURL
84*cdf0e10cSrcweir             The URL to lookup credentials for.
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir         @param xIH
87*cdf0e10cSrcweir             The interaction handler to use, for example if a master password is
88*cdf0e10cSrcweir             needed to access the password container.
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir         @return
91*cdf0e10cSrcweir             True, if the authentication request was handled successfully.
92*cdf0e10cSrcweir             False, otherwise.
93*cdf0e10cSrcweir      */
94*cdf0e10cSrcweir     bool handleAuthenticationRequest(
95*cdf0e10cSrcweir         com::sun::star::ucb::AuthenticationRequest const & rRequest,
96*cdf0e10cSrcweir         com::sun::star::uno::Reference<
97*cdf0e10cSrcweir             com::sun::star::ucb::XInteractionSupplyAuthentication > const &
98*cdf0e10cSrcweir                 xSupplyAuthentication,
99*cdf0e10cSrcweir         rtl::OUString const & rURL,
100*cdf0e10cSrcweir         com::sun::star::uno::Reference<
101*cdf0e10cSrcweir             com::sun::star::task::XInteractionHandler > const & xIH )
102*cdf0e10cSrcweir     SAL_THROW( (com::sun::star::uno::RuntimeException) );
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir     /** This member function adds credentials for the given URL to the password
105*cdf0e10cSrcweir         container.
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir         @param rURL
108*cdf0e10cSrcweir             The URL the credentials are valid for. rURL must not be empty.
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir         @param rUsername
111*cdf0e10cSrcweir             The user name.
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir         @param rPasswords
114*cdf0e10cSrcweir             This list of passwords.
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir         @param xIH
117*cdf0e10cSrcweir             The interaction handler to use, for example if a master password is
118*cdf0e10cSrcweir             needed to access the password container.
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir         @param bPersist
121*cdf0e10cSrcweir             True, the record will get stored persistently; restored upon
122*cdf0e10cSrcweir             password container initialization
123*cdf0e10cSrcweir             False, the record will be stored until password container instance
124*cdf0e10cSrcweir             gets destroyed.
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir         @return
127*cdf0e10cSrcweir             True, if the record was added successfully.
128*cdf0e10cSrcweir             False, otherwise.
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir     */
131*cdf0e10cSrcweir     bool addRecord( rtl::OUString const & rURL,
132*cdf0e10cSrcweir                     rtl::OUString const & rUsername,
133*cdf0e10cSrcweir                     com::sun::star::uno::Sequence< rtl::OUString > const &
134*cdf0e10cSrcweir                     rPasswords,
135*cdf0e10cSrcweir                     com::sun::star::uno::Reference<
136*cdf0e10cSrcweir                         com::sun::star::task::XInteractionHandler > const & xIH,
137*cdf0e10cSrcweir                     bool bPersist )
138*cdf0e10cSrcweir         SAL_THROW( (com::sun::star::uno::RuntimeException) );
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir     // ------------------------------------------------------------------------
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir private:
143*cdf0e10cSrcweir     com::sun::star::uno::Reference<
144*cdf0e10cSrcweir         com::sun::star::task::XPasswordContainer > m_xPasswordContainer;
145*cdf0e10cSrcweir };
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir // ============================================================================
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir class PasswordContainerInteractionHandler :
150*cdf0e10cSrcweir         public cppu::WeakImplHelper2< com::sun::star::lang::XServiceInfo,
151*cdf0e10cSrcweir                                       com::sun::star::task::XInteractionHandler >
152*cdf0e10cSrcweir {
153*cdf0e10cSrcweir public:
154*cdf0e10cSrcweir     PasswordContainerInteractionHandler(
155*cdf0e10cSrcweir         const com::sun::star::uno::Reference<
156*cdf0e10cSrcweir             com::sun::star::lang::XMultiServiceFactory >& rXSMgr );
157*cdf0e10cSrcweir     virtual ~PasswordContainerInteractionHandler();
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir     // XServiceInfo
160*cdf0e10cSrcweir     virtual ::rtl::OUString SAL_CALL getImplementationName()
161*cdf0e10cSrcweir         throw ( com::sun::star::uno::RuntimeException );
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL
164*cdf0e10cSrcweir     supportsService( const ::rtl::OUString& ServiceName )
165*cdf0e10cSrcweir         throw ( com::sun::star::uno::RuntimeException );
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir     virtual com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
168*cdf0e10cSrcweir     getSupportedServiceNames()
169*cdf0e10cSrcweir         throw ( com::sun::star::uno::RuntimeException );
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir     // XInteractionHandler
172*cdf0e10cSrcweir     virtual void SAL_CALL
173*cdf0e10cSrcweir     handle( const ::com::sun::star::uno::Reference<
174*cdf0e10cSrcweir                 ::com::sun::star::task::XInteractionRequest >& Request )
175*cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir     // Non-UNO interfaces
178*cdf0e10cSrcweir     static rtl::OUString
179*cdf0e10cSrcweir     getImplementationName_Static();
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir     static com::sun::star::uno::Sequence< rtl::OUString >
182*cdf0e10cSrcweir     getSupportedServiceNames_Static();
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir     static com::sun::star::uno::Reference<
185*cdf0e10cSrcweir             com::sun::star::lang::XSingleServiceFactory >
186*cdf0e10cSrcweir     createServiceFactory( const com::sun::star::uno::Reference<
187*cdf0e10cSrcweir             com::sun::star::lang::XMultiServiceFactory > & rxServiceMgr );
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir private:
190*cdf0e10cSrcweir     //com::sun::star::uno::Reference<
191*cdf0e10cSrcweir     //    com::sun::star::lang::XMultiServiceFactory > m_xSMgr;
192*cdf0e10cSrcweir     PasswordContainerHelper m_aPwContainerHelper;
193*cdf0e10cSrcweir };
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir } // namespace uui
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir #endif
198