webservices/wsstar/wsstarmessagehandlers/src/wsstarcredentialcollectorhandler.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 #include "wsstarcredentialcollectorhandler.h"
       
    28 #include "senlogger.h"
       
    29 #include <SenDateUtils.h>
       
    30 
       
    31 // Create instance of concrete ECOM interface implementation
       
    32 CWSStarCredentialCollectorHandler* CWSStarCredentialCollectorHandler::NewL(TAny* aHandlerCtx)
       
    33     {
       
    34     
       
    35     MSenHandlerContext* handlerCtx =
       
    36         reinterpret_cast<MSenHandlerContext*>(aHandlerCtx);
       
    37     CWSStarCredentialCollectorHandler* self = 
       
    38             new(ELeave)CWSStarCredentialCollectorHandler(*handlerCtx);
       
    39     CleanupStack::PushL (self);
       
    40     self->ConstructL();
       
    41     CleanupStack::Pop(self);
       
    42     return self;
       
    43     }
       
    44 
       
    45 // Constructor
       
    46 CWSStarCredentialCollectorHandler::CWSStarCredentialCollectorHandler(MSenHandlerContext& aCtx)
       
    47 :CSenMessageHandler(aCtx)
       
    48     {
       
    49     }
       
    50 
       
    51 // Destructor
       
    52 CWSStarCredentialCollectorHandler::~CWSStarCredentialCollectorHandler()
       
    53     {
       
    54         TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarCredentialCollectorHandler::\
       
    55                          ~CWSStarCredentialCollectorHandler()")));
       
    56     }
       
    57 
       
    58 // Second phase construction.
       
    59 void CWSStarCredentialCollectorHandler::ConstructL()
       
    60     {
       
    61     }
       
    62     
       
    63 TInt CWSStarCredentialCollectorHandler::InvokeL(MSenMessageContext& aCtx)
       
    64     {
       
    65     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarCredentialCollectorHandler::InvokeL(MSenMessageContext& aCtx)")));
       
    66     TInt result = KErrNone;
       
    67     CSenSoapMessage* message = 
       
    68         (CSenSoapMessage*)(aCtx.GetSenSoapEnvelopeL(SenContext::KSenCurrentSoapMessageCtxKey));
       
    69     if (message)
       
    70         {   
       
    71         if (aCtx.Direction()==SenContext::EOutgoing)
       
    72             {
       
    73             //1. first put timestamp in security section. 
       
    74             //Propably 1st tag processed by servers
       
    75 
       
    76 
       
    77             HBufC8* timestamp = NULL;
       
    78             const TDesC8*  createdValue = aCtx.GetDesC8L(WSStarContextKeys::KTimestampCreated);
       
    79             const TDesC8*  expiredValue = aCtx.GetDesC8L(WSStarContextKeys::KTimestampExpires);
       
    80                  
       
    81             if (createdValue)
       
    82                 {
       
    83                 TTime clientTime;
       
    84                 TTime mtTime;
       
    85                 const TDesC8* mtTimetd = aCtx.GetDesC8L(WSStarContextKeys::KPhoneTimeWhenMTResolved);
       
    86                 mtTime = SenDateUtils::FromXmlDateTimeL(*mtTimetd);
       
    87                 clientTime.UniversalTime();
       
    88                 if (clientTime != Time::NullTTime())
       
    89                     {
       
    90                     TTimeIntervalMicroSeconds  diff  = clientTime.MicroSecondsFrom(mtTime);
       
    91                     if (diff > 0)
       
    92                         {
       
    93                         TTime createTime = SenDateUtils::FromXmlDateTimeL(*createdValue);
       
    94                         TBuf8<SenDateUtils::KXmlDateTimeMaxLength> newCreateTime;
       
    95                         TInt leaveCode(KErrNone);
       
    96                         TRAP(leaveCode, SenDateUtils::ToXmlDateTimeUtf82L(newCreateTime, createTime + diff);)
       
    97                         if (!leaveCode)
       
    98                             {
       
    99                             User::LeaveIfError(
       
   100                                         ((MSenContext&)aCtx).Update(WSStarContextKeys::KTimestampCreated, 
       
   101                                         newCreateTime));
       
   102                             createdValue = &newCreateTime;
       
   103                             }
       
   104                         }
       
   105                  }
       
   106             //problem with signing if "expired" tag exists. 
       
   107             //Presently wssecurity is turned-off, so we can include this tag.
       
   108             if (expiredValue)  
       
   109                 {
       
   110                 CSenWsSecurityHeader::TimestampL(*createdValue, *expiredValue, timestamp);
       
   111                 CleanupStack::PushL(timestamp);
       
   112                 }
       
   113             else
       
   114                 {
       
   115                 CSenWsSecurityHeader::TimestampL(*createdValue, timestamp);
       
   116                 CleanupStack::PushL(timestamp);
       
   117                 }
       
   118             message->AddSecurityTokenL(*timestamp);
       
   119             CleanupStack::PopAndDestroy(timestamp);
       
   120                 }
       
   121 //2.after timestamp put else stuff like MT            
       
   122             const TDesC8* securityToken = aCtx.GetDesC8L(WSStarContextKeys::KSecurityToken);
       
   123             if (securityToken)
       
   124                 {
       
   125                 message->AddSecurityTokenL(*securityToken);
       
   126                 }
       
   127             else
       
   128                 {
       
   129                 TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarCredentialCollectorHandler::InvokeL\
       
   130                                 (MSenMessageContext& aCtx) -  \
       
   131                                 Security token in message context not exists")));
       
   132                 return KErrNone;
       
   133                 }            
       
   134             }
       
   135         }
       
   136     else
       
   137         {
       
   138         TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarCredentialCollectorHandler::InvokeL(MSenMessageContext& aCtx)\
       
   139                          - SOAP message in message context not exists")));
       
   140         result = KErrNotFound;
       
   141         }
       
   142     return result;
       
   143     }
       
   144 
       
   145 TInt CWSStarCredentialCollectorHandler::InitL(MSenHandlerContext& aCtx)
       
   146     {
       
   147     iHandlerContext = aCtx;
       
   148     return KErrNone;
       
   149     }
       
   150     
       
   151 SenHandler::THandlerDirection CWSStarCredentialCollectorHandler::Direction() const
       
   152     {
       
   153     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarCredentialCollectorHandler::Direction()")));
       
   154     return SenHandler::EOutgoing;
       
   155     };
       
   156 SenHandler::THandlerPhase CWSStarCredentialCollectorHandler::Phase()
       
   157     {
       
   158     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarCredentialCollectorHandler::Phase()")));
       
   159     return SenHandler::EMessage;
       
   160     };    
       
   161 RFileLogger* CWSStarCredentialCollectorHandler::Log() const
       
   162     {
       
   163     RFileLogger* pLog = NULL;
       
   164     TRAP_IGNORE( pLog = (RFileLogger*)iHandlerContext.GetAnyL(HandlerContextKey::KLogger); )
       
   165     return pLog;
       
   166     }
       
   167 // END OF FILE
       
   168