On further thought, while that solution works, it ties the code to the use of the Acegi framework since I then need to acess the application-specific information using code similar to below:
Code:
Authentication auth = (Authentication) request.getSession().getAttribute(HttpSessionIntegrationFilter.ACEGI_SECURITY_AUTHORIZATION_KEY);
MyUser user = (MyUser) auth.getPrincipal();
Sure I could encapsulate that code into a method that gets called any time I need to access app-specific information to reduce the dependency but it still feels like jumping through hoops. Or am I missing something?
Having a hook in AbstractProcessingFilter.doFilter would make things easier. Something like:
Code:
...
// Authentication success
if (logger.isDebugEnabled()) {
logger.debug("Authentication success: " + authResult.toString());
}
// ADDED CALLBACK
postAuthenticationCallback.doPostAuthentication(httpRequest);
httpRequest.getSession().setAttribute(HttpSessionIntegrationFilter.ACEGI_SECURITY_AUTHENTICATION_KEY, authResult);
...
This would be supported by a setter in AbstractProcessingFilter to be able to set the callback via Spring and PostAuthenticationCallback interface defining the doPostAuthentication method or something to the same effect.
In my case, I would write a PostAuthenticationCallback that would retrieve the appropriate MyUser object and put it in the session with the appropriate key. I could then access that object in the rest of my code without having to make it depend on Acegi Security.
Is it making any sense at all? Am I missing something really obvious?