summaryrefslogtreecommitdiff
path: root/ucb
diff options
context:
space:
mode:
authorSzymon Kłos <eszkadev@gmail.com>2016-03-15 16:25:28 +0100
committerStephan Bergmann <sbergman@redhat.com>2016-05-03 11:59:07 +0000
commitf23c32e4bf42a80455ebae10d830b7ffded4fa9f (patch)
tree44547685b0dcabb246329c778b167f9623b4efd5 /ucb
parent3beb146b34fa931e2d63f4738a3ae69fe286545f (diff)
tdf#98644 : better error message when wrong password entered
Change-Id: Idf4da8000cce43cb66cb94fdfc8be8a3d6909fa6 Reviewed-on: https://gerrit.libreoffice.org/23475 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'ucb')
-rw-r--r--ucb/source/ucp/cmis/cmis_content.cxx125
-rw-r--r--ucb/source/ucp/cmis/cmis_repo_content.cxx90
2 files changed, 123 insertions, 92 deletions
diff --git a/ucb/source/ucp/cmis/cmis_content.cxx b/ucb/source/ucp/cmis/cmis_content.cxx
index e4c64352c2ca..dea8ec7b01ef 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 1e4747b97851..75b3790510e5 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" );
- }
}
}