Fix middleware to not access session fields without user auth

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