webservices/wsstar/wsstarplugin/src/wsstarcobrandinghandler.cpp
changeset 0 62f9d29f7211
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 //co-branding CR
       
    22 #include <e32std.h>
       
    23 #include "wsstarcobrandinghandler.h"
       
    24 #include "wsstarcobrandingclient.h"
       
    25 #include "senpointermap.h"
       
    26 #include "wspolicy.h"
       
    27 #include "sendebug.h"
       
    28 #include "wsstardictionary.h"
       
    29 #include "MSenServicePolicy.h"
       
    30 #include "wsstarpolicymanager.h"
       
    31 #include "senlogger.h"
       
    32 
       
    33 //---------------------------------------------------------------------------
       
    34 // Create instance of concrete ECOM interface implementation
       
    35 //---------------------------------------------------------------------------
       
    36 //
       
    37 CWSStarCoBrandingHandler* CWSStarCoBrandingHandler::NewL(TAny* aHandlerCtx)
       
    38     {    
       
    39     MSenHandlerContext* handlerCtx = reinterpret_cast<MSenHandlerContext*>(aHandlerCtx);
       
    40     CWSStarCoBrandingHandler* self   = new (ELeave) CWSStarCoBrandingHandler(*handlerCtx);
       
    41     CleanupStack::PushL (self);
       
    42     self->ConstructL();
       
    43     CleanupStack::Pop(self);
       
    44     return self;
       
    45     }
       
    46 
       
    47 
       
    48 //---------------------------------------------------------------------------
       
    49 // Constructor
       
    50 //---------------------------------------------------------------------------
       
    51 //
       
    52 CWSStarCoBrandingHandler::CWSStarCoBrandingHandler(MSenHandlerContext& aCtx):CSenSessionHandler(aCtx)
       
    53     {
       
    54     }
       
    55 
       
    56 //---------------------------------------------------------------------------
       
    57 // Destructor
       
    58 //---------------------------------------------------------------------------
       
    59 //
       
    60 CWSStarCoBrandingHandler::~CWSStarCoBrandingHandler()
       
    61     {
       
    62     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("~CWSStarCoBrandingHandler::~CWSStarCoBrandingHandler()")));
       
    63     }
       
    64 
       
    65 //---------------------------------------------------------------------------
       
    66 // Second phase construction.
       
    67 //---------------------------------------------------------------------------
       
    68 //
       
    69 void CWSStarCoBrandingHandler::ConstructL()
       
    70     {
       
    71     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarCoBrandingHandler::ConstructL()")));
       
    72     }
       
    73 
       
    74 //---------------------------------------------------------------------------
       
    75 // the most emergent method in message handler interface.
       
    76 // Each sub-class must implement this method thus providing message processing routine.
       
    77 //---------------------------------------------------------------------------
       
    78 //
       
    79 TInt CWSStarCoBrandingHandler::InvokeL(MSenSessionContext& aCtx)
       
    80     {
       
    81     TLSLOG_L( KSenCoreServiceManagerLogChannelBase, KMinLogLevel, "CWSStarCoBrandingHandler::InvokeL(MSenMessageContext& aCtx)" );
       
    82 
       
    83 //getting data from input
       
    84     CWSStarServiceSession* pNewSession =
       
    85             (CWSStarServiceSession*)aCtx.GetSenRemoteServiceSessionL(
       
    86             WSStarContextKeys::KServiceSession());
       
    87     if (pNewSession->ProviderID() == KNullDesC8)
       
    88         {
       
    89         return KErrNone;
       
    90         }
       
    91 
       
    92 //try to find identity provider for curennt webService using its ProviderId
       
    93     CSenIdentityProvider* pIdentityProvider = IdentityProviderFromCoreL(
       
    94             pNewSession->ProviderID());
       
    95     if (!pIdentityProvider)
       
    96         {
       
    97         return KErrNotFound;
       
    98         }
       
    99         
       
   100     
       
   101     CWSStarTrustClient* pSTSClient = STSClientL(pIdentityProvider);
       
   102     if (pSTSClient)
       
   103             {
       
   104  
       
   105  
       
   106             CSIF* sif = (CSIF*)iHandlerContext.GetAnyL(HandlerContextKey::KSIF());
       
   107         
       
   108         
       
   109             CWSStarServiceSession* wsSTSSession =   
       
   110                                             pSTSClient->GetSTSSessionL();                           
       
   111  
       
   112             CWSStarCoBrandingClient* wsStarCoBrandingClient = 
       
   113                                 CWSStarCoBrandingClient::NewL(*sif,*Log());
       
   114             
       
   115             if (wsStarCoBrandingClient)
       
   116                     {
       
   117                     
       
   118                     CleanupStack:: PushL(wsStarCoBrandingClient);
       
   119                     
       
   120                     TInt error(KErrNone);
       
   121                     wsStarCoBrandingClient->SetHandlerCtx(&iHandlerContext);
       
   122                     //wsStarCoBrandingClient->SetVersion(iVersion);
       
   123                     
       
   124                     wsStarCoBrandingClient->SetCoBrandingSessionL(wsSTSSession);
       
   125 
       
   126                     //validate session of concrete WebService
       
   127                     HBufC8* errorMessage = NULL;
       
   128                     TInt leaveCode( KErrNone );
       
   129                     TRAP( leaveCode, error = wsStarCoBrandingClient->FetchSCTL( *pNewSession, errorMessage ); )    
       
   130 #ifdef _SENDEBUG
       
   131                     if( leaveCode )
       
   132                         {
       
   133                         TLSLOG_L( KSenCoreServiceManagerLogChannelBase, KMinLogLevel, "CWSStarCoBrandingHandler::InvokeL(MSenMessageContext& aCtx):" );
       
   134                         TLSLOG_L( KSenCoreServiceManagerLogChannelBase, KMinLogLevel, "- wsStarCoBrandingClient->FetchSCTL() leaved!" );
       
   135                         }
       
   136 #endif // _SENDEBUG                    
       
   137                     leaveCode = 0; // not used in release builds
       
   138                     //((MSenContext&)aCtx).Update(WSStarContextKeys::KReAuthNeeded, EFalse);
       
   139                     if (errorMessage)
       
   140                         {
       
   141                        ((MSenContext&)aCtx).Update(WSStarContextKeys:: KErrMessage,  *errorMessage);
       
   142                         }
       
   143                     delete errorMessage;
       
   144                     errorMessage = NULL;
       
   145                     //if credential expired session will use validator to obtain new
       
   146                     
       
   147                     // Core / XML DAO takes ownership of new session (will keep in array of SD):
       
   148                     // - new session HAS
       
   149                     //      - credential
       
   150                     //      - context which keep for example key for signing message        
       
   151                     // - if duplicate (equal primary keys) exists, it is deleted
       
   152                     
       
   153                     CleanupStack:: PopAndDestroy(wsStarCoBrandingClient);
       
   154                      
       
   155                     return error;
       
   156                     }
       
   157                else
       
   158                     {
       
   159                     return KErrNotFound;
       
   160                     }
       
   161                      
       
   162             }
       
   163        else
       
   164             {
       
   165             return KErrNotFound;
       
   166             }
       
   167             
       
   168                                 
       
   169      }
       
   170 
       
   171 //---------------------------------------------------------------------------
       
   172 // Obtain or construct STS client
       
   173 //---------------------------------------------------------------------------
       
   174 //
       
   175   
       
   176 CWSStarTrustClient* CWSStarCoBrandingHandler::STSClientL(CSenIdentityProvider*& aIdentityProvider)
       
   177 {
       
   178     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KNormalLogLevel,(_L("CWSStarPlugin::STSClientL")));
       
   179 
       
   180     CWSStarTrustClient* pSTSClient = NULL;
       
   181     //providerId from Identities.xml
       
   182     TPtrC8 providerId(KNullDesC8);
       
   183     if(aIdentityProvider)
       
   184         {
       
   185         providerId.Set(aIdentityProvider->ProviderID());
       
   186         }
       
   187 
       
   188     RPointerArray<CSenWSDescription> serviceDescriptions;
       
   189     CleanupClosePushL(serviceDescriptions);
       
   190         
       
   191     //try to find STS session in cache,some STS can be registered
       
   192     TInt retVal(KErrNone);
       
   193     
       
   194     TRAPD(error, retVal = iHandlerContext.GetSenCoreServiceManager()->ServiceDescriptionsL(serviceDescriptions, KWSStarSTSContract()));
       
   195     if(!retVal&&!error)
       
   196         {
       
   197         RPointerArray<CSenWSDescription> matches;
       
   198         CleanupClosePushL(matches);
       
   199         
       
   200         for(TInt i = 0; i < serviceDescriptions.Count(); i++)
       
   201             {
       
   202             //select XMLDescription from DAO where contract = STS, so we can cast
       
   203             pSTSClient = (CWSStarTrustClient*)serviceDescriptions[i];
       
   204             if(providerId.Length()>0)
       
   205                 {
       
   206                 TPtrC8 providerIDFromDescription = pSTSClient->ProviderID();
       
   207                 if(providerIDFromDescription == providerId)
       
   208                     {
       
   209                     matches.AppendL(pSTSClient);
       
   210                     }
       
   211                 }
       
   212             else
       
   213                 {
       
   214                 matches.AppendL(pSTSClient);
       
   215                 }
       
   216             }
       
   217         if(matches.Count())
       
   218             {
       
   219             pSTSClient =
       
   220                 reinterpret_cast<CWSStarTrustClient*>(matches[0]);
       
   221             pSTSClient->SetAccount(aIdentityProvider);
       
   222             }
       
   223         else
       
   224             {
       
   225             TLSLOG(KSenCoreServiceManagerLogChannelBase  , KNormalLogLevel,(_L("CWSStarValidateHandler::STSClient - No matching STS description available!")));
       
   226             pSTSClient = NULL;
       
   227             }
       
   228     
       
   229         //if we find multi sts client (different only with lifetime, probably Secure Context Token lifetime)
       
   230         if(matches.Count() > 1)
       
   231             {
       
   232             // search for a instance with longest validity
       
   233             for(TInt i = matches.Count()-1; i > 0 ; i--)
       
   234                 {
       
   235                 CWSStarTrustClient* pNewerSTSClient =
       
   236                   reinterpret_cast<CWSStarTrustClient*>(matches[i]);
       
   237                 CWSStarServiceSession* newerSession = (CWSStarServiceSession*)pNewerSTSClient->ServiceSession();
       
   238                 CWSStarServiceSession* session = (CWSStarServiceSession*)pSTSClient->ServiceSession();
       
   239                 
       
   240 				if(newerSession && session) // STSClient Session was not set, if not validated 
       
   241 					{
       
   242 					if(newerSession->ValidUntilL() > session->ValidUntilL())
       
   243 					  	{
       
   244 					    pSTSClient = pNewerSTSClient;
       
   245 					    pSTSClient->SetAccount(aIdentityProvider);
       
   246 					    }
       
   247 					}
       
   248                 }
       
   249             }
       
   250             CleanupStack::PopAndDestroy(2, &serviceDescriptions);
       
   251         }
       
   252     else
       
   253         {
       
   254           CleanupStack::PopAndDestroy(&serviceDescriptions);
       
   255         }
       
   256     
       
   257     
       
   258     //no session, so we have create new STS client, temporary code 
       
   259 
       
   260     //- if (!pSTSClient)
       
   261     //-    {
       
   262     //-    CSIF* sif = (CSIF*)iHandlerContext.GetAnyL(HandlerContextKey::KSIF());
       
   263     //-    pSTSClient = CWSStarTrustClient::NewL(*sif,*Log());
       
   264     //-    }
       
   265     return pSTSClient;
       
   266 }
       
   267 
       
   268 
       
   269 //---------------------------------------------------------------------------
       
   270 // 
       
   271 //---------------------------------------------------------------------------
       
   272 //  
       
   273 SenHandler::THandlerDirection CWSStarCoBrandingHandler::Direction() const
       
   274     {
       
   275     return SenHandler::EBoth;
       
   276     }
       
   277 
       
   278 //---------------------------------------------------------------------------
       
   279 // 
       
   280 //---------------------------------------------------------------------------
       
   281 //    
       
   282 SenHandler::THandlerPhase CWSStarCoBrandingHandler::Phase()
       
   283     {
       
   284     return SenHandler::EValidate;
       
   285     }
       
   286 //---------------------------------------------------------------------------
       
   287 // 
       
   288 //---------------------------------------------------------------------------
       
   289 //   
       
   290 CSenIdentityProvider* CWSStarCoBrandingHandler::IdentityProviderFromCoreL(
       
   291                                             const TDesC8& aProviderID)
       
   292     {
       
   293     TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KNormalLogLevel,"CWSStarCoBrandingHandler::IdentityProviderLFromCore");
       
   294     CSenIdentityProvider* pIdentityProvider = NULL;
       
   295     if(aProviderID.Length() > 0)
       
   296         {
       
   297         CDesC8ArrayFlat* array = new (ELeave) CDesC8ArrayFlat(1);
       
   298         CleanupStack::PushL(array);
       
   299         array->AppendL(aProviderID);
       
   300         pIdentityProvider = iHandlerContext.GetSenCoreServiceManager()->
       
   301                 IdentityProviderL(*array, ETrue);
       
   302         CleanupStack::PopAndDestroy(array);
       
   303         }
       
   304     return pIdentityProvider;
       
   305     }
       
   306 
       
   307 //---------------------------------------------------------------------------
       
   308 // Init implementation
       
   309 //---------------------------------------------------------------------------
       
   310 //
       
   311 TInt CWSStarCoBrandingHandler::InitL(MSenHandlerContext& aCtx)
       
   312     {
       
   313     iHandlerContext = aCtx;
       
   314     return KErrNone;
       
   315     }
       
   316 
       
   317 //---------------------------------------------------------------------------
       
   318 // 
       
   319 //---------------------------------------------------------------------------
       
   320 //    
       
   321 RFileLogger* CWSStarCoBrandingHandler::Log() const
       
   322     {
       
   323     RFileLogger* pLog = NULL;
       
   324     TRAP_IGNORE( pLog = (RFileLogger*)iHandlerContext.GetAnyL(HandlerContextKey::KLogger); )
       
   325     return pLog;
       
   326     }
       
   327     
       
   328 // END OF FILE
       
   329 
       
   330