1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 11 * Licensed to the Apache Software Foundation (ASF) under one or more 12 * contributor license agreements. See the NOTICE file distributed 13 * with this work for additional information regarding copyright 14 * ownership. The ASF licenses this file to you under the Apache 15 * License, Version 2.0 (the "License"); you may not use this file 16 * except in compliance with the License. You may obtain a copy of 17 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 18 */ 19 20 #ifndef INCLUDED_UUI_SOURCE_PASSWORDCONTAINER_HXX 21 #define INCLUDED_UUI_SOURCE_PASSWORDCONTAINER_HXX 22 23 #include <cppuhelper/implbase.hxx> 24 25 #include <com/sun/star/lang/XServiceInfo.hpp> 26 #include <com/sun/star/lang/XSingleServiceFactory.hpp> 27 #include <com/sun/star/task/XInteractionHandler2.hpp> 28 #include <com/sun/star/task/XPasswordContainer2.hpp> 29 30 namespace com { 31 namespace sun { 32 namespace star { 33 namespace lang { 34 class XMultiServiceFactory; 35 } 36 namespace ucb { 37 class AuthenticationRequest; 38 class XInteractionSupplyAuthentication; 39 } } } } 40 41 namespace uui { 42 43 44 /** Passwordcontainer UNO service (com.sun.star.task.PasswordContainer) helper. 45 */ 46 class PasswordContainerHelper 47 { 48 public: 49 explicit PasswordContainerHelper( 50 css::uno::Reference< css::uno::XComponentContext > const & xContext ); 51 52 53 /** This member function tries to handle an authentication interaction 54 request by looking up credentials for the given URL in the password 55 container service. 56 57 In case of success the given interaction continuation 58 (XInteractionSupplyAuthentication) is filled with the credentials found 59 in the password container. 60 61 Please note the continuation gets not "selected" by this 62 implementation. "Selecting" the continuation is up to the caller (e.g. 63 an implementation of XInteractionHandler::handle) of this function. 64 65 @param rRequest 66 The authentication request. 67 68 @param xSupplyAuthentication 69 The "supply authentication" interaction continuation. 70 71 @param rURL 72 The URL to lookup credentials for. 73 74 @param xIH 75 The interaction handler to use, for example if a master password is 76 needed to access the password container. 77 78 @return 79 True, if the authentication request was handled successfully. 80 False, otherwise. 81 */ 82 bool handleAuthenticationRequest( 83 css::ucb::AuthenticationRequest const & rRequest, 84 css::uno::Reference< css::ucb::XInteractionSupplyAuthentication > const & xSupplyAuthentication, 85 OUString const & rURL, 86 css::uno::Reference< css::task::XInteractionHandler2 > const & xIH ); 87 88 /** This member function adds credentials for the given URL to the password 89 container. 90 91 @param rURL 92 The URL the credentials are valid for. rURL must not be empty. 93 94 @param rUsername 95 The user name. 96 97 @param rPasswords 98 This list of passwords. 99 100 @param xIH 101 The interaction handler to use, for example if a master password is 102 needed to access the password container. 103 104 @param bPersist 105 True, the record will get stored persistently; restored upon 106 password container initialization 107 False, the record will be stored until password container instance 108 gets destroyed. 109 110 @return 111 True, if the record was added successfully. 112 False, otherwise. 113 114 */ 115 bool addRecord( OUString const & rURL, 116 OUString const & rUsername, 117 css::uno::Sequence< OUString > const & rPasswords, 118 css::uno::Reference< css::task::XInteractionHandler2 > const & xIH, 119 bool bPersist ); 120 121 122 private: 123 css::uno::Reference< css::task::XPasswordContainer2 > m_xPasswordContainer; 124 }; 125 126 127 class PasswordContainerInteractionHandler : 128 public cppu::WeakImplHelper< css::lang::XServiceInfo, 129 css::task::XInteractionHandler2 > 130 { 131 public: 132 explicit PasswordContainerInteractionHandler( 133 const css::uno::Reference< css::uno::XComponentContext >& xContext ); 134 virtual ~PasswordContainerInteractionHandler() override; 135 136 // XServiceInfo 137 virtual OUString SAL_CALL getImplementationName() override; 138 139 virtual sal_Bool SAL_CALL 140 supportsService( const OUString& ServiceName ) override; 141 142 virtual css::uno::Sequence< OUString > SAL_CALL 143 getSupportedServiceNames() override; 144 145 // XInteractionHandler2 146 virtual void SAL_CALL 147 handle( const css::uno::Reference< css::task::XInteractionRequest >& Request ) override; 148 149 virtual sal_Bool SAL_CALL 150 handleInteractionRequest( const css::uno::Reference< css::task::XInteractionRequest >& Request ) override; 151 152 // Non-UNO interfaces 153 static OUString 154 getImplementationName_Static(); 155 156 static css::uno::Sequence< OUString > 157 getSupportedServiceNames_Static(); 158 159 static css::uno::Reference< css::lang::XSingleServiceFactory > 160 createServiceFactory( const css::uno::Reference< css::lang::XMultiServiceFactory > & rxServiceMgr ); 161 162 private: 163 PasswordContainerHelper m_aPwContainerHelper; 164 }; 165 166 } // namespace uui 167 168 #endif 169 170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 171