LCOV - code coverage report
Current view: top level - ucb/source/ucp/cmis - auth_provider.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 40 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #define OUSTR_TO_STDSTR(s) string( OUStringToOString( s, RTL_TEXTENCODING_UTF8 ).getStr() )
      11             : #define STD_TO_OUSTR( str ) OUString( str.c_str(), str.length( ), RTL_TEXTENCODING_UTF8 )
      12             : 
      13             : #include <com/sun/star/task/XInteractionHandler.hpp>
      14             : 
      15             : #include <ucbhelper/simpleauthenticationrequest.hxx>
      16             : #include <ucbhelper/authenticationfallback.hxx>
      17             : 
      18             : #include "auth_provider.hxx"
      19             : 
      20             : using namespace com::sun::star;
      21             : using namespace std;
      22             : 
      23             : namespace cmis
      24             : {
      25             :     com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment> 
      26           0 :         AuthProvider::sm_xEnv;
      27           0 :     bool AuthProvider::authenticationQuery( string& username, string& password )
      28             :     {
      29           0 :         if ( m_xEnv.is() )
      30             :         {
      31             :             uno::Reference< task::XInteractionHandler > xIH
      32           0 :                 = m_xEnv->getInteractionHandler();
      33             : 
      34           0 :             if ( xIH.is() )
      35             :             {
      36             :                 rtl::Reference< ucbhelper::SimpleAuthenticationRequest > xRequest
      37             :                     = new ucbhelper::SimpleAuthenticationRequest(
      38             :                         m_sUrl, m_sBindingUrl, OUString(),
      39           0 :                         STD_TO_OUSTR( username ),
      40           0 :                         STD_TO_OUSTR( password ),
      41           0 :                         OUString(), true, false );
      42           0 :                 xIH->handle( xRequest.get() );
      43             : 
      44             :                 rtl::Reference< ucbhelper::InteractionContinuation > xSelection
      45           0 :                     = xRequest->getSelection();
      46             : 
      47           0 :                 if ( xSelection.is() )
      48             :                 {
      49             :                     // Handler handled the request.
      50             :                     uno::Reference< task::XInteractionAbort > xAbort(
      51           0 :                         xSelection.get(), uno::UNO_QUERY );
      52           0 :                     if ( !xAbort.is() )
      53             :                     {
      54             :                         const rtl::Reference<
      55             :                             ucbhelper::InteractionSupplyAuthentication > & xSupp
      56           0 :                             = xRequest->getAuthenticationSupplier();
      57             : 
      58           0 :                         username = OUSTR_TO_STDSTR( xSupp->getUserName() );
      59           0 :                         password = OUSTR_TO_STDSTR( xSupp->getPassword() );
      60             : 
      61           0 :                         return true;
      62           0 :                     }
      63           0 :                 }
      64           0 :             }
      65             :         }
      66           0 :         return false;
      67             :     }
      68             : 
      69           0 :     char* AuthProvider::onedriveAuthCodeFallback( const char* url,
      70             :             const char* /*username*/,
      71             :             const char* /*password*/ )
      72             :     {
      73             :         OUString instructions = "Open the following link in your browser and "
      74             :             "paste the code from the URL you have been redirected to in the "
      75             :             "box below. For example:\n"
      76           0 :             "https://login.live.com/oauth20_desktop.srf?code=YOUR_CODE&lc=1033";
      77           0 :         OUString url_oustr( url, strlen( url ), RTL_TEXTENCODING_UTF8 );
      78             :         const com::sun::star::uno::Reference< 
      79           0 :             com::sun::star::ucb::XCommandEnvironment> xEnv = getXEnv( );
      80             : 
      81           0 :         if ( xEnv.is() )
      82             :         {
      83             :             uno::Reference< task::XInteractionHandler > xIH
      84           0 :                 = xEnv->getInteractionHandler();
      85             : 
      86           0 :             if ( xIH.is() )
      87             :             {
      88             :                 rtl::Reference< ucbhelper::AuthenticationFallbackRequest > xRequest
      89             :                     = new ucbhelper::AuthenticationFallbackRequest (
      90           0 :                             instructions, url_oustr );
      91             : 
      92           0 :                 xIH->handle( xRequest.get() );
      93             : 
      94             :                 rtl::Reference< ucbhelper::InteractionContinuation > xSelection
      95           0 :                     = xRequest->getSelection();
      96             : 
      97           0 :                 if ( xSelection.is() )
      98             :                 {
      99             :                     // Handler handled the request.
     100             :                     const rtl::Reference< ucbhelper::InteractionAuthFallback >&
     101           0 :                         xAuthFallback = xRequest->getAuthFallbackInter( );
     102           0 :                     if ( xAuthFallback.is() )
     103             :                     {
     104           0 :                         OUString code = xAuthFallback->getCode( );
     105           0 :                         return strdup( OUSTR_TO_STDSTR( code ).c_str( ) );
     106             :                     }
     107           0 :                 }
     108           0 :             }
     109             :         }
     110             : 
     111           0 :         return strdup( "" );
     112             :     }
     113           0 : }
     114             : 
     115             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11