title: Liferay - PreLoginAction - Prevent User from Login
body: <p>i use a Liferay based website and try to implement a login hook which prevents a user login under certain conditions. I want to make it as simple as possible like:</p>
  
  <pre><code>    @Override
      public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException
      {
          if (condition)
          {
              //redirect to login page, send a message back but just don't let the user login
              //but don't block or ban him either.
          }
      }
  </code></pre>
  
  <p>It has to look like a wrong password error, but it has to be on portal side, before the user even logins (therefore PreLoginAction class)</p>
  
  <p>Edit: Okay, i used the logout and redirect method to go back to the login page. But i still want to generate a error message. I tried it like this</p>
  
  <pre><code>    @Override
      public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException
      {
          if (condition)
          {
              SessionErrors.add(request, "error");
              response.sendRedirect("/c/portal/logout");
          }
      }
  </code></pre>
  
  <p>and for the login.jsp i added the top line, but i guess its not working like that for the Login Actions. There is no error message showing</p>
  
  <pre><code>&lt;liferay-ui:error key="error" message="this-account-has-been-locked" /&gt;
  &lt;liferay-ui:error exception="&lt;%= AuthException.class %&gt;" message="authentication-failed" /&gt;
  &lt;liferay-ui:error exception="&lt;%= CompanyMaxUsersException.class %&gt;" message="unable-to-login-because-the-maximum-number-of-users-has-been-reached" /&gt;
  &lt;liferay-ui:error exception="&lt;%= CookieNotSupportedException.class %&gt;" message="authentication-failed-please-enable-browser-cookies" /&gt;
  &lt;liferay-ui:error exception="&lt;%= NoSuchUserException.class %&gt;" message="authentication-failed" /&gt;
  &lt;liferay-ui:error exception="&lt;%= PasswordExpiredException.class %&gt;" message="your-password-has-expired" /&gt;
  &lt;liferay-ui:error exception="&lt;%= UserEmailAddressException.class %&gt;" message="authentication-failed" /&gt;
  &lt;liferay-ui:error exception="&lt;%= UserLockoutException.class %&gt;" message="this-account-has-been-locked" /&gt;
  &lt;liferay-ui:error exception="&lt;%= UserPasswordException.class %&gt;" message="authentication-failed" /&gt;
  &lt;liferay-ui:error exception="&lt;%= UserScreenNameException.class %&gt;" message="authentication-failed" /&gt;
  </code></pre>
  
  <p>Is there another way?
  i also tried the line</p>
  
  <pre><code>request.getSession().setAttribute("loginError", "failure message");
  </code></pre>
  
  <p>and tried to read <code>${loginError}</code> in the jsp, but its also not working.</p>