title: Spring security shows 'Your login attempt was not successful due to' for custom membership
body: <p>I am puzzled with spring security, when I open sign-in page, it shows following error message <em>even before submitting the form</em>. I have no clue how to solve the issue.</p>
  
  <pre><code>Your login attempt was not successful due to 
  </code></pre>
  
  <p><strong>my-servlet.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns:mvc="http://www.springframework.org/schema/mvc"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:aop="http://www.springframework.org/schema/aop"
      xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd 
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd 
  http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.2.xsd 
  http://www.springframework.org/schema/aop 
  http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"&gt;
  
  
  .....
  
  &lt;bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
          destroy-method="close"&gt;
          &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
          &lt;property name="url" value="jdbc:mysql://localhost:8889/myproject" /&gt;
          &lt;property name="username" value="test" /&gt;
          &lt;property name="password" value="test" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
          depends-on="dataSource"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="packagesToScan" value="com.myproject.model" /&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;
                  &lt;prop key="hibernate.format_sql"&gt;true&lt;/prop&gt;
                  &lt;prop key="hibernate.use_sql_comments"&gt;true&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
                  &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
  &lt;bean id="transactionManager"
          class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory"&gt;&lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;tx:advice id="txAdvice" transaction-manager="transactionManager"&gt;
          &lt;tx:attributes&gt;
              &lt;tx:method name="get*" read-only="true" /&gt;
              &lt;tx:method name="find*" read-only="true" /&gt;
              &lt;tx:method name="*" /&gt;
          &lt;/tx:attributes&gt;
      &lt;/tx:advice&gt;
  
      &lt;aop:config&gt;
          &lt;aop:pointcut id="userServicePointCut"
              expression="execution(* com.myproject.service.*Service.*(..))" /&gt;
          &lt;aop:advisor advice-ref="txAdvice" pointcut-ref="userServicePointCut" /&gt;
      &lt;/aop:config&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>spring-security.xml</strong></p>
  
  <pre><code>&lt;beans:beans xmlns="http://www.springframework.org/schema/security"
      xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://www.springframework.org/schema/security
      http://www.springframework.org/schema/security/spring-security-3.2.xsd"&gt;
      &lt;beans:import resource='login-service.xml' /&gt; 
      &lt;http auto-config="true" use-expressions="true"&gt;
          &lt;intercept-url pattern="/" access="permitAll" /&gt;
          &lt;intercept-url pattern="/member**" access="hasRole('ROLE_MEMBER')" /&gt;
          &lt;intercept-url pattern="/signin" access="permitAll" /&gt;
          &lt;access-denied-handler error-page="/403" /&gt;
          &lt;form-login login-page="/signin" default-target-url="/index"
              authentication-failure-url="/signin?error" username-parameter="username"
              password-parameter="password" /&gt;
          &lt;logout logout-success-url="/login?logout" /&gt;
          &lt;!-- enable csrf protection --&gt;
          &lt;csrf /&gt;
      &lt;/http&gt;
      &lt;authentication-manager&gt;
          &lt;authentication-provider user-service-ref="myMemberDetailsService"&gt;
              &lt;password-encoder hash="bcrypt" /&gt;
          &lt;/authentication-provider&gt;
      &lt;/authentication-manager&gt;
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p><strong>login-service.xml</strong></p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"&gt;
  
             &lt;bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
          destroy-method="close"&gt;
          &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
          &lt;property name="url" value="jdbc:mysql://localhost:8889/myproject" /&gt;
          &lt;property name="username" value="test" /&gt;
          &lt;property name="password" value="test" /&gt;
      &lt;/bean&gt;
  
  
  
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>login page</strong></p>
  
  <pre><code>&lt;c:if test="${not empty SPRING_SECURITY_LAST_EXCEPTION}"&gt;
      &lt;font color="red"&gt; Your login attempt was not successful due
          to &lt;br /&gt;
      &lt;br /&gt; &lt;c:out value="${SPRING_SECURITY_LAST_EXCEPTION.message}" /&gt;.
      &lt;/font&gt;
  &lt;/c:if&gt;
  &lt;div class="row"&gt;
      &lt;div class="col-sm-7"&gt;
          &lt;div&gt;
              &lt;div&gt;
                  &lt;h2 class="panel-title"&gt;Log-in&lt;/h2&gt;
              &lt;/div&gt;
              &lt;c:if test="${not empty param.error}"&gt;
                  Invalid username and password.
              &lt;/c:if&gt;
              &lt;c:if test="${not empty error}"&gt;
                  &lt;div class="error"&gt;${error}&lt;/div&gt;
              &lt;/c:if&gt;
              &lt;c:if test="${not empty msg}"&gt;
                  &lt;div class="msg"&gt;${msg}&lt;/div&gt;
              &lt;/c:if&gt;
              &lt;div&gt;
                  &lt;form id="form-login" role="form" method="post"
                      action="&lt;c:url value='/j_spring_security_check' /&gt;"
                      class="relative form form-default"&gt;
                      &lt;input type="hidden" name="${_csrf.parameterName}"
                          value="${_csrf.token}" /&gt;
                      &lt;p class="leyend"&gt;* Required information&lt;/p&gt;
                      &lt;div class="form-group clearfix"&gt;
                          &lt;label for="input-email-01" class="col-xs-12 control-label"&gt;Email
                              *&lt;/label&gt;
                          &lt;div class="input-group col-sm-10"&gt;
                              &lt;span class="input-group-addon"&gt;@&lt;/span&gt; &lt;input type="email"
                                  name="username" id="input-email-01" class="form-control"
                                  placeholder="Enter email" required&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="form-group clearfix"&gt;
                          &lt;label for="input-password-01" class="col-xs-12 control-label"&gt;Password
                              *&lt;/label&gt;
                          &lt;div class="col-sm-10"&gt;
                              &lt;input type="password" name="password" id="input-password-01"
                                  class="form-control" placeholder="Enter password" required&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="form-group clearfix"&gt;
                          &lt;div class="col-xs-12"&gt;
                              &lt;button type="submit" class="btn btn-action btn-validate"&gt;Log
                                  In&lt;/button&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/form&gt;
  </code></pre>