On 3/1/06, Marco Mistroni <[EMAIL PROTECTED]> wrote:
> Hello all,
>    i have written an application that uses Acegi .
> my app integrates also JSF and spring using JSF-spring integration library
>
> I was wondering how can i access the current loggged in user (authenticated
> via acegi) as
> JSF bean....
> with  JSF-spring integration library, i can seee in my  JSF context all
> Spring declared
> beans (including acegi's )
>
> Any idea on how can i get hold of the user?
>
> will it be  something like <h:outputText value="#{.........}  ?
>
> anyone has any idea?

I would recommend you to write simple bean with getter method that
returns current logged in user from SecurityContext:

class CurrentUser {
  Object getPrincipal() {
    SecurityContext ctx = SecurityContextHolder.getContext();
    if (ctx == null)
      return null;
    return ctx.getAuthentication().getPrincipal();
  }
}

Register this bean in JSF application scope (under name currentUser)
and use it where JSF EL is allowed. F.e.:
 <h:outputText value="#{currentUser.principal} />

> thanx and regards
>  marco

Regards,
Konstantin

Reply via email to