Spring引导默认表单登录(/Login)在HTTPS实现后由于某种原因导致HTTP错误404
在application.properties中实现HTTPS后,我可以按照自己的意愿匿名访问WebSecurity配置适配器中指定的页面。但是,当我转到需要授权的页面时,我得到一个HTTP错误404页面未找到: “找不到此本地主机页找不到该网址的网页:https://localhost/login HTTP错误404” 如果我去掉application.properties中的https实现,那么我可以匿名进入我想要的页面,如果我进入其他页面,就会有一个不错的默认登录表单。为什么在实现https时不会发生同样的行为 应用程序。属性:Spring引导默认表单登录(/Login)在HTTPS实现后由于某种原因导致HTTP错误404,spring,spring-boot,ssl,spring-security,https,Spring,Spring Boot,Ssl,Spring Security,Https,在application.properties中实现HTTPS后,我可以按照自己的意愿匿名访问WebSecurity配置适配器中指定的页面。但是,当我转到需要授权的页面时,我得到一个HTTP错误404页面未找到: “找不到此本地主机页找不到该网址的网页:https://localhost/login HTTP错误404” 如果我去掉application.properties中的https实现,那么我可以匿名进入我想要的页面,如果我进入其他页面,就会有一个不错的默认登录表单。为什么在实现http
server.ssl.key-store-type=PKCS12
server.ssl.key-store=classpath:server4.p12
server.ssl.key-store-password=******
server.ssl.key-alias=1
security.require-ssl=true
WebSecurityConfig.java
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable().authorizeRequests().antMatchers("/", "/save","/success", "/images/**","/css/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin();
}
}
好的,我解决了这个问题。我有两个问题。第一个问题是我需要为/login/**指定一个antmatcher。另外,我的服务器在application.properties的端口80上运行,所以每次https://.. 浏览器通过443发送,除非我指定,否则不会显示https://localhost:80/.. WebSecurity适配器配置:
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable().authorizeRequests().antMatchers("/","/login/**", "/save","/success", "/images/**","/css/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin();
}
#default server port
server.port=443
#SSL
server.ssl.key-store-type=PKCS12
server.ssl.key-store=classpath:server4.p12
server.ssl.key-store-password=******
server.ssl.key-alias=1
security.require-ssl=true