【问题标题】:MySQL query in spring-security.xml for authorizationspring-security.xml 中的 MySQL 查询以进行授权
【发布时间】:2015-07-22 23:15:24
【问题描述】:

第一季度。 > 如何检查spring-security.xml中是否执行了以下两个查询?

 <jdbc-user-service data-source-ref="dataSource"
          users-by-username-query=
            "select user_login_name as username,user_password as password,user_type_id,role_id from sox_audit.sox_users where user_login_name=? and user_password=?"

           authorities-by-username-query=
            "select user_login_name as username,role_id as authority from sox_audit.sox_users where user_login_name ='sriram@gmail.com' and user_password='12345' "/>

我可以使用硬编码值登录并根据用户类型授予权限。但我不能通过从数据库中选择记录。

任何人都可以帮助我解决这个问题。

【问题讨论】:

  • 您的查询是错误的,完全错误。 users-by-username 应该返回 3 个值,用户名、密码和启用,仅此而已。它还应该只查询用户名而不是密码(即只有一个参数)。您的用户名权限具有相同的缺陷,它应该只将用户名作为参数而不是密码。所以基本上你的查询是错误的。请参阅the reference guide 了解返回什么以及用于查询的内容。

标签: java mysql spring spring-mvc spring-security


【解决方案1】:

我解决了。 事情是查询是错误的。 users-by-username-query 只需要 3 个参数。它应该是用户名、密码并从数据库启用。 还, authority-by-username-query 将采用 2 个参数。

 users-by-username-query=
            "select user_login_name as username,user_password as password,enabled from sox_audit.sox_users where user_login_name=?"

           authorities-by-username-query=
            "select user_login_name as username,authority from sox_audit.sox_users where user_login_name =?"/>

然后在 HomeController 中控制用户。这将完美运行。

【讨论】:

    【解决方案2】:

    为实现UserDetailsServiceJdbcDaoImpl 启用日志。 类似:

    log4j.logger.org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl=DEBUG
    

    如果这不起作用,请在此类上添加一些断点并在运行时对其进行调试。

    【讨论】:

      猜你喜欢
      • 2017-07-22
      • 2018-12-09
      • 2015-07-17
      • 2014-03-09
      • 1970-01-01
      • 2011-10-12
      • 1970-01-01
      • 2015-02-14
      相关资源
      最近更新 更多