2012-05-08 130 views
4

我想在我的web应用程序中使用Spring Security 3.1。我已经开始遵循这个特殊的tutorialSpring Security自定义用户授权表

我使用这里所使用的技术,其中在身份验证提供者是一个数据源

<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> 

所以,如果你发现我使用的电子邮件作为我的用户名和我没有启用列。

这似乎不起作用。

我的登录表单看起来像

<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> 

请告知至于如何得到这个工作,还是我失去了一些东西?

回答

4

我设法自己解决它。我修改了以下认证管理器配置:

<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>