org.postgresql.util。PSQLException:列索引超出范围:3,列数:2。

时间:2022-08-11 23:04:42

I decided to modify my application by adding there authentication using spring security and database. Before I was using plain authentication with user and password in XML. It worked fine.

我决定通过使用spring security和数据库添加身份验证来修改我的应用程序。在我使用XML的用户和密码进行简单身份验证之前。它工作得很好。

My authentication-manager looks like this

我的身份验证管理员是这样的。

<authentication-manager>
    <authentication-provider>
        <jdbc-user-service data-source-ref="dataSource"
        users-by-username-query="select username, password from pmc.username_password where username=?;"
        authorities-by-username-query="select a.username, b.role from pmc.username_password a, pmc.username_role b where a.username = b.username and a.username=?;" />
    </authentication-provider>
</authentication-manager>

But when I make an attempt to authenticate I've got exception

但是当我试图进行身份验证时,我有例外。

org.springframework.security.authentication.InternalAuthenticationServiceException: PreparedStatementCallback; SQL [select u
sername, password from pmc.username_password where username=?;]; The column index is out of range: 3, number of columns: 2.;
 nested exception is org.postgresql.util.PSQLException: The column index is out of range: 3, number of columns: 2.

What is wrong in my sql syntax in XML file?

XML文件中的sql语法有什么问题?

1 个解决方案

#1


7  

Spring Security expects three columns from the user query, in order:

Spring Security期望从用户查询中获得三列:

  1. username
  2. 用户名
  3. password
  4. 密码
  5. enabled (boolean)
  6. 启用(布尔)

You don't have the last. If you don't have have an equivalent to "enabled" in your database, you can use a TRUE constant.

你没有最后一个。如果您的数据库中没有“启用”的等效项,那么您可以使用一个真正的常量。

#1


7  

Spring Security expects three columns from the user query, in order:

Spring Security期望从用户查询中获得三列:

  1. username
  2. 用户名
  3. password
  4. 密码
  5. enabled (boolean)
  6. 启用(布尔)

You don't have the last. If you don't have have an equivalent to "enabled" in your database, you can use a TRUE constant.

你没有最后一个。如果您的数据库中没有“启用”的等效项,那么您可以使用一个真正的常量。