title: Spring security/hibernate: Bad credentials even if they're right?
body: <p>Hey I am having a bit of a mess with my springsecurity based login</p>
  
  <p>I'm keep getting the error "bad credentials"</p>
  
  <p>Here's my user table:</p>
  
  <p>![Usertable][1]</p>
  
  <p>Here's my dataSource from the applicationContext:</p>
  
  <pre><code>&lt;!-- database driver/location --&gt;
  &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
      &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
      &lt;property name="url" value="jdbc:mysql://localhost:3306/ams" /&gt;
      &lt;property name="username" value="root" /&gt;
      &lt;property name="password" value="root" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>and my securityContext:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:security="http://www.springframework.org/schema/security"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                http://www.springframework.org/schema/security 
                http://www.springframework.org/schema/security/spring-security-3.0.xsd"&gt;
  
      &lt;!-- &lt;security:http auto-config="true" access-decision-manager-ref="accessDecisionManager"&gt; --&gt;
      &lt;security:http auto-config="true"&gt;
          &lt;security:intercept-url pattern="/login/login.do" access="IS_AUTHENTICATED_ANONYMOUSLY" /&gt;
          &lt;security:intercept-url pattern="/login/doLogin.do" access="IS_AUTHENTICATED_ANONYMOUSLY" /&gt;
          &lt;security:intercept-url pattern="/lib/**" access="IS_AUTHENTICATED_ANONYMOUSLY" /&gt;
          &lt;security:intercept-url pattern="/css/**" access="IS_AUTHENTICATED_ANONYMOUSLY" /&gt;
          &lt;security:intercept-url pattern="/images/**" access="IS_AUTHENTICATED_ANONYMOUSLY" /&gt;
          &lt;security:intercept-url pattern="/resources/**" access="IS_AUTHENTICATED_ANONYMOUSLY" /&gt;
          &lt;security:intercept-url pattern="/**" access="IS_AUTHENTICATED_REMEMBERED" /&gt;
          &lt;security:form-login login-page="/login/login.do" authentication-failure-url="/login/login.do?login_error=true" default-target-url="/test/showTest.do"/&gt;
          &lt;security:logout logout-success-url="/login/login.do" invalidate-session="true" /&gt;
          &lt;security:remember-me key="rememberMe"/&gt;
      &lt;/security:http&gt;    
  
  
      &lt;security:authentication-manager&gt;
          &lt;security:authentication-provider&gt;
              &lt;security:jdbc-user-service data-source-ref="dataSource" 
              users-by-username-query="select USERNAME as username, PASSWORD as password, DELETED as deleted from ams.user where USERNAME=?"
              authorities-by-username-query="
                  select distinct user.USERNAME as username, permission.NAME as authority 
              from scu.user, scu.user_role, scu.role, scu.role_permission, scu.permission
              where user.ID=user_role.USER_ID AND user_role.ROLE_ID=role_permission.ROLE_ID AND role_permission.PERMISSION_ID=permission.ID AND user.USERNAME=?"/&gt;
              &lt;!-- security:password-encoder ref="passwordEncoder" /&gt; --&gt;
          &lt;/security:authentication-provider&gt;
      &lt;/security:authentication-manager&gt;
  
      &lt;bean id="passwordEncoder"
          class="org.springframework.security.authentication.encoding.ShaPasswordEncoder"&gt;
          &lt;constructor-arg value="256" /&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>When i try to login with: admin and init01</p>
  
  <p>it gives me the error bad credentials... =(</p>
  
  <p>ANY suggestions are appreciated!!!</p>