webservices/wsstar/wsstarplugin/src/wsstarserviceupdatehandler.cpp
changeset 0 62f9d29f7211
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2006-2006 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 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 #include "wsstarserviceupdatehandler.h"
       
    29 #include "wsstartrustclient.h"
       
    30 #include "sendebug.h"
       
    31 #include "senlogger.h"
       
    32 #include "SenSoapFault.h"
       
    33 #include "SenSoapMessage.h"
       
    34 #include "wsstarservicesession.h"
       
    35 #include "SenXmlUtils.h"
       
    36 #include "wsstarrstresponse.h"
       
    37 
       
    38 namespace WSSecureConversation
       
    39 { 
       
    40     //---------Faults data
       
    41     _LIT8( KBadContextToken, "BadContextToken");
       
    42 }
       
    43 namespace WSSecurity
       
    44 { 
       
    45     //---------Faults data
       
    46     _LIT8( KMessageExpired, "MessageExpired");
       
    47     _LIT8( KInvalidSecurity, "InvalidSecurity");
       
    48 }
       
    49 
       
    50 class CWSStarHandlerContext;
       
    51 // Create instance of concrete ECOM interface implementation
       
    52 CWSStarServiceUpdateHandler* CWSStarServiceUpdateHandler::NewL(TAny* aHandlerCtx)
       
    53     {
       
    54     
       
    55     MSenHandlerContext* handlerCtx =
       
    56         reinterpret_cast<MSenHandlerContext*>(aHandlerCtx);
       
    57     CWSStarServiceUpdateHandler* self   = new (ELeave) CWSStarServiceUpdateHandler(*handlerCtx);
       
    58     CleanupStack::PushL (self);
       
    59     self->ConstructL();
       
    60     CleanupStack::Pop(self);
       
    61     return self;
       
    62     }
       
    63 
       
    64 // Constructor
       
    65 CWSStarServiceUpdateHandler::CWSStarServiceUpdateHandler(MSenHandlerContext& aCtx):CSenSessionHandler(aCtx)
       
    66     {
       
    67     
       
    68     }
       
    69 
       
    70 // Destructor
       
    71 CWSStarServiceUpdateHandler::~CWSStarServiceUpdateHandler()
       
    72     {
       
    73     }
       
    74 
       
    75 // Second phase construction.
       
    76 void CWSStarServiceUpdateHandler::ConstructL()
       
    77     {
       
    78     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarServiceUpdateHandler::ConstructL()")));
       
    79     const TDesC8* version = iHandlerContext.GetDesC8L(HandlerContextKey::KVersion);
       
    80     if (version && 
       
    81         (*version == WSTrust::KTrustNamespace200502 || *version == WSTrust::KTrustNamespace200404))
       
    82         {
       
    83         iVersion = version;
       
    84         }
       
    85     else
       
    86         {
       
    87         iVersion = &WSTrust::KTrustNamespace200502;
       
    88         }
       
    89     }
       
    90     
       
    91 TInt CWSStarServiceUpdateHandler::InvokeL(MSenSessionContext& aCtx)
       
    92     {
       
    93     CSenSoapEnvelope* message = (CSenSoapEnvelope*)(aCtx.GetAnyL(SenContext::KSenCurrentSoapMessageCtxKey));//codescannerwarnings
       
    94     CWSStarServiceSession* pNewSession = (CWSStarServiceSession*)aCtx.GetSenRemoteServiceSessionL(WSStarContextKeys::KServiceSession());
       
    95     
       
    96     //abstract variable which represent probelm (it is code or subcode depends of soap version)
       
    97     TPtrC8 problem(KNullDesC8);
       
    98     if (message)
       
    99         {
       
   100         if ((aCtx.Direction()==SenContext::EIncoming) ||
       
   101             (aCtx.Direction()==SenContext::EBoth))
       
   102             {  
       
   103             if (message->IsFault())
       
   104                 {
       
   105                 CSenSoapFault* faultElement = message->FaultL();
       
   106                 if (faultElement)
       
   107                     {
       
   108                     if (message->NsUri() == KSenSoap12EnvelopeXmlns)
       
   109                         {
       
   110 //----------------SOAP1.2
       
   111                         TPtrC8 code = faultElement->FaultCode();
       
   112                         const CSenNamespace* nmSpaceCode = faultElement->Namespace(SenXmlUtils::NsPrefix(code), ETrue);
       
   113                         code.Set(SenXmlUtils::LocalName(code));
       
   114                         
       
   115                         if ((
       
   116                             (nmSpaceCode && 
       
   117                             nmSpaceCode->URI() == KSenSoap12EnvelopeXmlns) 
       
   118                             ||
       
   119                             !nmSpaceCode)
       
   120                             &&
       
   121                             code == KSender)
       
   122                             {
       
   123                             TPtrC8 subcode = faultElement->FaultSubcode();
       
   124                             const CSenNamespace* nmSpace = faultElement->Namespace(SenXmlUtils::NsPrefix(subcode), ETrue);
       
   125                             subcode.Set(SenXmlUtils::LocalName(subcode));
       
   126                             
       
   127                             if ((nmSpace && 
       
   128                                 nmSpace->URI() == *iVersion)
       
   129                                 ||
       
   130                                 !nmSpace) 
       
   131                                 {
       
   132                                 problem.Set(subcode);
       
   133                                 }    
       
   134                             }
       
   135                         else if (nmSpaceCode && nmSpaceCode->URI() == KSecurityXmlNs)
       
   136                             {
       
   137                             problem.Set(code);
       
   138                             }
       
   139                         }
       
   140                     else if (message->NsUri() == KSenSoapEnvelopeXmlns)
       
   141                         {
       
   142 //----------------SOAP1.1
       
   143                         TPtrC8 code = faultElement->FaultCode();
       
   144                         const CSenNamespace* nmSpace = faultElement->Namespace(SenXmlUtils::NsPrefix(code), ETrue);
       
   145                         code.Set(SenXmlUtils::LocalName(code));
       
   146                         if ((nmSpace && 
       
   147                             nmSpace->URI() == *iVersion))
       
   148                             {
       
   149                             problem.Set(code);
       
   150                             }    
       
   151                         }
       
   152 //------------------real logic                        
       
   153                     if (problem.Length()>0)
       
   154                         {
       
   155                         if( problem == WSTrust::KInvalidRequest ||
       
   156                             problem == WSTrust::KRequestFailed  ||
       
   157                             problem == WSTrust::KInvalidSecurityToken  ||
       
   158                             problem == WSTrust::KAuthenticationBadElements  ||
       
   159                                    
       
   160                             problem == WSTrust::KBadRequest  ||
       
   161                             problem == WSTrust::KExpiredData  ||
       
   162                             problem == WSTrust::KInvalidTimeRange  ||
       
   163                             problem == WSTrust::KInvalidScope  ||
       
   164                             problem == WSTrust::KUnableToRenew
       
   165                            )
       
   166                            {
       
   167                            ((MSenContext&)aCtx).Update(WSStarSession::KErrorLayer, WSStarSession::ETrust);
       
   168                            }
       
   169                         else if (problem == WSTrust::KRenewNeeded ||
       
   170                         
       
   171                                  problem == WSTrust::KFailedAuthentication ||
       
   172                                  problem == WSTrust::KInvalidSecurityToken ||
       
   173                                  problem == WSSecurity::KInvalidSecurity ||
       
   174                                  problem == WSSecureConversation::KBadContextToken ||
       
   175                                  problem == WSSecurity::KMessageExpired)
       
   176                             {
       
   177 				TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarServiceUpdateHandler::InvokeL")));
       
   178 				TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,problem);
       
   179 				TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarServiceUpdateHandler::InvokeL clear credential")));
       
   180                             ((MSenContext&)aCtx).Update(WSStarSession::KErrorLayer, WSStarSession::ETrust);
       
   181                             ((MSenContext&)aCtx).Update(WSStarContextKeys::KReAuthNeeded, ETrue);
       
   182                             pNewSession->ClearCredentialL();
       
   183                             pNewSession->SetStatusL();//in order to compute state
       
   184                             }
       
   185                         }
       
   186                     }
       
   187                 }
       
   188             else if (message->HasHeader())
       
   189                 {//checking for SCT (SecureContextToken)
       
   190                 CSenElement& el = message->HeaderL();
       
   191                 //HBufC8* msg = message->HeaderL().AsXmlL();
       
   192                                 
       
   193                 CSenElement* detached = el.DetachL();
       
   194                 CleanupStack::PushL(detached);
       
   195                 CSenElement& body = message->BodyL();
       
   196                 HBufC8* msg = detached->AsXmlL();
       
   197                 CleanupStack::PushL(msg);
       
   198                 message->AsElement().InsertElementL(*detached, body);
       
   199                 CleanupStack::Pop(2, detached);
       
   200                 CleanupStack::PushL(msg);
       
   201                 
       
   202                 //in case MSP Guide v3.0, seems that SCT comes in Body (not in header)
       
   203                 CWSStarRSTResponse* rstResponse =
       
   204                         CWSStarRSTResponse::NewLC(FALSE, KNullDesC8, iVersion);
       
   205                 //policy namespace has not be set, is not neccessary for SCT
       
   206                 CSenXmlReader* reader = const_cast<CSenXmlReader*>(aCtx.GetParser());
       
   207                 rstResponse->SetReader(*reader);
       
   208                 rstResponse->BuildFrom(*msg);
       
   209                 if (rstResponse->IsResponse())
       
   210                     {
       
   211                     if (rstResponse->IsContextToken())
       
   212                         {
       
   213                         CWSStarSessionContext* ssCtx = pNewSession->SessionContext();
       
   214                         ssCtx->SetTokenKeysL(*rstResponse, NULL, ETrue,ETrue);
       
   215                         #ifdef _SENDEBUG
       
   216                                 TPtrC8 endpoint = pNewSession->Endpoint();
       
   217                                 _LIT8(KCredsLogLine, "SCT has been delivered by backend TO service (%S), so present token will be replaced");
       
   218                                 CREDLOG_FORMAT((KSenCredsLogChannel, KSenCredsLogLevelNormal, KCredsLogLine,  &endpoint));
       
   219                         #endif           
       
   220                         //----update expires
       
   221                         /*
       
   222                         timestamp is calcualted
       
   223                         
       
   224                         if (rstResponse->CredentialExpires().Length())
       
   225                             {
       
   226                             ssCtx->Update(WSStarContextKeys::KTimestampExpires, rstResponse->CredentialExpires());
       
   227                             }
       
   228                         else
       
   229                             {
       
   230                             //ssCtx->Remove(WSStarContextKeys::KTimestampExpires);
       
   231                             }
       
   232                         //----update created
       
   233                         if (rstResponse->CredentialCreated().Length())
       
   234                             {
       
   235                             ssCtx->Update(WSStarContextKeys::KTimestampCreated, rstResponse->CredentialCreated());
       
   236                             }
       
   237                         else
       
   238                             {
       
   239                             ssCtx->Remove(WSStarContextKeys::KTimestampCreated);
       
   240                             }
       
   241                             */
       
   242                         //---remove SCT from BODY, it is not a bisness logic
       
   243                         //namespace if in SOAP element still will be not visible for user 
       
   244                         // becouse only HandleMessage(Body) is supported
       
   245                         
       
   246                         //after wave11 increment SCT is only in header so below logic is just for case
       
   247                         /*CSenElement& body = message->BodyL();
       
   248                         CSenElement* sct = GetSCTElementL(body);
       
   249                         if (sct)
       
   250                             {
       
   251                             sct = sct->DetachL();
       
   252                             delete sct;
       
   253                             sct = NULL;
       
   254                             }*/
       
   255                         //----end removing SCT from BODY
       
   256                         }
       
   257                     }
       
   258                 CleanupStack::PopAndDestroy(2, msg);
       
   259                 }
       
   260             }
       
   261         }
       
   262     return KErrNone;       
       
   263     }
       
   264     
       
   265 SenHandler::THandlerDirection CWSStarServiceUpdateHandler::Direction() const
       
   266     {
       
   267     return SenHandler::EIncoming;
       
   268     };
       
   269 SenHandler::THandlerPhase CWSStarServiceUpdateHandler::Phase()
       
   270     {
       
   271     return SenHandler::EMessage;
       
   272     };
       
   273 
       
   274 //---------------------------------------------------------------------------
       
   275 // Logger using during DEBUG mode
       
   276 //---------------------------------------------------------------------------
       
   277 //    
       
   278 RFileLogger* CWSStarServiceUpdateHandler::Log() const
       
   279     {
       
   280     RFileLogger* pLog = NULL;
       
   281     TRAP_IGNORE( pLog = (RFileLogger*)iHandlerContext.GetAnyL(HandlerContextKey::KLogger); )
       
   282     return pLog;
       
   283     }
       
   284 
       
   285 TInt CWSStarServiceUpdateHandler::InitL(MSenHandlerContext& aCtx)
       
   286     {
       
   287     iHandlerContext = aCtx;
       
   288     return KErrNone;
       
   289     }
       
   290 
       
   291 CSenElement* CWSStarServiceUpdateHandler::GetSCTElementL(CSenElement& aParent)
       
   292     {
       
   293     CSenElement* sct = NULL;
       
   294     sct = aParent.Element(*iVersion, WSTrust::KRSTResponseTag);
       
   295     if (!sct)
       
   296         {
       
   297         RPointerArray<CSenElement>& elementsBody = aParent.ElementsL();
       
   298         TInt count(elementsBody.Count());
       
   299         TInt i=0;
       
   300         while (i<count && !sct)
       
   301             {
       
   302             sct = GetSCTElementL(*elementsBody[i]);
       
   303             i++;
       
   304             }
       
   305         }
       
   306     return sct;
       
   307     }
       
   308 // END OF FILE
       
   309