Is this working with Basic Authentication, or does that only work with form based authentication? If there is a generic solution, then I'm fine to add it to the extlib core code.
BTW, I would advise you to use the user bean to get the effective user name, instead of calling the session method.