How can I check if a user is logged in using jsf?
This is how I am doing it and it's not working:
<ui:fragment rendered="#{!request.getUserPrincipal().getName().equalsIgnoreCase('anonymous')}">
<h:outputLink value="logout">
<h:outputText value="Logout" />
</h:outputLink>
</ui:fragment>
Just check if HttpServletRequest#getUserPrincipal()
is not null
.
<ui:fragment rendered="#{request.userPrincipal != null}">
<h:outputLink value="logout">
<h:outputText value="Logout" />
</h:outputLink>
</ui:fragment>
It also works for HttpServletRequest#getRemoteUser()
.
<ui:fragment rendered="#{request.remoteUser != null}">
<h:outputLink value="logout">
<h:outputText value="Logout" />
</h:outputLink>
</ui:fragment>