tags:

views:

18

answers:

1

This is my backing bean (deployed to GlassFish):

@ManagedBean
@DeclareRoles({ "USER" })
@RolesAllowed("USER")
public class MyBean {
  public MyBean() {}
  public final String getId() {
    Principal p = .. // how and where?
    return p.getName();
  }
}

How and where I can get java.security.Principal object to understand who is logged in now?

+1  A: 

You can obtain it by ExternalContext#getUserPrincipal().

Principal principal = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal();
BalusC