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