Search code examples
jsfrealmjdbcrealm

Obtain the user logged with JSF with Realm Glassfish


I'm using forms to do a login with a user with JSF, Glassfish and Realms linked to a database, exist some way to know the id, the username of some information to know the user logged?


Solution

  • I assume you mean JDBC security realm.

    FacesContext context = FacesContext.getCurrentInstance();
    HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
    
    String username = request.getUserPrincipal().getName();
    

    Then from the username, you can query the database to get any other user information you want.