diff options
author | obo <obo@openoffice.org> | 2010-06-18 13:31:23 +0200 |
---|---|---|
committer | obo <obo@openoffice.org> | 2010-06-18 13:31:23 +0200 |
commit | 716dcf5f571707c7189502aa707c25c80e1090da (patch) | |
tree | 2109310194c4d42bc6ee533c0e66939baabf659f | |
parent | 8c9b11794acc7edb27b603949abdeadf56f08743 (diff) | |
parent | 8360fcb0987c67c6d3b07c2d603b0632d369b3ec (diff) |
CWS-TOOLING: integrate CWS tl79
-rwxr-xr-x[-rw-r--r--] | dbaccess/source/core/dataaccess/datasource.cxx | 37 | ||||
-rwxr-xr-x | dbaccess/source/inc/OAuthenticationContinuation.hxx | 82 | ||||
-rwxr-xr-x[-rw-r--r--] | dbaccess/source/ui/dlg/DbAdminImpl.cxx | 84 | ||||
-rwxr-xr-x[-rw-r--r--] | dbaccess/source/ui/uno/dbinteraction.cxx | 3 |
4 files changed, 153 insertions, 53 deletions
diff --git a/dbaccess/source/core/dataaccess/datasource.cxx b/dbaccess/source/core/dataaccess/datasource.cxx index e3f75ef69..6a1151580 100644..100755 --- a/dbaccess/source/core/dataaccess/datasource.cxx +++ b/dbaccess/source/core/dataaccess/datasource.cxx @@ -38,6 +38,7 @@ #include "connection.hxx" #include "SharedConnection.hxx" #include "databasedocument.hxx" +#include "OAuthenticationContinuation.hxx" /** === begin UNO includes === **/ @@ -206,40 +207,10 @@ void SAL_CALL FlushNotificationAdapter::disposing( const EventObject& Source ) t impl_dispose( false ); } -//============================================================ -//= OAuthenticationContinuation -//============================================================ -class OAuthenticationContinuation : public OInteraction< XInteractionSupplyAuthentication > -{ - sal_Bool m_bRemberPassword : 1; // remember the password for this session ? - - ::rtl::OUString m_sUser; // the user - ::rtl::OUString m_sPassword; // the user's password - -public: - OAuthenticationContinuation(); - - sal_Bool SAL_CALL canSetRealm( ) throw(RuntimeException); - void SAL_CALL setRealm( const ::rtl::OUString& Realm ) throw(RuntimeException); - sal_Bool SAL_CALL canSetUserName( ) throw(RuntimeException); - void SAL_CALL setUserName( const ::rtl::OUString& UserName ) throw(RuntimeException); - sal_Bool SAL_CALL canSetPassword( ) throw(RuntimeException); - void SAL_CALL setPassword( const ::rtl::OUString& Password ) throw(RuntimeException); - Sequence< RememberAuthentication > SAL_CALL getRememberPasswordModes( RememberAuthentication& Default ) throw(RuntimeException); - void SAL_CALL setRememberPassword( RememberAuthentication Remember ) throw(RuntimeException); - sal_Bool SAL_CALL canSetAccount( ) throw(RuntimeException); - void SAL_CALL setAccount( const ::rtl::OUString& Account ) throw(RuntimeException); - Sequence< RememberAuthentication > SAL_CALL getRememberAccountModes( RememberAuthentication& Default ) throw(RuntimeException); - void SAL_CALL setRememberAccount( RememberAuthentication Remember ) throw(RuntimeException); - - ::rtl::OUString getUser() const { return m_sUser; } - ::rtl::OUString getPassword() const { return m_sPassword; } - sal_Bool getRememberPassword() const { return m_bRemberPassword; } -}; - //-------------------------------------------------------------------------- OAuthenticationContinuation::OAuthenticationContinuation() - :m_bRemberPassword(sal_True) // TODO: a meaningfull default + :m_bRemberPassword(sal_True), // TODO: a meaningfull default + m_bCanSetUserName(sal_True) { } @@ -260,7 +231,7 @@ sal_Bool SAL_CALL OAuthenticationContinuation::canSetUserName( ) throw(RuntimeE { // we alwas allow this, even if the database document is read-only. In this case, // it's simply that the user cannot store the new user name. - return sal_True; + return m_bCanSetUserName; } //-------------------------------------------------------------------------- diff --git a/dbaccess/source/inc/OAuthenticationContinuation.hxx b/dbaccess/source/inc/OAuthenticationContinuation.hxx new file mode 100755 index 000000000..8f44097e4 --- /dev/null +++ b/dbaccess/source/inc/OAuthenticationContinuation.hxx @@ -0,0 +1,82 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _DBACCESS_OAUTHENTICATIONCONTINUATION_HXX_ +#define _DBACCESS_OAUTHENTICATIONCONTINUATION_HXX_ + +#include "dbadllapi.hxx" + +#include <com/sun/star/ucb/XInteractionSupplyAuthentication.hpp> +#include <com/sun/star/ucb/RememberAuthentication.hpp> +#include <com/sun/star/uno/Sequence.hxx> + +#include <tools/string.hxx> +#include <comphelper/interaction.hxx> + + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + +class OOO_DLLPUBLIC_DBA OAuthenticationContinuation : + public comphelper::OInteraction< com::sun::star::ucb::XInteractionSupplyAuthentication > +{ + sal_Bool m_bRemberPassword : 1; // remember the password for this session ? + + sal_Bool m_bCanSetUserName; + ::rtl::OUString m_sUser; // the user + ::rtl::OUString m_sPassword; // the user's password + +public: + OAuthenticationContinuation(); + + sal_Bool SAL_CALL canSetRealm( ) throw(com::sun::star::uno::RuntimeException); + void SAL_CALL setRealm( const ::rtl::OUString& Realm ) throw(com::sun::star::uno::RuntimeException); + sal_Bool SAL_CALL canSetUserName( ) throw(com::sun::star::uno::RuntimeException); + void SAL_CALL setUserName( const ::rtl::OUString& UserName ) throw(com::sun::star::uno::RuntimeException); + sal_Bool SAL_CALL canSetPassword( ) throw(com::sun::star::uno::RuntimeException); + void SAL_CALL setPassword( const ::rtl::OUString& Password ) throw(com::sun::star::uno::RuntimeException); + com::sun::star::uno::Sequence< com::sun::star::ucb::RememberAuthentication > SAL_CALL getRememberPasswordModes( com::sun::star::ucb::RememberAuthentication& Default ) throw(com::sun::star::uno::RuntimeException); + void SAL_CALL setRememberPassword( com::sun::star::ucb::RememberAuthentication Remember ) throw(com::sun::star::uno::RuntimeException); + sal_Bool SAL_CALL canSetAccount( ) throw(com::sun::star::uno::RuntimeException); + void SAL_CALL setAccount( const ::rtl::OUString& Account ) throw(com::sun::star::uno::RuntimeException); + com::sun::star::uno::Sequence< com::sun::star::ucb::RememberAuthentication > SAL_CALL getRememberAccountModes( com::sun::star::ucb::RememberAuthentication& Default ) throw(com::sun::star::uno::RuntimeException); + void SAL_CALL setRememberAccount( com::sun::star::ucb::RememberAuthentication Remember ) throw(com::sun::star::uno::RuntimeException); + + void setCanChangeUserName( sal_Bool bVal ) { m_bCanSetUserName = bVal; } + ::rtl::OUString getUser() const { return m_sUser; } + ::rtl::OUString getPassword() const { return m_sPassword; } + sal_Bool getRememberPassword() const { return m_bRemberPassword; } +}; + +//........................................................................ +} // namespace dbaccess +//........................................................................ + +#endif // _DBACCESS_OAUTHENTICATIONCONTINUATION_HXX_ + diff --git a/dbaccess/source/ui/dlg/DbAdminImpl.cxx b/dbaccess/source/ui/dlg/DbAdminImpl.cxx index 04640808b..816d3d5e9 100644..100755 --- a/dbaccess/source/ui/dlg/DbAdminImpl.cxx +++ b/dbaccess/source/ui/dlg/DbAdminImpl.cxx @@ -47,6 +47,7 @@ #include "optionalboolitem.hxx" #include "propertysetitem.hxx" #include "stringlistitem.hxx" +#include "OAuthenticationContinuation.hxx" /** === begin UNO includes === **/ #include <com/sun/star/beans/PropertyAttribute.hpp> @@ -54,23 +55,32 @@ #include <com/sun/star/sdb/SQLContext.hpp> #include <com/sun/star/sdbc/XDriver.hpp> #include <com/sun/star/sdbc/XDriverAccess.hpp> +#include <com/sun/star/task/XInteractionHandler.hpp> +#include <com/sun/star/task/XInteractionRequest.hpp> +#include <com/sun/star/ucb/XInteractionSupplyAuthentication2.hpp> +#include <com/sun/star/ucb/AuthenticationRequest.hpp> /** === end UNO includes === **/ +#include <comphelper/interaction.hxx> #include <comphelper/property.hxx> #include <comphelper/sequence.hxx> +#include <comphelper/guarding.hxx> #include <connectivity/DriversConfig.hxx> #include <connectivity/dbexception.hxx> #include <osl/file.hxx> #include <svl/eitem.hxx> #include <svl/intitem.hxx> #include <svl/itempool.hxx> -#include <svtools/logindlg.hxx> #include <svl/poolitem.hxx> #include <svl/stritem.hxx> +#include <tools/urlobj.hxx> +#include <tools/diagnose_ex.h> #include <typelib/typedescription.hxx> +#include <vcl/svapp.hxx> #include <vcl/msgbox.hxx> #include <vcl/stdtext.hxx> #include <vcl/waitobj.hxx> +#include <vos/mutex.hxx> #include <algorithm> #include <functional> @@ -81,6 +91,8 @@ namespace dbaui using namespace ::dbtools; using namespace com::sun::star::uno; using namespace com::sun::star; +using namespace com::sun::star::ucb; +using namespace com::sun::star::task; using namespace com::sun::star::sdbc; using namespace com::sun::star::sdb; using namespace com::sun::star::lang; @@ -256,35 +268,73 @@ sal_Bool ODbDataSourceAdministrationHelper::getCurrentSettings(Sequence< Propert { SFX_ITEMSET_GET(*m_pItemSetHelper->getOutputSet(), pName, SfxStringItem, DSID_NAME, sal_True); - ::svt::LoginDialog aDlg(m_pParent, - LF_NO_PATH | LF_NO_ACCOUNT | LF_NO_ERRORTEXT | LF_USERNAME_READONLY, - String(), NULL); - - aDlg.SetName(pUser ? pUser->GetValue() : String()); - aDlg.ClearPassword(); // this will give the password field the focus + Reference< XModel > xModel( getDataSourceOrModel( m_xDatasource ), UNO_QUERY_THROW ); + ::comphelper::NamedValueCollection aArgs( xModel->getArgs() ); + Reference< XInteractionHandler > xHandler( aArgs.getOrDefault( "InteractionHandler", Reference< XInteractionHandler >() ) ); + if ( !xHandler.is() ) + { + // instantiate the default SDB interaction handler + xHandler = Reference< XInteractionHandler >( m_xORB->createInstance( SERVICE_TASK_INTERACTION_HANDLER ), UNO_QUERY ); + if ( !xHandler.is() ) + ShowServiceNotAvailableError(m_pParent->GetParent(), String(SERVICE_TASK_INTERACTION_HANDLER), sal_True); + } + String sName = pName ? pName->GetValue() : String(); String sLoginRequest(ModuleRes(STR_ENTER_CONNECTION_PASSWORD)); ::rtl::OUString sTemp = sName; sName = ::dbaui::getStrippedDatabaseName(NULL,sTemp); if ( sName.Len() ) - sLoginRequest.SearchAndReplaceAscii("$name$", sName); + sLoginRequest.SearchAndReplaceAscii("$name$", sName); else { sLoginRequest.SearchAndReplaceAscii("\"$name$\"", String()); sLoginRequest.SearchAndReplaceAscii("$name$", String()); // just to be sure that in other languages the string will be deleted } - aDlg.SetLoginRequestText(sLoginRequest); - - aDlg.SetSavePasswordText(ModuleRes(STR_REMEMBERPASSWORD_SESSION)); - aDlg.SetSavePassword(sal_True); - sal_Int32 nResult = aDlg.Execute(); - if (nResult != RET_OK) + // the request + AuthenticationRequest aRequest; + aRequest.ServerName = sName; + aRequest.Diagnostic = sLoginRequest; + aRequest.HasRealm = aRequest.HasAccount = sal_False; + // aRequest.Realm + aRequest.HasUserName = pUser != 0; + aRequest.UserName = pUser ? rtl::OUString(pUser->GetValue()) : ::rtl::OUString(); + aRequest.HasPassword = sal_True; + //aRequest.Password + aRequest.HasAccount = sal_False; + // aRequest.Account + + comphelper::OInteractionRequest* pRequest = new comphelper::OInteractionRequest(makeAny(aRequest)); + uno::Reference< XInteractionRequest > xRequest(pRequest); + + // build an interaction request + // two continuations (Ok and Cancel) + ::rtl::Reference< comphelper::OInteractionAbort > pAbort = new comphelper::OInteractionAbort; + ::rtl::Reference< dbaccess::OAuthenticationContinuation > pAuthenticate = new dbaccess::OAuthenticationContinuation; + pAuthenticate->setCanChangeUserName( sal_False ); + pAuthenticate->setRememberPassword( RememberAuthentication_SESSION ); + + // some knittings + pRequest->addContinuation(pAbort.get()); + pRequest->addContinuation(pAuthenticate.get()); + + // handle the request + try + { + ::vos::OGuard aSolarGuard(Application::GetSolarMutex()); + // release the mutex when calling the handler, it may need to lock the SolarMutex + xHandler->handle(xRequest); + } + catch(Exception&) + { + DBG_UNHANDLED_EXCEPTION(); + } + if (!pAuthenticate->wasSelected()) return sal_False; - - sPassword = aDlg.GetPassword(); - if (aDlg.IsSavePassword()) + + sPassword = pAuthenticate->getPassword(); + if (pAuthenticate->getRememberPassword()) m_pItemSetHelper->getWriteOutputSet()->Put(SfxStringItem(DSID_PASSWORD, sPassword)); } diff --git a/dbaccess/source/ui/uno/dbinteraction.cxx b/dbaccess/source/ui/uno/dbinteraction.cxx index 135838d79..e735c0331 100644..100755 --- a/dbaccess/source/ui/uno/dbinteraction.cxx +++ b/dbaccess/source/ui/uno/dbinteraction.cxx @@ -67,9 +67,6 @@ #ifndef _COM_SUN_STAR_SDB_XINTERACTIONDOCUMENTSAVE_HPP_ #include <com/sun/star/sdb/XInteractionDocumentSave.hpp> #endif -#ifndef _SVTOOLS_LOGINDLG_HXX_ -#include <svtools/logindlg.hxx> -#endif #ifndef SFX_QUERYSAVEDOCUMENT_HXX #include <sfx2/QuerySaveDocument.hxx> #endif |