I have this class where I am trying to configure WebSecurityConfigurerAdapter
. This code gives me permission to /
, /home
and /signup
without needing to get authenticated.
My question is how to implement ErrorController while using HttpSecurity
Bacially if I get the This application has no explicit mapping for /error
i dont want spring boot to prompt the login page first then to display the ErrorController
. I want just to execetue ErrorController
public class WebConfigAdapter extends WebSecurityConfigurerAdapter {
@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder(){
return new BCryptPasswordEncoder();
}
@Override
public void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity.authorizeRequests()
.antMatchers("/","/home","/signup").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
httpSecurity.csrf().disable();
}
}
My ErrorController
@Controller
public class ErrorControllerH implements ErrorController {
@Override
@RequestMapping("/error")
public String getErrorPath() {
return "redirect:/";
}
}