Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Struts 2 »

Interceptor + putting information on the request

Sarr, Nathan

2007-03-07

Replies:

Hello,



 I am using struts 2.0.6. I wrote an interceptor to use with Acegi
security to place the UserDetails object on the request so I could
access it on my JSP page. However when I tried to access the object on
the page, it was not found.



I then instead placed it on the session using the following which
worked:



[code]

final ActionContext context = invocation.getInvocationContext();

HttpServletRequest request = (HttpServletRequest)
context.get(HTTP_REQUEST);

HttpSession session = request.getSession();



Authentication auth =
SecurityContextHolder.getContext().getAuthentication();

if(auth != null)

{

  if(auth.getPrincipal() instanceof UserDetails)

  {

      IrUser user = (IrUser)auth.getPrincipal();

      session.setAttribute("user", user);

  }

}

return invocation.invoke();

[/code]



I was wondering is there any way to place this information on the
request in an interceptor.



Thanks for the help.

-Nate

©2008 junlu.com - Jax Systems, LLC, U.S.A.