Logo Search packages:      
Sourcecode: kmess version File versions  Download package

void PassportLoginService::sendSecureRequest ( SoapMessage message,
const QString &  requiredTokenName = QString() 
) [protected, inherited]

Send the authenticated SOAP request from a subclass.

For internal use only.

This method sends authenticated SOAP messages. It first needs to verify if the session's ticket tokens are still valid - and if not, request new ones then sends the request.

Parameters:
message The SOAP response message.

Definition at line 768 of file passportloginservice.cpp.

References SoapMessage::getHeader(), CurrentAccount::getToken(), PassportLoginService::inProgressRequests_, PassportLoginService::isWaitingForNewTokens_, PassportLoginService::login(), PassportLoginService::queuedRequests_, HttpSoapConnection::sendRequest(), and PassportLoginService::tokenExpirationDates_.

Referenced by AddressBookService::addContact(), AddressBookService::contactUpdate(), AddressBookService::createAddressBook(), OfflineImService::deleteMessages(), PassportLoginService::parseSoapFault(), PassportLoginService::parseSoapResult(), AddressBookService::retrieveAddressBook(), AddressBookService::retrieveGleams(), AddressBookService::retrieveMembershipLists(), and OfflineImService::storeMessage().

{
  // Send requests without authentication
  if( requiredTokenName.isEmpty() )
  {
    sendRequest( message );
    return;
  }

#ifdef KMESSDEBUG_PASSPORTLOGINSERVICE
  kDebug() << "Sending secure request with token:" << requiredTokenName;
#endif

  const QString &tokenValue( currentAccount_->getToken( requiredTokenName ) );
  const QDateTime &tokenExpiration( tokenExpirationDates_[ requiredTokenName ] );

  int timeDifference = QDateTime::currentDateTime().secsTo( tokenExpiration );

#ifdef KMESSDEBUG_PASSPORTLOGINSERVICE
  kDebug() << "Token has a value?" << (!tokenValue.isEmpty());
  kDebug() << "Current time:" << QDateTime::currentDateTime();
  kDebug() << "Token expires on:" << tokenExpiration << ", that is within seconds:" << timeDifference;
#endif

  // If there is no value for this token, or the token is about to expire, ask a new one
  if( tokenValue.isEmpty() || timeDifference < 10 )
  {
#ifdef KMESSDEBUG_PASSPORTLOGINSERVICE
    kDebug() << "Token is expired or invalid.";
#endif

    // Queue the message
    if( ! queuedRequests_.contains( message ) )
    {
      queuedRequests_.insert( message, requiredTokenName );
    }

    // We're already waiting for new tokens
    if( isWaitingForNewTokens_ )
    {
#ifdef KMESSDEBUG_PASSPORTLOGINSERVICE
      kDebug() << "Already requesting new tokens.";
#endif
      return;
    }

#ifdef KMESSDEBUG_PASSPORTLOGINSERVICE
    kDebug() << "Asking for new tokens.";
#endif

    // Ask for new tokens, altogether instead of just one at a time,
    // for convenience and bandwidth saving
    login();
    return;
  }

#ifdef KMESSDEBUG_PASSPORTLOGINSERVICE
  kDebug() << "Token is valid, adding it to the request.";
#endif

  // Insert the token value within the SOAP message header
  QDomNodeList list;
  QDomElement header( message->getHeader().toElement() );

  list = header.elementsByTagName( "TicketToken" );

  // There is no <TicketToken> tag: search for the <Ticket> tag
  if( list.isEmpty() )
  {
    list = header.elementsByTagName( "Ticket" );
  }

  // None of the ticket token tags were found, send the message as is
  if( list.isEmpty() )
  {
    kWarning() << "Token tag not found! Sending the request as is.";

    sendRequest( message );
    return;
  }

  for( uint index = 0; index < list.length(); ++index )
  {
    QDomElement item( list.item( index ).toElement() );

    // <TicketToken> tags directly contain the token value
    if( item.tagName() == "TicketToken" )
    {
#ifdef KMESSDEBUG_PASSPORTLOGINSERVICE
      kDebug() << "TicketToken tag found!";
#endif

      // If there is a child text node, simply replace its text
      if( item.firstChild().nodeType() == QDomNode::TextNode )
      {
        item.firstChild().toText().setNodeValue( tokenValue );
      }
      else
      {
        QDomText text( item.ownerDocument().createTextNode( tokenValue ) );
        item.appendChild( text );
      }
      break;
    }

    // <Ticket> tags contain the token value within the "passport" attribute
    if( item.tagName() == "Ticket" )
    {
#ifdef KMESSDEBUG_PASSPORTLOGINSERVICE
      kDebug() << "Ticket tag found!";
#endif
      item.setAttribute( "passport", tokenValue );
      break;
    }
  }

  // Remove the message from the queue (if it was there) and add it to the in progress messages
  if( queuedRequests_.contains( message ) )
  {
    queuedRequests_.remove( message );
  }
  inProgressRequests_.insert( message, requiredTokenName );

#ifdef KMESSDEBUG_PASSPORTLOGINSERVICE
  kDebug() << "Sending authenticated request.";
#endif

  // Send the changed message
  sendRequest( message );
}


Generated by  Doxygen 1.6.0   Back to index