title: How to make extra validation in Spring Security login form?
body: <p>I wonder how to make extra validation on login form before it will be processed by Spring Security. I'm thinking about some LoginController, LoginForm bean, but i don't know how to combine it together, how to configure it to work. My "visions" below. I've searched for some examples how to do that in Spring Security but can't find. Anybody helps with that ?</p>
  
  <p>LoginForm bean:</p>
  
  <pre><code>public class LoginForm {
      private String j_username;
      private String j_password;
      @NotEmpty
      private Boolean acceptTerms;
  
      public String getJ_password() {
          return j_password;
      }
  
      public String getJ_username() {
          return j_username;
      }
  
      public void setJ_password(String j_password) {
          this.j_password = j_password;
      }
  
      public void setJ_username(String j_username) {
          this.j_username = j_username;
      }
  
      public Boolean getAcceptTerms() {
          return acceptTerms;
      }
  
      public void setAcceptTerms(Boolean accept) {
          this.acceptTerms = acceptTerms;
      }
  }
  </code></pre>
  
  <p>Form:</p>
  
  <pre><code>&lt;c:url value="/login" var="secureUrl"/&gt;
  &lt;form:form id="jf" commandName="loginForm" action="${secureUrl}" method="post"&gt;
     &lt;form:input path="j_username"/&gt;
     &lt;form:input path="j_password"/&gt;
     &lt;form:checkbox path="acceptTerms"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>LoginController:</p>
  
  <pre><code>@Controller
  class LoginController {
      @RequestMapping(value = "/login", method = RequestMethod.POST)
      public String logging(@ModelAttribute @Valid LoginForm loginForm) {
                  ...
      }
  }
  </code></pre>