开发者

How to get a caller principal in my backing bean?

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?


You can obtain it by ExternalContext#getUserPrincipal().

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜