Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I understand that you're checking the presence of the logged-in user before displaying the content. This <em>may</em> be okay this way, but any user who opens the page without being logged-in will receive blank content. This is not very user friendly. You'd like to redirect a non-logged-in user to the login page.</p> <p>This is normally already taken into account if you're using Java EE provided container managed authentication. But if you're homegrowing authentication, you'd need to create a <a href="https://stackoverflow.com/tags/servlet-filters/info">servlet filter</a> for this. If you collect all restricted pages in a common folder like <code>/app</code> so that you can use a common URL pattern for the filter, e.g. <code>/app/*</code> (and put all public pages such as the login page <em>outside</em> this folder), then you should be able to filter out non-logged-in users as follows, assuming that <code>#{userBean}</code> is a session scoped JSF <code>@ManagedBean</code> or some session attribute which you've put in session scope yourself:</p> <pre><code>@WebFilter("/app/*") public class LoginFilter implements Filter { @Override public void init(FilterConfig config) throws ServletException { // NOOP. } @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; HttpSession session = request.getSession(false); UserBean user = (session != null) ? (UserBean) session.getAttribute("userBean") : null; if (user == null || user.getCognome() == null) { response.sendRedirect(request.getContextPath() + "/login.xhtml"); // No logged-in user found, so redirect to login page. } else { chain.doFilter(req, res); // Logged-in user found, so just continue request. } } @Override public void destroy() { // NOOP. } } </code></pre> <h3>See also:</h3> <ul> <li><a href="https://stackoverflow.com/questions/9965708/how-to-handle-authentication-authorization-with-users-in-a-database">How to handle authentication/authorization with users in a database?</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload