webservices/wsstar/wsstarmessagehandlers/src/wsstarpassporthandler.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 "wsstarpassporthandler.h"
       
    29 #include "SenXmlUtils.h"
       
    30 #include "wsstarmessageutils.h"
       
    31 #include "wsstartrustclient.h"
       
    32 #include "SenSoapFault.h"
       
    33 #include "senlogger.h"
       
    34 #include "sensaxutils.h"
       
    35 
       
    36 #ifdef RD_SEN_VTCP_SUPPORT
       
    37 #include "wsstarpassportheaderinbound.h"
       
    38 #endif//RD_SEN_VTCP_SUPPORT
       
    39 
       
    40 
       
    41 using namespace WSPassport32;
       
    42 
       
    43 // Create instance of concrete ECOM interface implementation
       
    44 CWSStarPassportHandler* CWSStarPassportHandler::NewL(TAny* aHandlerCtx)
       
    45     {
       
    46     MSenHandlerContext* ctx =
       
    47         reinterpret_cast<MSenHandlerContext*>( aHandlerCtx);
       
    48     CWSStarPassportHandler* self = new (ELeave) CWSStarPassportHandler(*ctx);
       
    49     CleanupStack::PushL (self);
       
    50     self->ConstructL();
       
    51     CleanupStack::Pop(self);
       
    52     return self;
       
    53     }
       
    54 TInt CWSStarPassportHandler::InvokeL(MSenMessageContext& aCtx)
       
    55     {
       
    56     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPassportHandler::InvokeL(MSenMessageContext& aCtx)")));
       
    57     CSenSoapEnvelope* message = 
       
    58         const_cast<CSenSoapEnvelope*>(aCtx.GetSenSoapEnvelopeL(
       
    59                                                 SenContext::KSenCurrentSoapMessageCtxKey));
       
    60     const TBool* boolValue = NULL;
       
    61     if (message)
       
    62         {
       
    63         _LIT8(KId,"Id");
       
    64         boolValue = aCtx.GetIntL(WSStarContextKeys::KPassportEnabled);
       
    65         if ((boolValue && *boolValue == (TBool)ETrue))
       
    66             {
       
    67             if (aCtx.Direction() == SenContext::EOutgoing)
       
    68                 {//------------------OUTGOING
       
    69                 CSenElement& header = message->HeaderL();
       
    70                 CSenElement& authInfo = header.AddElementL(KPassportXmlns,
       
    71                                                            KAuthInfoTag,
       
    72                                                            KAuthInfoQTag);
       
    73                 SenXmlUtils::AddAttributeL(authInfo, KId ,KPPAuthInfoAttrValue);
       
    74                 authInfo.AddElementL(KPassportXmlns, 
       
    75                                         KHostingAppTag, 
       
    76                                         KHostingAppQTag).SetContentL(KHostingAppTagValue);
       
    77                 authInfo.AddElementL(KPassportXmlns, 
       
    78                                         KBinaryVersionTag, 
       
    79                                         KBinaryVersionQTag).SetContentL(KBinaryVersionTagValue);
       
    80                 authInfo.AddElementL(KPassportXmlns, 
       
    81                                         KUIVersionTag, 
       
    82                                         KUIVersionQTag).SetContentL(KUIVersionTagValue);
       
    83                 authInfo.AddElementL(KPassportXmlns, 
       
    84                                         KCookiesTag, 
       
    85                                         KCookiesQTag).SetContentL(KCookiesTagValue);
       
    86                 authInfo.AddElementL(KPassportXmlns, 
       
    87                                         KRequestParamsTag, 
       
    88                                         KRequestParamsQTag).SetContentL(KRequestParamsTagValue);
       
    89                 CSenElement& body = message->BodyL();
       
    90                 CSenElement* multiEl = 
       
    91                     CWSStarMessageUtils::GetMarkedElementL(body, WSStarContextKeys::KMultiReqTagMark, 
       
    92                                                             EFalse);
       
    93                 if (multiEl)
       
    94                     {
       
    95                     multiEl->Set(KPassportXmlns, KRequestMultipleSecurityTokensTag, 
       
    96                                     KRequestMultipleSecurityTokensQTag);
       
    97                     }
       
    98                         
       
    99                 }
       
   100             else if(aCtx.Direction() == SenContext::EIncoming)
       
   101                 {//------------------INCOMING
       
   102                 TPtrC8 problem(KNullDesC8);
       
   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() == WSTrust::KTrustNamespace200502())
       
   129                                     {
       
   130                                     problem.Set(subcode);
       
   131                                     }    
       
   132                                 }
       
   133                             else if (nmSpaceCode && nmSpaceCode->URI() == KSecurityXmlNs)
       
   134                                 {
       
   135                                 problem.Set(code);
       
   136                                 }
       
   137                             }
       
   138                         else if (message->NsUri() == KSenSoapEnvelopeXmlns)
       
   139                             {
       
   140     //----------------SOAP1.1
       
   141                             TPtrC8 code = faultElement->FaultCode();
       
   142                             const CSenNamespace* nmSpace = faultElement->Namespace(SenXmlUtils::NsPrefix(code), ETrue);
       
   143                             code.Set(SenXmlUtils::LocalName(code));
       
   144                             if ((nmSpace && 
       
   145                                 nmSpace->URI() == WSTrust::KTrustNamespace200502()))
       
   146                                 {
       
   147                                 problem.Set(code);
       
   148                                 }    
       
   149                             }
       
   150     //------------------real logic                        
       
   151                         if (problem.Length()>0 && problem == WSTrust::KFailedAuthentication)
       
   152                             {
       
   153                             CSenElement* elem = NULL;
       
   154                             CSenElement& env = message->AsElement();
       
   155                             elem = CWSStarMessageUtils::FindElementL(KRedirectUrlTag, env);
       
   156                             if (elem)
       
   157                                 {
       
   158                                 const CSenNamespace* ns = elem->Namespace();
       
   159                                 if (ns && ns->URI() == KPassportFaultNamespaceXmlns)
       
   160                                     {
       
   161                                     ((MSenContext&)aCtx).Update(WSStarSession::KErrorLayer, WSStarSession::ETrust);
       
   162                                     ((MSenContext&)aCtx).Update(WSStarContextKeys::KReAuthNeeded, EFalse);
       
   163                                     ((MSenContext&)aCtx).Update(WSStarContextKeys::KRedirect, elem->Content());        
       
   164                                     }
       
   165                                 }
       
   166                             }
       
   167                         }
       
   168                     }
       
   169 		#ifdef RD_SEN_VTCP_SUPPORT					
       
   170                 else
       
   171                     {
       
   172                         TPtrC8 txtMessage = aCtx.GetMessageL();
       
   173                         if(message)
       
   174                         {
       
   175                             return HandleInboundL(aCtx, message);
       
   176                         }
       
   177                         else if(txtMessage.Length())
       
   178                         {
       
   179                             TInt ret(KErrNone);
       
   180                             TInt endTagStart;
       
   181                             TInt endTagEnd;
       
   182                             TInt startTagStart;
       
   183                             TInt startTagEnd;
       
   184                             TPtrC8 prefix;
       
   185 
       
   186                             ret = SenSaxUtils::SearchEndTagL(txtMessage,KSenSoapEnvelopeBodyName,
       
   187                                                              endTagStart, endTagEnd, prefix);
       
   188                             if ( ret != KErrNotFound )
       
   189                                 {
       
   190                                 ret = SenSaxUtils::SearchStartTagL(txtMessage,prefix,KSenSoapEnvelopeBodyName,
       
   191                                                                    startTagStart, startTagEnd);
       
   192                                 }
       
   193                             if ( ret != KErrNotFound )
       
   194                                 {
       
   195                                     TPtrC8 startPart(txtMessage.Ptr(),startTagEnd+1);
       
   196                                     TPtrC8 endPart(txtMessage.Ptr()+endTagStart,txtMessage.Size()-endTagStart);
       
   197                                     HBufC8* pXmlWithoutBody = HBufC8::NewLC(startPart.Length()+endPart.Length());
       
   198                                     pXmlWithoutBody->Des().Append(startPart);
       
   199                                     pXmlWithoutBody->Des().Append(endPart);
       
   200 
       
   201                                     CWSStarPassportHeaderInbound* inbound =
       
   202                                             CWSStarPassportHeaderInbound::NewLC();
       
   203                                     inbound->SetMessageContext(aCtx);
       
   204                                     CSenXmlReader& reader = const_cast<CSenXmlReader&>(*aCtx.GetParser());
       
   205                                     inbound->SetReader(reader);
       
   206                                     inbound->BuildFrom(*pXmlWithoutBody);
       
   207                                     CleanupStack::PopAndDestroy(inbound);
       
   208 
       
   209 
       
   210                                     CleanupStack::PopAndDestroy(pXmlWithoutBody);
       
   211         
       
   212                                 
       
   213                                 }
       
   214                             else//case with empty body - <S:Body/>, so we can parse all
       
   215                                 {
       
   216                                 CWSStarPassportHeaderInbound* inbound =
       
   217                                         CWSStarPassportHeaderInbound::NewLC();
       
   218                                 inbound->SetMessageContext(aCtx);
       
   219                                 CSenXmlReader& reader = const_cast<CSenXmlReader&>(*aCtx.GetParser());
       
   220                                 inbound->SetReader(reader);
       
   221                                 inbound->BuildFrom(txtMessage);
       
   222                                 CleanupStack::PopAndDestroy(inbound);                        
       
   223                                 }
       
   224                         }
       
   225 					}                        
       
   226 		#endif//RD_SEN_VTCP_SUPPORT
       
   227 				
       
   228                 }
       
   229             }
       
   230         }
       
   231     else
       
   232         {
       
   233         TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPassportHandler::InvokeL(MSenMessageContext& aCtx) - \
       
   234                         Soap message in message context not exists")));
       
   235         return KErrNotFound;
       
   236         }
       
   237     return KErrNone;    
       
   238     }    
       
   239 
       
   240 TInt CWSStarPassportHandler::HandleInboundL(MSenMessageContext& aCtx, CSenSoapEnvelope* aMessage)
       
   241     {
       
   242 
       
   243     CSenElement& header = aMessage->HeaderL();
       
   244 
       
   245     CWSStarMessageUtils::RArraySenElements elements;
       
   246     CWSStarMessageUtils::FindElementL(KCredProperty, header,elements);
       
   247     CSenElement* elem = NULL;
       
   248     TInt count(elements.Count());
       
   249     TInt i=0;
       
   250     while (i<count)
       
   251         {
       
   252         elem = elements[i];
       
   253         if (elem->LocalName() == WSPassport32::KCredProperty)
       
   254             {
       
   255             const TDesC8& nsUri = elem->NamespaceURI();
       
   256             if ((nsUri == WSPassport32::KPassportFaultNamespaceXmlns))
       
   257                 {
       
   258                     const TDesC8* ptr= elem->AttrValue(WSPassport32::KName);
       
   259                     if(*ptr == WSPassport32::KMainBrandID)
       
   260                     {
       
   261                         ((MSenContext&)aCtx).Update(WSStarContextKeys::KMainBrandID, elem->Content());
       
   262                     }
       
   263                  }
       
   264             }
       
   265         i++;
       
   266         }
       
   267     elements.Reset();
       
   268     
       
   269     CWSStarMessageUtils::RArraySenElements credProperties;
       
   270     CWSStarMessageUtils::FindElementL(KCredProperties, header,credProperties);
       
   271     elem = NULL;
       
   272     count = 0;
       
   273     count = credProperties.Count();
       
   274 	if(count == 1)
       
   275 	{
       
   276 		elem = credProperties[0];	
       
   277 		HBufC8* xmlSnippet = elem->AsXmlL();
       
   278 		CleanupStack::PushL(xmlSnippet);
       
   279 		((MSenContext&)aCtx).Update(WSStarContextKeys::KBrandIDList,xmlSnippet->Des() );		
       
   280  		CleanupStack::PopAndDestroy(xmlSnippet);
       
   281      		
       
   282 	}
       
   283     credProperties.Reset();
       
   284     
       
   285     return KErrNone;
       
   286             
       
   287     }
       
   288 SenHandler::THandlerDirection CWSStarPassportHandler::Direction() const
       
   289     {
       
   290     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPassportHandler::Direction()")));
       
   291     return SenHandler::EOutgoing;
       
   292     }
       
   293 SenHandler::THandlerPhase CWSStarPassportHandler::Phase()
       
   294     {
       
   295     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPassportHandler::Phase()")));
       
   296     return SenHandler::EMessage;
       
   297     }
       
   298 
       
   299 // Constructor
       
   300 CWSStarPassportHandler::CWSStarPassportHandler(MSenHandlerContext& aCtx)
       
   301 :CSenMessageHandler(aCtx)
       
   302     {
       
   303     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPassportHandler::CWSStarPassportHandler(MSenHandlerContext& aCtx)")));
       
   304     }
       
   305 
       
   306 // Destructor
       
   307 CWSStarPassportHandler::~CWSStarPassportHandler()
       
   308     {
       
   309     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPassportHandler::~CWSStarPassportHandler()")));
       
   310     }
       
   311 
       
   312 // Second phase construction.
       
   313 void CWSStarPassportHandler::ConstructL()
       
   314     {
       
   315     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPassportHandler::ConstructL()")));
       
   316     }
       
   317 
       
   318 TInt CWSStarPassportHandler::InitL(MSenHandlerContext& aCtx)
       
   319     {
       
   320     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPassportHandler::InitL(MSenHandlerContext& aCtx)")));
       
   321     iHandlerContext = aCtx;
       
   322     return KErrNone;
       
   323     }
       
   324 
       
   325 RFileLogger* CWSStarPassportHandler::Log() const
       
   326     {
       
   327     RFileLogger* pLog = NULL;
       
   328     TRAP_IGNORE( pLog = (RFileLogger*)iHandlerContext.GetAnyL(HandlerContextKey::KLogger); )
       
   329     return pLog;
       
   330     }
       
   331 
       
   332 // END OF FILE
       
   333