[英]How to use JDBC-Authentication of Spring Boot/Spring Security with Flyway
I am trying to set up my spring boot application that authenticates its users using the jdbcAuthentication and the default database scheme provided in the appendix of the spring security documentation. 我试图设置我的Spring Boot应用程序,该应用程序使用jdbcAuthentication和spring安全文档附录中提供的默认数据库方案对用户进行身份验证。 But i am stuck getting this exception during the database initialization: 但是我在数据库初始化期间一直遇到这个异常:
org.flywaydb.core.api.FlywayException: Found non-empty schema "PUBLIC" without metadata table! org.flywaydb.core.api.FlywayException:找到了没有元数据表的非空模式“ PUBLIC”! Use baseline() or set baselineOnMigrate to true to initialize the metadata table. 使用baseline()或将baselineOnMigrate设置为true来初始化元数据表。
The configuration of the authentication manager looks like this: 身份验证管理器的配置如下所示:
@Configuration
@EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private DataSource dataSource;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.httpBasic()
.realmName("shipment2rss")
.and()
.logout()
.permitAll();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.jdbcAuthentication()
.dataSource(dataSource)
.withDefaultSchema();
}
}
I have read that the problem seams to be that the method configureGlobal(AuthenticationManagerBuilder )
is invoked before the Flyway-related code gets executed (see How to use Flyway in Spring Boot with JDBC Security? ) but found no step-by-step guide how to work around this specific problem. 我已经读过,问题似乎是在执行与Flyway相关的代码之前调用了configureGlobal(AuthenticationManagerBuilder )
方法(请参阅如何在具有JDBC Security的Spring Boot中使用Flyway? ),但找不到逐步指南解决此特定问题。
Can anyone give me such a guide or point me to a website that does? 谁能给我这样的指导或指向我做的网站?
EDIT I uploaded a project to show the problem at github: https://github.com/smilingj/springboot-authentication-flyway-sample/tree/e48ce63568776d99e49a9548d8362168cc3a3367 编辑我在github上上传了一个项目来显示问题: https : //github.com/smilingj/springboot-authentication-flyway-sample/tree/e48ce63568776d99e49a9548d8362168cc3a3367
When configuring the jdbcAuthentication
and calling withDefaultSchema
that directly creates the schema and does so before Flyway has any change to create the schema. 在配置jdbcAuthentication
并调用withDefaultSchema
,它会直接创建架构,并在Flyway进行任何更改以创建架构之前这样做。
Flyway now detects it is already there instead of it being allowed to create the schema and it complains about that. Flyway现在检测到它已经存在,而不是被允许创建模式,并且它抱怨。
You have 2 possible solutions 您有2种可能的解决方案
FlywayMigrationStrategy
and set the baselineOnMigrate
property to true
. 扩展FlywayMigrationStrategy
并将baselineOnMigrate
属性设置为true
。 withDefaultSchema
and simply add the sql to create the Spring Security tables to Flyway. 要启用该功能,请删除对withDefaultSchema
的调用,只需添加sql以将Spring Security表创建到withDefaultSchema
。 The SQL files are part of the Spring Security distribution. SQL文件是Spring Security发行版的一部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.