How to access current user from a global scoped component in ATG

This article describes how to look up a session-scoped user profile component from a global scope component that has no access to a DynamoHttpServletRequest object. To achieve this functionality, we will use a ThreadLocal field an ATG feature called Insertable Servlet. When a request object is created, it goes through a pipeline of Insertable Servlets. We are going to create our own implementation of Insertable Servlet by extending atg.servlet.pipeline.InsertableServletImpl which will store current request to a ThreadLocal variable via a helper class (e.g. RequestContainer). Then, we’re going to inject this RequestContainer in every component that needs to look up the profile (or other components).

Here is the code.

Read More →