webservices/idwsfsecuritymechanism/src/senidwsfplainsaslmechanism.cpp
changeset 0 62f9d29f7211
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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 // INCLUDE FILES
       
    26 #include <SenXmlUtils.h>
       
    27 
       
    28 #include "senidwsfplainsaslmechanism.h"
       
    29 #include "msencoreservicemanager.h"
       
    30 
       
    31 namespace
       
    32     {
       
    33     //_LIT(KPlain,  "PLAIN");
       
    34     _LIT8(KPlain,   "PLAIN");
       
    35     }
       
    36 
       
    37 // Create instance of concrete ECOM interface implementation
       
    38 CSenIdWsfPlainSaslMechanism* CSenIdWsfPlainSaslMechanism::NewL(
       
    39                                     MSenCoreServiceManager& aServiceManager)
       
    40     {
       
    41     CSenIdWsfPlainSaslMechanism* pNew =
       
    42                         CSenIdWsfPlainSaslMechanism::NewLC(aServiceManager);
       
    43     CleanupStack::Pop();
       
    44     return pNew;
       
    45     }
       
    46 
       
    47 
       
    48 CSenIdWsfPlainSaslMechanism* CSenIdWsfPlainSaslMechanism::NewLC(
       
    49                                     MSenCoreServiceManager& aServiceManager)
       
    50     {
       
    51     CSenIdWsfPlainSaslMechanism* pNew =
       
    52                     new (ELeave) CSenIdWsfPlainSaslMechanism(aServiceManager);
       
    53     CleanupStack::PushL(pNew);
       
    54     return pNew;
       
    55     }
       
    56 
       
    57 CSenIdWsfPlainSaslMechanism::CSenIdWsfPlainSaslMechanism(
       
    58                                     MSenCoreServiceManager& aServiceManager)
       
    59 : CSenSecurityMechanism(aServiceManager)
       
    60     {
       
    61     }
       
    62 
       
    63 CSenIdWsfPlainSaslMechanism::~CSenIdWsfPlainSaslMechanism()
       
    64     {
       
    65     delete ipPassword;
       
    66     }
       
    67 
       
    68 
       
    69 void CSenIdWsfPlainSaslMechanism::SetIdentity(
       
    70                                     CSenIdentityProvider* aIdentityProvider,
       
    71                                     MSenIdentityManager* aIdentityManager)
       
    72     {
       
    73     TInt leaveCode(KErrNone);
       
    74     TRAP(leaveCode, SetIdentityL(aIdentityProvider, aIdentityManager);)
       
    75     leaveCode=0; // not used
       
    76     }
       
    77 
       
    78 void CSenIdWsfPlainSaslMechanism::SetIdentityL(
       
    79                                     CSenIdentityProvider* aIdentityProvider,
       
    80                                     MSenIdentityManager* aIdentityManager)
       
    81     {
       
    82     CSaslMechanism::SetIdentity(aIdentityProvider,aIdentityManager);
       
    83 
       
    84     TPtrC8 password = ipAccount->Password();
       
    85 
       
    86     delete ipPassword;
       
    87     ipPassword = NULL;
       
    88 
       
    89     if (password != KNullDesC8)
       
    90         {
       
    91         ipPassword = SenXmlUtils::DecodeHttpCharactersLC(password);
       
    92         CleanupStack::Pop(); // DecodeHttpCharactersLC
       
    93         }
       
    94     else
       
    95         {
       
    96         HBufC8* pPassword2 = CSaslMechanism::Password8L();
       
    97         if(pPassword2)
       
    98             {
       
    99             ipPassword = pPassword2;
       
   100             }
       
   101         else
       
   102             {
       
   103             ipPassword = KNullDesC8().AllocL();
       
   104             }
       
   105         }
       
   106     }
       
   107     
       
   108 
       
   109 TBool CSenIdWsfPlainSaslMechanism::IsPasswordFromUser()
       
   110     {
       
   111         TBool retVal;
       
   112 
       
   113         if (!ipAccount)
       
   114             {
       
   115             retVal = EFalse;
       
   116             }
       
   117         else
       
   118             {
       
   119             retVal = (ipAccount->Password() == KNullDesC8);
       
   120             }
       
   121 
       
   122         return retVal;
       
   123     }
       
   124 
       
   125 void CSenIdWsfPlainSaslMechanism::ClearPasswordL()
       
   126     {
       
   127     if (ipAccount)
       
   128         {
       
   129         CSenElement& element = ipAccount->AsElement();
       
   130         delete element.RemoveElement(KSenIdpPasswordLocalname);
       
   131         }
       
   132     delete ipPassword;
       
   133     ipPassword = NULL;
       
   134     HBufC8* pPassword = Password8L();
       
   135     if (pPassword)
       
   136         {
       
   137         ipPassword = pPassword;
       
   138         }
       
   139     }
       
   140 
       
   141 TInt CSenIdWsfPlainSaslMechanism::MaxAttempts()
       
   142     {
       
   143     return 3;
       
   144     }
       
   145 
       
   146 const TDesC8& CSenIdWsfPlainSaslMechanism::Name()
       
   147     {
       
   148     return KPlain();
       
   149     }
       
   150 
       
   151 TInt CSenIdWsfPlainSaslMechanism::HandleResponseL(
       
   152     MSenSaslMessage& /* aResponse */,
       
   153     MSenSaslMessage& aNewRequest
       
   154     )
       
   155     {
       
   156     TPtrC8 authzId = ipAccount->AuthzID();
       
   157     TPtrC8 authnId = ipAccount->AdvisoryAuthnID();
       
   158 
       
   159     if (authnId == KNullDesC8)
       
   160         {
       
   161         authnId.Set(authzId);
       
   162         authzId.Set(KNullDesC8);
       
   163         }
       
   164 
       
   165     TPtrC8 password(KNullDesC8);
       
   166 
       
   167     if(ipPassword)
       
   168         {
       
   169         password.Set(ipPassword->Des());
       
   170         }
       
   171 
       
   172     HBufC8* pSharedSecret = TransformL(password);
       
   173     CleanupStack::PushL(pSharedSecret);
       
   174 
       
   175     HBufC8* pData = HBufC8::NewLC(authzId.Length()
       
   176                                 + authnId.Length()
       
   177                                 + pSharedSecret->Length() + 2);
       
   178     TPtr8 data = pData->Des();
       
   179 
       
   180     if(authnId!=authzId)
       
   181         {
       
   182         data.Append(authzId); //  if authzId == authnId, leave out authzId
       
   183         }
       
   184 
       
   185     data.Append('\x00');    // NOTE, this zero line is a MUST,
       
   186                             // even if no authzId was added
       
   187     data.Append(authnId);
       
   188     data.Append('\x00');
       
   189     data.Append(*pSharedSecret);
       
   190     TInt retVal = aNewRequest.ConstructRequestFromL(KPlain, *pData);
       
   191     CleanupStack::PopAndDestroy(); // pData;
       
   192     CleanupStack::PopAndDestroy(); // pSharedSecret
       
   193     return retVal;
       
   194     }
       
   195 
       
   196 // End of File