【问题标题】:Spring Security Custom User Authorization TablesSpring Security 自定义用户授权表
【发布时间】:2012-05-17 18:18:14
【问题描述】:

我正在尝试在我的 Web 应用程序中使用 Spring Security 3.1。我开始关注这个特定的tutorial。

我正在使用此处使用的技术,其中身份验证提供程序是数据源

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

请告知如何让这个工作或我错过了什么?

【问题讨论】:

    标签: spring-security


    【解决方案1】:

    我自己设法解决了。我修改了 authentication-manager 配置如下

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

    【讨论】:

      猜你喜欢
      • 2016-04-23
      • 1970-01-01
      • 2013-03-06
      • 2015-10-21
      • 1970-01-01
      • 2019-02-06
      • 2013-02-13
      • 2023-03-05
      • 2021-03-13
      相关资源
      最近更新 更多