I am trying to configure one path (/ basic) in my MVC-based spring-boot spring application to be the main auth protected. I'm just going to configure this using my own configuration options, so the username and password are just โadminโ and โadminโ.
This currently works for the / main path (they prompt me and can log in correctly). The problem is that logging out does not work (and I'm not sure why), as well as other paths (like the others shown) are being requested for basic credentials (before always failing).
static class MyApplicationSecurity extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/open").permitAll();
http.authorizeRequests().antMatchers("/other").denyAll();
http.authorizeRequests().antMatchers("/basic").authenticated().and().httpBasic().and().logout().logoutUrl("/basic/logout").invalidateHttpSession(true).logoutSuccessUrl("/");
}
}
I expected / other to always fail, but I donโt understand why basic auth./open works for it, it works as expected. I also do not understand why / basic / logout does not log me out (it also does not generate error messages). I have a simple bit of code as a placeholder for the exit endpoint, but if I donโt have it, then I get 404. The "home" view is my root web application, so I just want to send the user there after logging out.
@RequestMapping("/logout")
public ModelAndView logout() {
return new ModelAndView("home");
}
UPDATE: Here is a solution that seemed to work at the end (except for the part of the exit from the system still not working):
@Configuration
@Order(1)
public static class OAuthSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/oauth").authorizeRequests().anyRequest().denyAll();
}
}
@Configuration
public static class BasicAuthConfigurationAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/basic").authorizeRequests().anyRequest().authenticated().and().httpBasic();
http.logout().permitAll().logoutUrl("/logout").logoutSuccessUrl("/").invalidateHttpSession(true);
}
}
source
share