How to check if is user logged in?

前端 未结 3 1870
不思量自难忘°
不思量自难忘° 2020-12-05 16:56

I want do display a login link when the user isn\'t logged in and a logout link when the user is logged in. I\'m using container managed security as defined in web.xml

3条回答
  •  被撕碎了的回忆
    2020-12-05 17:26

    This depends on your definition of "logged in". Usually you can login an user in your application by implementing your own login mechanism. Otherwise you are using some container dependent mechanism which your server will take care of.

    For the container managed method you can usually check FacesContext with its ExternalContext.

    FacesContext.getExternalContext().getRemoteUser();
    

    You can put that method into a helper bean and check it with the rendered attribute of your link component.

    If you implement your own system its totally up to you.

提交回复
热议问题