1*b16fc349SAndrew Rist /************************************************************** 2*b16fc349SAndrew Rist * 3*b16fc349SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*b16fc349SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*b16fc349SAndrew Rist * distributed with this work for additional information 6*b16fc349SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*b16fc349SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*b16fc349SAndrew Rist * "License"); you may not use this file except in compliance 9*b16fc349SAndrew Rist * with the License. You may obtain a copy of the License at 10*b16fc349SAndrew Rist * 11*b16fc349SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*b16fc349SAndrew Rist * 13*b16fc349SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*b16fc349SAndrew Rist * software distributed under the License is distributed on an 15*b16fc349SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b16fc349SAndrew Rist * KIND, either express or implied. See the License for the 17*b16fc349SAndrew Rist * specific language governing permissions and limitations 18*b16fc349SAndrew Rist * under the License. 19*b16fc349SAndrew Rist * 20*b16fc349SAndrew Rist *************************************************************/ 21*b16fc349SAndrew Rist 22*b16fc349SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef INCLUDED_UUI_PASSWORDCONTAINER_HXX 25cdf0e10cSrcweir #define INCLUDED_UUI_PASSWORDCONTAINER_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "cppuhelper/implbase2.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include "com/sun/star/lang/XServiceInfo.hpp" 30cdf0e10cSrcweir #include "com/sun/star/lang/XSingleServiceFactory.hpp" 31cdf0e10cSrcweir #include "com/sun/star/task/XInteractionHandler.hpp" 32cdf0e10cSrcweir #include "com/sun/star/task/XPasswordContainer.hpp" 33cdf0e10cSrcweir 34cdf0e10cSrcweir namespace com { 35cdf0e10cSrcweir namespace sun { 36cdf0e10cSrcweir namespace star { 37cdf0e10cSrcweir namespace lang { 38cdf0e10cSrcweir class XMultiServiceFactory; 39cdf0e10cSrcweir } 40cdf0e10cSrcweir namespace ucb { 41cdf0e10cSrcweir class AuthenticationRequest; 42cdf0e10cSrcweir class XInteractionSupplyAuthentication; 43cdf0e10cSrcweir } } } } 44cdf0e10cSrcweir 45cdf0e10cSrcweir namespace uui { 46cdf0e10cSrcweir 47cdf0e10cSrcweir // ============================================================================ 48cdf0e10cSrcweir 49cdf0e10cSrcweir /** Passwordcontainer UNO service (com.sun.star.task.PasswordContainer) helper. 50cdf0e10cSrcweir */ 51cdf0e10cSrcweir class PasswordContainerHelper 52cdf0e10cSrcweir { 53cdf0e10cSrcweir public: 54cdf0e10cSrcweir PasswordContainerHelper( 55cdf0e10cSrcweir com::sun::star::uno::Reference< 56cdf0e10cSrcweir com::sun::star::lang::XMultiServiceFactory > const & 57cdf0e10cSrcweir xServiceFactory ); 58cdf0e10cSrcweir 59cdf0e10cSrcweir // ------------------------------------------------------------------------ 60cdf0e10cSrcweir 61cdf0e10cSrcweir /** This member function tries to handle an authentication interaction 62cdf0e10cSrcweir request by looking up credentials for the given URL in the password 63cdf0e10cSrcweir container service. 64cdf0e10cSrcweir 65cdf0e10cSrcweir In case of success the given interaction continuation 66cdf0e10cSrcweir (XInteractionSupplyAuthentication) is filled with the credentials found 67cdf0e10cSrcweir in the password container. 68cdf0e10cSrcweir 69cdf0e10cSrcweir Please note the the continuation gets not "selected" by this 70cdf0e10cSrcweir implementation. "Selecting" the continuation is up to the caller (e.g. 71cdf0e10cSrcweir an implementation of XInteractionHandler::handle) of this function. 72cdf0e10cSrcweir 73cdf0e10cSrcweir @param rRequest 74cdf0e10cSrcweir The authentication request. 75cdf0e10cSrcweir 76cdf0e10cSrcweir @param xSupplyAuthentication 77cdf0e10cSrcweir The "supply authentication" interaction continuation. 78cdf0e10cSrcweir 79cdf0e10cSrcweir @param rURL 80cdf0e10cSrcweir The URL to lookup credentials for. 81cdf0e10cSrcweir 82cdf0e10cSrcweir @param xIH 83cdf0e10cSrcweir The interaction handler to use, for example if a master password is 84cdf0e10cSrcweir needed to access the password container. 85cdf0e10cSrcweir 86cdf0e10cSrcweir @return 87cdf0e10cSrcweir True, if the authentication request was handled successfully. 88cdf0e10cSrcweir False, otherwise. 89cdf0e10cSrcweir */ 90cdf0e10cSrcweir bool handleAuthenticationRequest( 91cdf0e10cSrcweir com::sun::star::ucb::AuthenticationRequest const & rRequest, 92cdf0e10cSrcweir com::sun::star::uno::Reference< 93cdf0e10cSrcweir com::sun::star::ucb::XInteractionSupplyAuthentication > const & 94cdf0e10cSrcweir xSupplyAuthentication, 95cdf0e10cSrcweir rtl::OUString const & rURL, 96cdf0e10cSrcweir com::sun::star::uno::Reference< 97cdf0e10cSrcweir com::sun::star::task::XInteractionHandler > const & xIH ) 98cdf0e10cSrcweir SAL_THROW( (com::sun::star::uno::RuntimeException) ); 99cdf0e10cSrcweir 100cdf0e10cSrcweir /** This member function adds credentials for the given URL to the password 101cdf0e10cSrcweir container. 102cdf0e10cSrcweir 103cdf0e10cSrcweir @param rURL 104cdf0e10cSrcweir The URL the credentials are valid for. rURL must not be empty. 105cdf0e10cSrcweir 106cdf0e10cSrcweir @param rUsername 107cdf0e10cSrcweir The user name. 108cdf0e10cSrcweir 109cdf0e10cSrcweir @param rPasswords 110cdf0e10cSrcweir This list of passwords. 111cdf0e10cSrcweir 112cdf0e10cSrcweir @param xIH 113cdf0e10cSrcweir The interaction handler to use, for example if a master password is 114cdf0e10cSrcweir needed to access the password container. 115cdf0e10cSrcweir 116cdf0e10cSrcweir @param bPersist 117cdf0e10cSrcweir True, the record will get stored persistently; restored upon 118cdf0e10cSrcweir password container initialization 119cdf0e10cSrcweir False, the record will be stored until password container instance 120cdf0e10cSrcweir gets destroyed. 121cdf0e10cSrcweir 122cdf0e10cSrcweir @return 123cdf0e10cSrcweir True, if the record was added successfully. 124cdf0e10cSrcweir False, otherwise. 125cdf0e10cSrcweir 126cdf0e10cSrcweir */ 127cdf0e10cSrcweir bool addRecord( rtl::OUString const & rURL, 128cdf0e10cSrcweir rtl::OUString const & rUsername, 129cdf0e10cSrcweir com::sun::star::uno::Sequence< rtl::OUString > const & 130cdf0e10cSrcweir rPasswords, 131cdf0e10cSrcweir com::sun::star::uno::Reference< 132cdf0e10cSrcweir com::sun::star::task::XInteractionHandler > const & xIH, 133cdf0e10cSrcweir bool bPersist ) 134cdf0e10cSrcweir SAL_THROW( (com::sun::star::uno::RuntimeException) ); 135cdf0e10cSrcweir 136cdf0e10cSrcweir // ------------------------------------------------------------------------ 137cdf0e10cSrcweir 138cdf0e10cSrcweir private: 139cdf0e10cSrcweir com::sun::star::uno::Reference< 140cdf0e10cSrcweir com::sun::star::task::XPasswordContainer > m_xPasswordContainer; 141cdf0e10cSrcweir }; 142cdf0e10cSrcweir 143cdf0e10cSrcweir // ============================================================================ 144cdf0e10cSrcweir 145cdf0e10cSrcweir class PasswordContainerInteractionHandler : 146cdf0e10cSrcweir public cppu::WeakImplHelper2< com::sun::star::lang::XServiceInfo, 147cdf0e10cSrcweir com::sun::star::task::XInteractionHandler > 148cdf0e10cSrcweir { 149cdf0e10cSrcweir public: 150cdf0e10cSrcweir PasswordContainerInteractionHandler( 151cdf0e10cSrcweir const com::sun::star::uno::Reference< 152cdf0e10cSrcweir com::sun::star::lang::XMultiServiceFactory >& rXSMgr ); 153cdf0e10cSrcweir virtual ~PasswordContainerInteractionHandler(); 154cdf0e10cSrcweir 155cdf0e10cSrcweir // XServiceInfo 156cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getImplementationName() 157cdf0e10cSrcweir throw ( com::sun::star::uno::RuntimeException ); 158cdf0e10cSrcweir 159cdf0e10cSrcweir virtual sal_Bool SAL_CALL 160cdf0e10cSrcweir supportsService( const ::rtl::OUString& ServiceName ) 161cdf0e10cSrcweir throw ( com::sun::star::uno::RuntimeException ); 162cdf0e10cSrcweir 163cdf0e10cSrcweir virtual com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL 164cdf0e10cSrcweir getSupportedServiceNames() 165cdf0e10cSrcweir throw ( com::sun::star::uno::RuntimeException ); 166cdf0e10cSrcweir 167cdf0e10cSrcweir // XInteractionHandler 168cdf0e10cSrcweir virtual void SAL_CALL 169cdf0e10cSrcweir handle( const ::com::sun::star::uno::Reference< 170cdf0e10cSrcweir ::com::sun::star::task::XInteractionRequest >& Request ) 171cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 172cdf0e10cSrcweir 173cdf0e10cSrcweir // Non-UNO interfaces 174cdf0e10cSrcweir static rtl::OUString 175cdf0e10cSrcweir getImplementationName_Static(); 176cdf0e10cSrcweir 177cdf0e10cSrcweir static com::sun::star::uno::Sequence< rtl::OUString > 178cdf0e10cSrcweir getSupportedServiceNames_Static(); 179cdf0e10cSrcweir 180cdf0e10cSrcweir static com::sun::star::uno::Reference< 181cdf0e10cSrcweir com::sun::star::lang::XSingleServiceFactory > 182cdf0e10cSrcweir createServiceFactory( const com::sun::star::uno::Reference< 183cdf0e10cSrcweir com::sun::star::lang::XMultiServiceFactory > & rxServiceMgr ); 184cdf0e10cSrcweir 185cdf0e10cSrcweir private: 186cdf0e10cSrcweir //com::sun::star::uno::Reference< 187cdf0e10cSrcweir // com::sun::star::lang::XMultiServiceFactory > m_xSMgr; 188cdf0e10cSrcweir PasswordContainerHelper m_aPwContainerHelper; 189cdf0e10cSrcweir }; 190cdf0e10cSrcweir 191cdf0e10cSrcweir } // namespace uui 192cdf0e10cSrcweir 193cdf0e10cSrcweir #endif 194