我目前正在努力设置一个具有默认安全性的基本Spring Boot 2应用程序(根据Spring Boot 2.0 Migration Guide)。
我的问题是,虽然我没有创建自定义WebSecurityConfigurationAdapter
我无法使用默认表单登录(使用生成的密码)登录,但登录页面只是刷新,没有显示凭据的指示正确或不正确。这是登录尝试后的页面:
gradle.build
文件:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:2.0.1.RELEASE"
}
}
apply plugin: "java"
apply plugin: "org.springframework.boot"
apply plugin: "io.spring.dependency-management"
bootJar {
baseName = "sample-service"
version = "0.0.1"
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile "org.springframework.boot:spring-boot-starter-web"
testCompile "org.springframework.boot:spring-boot-starter-test"
// DevTools
compile "org.springframework.boot:spring-boot-devtools"
// Security
compile "org.springframework.boot:spring-boot-starter-security"
}
WebSecurityConfigurerAdapter
@EnableWebSecurity
PasswordEncoder
我是否会错过有关Spring Boot 2.0中引入的默认安全性的一些信息?
/error
页面受默认安全保护,因此显示了新的/login
页面(重定向到错误页面时)。
使用调试日志级别(由mohax建议)跳过日志我找到了条目
2018-04-14 17:49:51.680 DEBUG 236 --- [nio-8080-exec-5] o.a.c.c.C.[Tomcat].[localhost] : Processing ErrorPage[errorCode=0, location=/error]
收到登录发帖请求时。这很奇怪,因为登录时没有显示错误。使用配置程序WebSecurity
忽略错误页面会导致登录尝试后显示403 Forbidden错误。