Spring Security User Authorization Tables

I am trying to use Spring Security 3.1 in my web application. I started with this specific tutorial .

I use the technique used here where there is a data source in the authentication provider

<authentication-manager>
    <authentication-provider>
        <jdbc-user-service data-source-ref="dataSource"

           users-by-username-query="
              select email,password 
              from usr where email=?" 

           authorities-by-username-query="
              select u.email, ur.authority from usr u, usr_roles ur 
              where u.usr_id = ur.usr_id and u.email =?  " 

        />
    </authentication-provider>
</authentication-manager>

So, if you notice that I am using the email as my username and I do not have a permitted column.

This does not work.

My login form looks like

<form name="f" action="<c:url value="j_spring_security_check" />" method="POST">
    <table>
        <tr>
        <td>User:</td>
        <td><input type="text" name="j_username" value=""></td>
        </tr>
        <tr>
        <td>Password:</td>
        <td><input type="password" name="j_password" />
        </td>
        </tr>
        <tr>
        <td colspan="2">
                <input name="submit" type="submit" value="submit" />
            </td>
        </tr>
        <tr>
        <td colspan="2">
                <input name="reset" type="reset" />
        </td>
        </tr>
    </table>
</form>

Please advise how to do this, or am I missing something?

+5
source share
1 answer

I managed to solve it myself. I changed the authentication manager configuration as follows

<authentication-manager>
      <authentication-provider>

            <jdbc-user-service data-source-ref="dataSource"

           users-by-username-query="
              select * from (select email as username,password,1 as enabled 
              from usr) where username=?" 

           authorities-by-username-query="
             select * from
            (select u.email username, ur.authority AUTHORITY 
            from usr u, usr_role ur 
              where u.usr_id = ur.usr_id) where  username = ? " 

        />
      </authentication-provider>
    </authentication-manager>
+5
source

All Articles