Search code examples
jsf-2shiro

How to get current user name in jsf page with shiro?


i am using shiro for security management in my jsf application and i was wondering how to get the current user name in jsf page, please advise.

i tried <shiro:principal/> but it always returns empty string although user is logged in.


Solution

  • Shiro tags are for JSP, not for Facelets. Shiro is still hanging in J2EE era and needs to catch up the new world known as "Java EE" yet, including JSP's successor Facelets.

    It's fortunately at least available the same way as with container managed authentication, via HttpServletRequest#getRemoteUser():

    <p>Welcome, #{request.remoteUser}</p>
    

    See also: