My app serves both web pages and rest endpoints (Spring boot + Spring 4)
I'm trying to set a basic InMemoryAuth, but /logout does not work.
From browser, it redirects to /login?logout with a 404 and no effect to user session.
@EnableWebSecurity
@Configuration
class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/rest/**").hasRole("USER")
.antMatchers("/ui/**").hasRole("USER")
.and().logout()
.logoutUrl("/logout")
.and().httpBasic()
.and().csrf().disable();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("pass").roles("USER");
}
}
EDIT
with the followind chain
http
.authorizeRequests().anyRequest().authenticated()
.and().logout().logoutUrl("/logout").logoutSuccessUrl("/").permitAll()
.and().httpBasic()
.and().csrf().disable();
and a root page defined, no 404 error.
With debug enabled, I'm able to see
Logging out user 'org.springframework.security.authentication.UsernamePasswordAuthenticationToken@442b5a9f: Principal: org.springframework.security.core.userdetails.User@36ebcb: Username: user; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_USER; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@b364: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: null; Granted Authorities: ROLE_USER' and transferring to logout destination
Invalidating session: B264148444D372CFC899A5B920818B68
but the browser does not ask user/passwd anymore, i'm able to access all urls..