@@ -1326,7 +1326,7 @@ bool cWebemRequestHandler::CheckAuthentication(WebEmSession & session, const req
1326
1326
session.id = sSID ;
1327
1327
}
1328
1328
session.auth_token = sAuthToken ;
1329
- // Check authen_token
1329
+ // Check authen_token and restore session
1330
1330
if (checkAuthToken (session)) {
1331
1331
// user is authenticated
1332
1332
return true ;
@@ -1386,7 +1386,10 @@ bool cWebemRequestHandler::CheckAuthentication(WebEmSession & session, const req
1386
1386
return false ;
1387
1387
}
1388
1388
1389
- bool cWebemRequestHandler::checkAuthToken (const WebEmSession & session) {
1389
+ /* *
1390
+ * Check authentication token if exists and restore the user session if necessary
1391
+ */
1392
+ bool cWebemRequestHandler::checkAuthToken (WebEmSession & session) {
1390
1393
session_store* sstore = myWebem->GetSessionStore ();
1391
1394
if (sstore == NULL ) {
1392
1395
_log.Log (LOG_ERROR, " CheckAuthToken([%s_%s]) : no store defined" , session.id .c_str (), session.auth_token .c_str ());
@@ -1408,10 +1411,32 @@ bool cWebemRequestHandler::checkAuthToken(const WebEmSession & session) {
1408
1411
return false ;
1409
1412
}
1410
1413
1411
- // TODO : Restore session ?
1412
- // session.username = base64_decode(storedSession.username);
1413
-
1414
1414
_log.Log (LOG_STATUS, " CheckAuthToken(%s_%s_%s) : user authenticated" , session.id .c_str (), session.auth_token .c_str (), session.username .c_str ());
1415
+
1416
+ if (session.username .empty ()) {
1417
+ // Restore session if user exists and session does not already exist
1418
+ bool userExists = false ;
1419
+ session.username = storedSession.username ;
1420
+ std::vector<_tWebUserPassword>::iterator ittu;
1421
+ for (ittu=myWebem->m_userpasswords .begin (); ittu!=myWebem->m_userpasswords .end (); ++ittu) {
1422
+ if (ittu->Username == session.username ) { // the user still exists
1423
+ userExists = true ;
1424
+ session.rights = ittu->userrights ;
1425
+ break ;
1426
+ }
1427
+ }
1428
+ if (!userExists) {
1429
+ _log.Log (LOG_ERROR, " CheckAuthToken(%s_%s) : cannot restore session user not found" , session.id .c_str (), session.auth_token .c_str ());
1430
+ removeAuthToken (session.id );
1431
+ return false ;
1432
+ }
1433
+ std::map<std::string, WebEmSession>::iterator itts = myWebem->m_sessions .find (session.id );
1434
+ if (itts == myWebem->m_sessions .end ()) {
1435
+ _log.Log (LOG_STATUS, " CheckAuthToken(%s_%s_%s) : restore session" , session.id .c_str (), session.auth_token .c_str (), session.username .c_str ());
1436
+ myWebem->m_sessions [session.id ] = session;
1437
+ }
1438
+ }
1439
+
1415
1440
return true ;
1416
1441
}
1417
1442
0 commit comments