开发者

How to get a caller principal in my backing bean?

开发者 https://www.devze.com 2023-01-10 14:10 出处:网络
This is my backing bean (deployed to GlassFish): @ManagedBean @DeclareRoles({ \"USER\" }) @RolesAllowed(\"USER\")

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

精彩评论

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