原因:PreparedStatementCallback;错误 SQL 语法
Reason: PreparedStatementCallback; bad SQL grammar
我一直在尝试使用具有 Spring 安全性的 Postgres 数据库进行身份验证。
这是我的SQLtable定义:
CREATE TABLE "UTILISATEUR" (
"IdUtilisateur" serial NOT NULL,
"Nom" character varying(50),
"Prenom" character varying(50),
"Profil" character varying(50),
"Pseudo" character varying(20),
"IdSite" integer DEFAULT 0,
"Password" character varying(1024),
role character varying(45),
CONSTRAINT "UTILISATEUR_pkey" PRIMARY KEY ("IdUtilisateur"),
CONSTRAINT fk1u FOREIGN KEY (role)
REFERENCES "Role" (role) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
);
这是我的 class spring 安全配置:
package com.ardia.MDValidation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import javax.sql.DataSource ;
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
//Pour l'authentification des Utilisateur de Table Utilisateur
@Autowired
public void GlobalConfig(AuthenticationManagerBuilder auth,DataSource dataSource) throws Exception {
auth.jdbcAuthentication()
.dataSource(dataSource)
.usersByUsernameQuery("select Pseudo as principal , Password as credentials from UTILISATEUR where Pseudo = ? ")
.authoritiesByUsernameQuery("select Pseudo as principal , role as role from UTILISATEUR where Pseudo = ? ")
.rolePrefix("_ROLE");
}
//ne pas appliqué la securité sur les ressources
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring()
.antMatchers("/bootstrap/css/**","/css/**");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.formLogin()
.permitAll();
}
}
它曾经与内存用户一起工作。现在我不能让它工作是因为 SQL 语法。或者我应该更改 table 名称,因为在错误中用户名是小写的,而我的 table 名称是大写的?
这是错误:
org.postgresql.util.PSQLException: ERREUR: la relation « utilisateur » n'existe pas Position : 32
我发现了问题
当您使用 jdbcAuthentication()
执行查询时,它似乎强制列和 table 名称为小写。有谁知道如何更改它?
创建您的 table 的人选择使用双引号保留 CaMeL 大小写标识符。现在你必须在任何地方使用匹配的大小写和双引号 table 和列名。
由于双引号在您的客户端中具有特殊含义,因此您必须对特殊字符进行转义或编码。我不熟悉Spring。也许用反斜杠转义?
"SELECT \"Pseudo\" AS principal, \"Password\"; AS credentials
FROM \"UTILISATEUR\" WHERE \"Pseudo\" = ? "
等等
相关:
- Are PostgreSQL column names case-sensitive?
我一直在尝试使用具有 Spring 安全性的 Postgres 数据库进行身份验证。
这是我的SQLtable定义:
CREATE TABLE "UTILISATEUR" (
"IdUtilisateur" serial NOT NULL,
"Nom" character varying(50),
"Prenom" character varying(50),
"Profil" character varying(50),
"Pseudo" character varying(20),
"IdSite" integer DEFAULT 0,
"Password" character varying(1024),
role character varying(45),
CONSTRAINT "UTILISATEUR_pkey" PRIMARY KEY ("IdUtilisateur"),
CONSTRAINT fk1u FOREIGN KEY (role)
REFERENCES "Role" (role) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
);
这是我的 class spring 安全配置:
package com.ardia.MDValidation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import javax.sql.DataSource ;
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
//Pour l'authentification des Utilisateur de Table Utilisateur
@Autowired
public void GlobalConfig(AuthenticationManagerBuilder auth,DataSource dataSource) throws Exception {
auth.jdbcAuthentication()
.dataSource(dataSource)
.usersByUsernameQuery("select Pseudo as principal , Password as credentials from UTILISATEUR where Pseudo = ? ")
.authoritiesByUsernameQuery("select Pseudo as principal , role as role from UTILISATEUR where Pseudo = ? ")
.rolePrefix("_ROLE");
}
//ne pas appliqué la securité sur les ressources
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring()
.antMatchers("/bootstrap/css/**","/css/**");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.formLogin()
.permitAll();
}
}
它曾经与内存用户一起工作。现在我不能让它工作是因为 SQL 语法。或者我应该更改 table 名称,因为在错误中用户名是小写的,而我的 table 名称是大写的?
这是错误:
org.postgresql.util.PSQLException: ERREUR: la relation « utilisateur » n'existe pas Position : 32
我发现了问题
当您使用 jdbcAuthentication()
执行查询时,它似乎强制列和 table 名称为小写。有谁知道如何更改它?
创建您的 table 的人选择使用双引号保留 CaMeL 大小写标识符。现在你必须在任何地方使用匹配的大小写和双引号 table 和列名。
由于双引号在您的客户端中具有特殊含义,因此您必须对特殊字符进行转义或编码。我不熟悉Spring。也许用反斜杠转义?
"SELECT \"Pseudo\" AS principal, \"Password\"; AS credentials
FROM \"UTILISATEUR\" WHERE \"Pseudo\" = ? "
等等
相关:
- Are PostgreSQL column names case-sensitive?