[Libreoffice-commits] core.git: ucb/source
Szymon Kłos
eszkadev at gmail.com
Tue May 3 11:59:37 UTC 2016
ucb/source/ucp/cmis/cmis_content.cxx | 125 +++++++++++++++++-------------
ucb/source/ucp/cmis/cmis_repo_content.cxx | 90 ++++++++++++---------
2 files changed, 123 insertions(+), 92 deletions(-)
New commits:
commit f23c32e4bf42a80455ebae10d830b7ffded4fa9f
Author: Szymon Kłos <eszkadev at gmail.com>
Date: Tue Mar 15 16:25:28 2016 +0100
tdf#98644 : better error message when wrong password entered
Change-Id: Idf4da8000cce43cb66cb94fdfc8be8a3d6909fa6
Reviewed-on: https://gerrit.libreoffice.org/23475
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
diff --git a/ucb/source/ucp/cmis/cmis_content.cxx b/ucb/source/ucp/cmis/cmis_content.cxx
index e4c6435..dea8ec7 100644
--- a/ucb/source/ucp/cmis/cmis_content.cxx
+++ b/ucb/source/ucp/cmis/cmis_content.cxx
@@ -366,62 +366,79 @@ namespace cmis
string rUsername = OUSTR_TO_STDSTR( m_aURL.getUsername( ) );
string rPassword = OUSTR_TO_STDSTR( m_aURL.getPassword( ) );
- if ( authProvider.authenticationQuery( rUsername, rPassword ) )
+
+ bool bIsDone = false;
+
+ while ( !bIsDone )
{
- // Initiate a CMIS session and register it as we found nothing
- libcmis::OAuth2DataPtr oauth2Data;
- if ( m_aURL.getBindingUrl( ) == GDRIVE_BASE_URL )
- oauth2Data.reset( new libcmis::OAuth2Data(
- GDRIVE_AUTH_URL, GDRIVE_TOKEN_URL,
- GDRIVE_SCOPE, GDRIVE_REDIRECT_URI,
- GDRIVE_CLIENT_ID, GDRIVE_CLIENT_SECRET ) );
- if ( m_aURL.getBindingUrl().startsWith( ALFRESCO_CLOUD_BASE_URL ) )
- oauth2Data.reset( new libcmis::OAuth2Data(
- ALFRESCO_CLOUD_AUTH_URL, ALFRESCO_CLOUD_TOKEN_URL,
- ALFRESCO_CLOUD_SCOPE, ALFRESCO_CLOUD_REDIRECT_URI,
- ALFRESCO_CLOUD_CLIENT_ID, ALFRESCO_CLOUD_CLIENT_SECRET ) );
- if ( m_aURL.getBindingUrl( ) == ONEDRIVE_BASE_URL )
+ if ( authProvider.authenticationQuery( rUsername, rPassword ) )
{
- libcmis::SessionFactory::setOAuth2AuthCodeProvider( authProvider.onedriveAuthCodeFallback );
- oauth2Data.reset( new libcmis::OAuth2Data(
- ONEDRIVE_AUTH_URL, ONEDRIVE_TOKEN_URL,
- ONEDRIVE_SCOPE, ONEDRIVE_REDIRECT_URI,
- ONEDRIVE_CLIENT_ID, ONEDRIVE_CLIENT_SECRET ) );
- }
- m_pSession = libcmis::SessionFactory::createSession(
- OUSTR_TO_STDSTR( m_aURL.getBindingUrl( ) ),
- rUsername, rPassword, OUSTR_TO_STDSTR( m_aURL.getRepositoryId( ) ), false, oauth2Data );
- if ( m_pSession == nullptr )
- {
- // Fail: session was not created
- ucbhelper::cancelCommandExecution(
- ucb::IOErrorCode_INVALID_DEVICE,
- generateErrorArguments(m_aURL),
- xEnv);
- }
- else if ( m_pSession->getRepository() == nullptr )
- {
- // Fail: no repository or repository is invalid
- ucbhelper::cancelCommandExecution(
- ucb::IOErrorCode_INVALID_DEVICE,
- generateErrorArguments(m_aURL),
- xEnv,
- "error accessing a repository");
+ // Initiate a CMIS session and register it as we found nothing
+ libcmis::OAuth2DataPtr oauth2Data;
+ if ( m_aURL.getBindingUrl( ) == GDRIVE_BASE_URL )
+ oauth2Data.reset( new libcmis::OAuth2Data(
+ GDRIVE_AUTH_URL, GDRIVE_TOKEN_URL,
+ GDRIVE_SCOPE, GDRIVE_REDIRECT_URI,
+ GDRIVE_CLIENT_ID, GDRIVE_CLIENT_SECRET ) );
+ if ( m_aURL.getBindingUrl().startsWith( ALFRESCO_CLOUD_BASE_URL ) )
+ oauth2Data.reset( new libcmis::OAuth2Data(
+ ALFRESCO_CLOUD_AUTH_URL, ALFRESCO_CLOUD_TOKEN_URL,
+ ALFRESCO_CLOUD_SCOPE, ALFRESCO_CLOUD_REDIRECT_URI,
+ ALFRESCO_CLOUD_CLIENT_ID, ALFRESCO_CLOUD_CLIENT_SECRET ) );
+ if ( m_aURL.getBindingUrl( ) == ONEDRIVE_BASE_URL )
+ {
+ libcmis::SessionFactory::setOAuth2AuthCodeProvider( authProvider.onedriveAuthCodeFallback );
+ oauth2Data.reset( new libcmis::OAuth2Data(
+ ONEDRIVE_AUTH_URL, ONEDRIVE_TOKEN_URL,
+ ONEDRIVE_SCOPE, ONEDRIVE_REDIRECT_URI,
+ ONEDRIVE_CLIENT_ID, ONEDRIVE_CLIENT_SECRET ) );
+ }
+ try
+ {
+ m_pSession = libcmis::SessionFactory::createSession(
+ OUSTR_TO_STDSTR( m_aURL.getBindingUrl( ) ),
+ rUsername, rPassword, OUSTR_TO_STDSTR( m_aURL.getRepositoryId( ) ), false, oauth2Data );
+
+ if ( m_pSession == nullptr )
+ {
+ // Fail: session was not created
+ ucbhelper::cancelCommandExecution(
+ ucb::IOErrorCode_INVALID_DEVICE,
+ generateErrorArguments(m_aURL),
+ xEnv);
+ }
+ else if ( m_pSession->getRepository() == nullptr )
+ {
+ // Fail: no repository or repository is invalid
+ ucbhelper::cancelCommandExecution(
+ ucb::IOErrorCode_INVALID_DEVICE,
+ generateErrorArguments(m_aURL),
+ xEnv,
+ "error accessing a repository");
+ }
+ else
+ {
+ m_pProvider->registerSession(sSessionId, m_aURL.getUsername( ), m_pSession);
+ }
+
+ bIsDone = true;
+ }
+ catch( const libcmis::Exception & e )
+ {
+ if ( e.getType().compare( "permissionDenied" ) != 0 )
+ throw;
+ }
}
else
{
- m_pProvider->registerSession(sSessionId, m_aURL.getUsername( ), m_pSession);
+ // Silently fail as the user cancelled the authentication
+ ucbhelper::cancelCommandExecution(
+ ucb::IOErrorCode_ABORT,
+ uno::Sequence< uno::Any >( 0 ),
+ xEnv );
+ throw uno::RuntimeException( );
}
}
- else
- {
- // Silently fail as the user cancelled the authentication
- ucbhelper::cancelCommandExecution(
- ucb::IOErrorCode_ABORT,
- uno::Sequence< uno::Any >( 0 ),
- xEnv );
- throw uno::RuntimeException( );
- }
}
return m_pSession;
}
@@ -559,11 +576,13 @@ namespace cmis
catch ( const libcmis::Exception& e )
{
SAL_INFO( "ucb.ucp.cmis", "Unexpected libcmis exception: " << e.what( ) );
+
ucbhelper::cancelCommandExecution(
- ucb::IOErrorCode_GENERAL,
- uno::Sequence< uno::Any >( 0 ),
- xEnv,
- OUString::createFromAscii( e.what( ) ) );
+ ucb::IOErrorCode_GENERAL,
+ uno::Sequence< uno::Any >( 0 ),
+ xEnv,
+ OUString::createFromAscii( e.what( ) ) );
+
}
return bIsFolder;
}
diff --git a/ucb/source/ucp/cmis/cmis_repo_content.cxx b/ucb/source/ucp/cmis/cmis_repo_content.cxx
index 1e4747b..75b3790 100644
--- a/ucb/source/ucp/cmis/cmis_repo_content.cxx
+++ b/ucb/source/ucp/cmis/cmis_repo_content.cxx
@@ -163,59 +163,71 @@ namespace cmis
string rUsername = OUSTR_TO_STDSTR( m_aURL.getUsername( ) );
string rPassword = OUSTR_TO_STDSTR( m_aURL.getPassword( ) );
- if ( authProvider.authenticationQuery( rUsername, rPassword ) )
+
+ bool bIsDone = false;
+
+ while( !bIsDone )
{
- try
+ if ( authProvider.authenticationQuery( rUsername, rPassword ) )
{
- // Create a session to get repositories
- libcmis::OAuth2DataPtr oauth2Data;
- if ( m_aURL.getBindingUrl( ) == GDRIVE_BASE_URL )
- oauth2Data.reset( new libcmis::OAuth2Data(
- GDRIVE_AUTH_URL, GDRIVE_TOKEN_URL,
- GDRIVE_SCOPE, GDRIVE_REDIRECT_URI,
- GDRIVE_CLIENT_ID, GDRIVE_CLIENT_SECRET ) );
- if ( m_aURL.getBindingUrl().startsWith( ALFRESCO_CLOUD_BASE_URL ) )
- oauth2Data.reset( new libcmis::OAuth2Data(
- ALFRESCO_CLOUD_AUTH_URL, ALFRESCO_CLOUD_TOKEN_URL,
- ALFRESCO_CLOUD_SCOPE, ALFRESCO_CLOUD_REDIRECT_URI,
- ALFRESCO_CLOUD_CLIENT_ID, ALFRESCO_CLOUD_CLIENT_SECRET ) );
- if ( m_aURL.getBindingUrl( ) == ONEDRIVE_BASE_URL )
+ try
{
- libcmis::SessionFactory::setOAuth2AuthCodeProvider( authProvider.onedriveAuthCodeFallback );
- oauth2Data.reset( new libcmis::OAuth2Data(
- ONEDRIVE_AUTH_URL, ONEDRIVE_TOKEN_URL,
- ONEDRIVE_SCOPE, ONEDRIVE_REDIRECT_URI,
- ONEDRIVE_CLIENT_ID, ONEDRIVE_CLIENT_SECRET ) );
+ // Create a session to get repositories
+ libcmis::OAuth2DataPtr oauth2Data;
+ if ( m_aURL.getBindingUrl( ) == GDRIVE_BASE_URL )
+ oauth2Data.reset( new libcmis::OAuth2Data(
+ GDRIVE_AUTH_URL, GDRIVE_TOKEN_URL,
+ GDRIVE_SCOPE, GDRIVE_REDIRECT_URI,
+ GDRIVE_CLIENT_ID, GDRIVE_CLIENT_SECRET ) );
+ if ( m_aURL.getBindingUrl().startsWith( ALFRESCO_CLOUD_BASE_URL ) )
+ oauth2Data.reset( new libcmis::OAuth2Data(
+ ALFRESCO_CLOUD_AUTH_URL, ALFRESCO_CLOUD_TOKEN_URL,
+ ALFRESCO_CLOUD_SCOPE, ALFRESCO_CLOUD_REDIRECT_URI,
+ ALFRESCO_CLOUD_CLIENT_ID, ALFRESCO_CLOUD_CLIENT_SECRET ) );
+ if ( m_aURL.getBindingUrl( ) == ONEDRIVE_BASE_URL )
+ {
+ libcmis::SessionFactory::setOAuth2AuthCodeProvider( authProvider.onedriveAuthCodeFallback );
+ oauth2Data.reset( new libcmis::OAuth2Data(
+ ONEDRIVE_AUTH_URL, ONEDRIVE_TOKEN_URL,
+ ONEDRIVE_SCOPE, ONEDRIVE_REDIRECT_URI,
+ ONEDRIVE_CLIENT_ID, ONEDRIVE_CLIENT_SECRET ) );
+ }
+
+ std::unique_ptr<libcmis::Session> session(libcmis::SessionFactory::createSession(
+ OUSTR_TO_STDSTR( m_aURL.getBindingUrl( ) ),
+ rUsername, rPassword, "", false, oauth2Data ));
+ if (!session)
+ ucbhelper::cancelCommandExecution(
+ ucb::IOErrorCode_INVALID_DEVICE,
+ uno::Sequence< uno::Any >( 0 ),
+ xEnv );
+ m_aRepositories = session->getRepositories( );
+
+ bIsDone = true;
}
+ catch ( const libcmis::Exception& e )
+ {
+ SAL_INFO( "ucb.ucp.cmis", "Error getting repositories: " << e.what() );
- std::unique_ptr<libcmis::Session> session(libcmis::SessionFactory::createSession(
- OUSTR_TO_STDSTR( m_aURL.getBindingUrl( ) ),
- rUsername, rPassword, "", false, oauth2Data ));
- if (!session)
- ucbhelper::cancelCommandExecution(
+ if ( e.getType().compare( "permissionDenied" ) != 0 )
+ {
+ ucbhelper::cancelCommandExecution(
ucb::IOErrorCode_INVALID_DEVICE,
uno::Sequence< uno::Any >( 0 ),
xEnv );
- m_aRepositories = session->getRepositories( );
+ }
+ }
}
- catch (const libcmis::Exception& e)
+ else
{
- SAL_INFO( "ucb.ucp.cmis", "Error getting repositories: " << e.what() );
+ // Throw user cancelled exception
ucbhelper::cancelCommandExecution(
- ucb::IOErrorCode_INVALID_DEVICE,
+ ucb::IOErrorCode_ABORT,
uno::Sequence< uno::Any >( 0 ),
- xEnv );
+ xEnv,
+ "Authentication cancelled" );
}
}
- else
- {
- // Throw user cancelled exception
- ucbhelper::cancelCommandExecution(
- ucb::IOErrorCode_ABORT,
- uno::Sequence< uno::Any >( 0 ),
- xEnv,
- "Authentication cancelled" );
- }
}
}
More information about the Libreoffice-commits
mailing list