Spring Boot Default Form Login (/ login) по какой-то причине вызывает HTTP ERROR 404 после реализации HTTPS - PullRequest
1 голос
/ 14 июля 2020

После внедрения HTTPS в application.properties я могу go анонимно переходить на страницы, указанные в моем WebSecurityConfigurerAdapter, как я хочу. Однако, когда я go перехожу на страницу, требующую авторизации, я получаю сообщение HTTP ERROR 404 page not found:

«Эта страница localhost не может быть найдена. Веб-страница для веб-адреса не найдена: https://localhost/login HTTP. ОШИБКА 404 ".

Если я уберу реализацию https в application.properties, тогда я смогу go переходить на страницы, которые хочу анонимно, а если я go на что-нибудь еще, появится удобная форма входа по умолчанию. Почему такое же поведение не происходит с реализованным https ????

application.properties:

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();
    }

}

1 Ответ

1 голос
/ 14 июля 2020

Хорошо, я решил это. У меня было две проблемы. Первая проблема заключается в том, что мне нужно было указать antmatcher для / login / **. Кроме того, мой сервер работает на порту 80 в application.properties, поэтому каждый раз, когда я собирался https://.., браузер отправлял его через 443, и он не отображался, если я не указал https://localhost: 80 /..

Конфигурация WebSecurityAdapter:

  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

...