ACEGI Tag to Access Currently Logged In User Object
I have a legacy java webapp which uses Acegi Security. I am trying to remove all java scriplets from jsp pages. Is there any ACEGI tag which could be used to replace the following expression:
SecurityContextHolder.getContext().getAuthentication()
The above expression returns the currently logged in user object. For example, I might have a JSP page which says "Hello, Bob your birthday is on Jan 1 1980." where the name "Bob" and the birthday are extracted from Bob'开发者_如何学运维s user object.
Note: I know that my Struts Action could declare the User object and initialize it to the value of the above code, but I would prefer to directly access the currently logged in user from the JSP page.
Why not generate your own taglib containing the missing tags? It's very easy to do and you'll have all the code localized to a very tight area in case there are changes you want to make (like logging anytime a superuser logs in).
There is the rather bizarre authentication
tag in acegi.
<authz:authentication operation="name"/>
Will output the value of getName
on the current principal.
It's not the most useful, but would be a good place to start if you implement your own version.
精彩评论