Re: appfuse generated basic struts project how to access the logged in user from action

2008-02-12 Thread Jeromy Evans

Prashant Khanal wrote:


To get the logged in user from the action i used :
SecurityContext ctx = SecurityContextHolder.getContext();
if (ctx != null) {
Authentication auth = ctx.getAuthentication();
User loggedInUser = (User) auth.getPrincipal();
}

  


As an alternative, your action may implement PrincipalAware

http://struts.apache.org/2.x/docs/servlet-config-interceptor.html

The advantage of PrincipalAware over the static call above is that it's 
easier to unit-test your action outside of the servlet context and it's 
clear to other developers that the action requires the principal.


regards,
Jeromy Evans

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: appfuse generated basic struts project how to access the logged in user from action

2008-02-12 Thread Prashant Khanal
hello all
anyway i got the answer but dunno whether or not it is appropriate
i wrapped the jsp snippet to hide it if the user is not logged in as

Welcome
, logout


To get the logged in user from the action i used :
SecurityContext ctx = SecurityContextHolder.getContext();
if (ctx != null) {
Authentication auth = ctx.getAuthentication();
User loggedInUser = (User) auth.getPrincipal();
}



On 2/13/08, Prashant Khanal <[EMAIL PROTECTED]> wrote:
>
> Hello all,
>
> I am working on the appfuse generated basic struts 2 project. It uses
> acegi as a security framework for authentication and authorization. How can
> i access the logged in user from the action?
> To show the logged in user in the header.jsp page i used a jstl tag
> provided by acegi as:
> Welcome, logout
> unfortunately this is also shown in login page as Welcome anonymous,
> logout :)
> how can i hide that based on whether or not the user is logged in?
>
>
> --
> Thanks,
> Prashant Khanal
>
>


-- 
Thanks,
Prashant Khanal
[EMAIL PROTECTED]
Solutions for your information
_
Yomari Pvt. Ltd.
HB Complex, Ekantakuna, Lalitpur.
G.P.O. Box: 21295
Kathmandu, Nepal
Tel: 977 (1) 5000111, 2113000
Fax: 977 (1) 5000157
http://www.yomari.com

Your guide to Nepal on the Net.
http://www.nepalhomepage.com


appfuse generated basic struts project how to access the logged in user from action

2008-02-12 Thread Prashant Khanal
Hello all,

I am working on the appfuse generated basic struts 2 project. It uses acegi
as a security framework for authentication and authorization. How can i
access the logged in user from the action?
To show the logged in user in the header.jsp page i used a jstl tag provided
by acegi as:
Welcome, logout
unfortunately this is also shown in login page as Welcome anonymous, logout
:)
how can i hide that based on whether or not the user is logged in?


-- 
Thanks,
Prashant Khanal