|
1 /* |
|
2 * Copyright (c) 2008 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 // INCLUDE FILES |
|
19 #include "wsovioauthclient.h" |
|
20 |
|
21 #include <s32mem.h> |
|
22 #include <f32file.h> |
|
23 #include <s32file.h> |
|
24 #include <SenXmlUtils.h> |
|
25 #include "sencryptoutils.h" |
|
26 |
|
27 #include "wsoviservicesession.h" |
|
28 #include "SenXmlUtils.h" |
|
29 #include "msencoreservicemanager.h" |
|
30 #include "sendebug.h" |
|
31 #include "senlogger.h" |
|
32 #include "MSenServiceDescription.h" |
|
33 #include "SenServiceConnection.h" |
|
34 #include "seninternalserviceconsumer.h" |
|
35 #include <SenCredential.h> |
|
36 #include "wsoviplugin.h" |
|
37 #include "SenHttpTransportProperties.h" |
|
38 #include "senwspattern.h" |
|
39 #include "wsovicons.h" |
|
40 #include "wsovitokencreationresponse.h" |
|
41 #include "sencryptoutils.h" |
|
42 #include "wsoviutils.h" |
|
43 |
|
44 namespace |
|
45 { |
|
46 _LIT8(KRemoteConsumer, "RemoteConsumer"); |
|
47 } |
|
48 |
|
49 |
|
50 using namespace OAuth; |
|
51 //--------------------------------------------------------------------------- |
|
52 // Creates and returns a new instace of this class. |
|
53 //--------------------------------------------------------------------------- |
|
54 // |
|
55 CWSOviOAuthClient* CWSOviOAuthClient::NewL( |
|
56 CSIF& aSIF) |
|
57 { |
|
58 CWSOviOAuthClient* pNew = NewLC(aSIF); |
|
59 CleanupStack::Pop(pNew); |
|
60 return pNew; |
|
61 } |
|
62 |
|
63 //--------------------------------------------------------------------------- |
|
64 // Creates and returns a new instace of this class and leaves the object on the cleanup stack |
|
65 //--------------------------------------------------------------------------- |
|
66 // |
|
67 CWSOviOAuthClient* CWSOviOAuthClient::NewLC( |
|
68 CSIF& aSIF) |
|
69 { |
|
70 CWSOviOAuthClient* pNew = |
|
71 new (ELeave) CWSOviOAuthClient( |
|
72 aSIF, |
|
73 MSenServiceDescription::EOviOAuthClient); |
|
74 |
|
75 CleanupStack::PushL(pNew); |
|
76 pNew->BaseConstructL(); |
|
77 return pNew; |
|
78 } |
|
79 |
|
80 //--------------------------------------------------------------------------- |
|
81 // Constructor |
|
82 //--------------------------------------------------------------------------- |
|
83 // |
|
84 CWSOviOAuthClient::CWSOviOAuthClient( |
|
85 CSIF& aSIF, |
|
86 TDescriptionClassType aType) |
|
87 : CSenInternalServiceConsumer(aType, aSIF) |
|
88 { |
|
89 } |
|
90 |
|
91 void CWSOviOAuthClient::BaseConstructL() |
|
92 { |
|
93 CSenInternalServiceConsumer::ConstructL(); |
|
94 TLSLOG(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,(_L("CWSOviOAuthClient::ConstructL()"))); |
|
95 } |
|
96 |
|
97 //--------------------------------------------------------------------------- |
|
98 // Destructor |
|
99 //--------------------------------------------------------------------------- |
|
100 // |
|
101 CWSOviOAuthClient::~CWSOviOAuthClient() |
|
102 { |
|
103 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"CWSOviOAuthClient::~CWSOviTrustClient"); |
|
104 delete iAuthSession; |
|
105 delete iBody; |
|
106 } |
|
107 |
|
108 |
|
109 //--------------------------------------------------------------------------- |
|
110 // The most siginificant method of this class. Make validation of session, |
|
111 // credentails obtained if needed. |
|
112 // Sequential logic, synchronized, |
|
113 //--------------------------------------------------------------------------- |
|
114 // |
|
115 TInt CWSOviOAuthClient::ValidateL( CWSOviServiceSession& aSession, |
|
116 HBufC8*& aErrorMessage, |
|
117 TBool aOnlySharing ) |
|
118 |
|
119 { |
|
120 // iAuthSession->CompleteServerMessagesOnOffL(ETrue); |
|
121 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"CWSOviOAuthClient::ValidateL(..)"); |
|
122 TInt retVal(KErrNone); // for returning error codes |
|
123 iWSOviServiceSession = &aSession; // save session |
|
124 |
|
125 //---------------------- |
|
126 //0 token sharing, only if scope of token is not applied |
|
127 //---------------------- |
|
128 TBool sharingSucceed = EFalse; |
|
129 RPointerArray<CSenWSDescription> oviSDs; |
|
130 CleanupClosePushL(oviSDs); |
|
131 CSenWSPattern* pattern = CSenWSPattern::NewLC(); |
|
132 |
|
133 //select * from session_of_SD where session is (ovi framework, and has same provideId && No scope of token) |
|
134 |
|
135 pattern->SetFrameworkIdL(KDefaultOviFrameworkID); |
|
136 pattern->AsElement().AddElementL(KSenIdpProviderIdLocalname).SetContentL(iIdentityProvider->ProviderID()); |
|
137 //if (iWSOviServiceSession->ScopeToken() == EFalse) then pattern->SetScopeToken(EFalse) |
|
138 CWSOviServiceSession* oviSession = NULL; |
|
139 TRAP(retVal, retVal = Framework().Manager().ServiceDescriptionsL(oviSDs, *pattern)); |
|
140 |
|
141 if(!retVal) |
|
142 { |
|
143 TInt count = oviSDs.Count(); |
|
144 for(TInt i = 0; i < oviSDs.Count(); i++) |
|
145 { |
|
146 //all sessions, to eliminate client, just for case we check type |
|
147 TDescriptionClassType dt = oviSDs[i]->DescriptionClassType(); |
|
148 if (dt == MSenServiceDescription::EOviServiceSession) |
|
149 { |
|
150 oviSession = (CWSOviServiceSession*)oviSDs[i]; |
|
151 //dont share to itself |
|
152 if (oviSession != iWSOviServiceSession) |
|
153 { |
|
154 TRAPD(err, retVal = oviSession->ShareTokenWithL( |
|
155 iWSOviServiceSession)); |
|
156 if ((retVal == KErrNone) && (err == KErrNone)) |
|
157 { |
|
158 sharingSucceed = ETrue; |
|
159 break; |
|
160 } |
|
161 } |
|
162 } |
|
163 } |
|
164 if ( !sharingSucceed ) |
|
165 { |
|
166 // Did not find valid token (<=> sharingSucceed == EFalse) |
|
167 // |
|
168 // Try to search valid toeken directly from CredentialManager |
|
169 // (This is needed especially in case when token is imported |
|
170 // through Public API |
|
171 // => There is not yet Session which holds imported token) |
|
172 if ( iWSOviServiceSession->TryToSearchValidCredentialL() == KErrNone ) //codescannerwarnings |
|
173 { |
|
174 iWSOviServiceSession->SetStatusL(); |
|
175 iWSOviServiceSession->AddSecurityTokenToContextL(); |
|
176 sharingSucceed = ETrue; |
|
177 } |
|
178 } |
|
179 } |
|
180 CleanupStack::PopAndDestroy(2, &oviSDs); |
|
181 |
|
182 |
|
183 if (sharingSucceed) |
|
184 { |
|
185 iWSOviServiceSession->SetTrustAnchorL(iIdentityProvider->ProviderID()); |
|
186 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"CWSOviOAuthClient::ValidateL(..) - sharing succed, we don't need more validation"); |
|
187 return KErrNone; |
|
188 } |
|
189 if (aOnlySharing) |
|
190 { |
|
191 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"CWSStarTrustClient::ValidateL(..) - only sharing was allowed so NO continuation"); |
|
192 return KErrNone; |
|
193 } |
|
194 |
|
195 //----------------- |
|
196 //1 Init session |
|
197 //----------------- |
|
198 |
|
199 if (!iAuthSession)// if AuthenticationClient has NOT been registered earlier |
|
200 { |
|
201 iAuthSession = CWSOviServiceSession::NewL(Framework()); |
|
202 iAuthSession->InitializeFromL(*this); |
|
203 iAuthSession->SetEndPointL(iIdentityProvider->Endpoint()); |
|
204 iAuthSession->SetContractL(KWSOviAuthenticationServiceContract); |
|
205 iAuthSession->AddConsumerL(*this); |
|
206 } |
|
207 CSenXmlReader* reader = Framework().Manager().XMLReader(); |
|
208 CWSOviSessionContext* NAUTHSsnContext = iAuthSession->SessionContext(); |
|
209 |
|
210 |
|
211 |
|
212 //----------------- |
|
213 //2.preparing context |
|
214 //----------------------- |
|
215 TInt retryCounter(0); |
|
216 TBool retry(ETrue); |
|
217 TBool authenticationInfoPromptedFromUser(EFalse); |
|
218 TPckgBuf<TSenAuthentication> authInfo; |
|
219 HBufC8* response = NULL; |
|
220 MSenRemoteServiceConsumer* pConsumer = NULL; |
|
221 |
|
222 while ( retry ) // Authentication loop starts |
|
223 { |
|
224 retry = EFalse; |
|
225 //building body |
|
226 CWSOviPlugin& frmWSOvi = (CWSOviPlugin&)Framework(); |
|
227 const TDesC8* version = iHndCtx->GetDesC8L(HandlerContextKey::KVersion); |
|
228 TTime time; |
|
229 time.UniversalTime(); |
|
230 |
|
231 TPtrC8 userName(KNullDesC8); |
|
232 TPtrC8 password(KNullDesC8); |
|
233 if ( authenticationInfoPromptedFromUser ) |
|
234 { |
|
235 userName.Set(authInfo().iUsername); |
|
236 password.Set(authInfo().iPassword); |
|
237 } |
|
238 else |
|
239 { |
|
240 userName.Set(iIdentityProvider->UserName()); |
|
241 password.Set(iIdentityProvider->Password()); |
|
242 } |
|
243 HBufC8* created(NULL); |
|
244 CWSOviSessionContext* sessioncontext = iWSOviServiceSession->SessionContext(); |
|
245 const TInt* diffHandlerContext = iHndCtx->GetIntL(HandlerContextKey::KDiff); |
|
246 if( diffHandlerContext && *diffHandlerContext > 0 ) |
|
247 { |
|
248 TTimeIntervalMinutes minutes(*diffHandlerContext); |
|
249 TTime diff = time - minutes; |
|
250 time -= TTimeIntervalMicroSeconds(diff.Int64()); |
|
251 created = SenCryptoUtils::GetTimestampL(time); |
|
252 } |
|
253 else |
|
254 { |
|
255 created = SenCryptoUtils::GetTimestampL(); |
|
256 } |
|
257 CleanupStack::PushL(created); |
|
258 CreateBodyL(*version, |
|
259 userName, |
|
260 password, |
|
261 *created); |
|
262 CleanupStack::PopAndDestroy(created); |
|
263 |
|
264 |
|
265 //----------------- |
|
266 //_____________________________________SYNC Sending____________________________________________ |
|
267 |
|
268 CSenHttpTransportProperties* transProp = CSenHttpTransportProperties::NewLC(); |
|
269 |
|
270 // IAP dialog used to appear though IAP id is provided as a part of Service Description |
|
271 // Get the IAP setting and accordingly set the transport properties |
|
272 TUint32 id = 0; |
|
273 TInt getIapRetCode = IapId(id); |
|
274 |
|
275 // Check whether IAP ID is pre-defined, and copy it only if such property value is found |
|
276 //if ( getIapRetCode == KErrNone && id < 4294967295) // unsigned 4294967295 == -1 signed |
|
277 if ( getIapRetCode == KErrNone && id < (TUint32)KErrNotFound) // unsigned 4294967295 == -1 signed |
|
278 { |
|
279 transProp->SetIapIdL(id); |
|
280 } |
|
281 // ETMI-6WAGDB end |
|
282 |
|
283 //limit http timeout, |
|
284 // if NAUTH hangs and can not send any response, then we block every async client method. |
|
285 // Possibel revalidation during sendL can take too long time therefore we create new limit |
|
286 transProp->SetMaxTimeToLiveL(WSOviSession::KMaxHttpTimeOut); |
|
287 transProp->SetBoolPropertyL(OAuth::KNeedSecurity(), EFalse); |
|
288 transProp->SetEndpointResourceL(WSOviSession::KTokenEndpointSuffix()); |
|
289 // transProp->SetContentTypeL(KFormUrlEncoded()); |
|
290 |
|
291 //set consumer keys for proper DB |
|
292 HBufC8* providerTP(NULL); |
|
293 iIdentityProvider->TransportPropertiesL(providerTP); |
|
294 if (providerTP) |
|
295 { |
|
296 CleanupStack::PushL(providerTP); |
|
297 CSenHttpTransportProperties* httpProviderTP = CSenHttpTransportProperties::NewLC(*providerTP, *reader); |
|
298 if (httpProviderTP) |
|
299 { |
|
300 TPtrC8 content(KNullDesC8); |
|
301 httpProviderTP->PropertyL(KNCIMConsumerKeyId , content); |
|
302 if (content.Length()) |
|
303 { |
|
304 transProp->SetPropertyL(KNCIMConsumerKeyId, content); |
|
305 } |
|
306 httpProviderTP->PropertyL(KNCIMConsumerSecret , content); |
|
307 if (content.Length()) |
|
308 { |
|
309 transProp->SetPropertyL(KNCIMConsumerSecret, content); |
|
310 } |
|
311 httpProviderTP->PropertyL(KNCIMConsumerServiceId , content); |
|
312 if (content.Length()) |
|
313 { |
|
314 transProp->SetPropertyL(KNCIMConsumerServiceId, content); |
|
315 } |
|
316 /*TUint32 id = 0; |
|
317 if (! httpProviderTP->SnapIdL(id)) |
|
318 { |
|
319 transProp->SetSnapIdL(id); |
|
320 }*/ |
|
321 CleanupStack::PopAndDestroy(httpProviderTP); |
|
322 } |
|
323 CleanupStack::PopAndDestroy(providerTP); |
|
324 } |
|
325 |
|
326 // setting SNAP/IAP |
|
327 if(!iAuthSession->IapId(id) ) |
|
328 { |
|
329 transProp->SetIapIdL(id); |
|
330 transProp->SetSnapIdL(0); |
|
331 } |
|
332 else if(!iAuthSession->SnapId(id) ) |
|
333 { |
|
334 transProp->SetSnapIdL(id); |
|
335 transProp->SetIapIdL(0); |
|
336 } |
|
337 |
|
338 |
|
339 HBufC8* transPropAsXml = transProp->AsUtf8LC(); |
|
340 // HBufC8* bodyEncodedUrl = CWSOviUtils::FormEncodeCharsLC(*pBody); |
|
341 // _LIT8(KXmlContent, "XMLContent="); |
|
342 // HBufC8* allBody = HBufC8::NewL(KXmlContent().Length()+bodyEncodedUrl->Length()); |
|
343 // allBody->Des().Append(KXmlContent()); |
|
344 // allBody->Des().Append(*bodyEncodedUrl); |
|
345 // CleanupStack::PushL(allBody); |
|
346 //----------------- |
|
347 //3.submitting |
|
348 //------------------- |
|
349 retVal = iAuthSession->SubmitL(*iBody, *transPropAsXml, *this, response); |
|
350 |
|
351 aSession.SetTransportL(ipTransport);//ownership moved |
|
352 ipTransport = NULL; |
|
353 |
|
354 if (!response) |
|
355 { |
|
356 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"CWSOviOAuthClient::ValidateL - Response is empty - 1"); |
|
357 CleanupStack::PopAndDestroy(transPropAsXml); |
|
358 CleanupStack::PopAndDestroy(transProp); |
|
359 return retVal; |
|
360 } |
|
361 |
|
362 const TInt* diffContext = iHndCtx->GetIntL(HandlerContextKey::KDiff); |
|
363 if (diffContext && *diffContext > 0) |
|
364 { |
|
365 delete response; |
|
366 response = NULL; |
|
367 TTime time; |
|
368 time.UniversalTime(); |
|
369 TTimeIntervalMinutes minutes(*diffContext); |
|
370 TTime diff = time-minutes; |
|
371 time -= TTimeIntervalMicroSeconds(diff.Int64()); |
|
372 HBufC8* created = SenCryptoUtils::GetTimestampL(time); |
|
373 CleanupStack::PushL(created); |
|
374 CreateBodyL(*version, |
|
375 userName, |
|
376 password, |
|
377 *created); |
|
378 CleanupStack::PopAndDestroy(created); |
|
379 retVal = iAuthSession->SubmitL(*iBody, *transPropAsXml, *this, response); |
|
380 aSession.SetTransportL(ipTransport);//ownership moved |
|
381 ipTransport = NULL; |
|
382 } |
|
383 |
|
384 CleanupStack::PopAndDestroy(transPropAsXml); |
|
385 CleanupStack::PopAndDestroy(transProp); |
|
386 CleanupStack::PushL(response); |
|
387 |
|
388 if ( retVal ) |
|
389 { |
|
390 CWSOviSessionContext* pSessionContext = iWSOviServiceSession->SessionContext(); |
|
391 TAny* ptr = pSessionContext->GetAnyL(KRemoteConsumer()); //codescannerwarnings |
|
392 if ( ptr ) |
|
393 { |
|
394 pConsumer = REINTERPRET_CAST(MSenRemoteServiceConsumer*, ptr); |
|
395 } |
|
396 else |
|
397 { |
|
398 pConsumer = iWSOviServiceSession->Consumer(); |
|
399 } |
|
400 |
|
401 if ( pConsumer && !pConsumer->HasAuthenticationCallback() && |
|
402 retryCounter < 3 ) |
|
403 { |
|
404 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"CWSOviOAuthClient::ValidateL - Consumer does not have AuthenticationCallback"); |
|
405 |
|
406 const TDesC8* pValue = iIdentityProvider->AsElement().AttrValue( KSenAttrPromptUserInfo ); |
|
407 |
|
408 #ifdef _RD_SEN_WS_STAR_DO_NOT_PROMPT_AUTHINFO_BY_DEFAULT |
|
409 if ( pValue && *pValue != _L8("false") ) |
|
410 // attribute has to exist, otherwise logic defaults to: DO NOT PROMPT |
|
411 #else |
|
412 if ( !pValue || *pValue != _L8("false") ) |
|
413 // even when attribute does NOT exist, or when it does and has any other value but "false", default to: PROMPT |
|
414 #endif |
|
415 { |
|
416 const TBool* renewingPtr = NAUTHSsnContext->GetIntL(WSOviContextKeys::KReAuthNeeded); |
|
417 if ( renewingPtr && *renewingPtr ) |
|
418 { |
|
419 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KNormalLogLevel,"- Prompt is used to get AuthenticationInfo"); |
|
420 TInt ret = (Framework().Manager()).AuthenticationForL(*iIdentityProvider, |
|
421 authInfo); |
|
422 if ( ret == KErrNone ) |
|
423 { |
|
424 retryCounter++; |
|
425 retry = ETrue; |
|
426 authenticationInfoPromptedFromUser = ETrue; |
|
427 } |
|
428 } |
|
429 } |
|
430 else |
|
431 { |
|
432 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KNormalLogLevel,"CWSOviOAuthClient::ValidateL - promptUserInfo = false"); |
|
433 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KNormalLogLevel," => prompt is not used."); |
|
434 } |
|
435 } |
|
436 if ( pConsumer && pConsumer->HasAuthenticationCallback() && |
|
437 retryCounter < 3 ) |
|
438 { |
|
439 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KNormalLogLevel,"CWSOviOAuthClient::ValidateL - Consumer has AuthenticationCallback"); |
|
440 |
|
441 const TDesC8* pValue = iIdentityProvider->AsElement().AttrValue( KSenAttrPromptUserInfo ); |
|
442 |
|
443 if ( !pValue || *pValue != _L8("false") ) |
|
444 { |
|
445 const TBool* renewingPtr = NAUTHSsnContext->GetIntL(WSOviContextKeys::KReAuthNeeded); |
|
446 if ( renewingPtr && *renewingPtr ) |
|
447 { |
|
448 retVal = KErrSenFailedAuthentication; |
|
449 } |
|
450 } |
|
451 else |
|
452 { |
|
453 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KNormalLogLevel,"CWSOviOAuthClient::ValidateL - UserInfoPrompt = false"); |
|
454 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KNormalLogLevel," => AuthenticationCallback is not used."); |
|
455 } |
|
456 |
|
457 } |
|
458 } |
|
459 |
|
460 if ( retry ) |
|
461 { |
|
462 CleanupStack::PopAndDestroy(response); |
|
463 } |
|
464 } // Authentication loop ends |
|
465 |
|
466 HBufC8* ttlCreated = SenCryptoUtils::GetTimestampL(); |
|
467 CleanupStack::PushL(ttlCreated); |
|
468 User::LeaveIfError(iWSOviServiceSession->SessionContext()->Update(WSOviContextKeys::KTokenCreationTime,*ttlCreated)); |
|
469 CleanupStack::PopAndDestroy(ttlCreated); |
|
470 |
|
471 |
|
472 if (retVal != KErrNone) |
|
473 { |
|
474 TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase , KNormalLogLevel, _L8("CWSOviOAuthClient::ValidateL - error when submit to NAUTH %d"), retVal)); |
|
475 iWSOviServiceSession->SessionContext()->Remove(WSOviContextKeys::KTokenCreationTime); |
|
476 |
|
477 if (response) |
|
478 { |
|
479 aErrorMessage = response; |
|
480 } |
|
481 |
|
482 CleanupStack::Pop(response); |
|
483 return retVal; |
|
484 } |
|
485 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"CWSOviOAuthClient::ValidateL - response from NAUTH is a valid SOAP"); |
|
486 //----------------- |
|
487 //4 building response |
|
488 //----------------- |
|
489 CWSOviTokenCreationResponse* responseFragment = CWSOviTokenCreationResponse::NewLC(); |
|
490 responseFragment->SetReader(*Framework().Manager().XMLReader()); |
|
491 responseFragment->BuildFrom(*response); |
|
492 |
|
493 TPtrC8 ttl = responseFragment->TTL(); |
|
494 TBool ttlInfinitive = EFalse; |
|
495 // _LIT8(KTempTTL,"1000"); |
|
496 if (ttl.Length()) |
|
497 { |
|
498 TLSLOG(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,ttl); |
|
499 User::LeaveIfError(iWSOviServiceSession->SessionContext()->Update(WSOviContextKeys::KTTL,ttl)); |
|
500 } |
|
501 else |
|
502 { |
|
503 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"CWSOviOAuthClient::ValidateL - ttl is missing"); |
|
504 const TInt KMaxTTLLength = 20; |
|
505 TBuf8<KMaxTTLLength> ttlMaxInt; |
|
506 ttlMaxInt.AppendNum(KMaxTInt); |
|
507 User::LeaveIfError(iWSOviServiceSession->SessionContext()->Update(WSOviContextKeys::KTTL,ttlMaxInt)); |
|
508 ttlInfinitive = ETrue; |
|
509 } |
|
510 TPtrC8 tokenSecret = responseFragment->TokenSecret(); |
|
511 if (tokenSecret.Length()) |
|
512 { |
|
513 TLSLOG(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,tokenSecret); |
|
514 User::LeaveIfError(iWSOviServiceSession->SessionContext()->Update(WSOviContextKeys::KTokenSecret,tokenSecret)); |
|
515 } |
|
516 TPtrC8 token = responseFragment->Token(); |
|
517 if (!token.Length()) |
|
518 { |
|
519 iWSOviServiceSession->SessionContext()->Remove(WSOviContextKeys::KTokenCreationTime); |
|
520 retVal = KErrNotFound; |
|
521 } |
|
522 else |
|
523 { |
|
524 TLSLOG_ALL(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,token); |
|
525 if (!iWSOviServiceSession->ExistConsumerL()) |
|
526 { |
|
527 iWSOviServiceSession->SessionContext()->Remove(WSOviContextKeys::KTokenCreationTime); |
|
528 retVal = KErrNotFound; |
|
529 } |
|
530 else |
|
531 { |
|
532 iWSOviServiceSession->SetTrustAnchorL(iIdentityProvider->ProviderID()); |
|
533 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"CWSOviOAuthClient::ValidateL - set ctx basing on response"); |
|
534 retVal = iWSOviServiceSession->SessionContext()->SetTokenKeysL(token); |
|
535 if (retVal) |
|
536 { |
|
537 aErrorMessage = response; |
|
538 } |
|
539 } |
|
540 } |
|
541 CleanupStack::PopAndDestroy(responseFragment); |
|
542 |
|
543 if (!aErrorMessage) |
|
544 { |
|
545 if (!ttlInfinitive) |
|
546 { |
|
547 iWSOviServiceSession->ActiveTicketObserverL(); |
|
548 } |
|
549 CleanupStack::PopAndDestroy(response); |
|
550 } |
|
551 else |
|
552 { |
|
553 CleanupStack::Pop(response); |
|
554 } |
|
555 return retVal; |
|
556 } |
|
557 |
|
558 |
|
559 |
|
560 //--------------------------------------------------------------------------- |
|
561 // SetStatus |
|
562 //--------------------------------------------------------------------------- |
|
563 // |
|
564 |
|
565 void CWSOviOAuthClient::SetStatus(TInt /*aStatus */) |
|
566 { |
|
567 // No implementation in Java |
|
568 } |
|
569 |
|
570 //--------------------------------------------------------------------------- |
|
571 // SetAccount |
|
572 //--------------------------------------------------------------------------- |
|
573 // |
|
574 void CWSOviOAuthClient::SetAccount( |
|
575 CSenIdentityProvider* aIdentityProvicer) |
|
576 { |
|
577 iIdentityProvider = aIdentityProvicer; |
|
578 } |
|
579 |
|
580 |
|
581 //--------------------------------------------------------------------------- |
|
582 // ServiceSession |
|
583 //--------------------------------------------------------------------------- |
|
584 // |
|
585 CSenServiceSession* CWSOviOAuthClient::ServiceSession() |
|
586 { |
|
587 return iWSOviServiceSession; |
|
588 } |
|
589 |
|
590 //--------------------------------------------------------------------------- |
|
591 // Obtain Transport using a factory from Core Manager |
|
592 //--------------------------------------------------------------------------- |
|
593 // |
|
594 MSenTransport& CWSOviOAuthClient::TransportL() |
|
595 { |
|
596 if(!ipTransport) |
|
597 { |
|
598 // Core is capable of working as transport factory, too. |
|
599 // The returned transport instancies may or may not be |
|
600 // ECOM plugins: |
|
601 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"CWSOviOAuthClient::Instantiating new transport"); |
|
602 ipTransport = Framework().Manager().CreateL(*iAuthSession, iAuthSession); |
|
603 } |
|
604 return *ipTransport; |
|
605 } |
|
606 //--------------------------------------------------------------------------- |
|
607 // SetNAUTHSessionL |
|
608 //--------------------------------------------------------------------------- |
|
609 // |
|
610 void CWSOviOAuthClient::SetAuthSessionL( |
|
611 CWSOviServiceSession* aSession) |
|
612 { |
|
613 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"CWSOviOAuthClient::SetServiceSessionL"); |
|
614 _LIT8(KTouch, "touch"); |
|
615 // free memory |
|
616 //delete iAuthSession; |
|
617 const TDesC8* attrValue = aSession->AsElement().AttrValue(KTouch); |
|
618 if(attrValue != NULL) |
|
619 { |
|
620 AsElement().AddAttrL(KTouch, *attrValue); |
|
621 } |
|
622 iAuthSession = aSession; |
|
623 if(iAuthSession) |
|
624 { |
|
625 iAuthSession->AddConsumerL(*this); |
|
626 } |
|
627 } |
|
628 |
|
629 |
|
630 //--------------------------------------------------------------------------- |
|
631 // Getter for endpoint |
|
632 //--------------------------------------------------------------------------- |
|
633 // |
|
634 TPtrC8 CWSOviOAuthClient::Endpoint() |
|
635 { |
|
636 return iAuthSession->Endpoint(); |
|
637 } |
|
638 //--------------------------------------------------------------------------- |
|
639 // Getter for contract |
|
640 //--------------------------------------------------------------------------- |
|
641 // |
|
642 TPtrC8 CWSOviOAuthClient::Contract() |
|
643 { |
|
644 return iAuthSession->Contract(); |
|
645 } |
|
646 //--------------------------------------------------------------------------- |
|
647 // Getter for providerId |
|
648 //--------------------------------------------------------------------------- |
|
649 // |
|
650 TPtrC8 CWSOviOAuthClient::ProviderID() |
|
651 { |
|
652 return iAuthSession->ProviderID(); |
|
653 } |
|
654 |
|
655 //--------------------------------------------------------------------------- |
|
656 // Getter for framework |
|
657 //--------------------------------------------------------------------------- |
|
658 // |
|
659 TPtrC8 CWSOviOAuthClient::FrameworkId() |
|
660 { |
|
661 return iAuthSession->FrameworkId(); |
|
662 } |
|
663 //--------------------------------------------------------------------------- |
|
664 // serialie to xml |
|
665 //--------------------------------------------------------------------------- |
|
666 // |
|
667 void CWSOviOAuthClient::WriteAsXMLToL(RWriteStream& aWriteStream) |
|
668 { |
|
669 iAuthSession->WriteAsXMLToL(aWriteStream); |
|
670 } |
|
671 |
|
672 MSenServicePolicy* CWSOviOAuthClient::ServicePolicy() |
|
673 { |
|
674 return iAuthSession->ServicePolicy(); |
|
675 } |
|
676 TInt CWSOviOAuthClient::IapId(TUint32& aCurrentIapId) |
|
677 { |
|
678 return iAuthSession->IapId(aCurrentIapId); |
|
679 } |
|
680 |
|
681 |
|
682 |
|
683 TBool CWSOviOAuthClient::HasSuperClass( TDescriptionClassType aType ) |
|
684 { |
|
685 if( aType == MSenServiceDescription::ESenInternalServiceConsumer ) // direct superclass! |
|
686 { |
|
687 // If asked type is the know *direct* father/mother, return true: |
|
688 return ETrue; |
|
689 } |
|
690 else |
|
691 { |
|
692 // Otherwise, ask from superclass (chain, recursively) |
|
693 return CSenInternalServiceConsumer::HasSuperClass( aType ); |
|
694 } |
|
695 } |
|
696 |
|
697 void CWSOviOAuthClient::SetHandlerCtx(MSenHandlerContext* aHndCtx) |
|
698 { |
|
699 iHndCtx = aHndCtx; |
|
700 } |
|
701 TBool CWSOviOAuthClient::HasEqualPrimaryKeysL(MSenServiceDescription& aCandidate) |
|
702 { |
|
703 TBool retVal(EFalse); |
|
704 if ( CSenWSDescription::HasEqualPrimaryKeysL(aCandidate) ) |
|
705 { |
|
706 // Endpoint, Contract and FrameworkID match, all of them. |
|
707 // Now, in WS-Ovi, also check ProviderID |
|
708 if (aCandidate.DescriptionClassType() == DescriptionClassType()) |
|
709 { |
|
710 CWSOviOAuthClient& AuthenticationCandidate = (CWSOviOAuthClient&)aCandidate; |
|
711 if (AuthenticationCandidate.ProviderID() == ProviderID()) |
|
712 { |
|
713 retVal = ETrue; |
|
714 } |
|
715 } |
|
716 } |
|
717 return retVal; |
|
718 } |
|
719 |
|
720 void CWSOviOAuthClient::CreateBodyL(const TDesC8& aXmlNs, const TDesC8& aUsername, const TDesC8& aPassword, const TDesC8& aCreated) |
|
721 { |
|
722 delete iBody; |
|
723 iBody = NULL; |
|
724 HBufC8* nonce = SenCryptoUtils::GetRandomNonceL(); |
|
725 CleanupStack::PushL(nonce); |
|
726 HBufC8* passDec = SenXmlUtils::DecodeHttpCharactersLC( aPassword ); |
|
727 HBufC8* digest = CWSOviUtils::DigestAuthStringL(*nonce, aCreated, aUsername, *passDec); |
|
728 CleanupStack::PopAndDestroy(passDec); |
|
729 CleanupStack::PushL(digest); |
|
730 |
|
731 iBody = HBufC8::NewL(KCreationRequestFormat8().Length() |
|
732 + aXmlNs.Length() |
|
733 + aUsername.Length() |
|
734 + nonce->Length() |
|
735 + aCreated.Length() |
|
736 + digest->Length()); |
|
737 TPtr8 ptr = iBody->Des(); |
|
738 ptr.Format(KCreationRequestFormat8, |
|
739 &aXmlNs, |
|
740 &aUsername, |
|
741 &(nonce->Des()), |
|
742 &aCreated, |
|
743 &(digest->Des())); |
|
744 CleanupStack::PopAndDestroy(digest); |
|
745 CleanupStack::PopAndDestroy(nonce); |
|
746 } |
|
747 |
|
748 TBool CWSOviOAuthClient::Matches(MSenServiceDescription& aOtherServiceDescription) |
|
749 { |
|
750 return iAuthSession->Matches(aOtherServiceDescription); |
|
751 } |
|
752 // End of file |
|
753 |