|
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 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 #include "wsovivalidatehandler.h" |
|
26 #include "wsovioauthclient.h" |
|
27 #include "sendebug.h" |
|
28 #include "senlogger.h" |
|
29 |
|
30 class CWSOviHandlerContext; |
|
31 |
|
32 //--------------------------------------------------------------------------- |
|
33 // Create instance of concrete ECOM interface implementation |
|
34 //--------------------------------------------------------------------------- |
|
35 // |
|
36 CWSOviValidateHandler* CWSOviValidateHandler::NewL(TAny* aHandlerCtx) |
|
37 { |
|
38 |
|
39 MSenHandlerContext* handlerCtx = |
|
40 reinterpret_cast<MSenHandlerContext*>(aHandlerCtx); |
|
41 CWSOviValidateHandler* self = new (ELeave) CWSOviValidateHandler(*handlerCtx); |
|
42 CleanupStack::PushL (self); |
|
43 self->ConstructL(); |
|
44 CleanupStack::Pop(self); |
|
45 return self; |
|
46 } |
|
47 |
|
48 |
|
49 //--------------------------------------------------------------------------- |
|
50 // Constructor |
|
51 //--------------------------------------------------------------------------- |
|
52 // |
|
53 CWSOviValidateHandler::CWSOviValidateHandler(MSenHandlerContext& aCtx):CSenSessionHandler(aCtx) |
|
54 { |
|
55 } |
|
56 |
|
57 //--------------------------------------------------------------------------- |
|
58 // Destructor |
|
59 //--------------------------------------------------------------------------- |
|
60 // |
|
61 CWSOviValidateHandler::~CWSOviValidateHandler() |
|
62 { |
|
63 } |
|
64 |
|
65 //--------------------------------------------------------------------------- |
|
66 // Second phase construction. |
|
67 //--------------------------------------------------------------------------- |
|
68 // |
|
69 void CWSOviValidateHandler::ConstructL() |
|
70 { |
|
71 TLSLOG(KSenCoreServiceManagerLogChannelBase , KNormalLogLevel,(_L("CWSOviValidateHandler::ConstructL()"))); |
|
72 } |
|
73 |
|
74 |
|
75 //--------------------------------------------------------------------------- |
|
76 // the most emergent method in message handler interface. |
|
77 // Each sub-class must implement this method thus providing message processing routine. |
|
78 //--------------------------------------------------------------------------- |
|
79 // |
|
80 TInt CWSOviValidateHandler::InvokeL(MSenSessionContext& aCtx) |
|
81 { |
|
82 |
|
83 //getting data from input |
|
84 CWSOviServiceSession* pNewSession = |
|
85 (CWSOviServiceSession*)aCtx.GetSenRemoteServiceSessionL( |
|
86 WSOviContextKeys::KServiceSession()); |
|
87 if (pNewSession->ProviderID() == KNullDesC8) |
|
88 { |
|
89 return KErrNone; |
|
90 } |
|
91 //try to find identity provider for curennt webService using its ProviderId |
|
92 CSenIdentityProvider* pIdentityProvider = IdentityProviderFromCoreL( |
|
93 pNewSession->ProviderID()); |
|
94 if (!pIdentityProvider) |
|
95 { |
|
96 return KErrNotFound; |
|
97 } |
|
98 |
|
99 const TBool* onlySharingPtr = ((MSenContext&)aCtx).GetIntL(WSOviContextKeys::KOnlySharing); |
|
100 TBool onlySharing; |
|
101 if (onlySharingPtr) |
|
102 { |
|
103 onlySharing = *onlySharingPtr; |
|
104 } |
|
105 else |
|
106 { |
|
107 onlySharing = ETrue; |
|
108 } |
|
109 |
|
110 CWSOviOAuthClient* pAuthClient = AuthClientL(pIdentityProvider); |
|
111 if (pAuthClient) |
|
112 { |
|
113 TInt error(KErrNone); |
|
114 pAuthClient->SetHandlerCtx(&iHandlerContext); |
|
115 //validate session of concrete WebService |
|
116 HBufC8* errorMessage = NULL; |
|
117 TRAPD(lerror, error = pAuthClient->ValidateL(*pNewSession, errorMessage, onlySharing);) |
|
118 ((MSenContext&)aCtx).Update(WSOviContextKeys::KReAuthNeeded, EFalse); |
|
119 if (errorMessage) |
|
120 { |
|
121 ((MSenContext&)aCtx).Update(WSOviContextKeys::KErrMessage, *errorMessage); |
|
122 } |
|
123 delete errorMessage; |
|
124 errorMessage = NULL; |
|
125 if (lerror) return lerror; |
|
126 //if credential expired session will use validator to obtain new |
|
127 |
|
128 // Core / XML DAO takes ownership of new session (will keep in array of SD): |
|
129 // - new session HAS |
|
130 // - credential |
|
131 // - if duplicate (equal primary keys) exiAuth, it is deleted |
|
132 return error; |
|
133 } |
|
134 else |
|
135 { |
|
136 return KErrNotFound; |
|
137 } |
|
138 |
|
139 } |
|
140 |
|
141 SenHandler::THandlerDirection CWSOviValidateHandler::Direction() const |
|
142 { |
|
143 return SenHandler::EBoth; |
|
144 }; |
|
145 SenHandler::THandlerPhase CWSOviValidateHandler::Phase() |
|
146 { |
|
147 return SenHandler::EValidate; |
|
148 }; |
|
149 |
|
150 //--------------------------------------------------------------------------- |
|
151 // Obtain or construct Auth client |
|
152 //--------------------------------------------------------------------------- |
|
153 // |
|
154 |
|
155 CWSOviOAuthClient* CWSOviValidateHandler::AuthClientL(CSenIdentityProvider*& aIdentityProvider) |
|
156 { |
|
157 TLSLOG(KSenCoreServiceManagerLogChannelBase , KNormalLogLevel,(_L("CWSOviValidateHandler::AuthClientL"))); |
|
158 |
|
159 CWSOviOAuthClient* pAuthClient = NULL; |
|
160 //providerId from Identities.xml |
|
161 TPtrC8 providerId(KNullDesC8); |
|
162 if(aIdentityProvider) |
|
163 { |
|
164 providerId.Set(aIdentityProvider->ProviderID()); |
|
165 } |
|
166 |
|
167 RPointerArray<CSenWSDescription> serviceDescriptions; |
|
168 CleanupClosePushL(serviceDescriptions); |
|
169 |
|
170 //try to find Auth session in cache,some Auth can be registered |
|
171 TInt retVal(KErrNone); |
|
172 |
|
173 TRAPD(error, retVal = iHandlerContext.GetSenCoreServiceManager()->ServiceDescriptionsL(serviceDescriptions, KWSOviAuthenticationServiceContract())); |
|
174 if(!retVal&&!error) |
|
175 { |
|
176 RPointerArray<CSenWSDescription> matches; |
|
177 CleanupClosePushL(matches); |
|
178 |
|
179 for(TInt i = 0; i < serviceDescriptions.Count(); i++) |
|
180 { |
|
181 //select XMLDescription from DAO where contract = Auth, so we can cast |
|
182 if (serviceDescriptions[i]->DescriptionClassType() == MSenServiceDescription::EOviOAuthClient) |
|
183 { |
|
184 pAuthClient = (CWSOviOAuthClient*)serviceDescriptions[i]; |
|
185 if(providerId.Length()>0) |
|
186 { |
|
187 TPtrC8 providerIDFromDescription = pAuthClient->ProviderID(); |
|
188 if(providerIDFromDescription == providerId) |
|
189 { |
|
190 matches.AppendL(pAuthClient); |
|
191 } |
|
192 } |
|
193 else |
|
194 { |
|
195 matches.AppendL(pAuthClient); |
|
196 } |
|
197 } |
|
198 } |
|
199 if(matches.Count()) |
|
200 { |
|
201 pAuthClient = |
|
202 reinterpret_cast<CWSOviOAuthClient*>(matches[0]); |
|
203 pAuthClient->SetAccount(aIdentityProvider); |
|
204 } |
|
205 else |
|
206 { |
|
207 TLSLOG(KSenCoreServiceManagerLogChannelBase , KNormalLogLevel,(_L("CWSOviValidateHandler::AuthClient - No matching AuthClient description available!"))); |
|
208 pAuthClient = NULL; |
|
209 } |
|
210 |
|
211 //if we find multi Auth client (different only with lifetime, probably Secure Context Token lifetime) |
|
212 if(matches.Count() > 1) |
|
213 { |
|
214 // search for a instance with longest validity |
|
215 for(TInt i = matches.Count()-1; i > 0 ; i--) |
|
216 { |
|
217 CWSOviOAuthClient* pNewerAuthClient = |
|
218 reinterpret_cast<CWSOviOAuthClient*>(matches[i]); |
|
219 CWSOviServiceSession* newerSession = (CWSOviServiceSession*)pNewerAuthClient->ServiceSession(); |
|
220 CWSOviServiceSession* session = (CWSOviServiceSession*)pAuthClient->ServiceSession(); |
|
221 |
|
222 if(newerSession && session) // AuthClient Session was not set, if not validated |
|
223 { |
|
224 if(newerSession->ValidUntilL() > session->ValidUntilL()) |
|
225 { |
|
226 pAuthClient = pNewerAuthClient; |
|
227 pAuthClient->SetAccount(aIdentityProvider); |
|
228 } |
|
229 } |
|
230 } |
|
231 } |
|
232 CleanupStack::PopAndDestroy(2, &serviceDescriptions); |
|
233 } |
|
234 else |
|
235 { |
|
236 CleanupStack::PopAndDestroy(&serviceDescriptions); |
|
237 } |
|
238 return pAuthClient; |
|
239 } |
|
240 |
|
241 //--------------------------------------------------------------------------- |
|
242 // Create IdentityProvider from CoreManager |
|
243 //--------------------------------------------------------------------------- |
|
244 // |
|
245 CSenIdentityProvider* CWSOviValidateHandler::IdentityProviderFromCoreL( |
|
246 const TDesC8& aProviderID) |
|
247 { |
|
248 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KNormalLogLevel,"CWSOviValidateHandler::IdentityProviderLFromCore"); |
|
249 CSenIdentityProvider* pIdentityProvider = NULL; |
|
250 if(aProviderID.Length() > 0) |
|
251 { |
|
252 CDesC8ArrayFlat* array = new (ELeave) CDesC8ArrayFlat(1); |
|
253 CleanupStack::PushL(array); |
|
254 array->AppendL(aProviderID); |
|
255 pIdentityProvider = iHandlerContext.GetSenCoreServiceManager()-> |
|
256 IdentityProviderL(*array, ETrue); |
|
257 CleanupStack::PopAndDestroy(array); |
|
258 } |
|
259 return pIdentityProvider; |
|
260 } |
|
261 |
|
262 //--------------------------------------------------------------------------- |
|
263 // Init implementation |
|
264 //--------------------------------------------------------------------------- |
|
265 // |
|
266 TInt CWSOviValidateHandler::InitL(MSenHandlerContext& aCtx) |
|
267 { |
|
268 iHandlerContext = aCtx; |
|
269 return KErrNone; |
|
270 } |
|
271 RFileLogger* CWSOviValidateHandler::Log() const |
|
272 { |
|
273 RFileLogger* pLog = NULL; |
|
274 TRAP_IGNORE( pLog = (RFileLogger*)iHandlerContext.GetAnyL(HandlerContextKey::KLogger); ) |
|
275 return pLog; |
|
276 } |
|
277 MSenHandlerContext& CWSOviValidateHandler::HandlerContext() |
|
278 { |
|
279 return iHandlerContext; |
|
280 } |
|
281 // END OF FILE |
|
282 |