Fix middleware to not access session fields without user auth

Change-Id: Idc2b71aa9ca08570e870ac6e356211dfbaa7a726
Fixes: bug #1211535
Merge "Fix middleware to not access session fields without user auth"