I use spring security 6.2.1 with spring boot 3.2 to handle login to my web application.
Unfortunately, I'm not able to disable the default login form of spring security. I want to use my own custom login form but I'm always redirected to the spring default form.
This is my filter :
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
try {
http
// ...
.httpBasic(httpBasic -> httpBasic.disable())
.authorizeHttpRequests((authorizeExchange) -> authorizeExchange
.requestMatchers("/mylogin").permitAll()
.anyRequest().permitAll())
.csrf((csrf) -> csrf.disable())
.formLogin(form -> form.loginPage("/login").permitAll());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return http.build();
}
I enter http://127.0.0.1:8080/mylogin and I expect to be redirected to my custom page and not the default one !!!
I followed this page to use my custom login page but I always see the default one. https://docs.spring.io/spring-security/reference/servlet/authentication/passwords/form.html
Here are my logs
2024-01-03 11:30:35.602 | DEBUG | parallel-1 | WebSessionServerRequestCache:83 | | Request added to WebSession: '/mylogin'
2024-01-03 11:30:35.603 | DEBUG | parallel-1 | DefaultServerRedirectStrategy:54 | | Redirecting to '/login'
2024-01-03 11:30:35.638 | DEBUG | http-nio-8080-exec-4 | OrServerWebExchangeMatcher:57 | | Trying to match using PathMatcherServerWebExchangeMatcher{pattern='/login', method=POST}
2024-01-03 11:30:35.639 | DEBUG | http-nio-8080-exec-4 | PathPatternParserServerWebExchangeMatcher:82 | | Request 'GET /login' doesn't match 'POST /login'
2024-01-03 11:30:35.639 | DEBUG | http-nio-8080-exec-4 | OrServerWebExchangeMatcher:62 | | No matches found
2024-01-03 11:30:35.639 | DEBUG | http-nio-8080-exec-4 | OrServerWebExchangeMatcher:57 | | Trying to match using PathMatcherServerWebExchangeMatcher{pattern='/login', method=GET}
2024-01-03 11:30:35.640 | DEBUG | http-nio-8080-exec-4 | PathPatternParserServerWebExchangeMatcher:100 | | Checking match of request : '/login'; against '/login'
2024-01-03 11:30:35.640 | DEBUG | http-nio-8080-exec-4 | OrServerWebExchangeMatcher:62 | | matched
I'm exhausted because I've tested probably 20 piece of code !!!!!!!!!!
I found my problem after a lot of debugging & investigations. Problem comes from this dependency inside my pom. In fact I had a spring project to act as a web server and also as an API Gateway. But they are not compliant together. Kind of conflicts between webflux from spring cloud starter gateway and my spring starter web. I removed it and now all pieces of code I've tested work. I created another project only acting as API gateway