dbaccess/source/core/dataaccess/databasecontext.cxx | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+)
New commits: commit 5b064206d83c6854e292e93de168fbf802201e5b Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Sun Aug 17 22:44:03 2025 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Sun Aug 17 21:23:50 2025 +0200 tdf#167960: store also username associated with this password The problem was, that the password that got stored as a transient session-persistent property, could be for one user; but after the reload, it could be reused for another user, stored in the file. That resulted in a failed authentication attempt; but since the password was present, it didn't ask for a new attempt, but failed the connection. This change stores the current user name along with the password; and when loading the document next time, it checks the username set in the document (i.e., that will be used for logon), and if it's different from the name used with the stored password, the password is not reused. Change-Id: I8f971e641492e3ab93dabfce38d376a06339be3d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189828 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/dbaccess/source/core/dataaccess/databasecontext.cxx b/dbaccess/source/core/dataaccess/databasecontext.cxx index fc5dc5f0907e..e1a3cf4f068c 100644 --- a/dbaccess/source/core/dataaccess/databasecontext.cxx +++ b/dbaccess/source/core/dataaccess/databasecontext.cxx @@ -385,6 +385,7 @@ void ODatabaseContext::setTransientProperties(const OUString& _sURL, ODatabaseMo try { OUString sAuthFailedPassword; + Any aUser, aPassword; Reference< XPropertySet > xDSProps( _rDataSourceModel.getOrCreateDataSource(), UNO_QUERY_THROW ); const Sequence< PropertyValue >& rSessionPersistentProps = m_aDatasourceProperties[_sURL]; for ( auto const & prop : rSessionPersistentProps ) @@ -393,6 +394,14 @@ void ODatabaseContext::setTransientProperties(const OUString& _sURL, ODatabaseMo { OSL_VERIFY( prop.Value >>= sAuthFailedPassword ); } + else if (prop.Name == PROPERTY_USER) + { + aUser = prop.Value; + } + else if (prop.Name == PROPERTY_PASSWORD) + { + aPassword = prop.Value; + } else { xDSProps->setPropertyValue( prop.Name, prop.Value ); @@ -400,6 +409,12 @@ void ODatabaseContext::setTransientProperties(const OUString& _sURL, ODatabaseMo } _rDataSourceModel.m_sFailedPassword = sAuthFailedPassword; + // tdf#167960: only restore password, if the username is unchanged + if (aPassword.hasValue() && aUser.hasValue()) + { + if (aUser == xDSProps->getPropertyValue(PROPERTY_USER)) + xDSProps->setPropertyValue(PROPERTY_PASSWORD, aPassword); + } } catch( const Exception& ) { @@ -460,6 +475,16 @@ void ODatabaseContext::storeTransientProperties( ODatabaseModelImpl& _rModelImpl aRememberProps.put( rProperty.Name, xSource->getPropertyValue( rProperty.Name ) ); } } + if (aRememberProps.has(PROPERTY_PASSWORD)) + { + // tdf#167960: store also username associated with this password. + // It may happen, that the next time this document is loaded, it gets another username. + // It happens e.g. if this time a different username and password were used, which are + // now saved in the model's PROPERTY_USER / PROPERTY_PASSWORD; but the document is not + // modified to write that username to file. The next time it is opened, the previously + // stored name is loaded. We can detect the change, using this stored value. + aRememberProps.put(PROPERTY_USER, xSource->getPropertyValue(PROPERTY_USER)); + } } catch ( const Exception& ) {